mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-14 16:33:28 +00:00
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
This commit is contained in:
parent
78914e772f
commit
14712a6abf
@ -8,6 +8,9 @@
|
|||||||
|
|
||||||
namespace opt {
|
namespace opt {
|
||||||
|
|
||||||
|
AnnotationID ConstRules::AID(AnnotationManager::getID("opt::ConstRules",
|
||||||
|
&ConstRules::find));
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// TemplateRules Class
|
// TemplateRules Class
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
@ -128,9 +131,8 @@ class TemplateRules : public ConstRules {
|
|||||||
//
|
//
|
||||||
// EmptyRules provides a concrete base class of ConstRules that does nothing
|
// EmptyRules provides a concrete base class of ConstRules that does nothing
|
||||||
//
|
//
|
||||||
static // EmptyInst is static
|
|
||||||
struct EmptyRules : public TemplateRules<ConstPoolVal, EmptyRules> {
|
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.
|
// BoolRules provides a concrete base class of ConstRules for the 'bool' type.
|
||||||
//
|
//
|
||||||
static // BoolTyInst is static...
|
|
||||||
struct BoolRules : public TemplateRules<ConstPoolBool, BoolRules> {
|
struct BoolRules : public TemplateRules<ConstPoolBool, BoolRules> {
|
||||||
|
|
||||||
inline static ConstPoolVal *Not(const ConstPoolBool *V) {
|
inline static ConstPoolVal *Not(const ConstPoolBool *V) {
|
||||||
@ -156,7 +157,7 @@ struct BoolRules : public TemplateRules<ConstPoolBool, BoolRules> {
|
|||||||
const ConstPoolBool *V2) {
|
const ConstPoolBool *V2) {
|
||||||
return ConstPoolBool::get(V1->getValue() & V2->getValue());
|
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
|
// 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 :)
|
// 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
|
// 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
|
// type.
|
||||||
// is only hit at most once per type.
|
|
||||||
//
|
//
|
||||||
const ConstRules *ConstRules::find(const Type *Ty) {
|
Annotation *ConstRules::find(AnnotationID AID, const Annotable *TyA, void *) {
|
||||||
const ConstRules *Result;
|
assert(AID == ConstRules::AID && "Bad annotation for factory!");
|
||||||
|
const Type *Ty = ((const Value*)TyA)->castTypeAsserting();
|
||||||
|
|
||||||
switch (Ty->getPrimitiveID()) {
|
switch (Ty->getPrimitiveID()) {
|
||||||
case Type::BoolTyID: Result = &BoolTyInst; break;
|
case Type::BoolTyID: return new BoolRules();
|
||||||
case Type::SByteTyID: Result = &SByteTyInst; break;
|
case Type::SByteTyID:
|
||||||
case Type::UByteTyID: Result = &UByteTyInst; break;
|
return new DirectRules<ConstPoolSInt, signed char , &Type::SByteTy>();
|
||||||
case Type::ShortTyID: Result = &ShortTyInst; break;
|
case Type::UByteTyID:
|
||||||
case Type::UShortTyID: Result = &UShortTyInst; break;
|
return new DirectRules<ConstPoolUInt, unsigned char , &Type::UByteTy>();
|
||||||
case Type::IntTyID: Result = &IntTyInst; break;
|
case Type::ShortTyID:
|
||||||
case Type::UIntTyID: Result = &UIntTyInst; break;
|
return new DirectRules<ConstPoolSInt, signed short, &Type::ShortTy>();
|
||||||
case Type::LongTyID: Result = &LongTyInst; break;
|
case Type::UShortTyID:
|
||||||
case Type::ULongTyID: Result = &ULongTyInst; break;
|
return new DirectRules<ConstPoolUInt, unsigned short, &Type::UShortTy>();
|
||||||
case Type::FloatTyID: Result = &FloatTyInst; break;
|
case Type::IntTyID:
|
||||||
case Type::DoubleTyID: Result = &DoubleTyInst; break;
|
return new DirectRules<ConstPoolSInt, signed int , &Type::IntTy>();
|
||||||
default: Result = &EmptyInst; break;
|
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user