aboutsummaryrefslogtreecommitdiff
path: root/lib/VMCore/ConstantFold.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2001-09-09 21:01:20 +0000
committerChris Lattner <sabre@nondot.org>2001-09-09 21:01:20 +0000
commit14712a6abf2587666e8171cbb6ebe6ffab3ea514 (patch)
tree10f519c784a8983b2b51bc025e1ddb346862f63f /lib/VMCore/ConstantFold.cpp
parent78914e772f4988dd5e521b49e2e9b208fa1b02ab (diff)
Clean up ConstRules stuff to use annotations instead of a mutable member in Type
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@515 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/ConstantFold.cpp')
-rw-r--r--lib/VMCore/ConstantFold.cpp67
1 files changed, 33 insertions, 34 deletions
diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp
index 1a8def42e6..3ed8558418 100644
--- a/lib/VMCore/ConstantFold.cpp
+++ b/lib/VMCore/ConstantFold.cpp
@@ -8,6 +8,9 @@
namespace opt {
+AnnotationID ConstRules::AID(AnnotationManager::getID("opt::ConstRules",
+ &ConstRules::find));
+
//===----------------------------------------------------------------------===//
// TemplateRules Class
//===----------------------------------------------------------------------===//
@@ -128,9 +131,8 @@ class TemplateRules : public ConstRules {
//
// EmptyRules provides a concrete base class of ConstRules that does nothing
//
-static // EmptyInst is static
struct EmptyRules : public TemplateRules<ConstPoolVal, EmptyRules> {
-} EmptyInst;
+};
@@ -140,7 +142,6 @@ struct EmptyRules : public TemplateRules<ConstPoolVal, EmptyRules> {
//
// BoolRules provides a concrete base class of ConstRules for the 'bool' type.
//
-static // BoolTyInst is static...
struct BoolRules : public TemplateRules<ConstPoolBool, BoolRules> {
inline static ConstPoolVal *Not(const ConstPoolBool *V) {
@@ -156,7 +157,7 @@ struct BoolRules : public TemplateRules<ConstPoolBool, BoolRules> {
const ConstPoolBool *V2) {
return ConstPoolBool::get(V1->getValue() & V2->getValue());
}
-} BoolTyInst;
+};
//===----------------------------------------------------------------------===//
@@ -231,41 +232,39 @@ struct DirectRules
// code. Thank goodness C++ compilers are great at stomping out layers of
// templates... can you imagine having to do this all by hand? (/me is lazy :)
//
-static DirectRules<ConstPoolSInt, signed char , &Type::SByteTy> SByteTyInst;
-static DirectRules<ConstPoolUInt, unsigned char , &Type::UByteTy> UByteTyInst;
-static DirectRules<ConstPoolSInt, signed short, &Type::ShortTy> ShortTyInst;
-static DirectRules<ConstPoolUInt, unsigned short, &Type::UShortTy> UShortTyInst;
-static DirectRules<ConstPoolSInt, signed int , &Type::IntTy> IntTyInst;
-static DirectRules<ConstPoolUInt, unsigned int , &Type::UIntTy> UIntTyInst;
-static DirectRules<ConstPoolSInt, int64_t , &Type::LongTy> LongTyInst;
-static DirectRules<ConstPoolUInt, uint64_t , &Type::ULongTy> ULongTyInst;
-static DirectRules<ConstPoolFP , float , &Type::FloatTy> FloatTyInst;
-static DirectRules<ConstPoolFP , double , &Type::DoubleTy> DoubleTyInst;
-
// ConstRules::find - Return the constant rules that take care of the specified
-// type. Note that this is cached in the Type value itself, so switch statement
-// is only hit at most once per type.
+// type.
//
-const ConstRules *ConstRules::find(const Type *Ty) {
- const ConstRules *Result;
+Annotation *ConstRules::find(AnnotationID AID, const Annotable *TyA, void *) {
+ assert(AID == ConstRules::AID && "Bad annotation for factory!");
+ const Type *Ty = ((const Value*)TyA)->castTypeAsserting();
+
switch (Ty->getPrimitiveID()) {
- case Type::BoolTyID: Result = &BoolTyInst; break;
- case Type::SByteTyID: Result = &SByteTyInst; break;
- case Type::UByteTyID: Result = &UByteTyInst; break;
- case Type::ShortTyID: Result = &ShortTyInst; break;
- case Type::UShortTyID: Result = &UShortTyInst; break;
- case Type::IntTyID: Result = &IntTyInst; break;
- case Type::UIntTyID: Result = &UIntTyInst; break;
- case Type::LongTyID: Result = &LongTyInst; break;
- case Type::ULongTyID: Result = &ULongTyInst; break;
- case Type::FloatTyID: Result = &FloatTyInst; break;
- case Type::DoubleTyID: Result = &DoubleTyInst; break;
- default: Result = &EmptyInst; break;
+ case Type::BoolTyID: return new BoolRules();
+ case Type::SByteTyID:
+ return new DirectRules<ConstPoolSInt, signed char , &Type::SByteTy>();
+ case Type::UByteTyID:
+ return new DirectRules<ConstPoolUInt, unsigned char , &Type::UByteTy>();
+ case Type::ShortTyID:
+ return new DirectRules<ConstPoolSInt, signed short, &Type::ShortTy>();
+ case Type::UShortTyID:
+ return new DirectRules<ConstPoolUInt, unsigned short, &Type::UShortTy>();
+ case Type::IntTyID:
+ return new DirectRules<ConstPoolSInt, signed int , &Type::IntTy>();
+ case Type::UIntTyID:
+ return new DirectRules<ConstPoolUInt, unsigned int , &Type::UIntTy>();
+ case Type::LongTyID:
+ return new DirectRules<ConstPoolSInt, int64_t , &Type::LongTy>();
+ case Type::ULongTyID:
+ return new DirectRules<ConstPoolUInt, uint64_t , &Type::ULongTy>();
+ case Type::FloatTyID:
+ return new DirectRules<ConstPoolFP , float , &Type::FloatTy>();
+ case Type::DoubleTyID:
+ return new DirectRules<ConstPoolFP , double , &Type::DoubleTy>();
+ default:
+ return new EmptyRules();
}
-
- Ty->setConstRules(Result); // Cache the value for future short circuiting!
- return Result;
}