From 14712a6abf2587666e8171cbb6ebe6ffab3ea514 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 9 Sep 2001 21:01:20 +0000 Subject: [PATCH] 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 --- lib/VMCore/ConstantFold.cpp | 67 ++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 34 deletions(-) diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp index 1a8def42e6d..3ed85584184 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 { -} EmptyInst; +}; @@ -140,7 +142,6 @@ struct EmptyRules : public TemplateRules { // // BoolRules provides a concrete base class of ConstRules for the 'bool' type. // -static // BoolTyInst is static... struct BoolRules : public TemplateRules { inline static ConstPoolVal *Not(const ConstPoolBool *V) { @@ -156,7 +157,7 @@ struct BoolRules : public TemplateRules { 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 SByteTyInst; -static DirectRules UByteTyInst; -static DirectRules ShortTyInst; -static DirectRules UShortTyInst; -static DirectRules IntTyInst; -static DirectRules UIntTyInst; -static DirectRules LongTyInst; -static DirectRules ULongTyInst; -static DirectRules FloatTyInst; -static DirectRules 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(); + case Type::UByteTyID: + return new DirectRules(); + case Type::ShortTyID: + return new DirectRules(); + case Type::UShortTyID: + return new DirectRules(); + case Type::IntTyID: + return new DirectRules(); + case Type::UIntTyID: + return new DirectRules(); + case Type::LongTyID: + return new DirectRules(); + case Type::ULongTyID: + return new DirectRules(); + case Type::FloatTyID: + return new DirectRules(); + case Type::DoubleTyID: + return new DirectRules(); + default: + return new EmptyRules(); } - - Ty->setConstRules(Result); // Cache the value for future short circuiting! - return Result; }