mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-09 11:25:55 +00:00
Make ConstantInt::getTrue/getFalse be llvm_shutdown safe.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34443 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -40,6 +40,7 @@ struct ConvertConstantType;
|
|||||||
/// represents both boolean and integral constants.
|
/// represents both boolean and integral constants.
|
||||||
/// @brief Class for constant integers.
|
/// @brief Class for constant integers.
|
||||||
class ConstantInt : public Constant {
|
class ConstantInt : public Constant {
|
||||||
|
static ConstantInt *TheTrueVal, *TheFalseVal;
|
||||||
protected:
|
protected:
|
||||||
uint64_t Val;
|
uint64_t Val;
|
||||||
protected:
|
protected:
|
||||||
@@ -73,14 +74,12 @@ public:
|
|||||||
|
|
||||||
/// getTrue/getFalse - Return the singleton true/false values.
|
/// getTrue/getFalse - Return the singleton true/false values.
|
||||||
static inline ConstantInt *getTrue() {
|
static inline ConstantInt *getTrue() {
|
||||||
static ConstantInt *T = 0;
|
if (TheTrueVal) return TheTrueVal;
|
||||||
if (T) return T;
|
return CreateTrueFalseVals(true);
|
||||||
return T = new ConstantInt(Type::Int1Ty, 1);
|
|
||||||
}
|
}
|
||||||
static inline ConstantInt *getFalse() {
|
static inline ConstantInt *getFalse() {
|
||||||
static ConstantInt *F = 0;
|
if (TheFalseVal) return TheFalseVal;
|
||||||
if (F) return F;
|
return CreateTrueFalseVals(false);
|
||||||
return F = new ConstantInt(Type::Int1Ty, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return a ConstantInt with the specified value for the specified type. The
|
/// Return a ConstantInt with the specified value for the specified type. The
|
||||||
@@ -165,6 +164,9 @@ public:
|
|||||||
static bool classof(const Value *V) {
|
static bool classof(const Value *V) {
|
||||||
return V->getValueType() == ConstantIntVal;
|
return V->getValueType() == ConstantIntVal;
|
||||||
}
|
}
|
||||||
|
static void ResetTrueFalse() { TheTrueVal = TheFalseVal = 0; }
|
||||||
|
private:
|
||||||
|
static ConstantInt *CreateTrueFalseVals(bool WhichOne);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@@ -800,6 +800,7 @@ public:
|
|||||||
//
|
//
|
||||||
static ManagedStatic<ValueMap<uint64_t, IntegerType, ConstantInt> >IntConstants;
|
static ManagedStatic<ValueMap<uint64_t, IntegerType, ConstantInt> >IntConstants;
|
||||||
|
|
||||||
|
|
||||||
// Get a ConstantInt from an int64_t. Note here that we canoncialize the value
|
// Get a ConstantInt from an int64_t. Note here that we canoncialize the value
|
||||||
// to a uint64_t value that has been zero extended down to the size of the
|
// to a uint64_t value that has been zero extended down to the size of the
|
||||||
// integer type of the ConstantInt. This allows the getZExtValue method to
|
// integer type of the ConstantInt. This allows the getZExtValue method to
|
||||||
@@ -807,14 +808,32 @@ static ManagedStatic<ValueMap<uint64_t, IntegerType, ConstantInt> >IntConstants;
|
|||||||
// extended. getZExtValue is more common in LLVM than getSExtValue().
|
// extended. getZExtValue is more common in LLVM than getSExtValue().
|
||||||
ConstantInt *ConstantInt::get(const Type *Ty, int64_t V) {
|
ConstantInt *ConstantInt::get(const Type *Ty, int64_t V) {
|
||||||
const IntegerType *ITy = cast<IntegerType>(Ty);
|
const IntegerType *ITy = cast<IntegerType>(Ty);
|
||||||
if (Ty == Type::Int1Ty)
|
|
||||||
if (V & 1)
|
|
||||||
return getTrue();
|
|
||||||
else
|
|
||||||
return getFalse();
|
|
||||||
return IntConstants->getOrCreate(ITy, V & ITy->getBitMask());
|
return IntConstants->getOrCreate(ITy, V & ITy->getBitMask());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ConstantInt *ConstantInt::TheTrueVal = 0;
|
||||||
|
ConstantInt *ConstantInt::TheFalseVal = 0;
|
||||||
|
|
||||||
|
void CleanupTrueFalse(void *) {
|
||||||
|
ConstantInt::ResetTrueFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
static ManagedCleanup<CleanupTrueFalse> TrueFalseCleanup;
|
||||||
|
|
||||||
|
ConstantInt *ConstantInt::CreateTrueFalseVals(bool WhichOne) {
|
||||||
|
assert(TheTrueVal == 0 && TheFalseVal == 0);
|
||||||
|
TheTrueVal = get(Type::Int1Ty, 1);
|
||||||
|
TheFalseVal = get(Type::Int1Ty, 0);
|
||||||
|
|
||||||
|
// Ensure that llvm_shutdown nulls out TheTrueVal/TheFalseVal.
|
||||||
|
TrueFalseCleanup.Register();
|
||||||
|
|
||||||
|
return WhichOne ? TheTrueVal : TheFalseVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//---- ConstantFP::get() implementation...
|
//---- ConstantFP::get() implementation...
|
||||||
//
|
//
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
Reference in New Issue
Block a user