[llvm-commits] CVS: llvm/lib/VMCore/Constants.cpp
Chris Lattner
sabre at nondot.org
Mon Feb 19 22:11:59 PST 2007
Changes in directory llvm/lib/VMCore:
Constants.cpp updated: 1.216 -> 1.217
---
Log message:
Make ConstantInt::getTrue/getFalse be llvm_shutdown safe.
---
Diffs of the changes: (+24 -5)
Constants.cpp | 29 ++++++++++++++++++++++++-----
1 files changed, 24 insertions(+), 5 deletions(-)
Index: llvm/lib/VMCore/Constants.cpp
diff -u llvm/lib/VMCore/Constants.cpp:1.216 llvm/lib/VMCore/Constants.cpp:1.217
--- llvm/lib/VMCore/Constants.cpp:1.216 Mon Feb 19 23:55:46 2007
+++ llvm/lib/VMCore/Constants.cpp Tue Feb 20 00:11:36 2007
@@ -800,6 +800,7 @@
//
static ManagedStatic<ValueMap<uint64_t, IntegerType, ConstantInt> >IntConstants;
+
// 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
// integer type of the ConstantInt. This allows the getZExtValue method to
@@ -807,14 +808,32 @@
// extended. getZExtValue is more common in LLVM than getSExtValue().
ConstantInt *ConstantInt::get(const Type *Ty, int64_t V) {
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());
}
+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...
//
namespace llvm {
More information about the llvm-commits
mailing list