Revert "LLVMContext: Store APInt/APFloat directly into the ConstantInt/FP DenseMaps."
[oota-llvm.git] / lib / IR / Constants.cpp
index c4b18adc6162a0bcfe4938dd6bca8181099290d2..e0cb835c2c675eb5940501102946dad066dd4627 100644 (file)
@@ -555,17 +555,18 @@ Constant *ConstantInt::getFalse(Type *Ty) {
 }
 
 
-// Get a ConstantInt from an APInt.
+// Get a ConstantInt from an APInt. Note that the value stored in the DenseMap 
+// as the key, is a DenseMapAPIntKeyInfo::KeyTy which has provided the
+// operator== and operator!= to ensure that the DenseMap doesn't attempt to
+// compare APInt's of different widths, which would violate an APInt class
+// invariant which generates an assertion.
 ConstantInt *ConstantInt::get(LLVMContext &Context, const APInt &V) {
+  // Get the corresponding integer type for the bit width of the value.
+  IntegerType *ITy = IntegerType::get(Context, V.getBitWidth());
   // get an existing value or the insertion position
   LLVMContextImpl *pImpl = Context.pImpl;
-  ConstantInt *&Slot = pImpl->IntConstants[V];
-  if (!Slot) {
-    // Get the corresponding integer type for the bit width of the value.
-    IntegerType *ITy = IntegerType::get(Context, V.getBitWidth());
-    Slot = new ConstantInt(ITy, V);
-  }
-  assert(Slot->getType() == IntegerType::get(Context, V.getBitWidth()));
+  ConstantInt *&Slot = pImpl->IntConstants[DenseMapAPIntKeyInfo::KeyTy(V, ITy)];
+  if (!Slot) Slot = new ConstantInt(ITy, V);
   return Slot;
 }
 
@@ -688,7 +689,7 @@ Constant *ConstantFP::getZeroValueForNegation(Type *Ty) {
 ConstantFP* ConstantFP::get(LLVMContext &Context, const APFloat& V) {
   LLVMContextImpl* pImpl = Context.pImpl;
 
-  ConstantFP *&Slot = pImpl->FPConstants[V];
+  ConstantFP *&Slot = pImpl->FPConstants[DenseMapAPFloatKeyInfo::KeyTy(V)];
 
   if (!Slot) {
     Type *Ty;