summaryrefslogtreecommitdiffstats
path: root/llvm/lib/IR/Constants.cpp
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2014-12-05 17:03:01 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2014-12-05 17:03:01 +0000
commitf8caa285171ac000827b4ef52d16bc6331425ed9 (patch)
tree7f39250d036690e4b3aa16fc91a6579c38776a8e /llvm/lib/IR/Constants.cpp
parent324ed20dcd6ecbd9f394e817745288b7451edb7b (diff)
downloadbcm5719-llvm-f8caa285171ac000827b4ef52d16bc6331425ed9.tar.gz
bcm5719-llvm-f8caa285171ac000827b4ef52d16bc6331425ed9.zip
LLVMContext: Store APInt/APFloat directly into the ConstantInt/FP DenseMaps.
Required some APInt massaging to get proper empty/tombstone values. Apart from making the code a bit simpler this also reduces the bucket size of the ConstantInt map from 32 to 24 bytes. llvm-svn: 223478
Diffstat (limited to 'llvm/lib/IR/Constants.cpp')
-rw-r--r--llvm/lib/IR/Constants.cpp19
1 files changed, 9 insertions, 10 deletions
diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp
index e0cb835c2c6..c4b18adc616 100644
--- a/llvm/lib/IR/Constants.cpp
+++ b/llvm/lib/IR/Constants.cpp
@@ -555,18 +555,17 @@ Constant *ConstantInt::getFalse(Type *Ty) {
}
-// 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.
+// Get a ConstantInt from an APInt.
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[DenseMapAPIntKeyInfo::KeyTy(V, ITy)];
- if (!Slot) Slot = new ConstantInt(ITy, V);
+ 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()));
return Slot;
}
@@ -689,7 +688,7 @@ Constant *ConstantFP::getZeroValueForNegation(Type *Ty) {
ConstantFP* ConstantFP::get(LLVMContext &Context, const APFloat& V) {
LLVMContextImpl* pImpl = Context.pImpl;
- ConstantFP *&Slot = pImpl->FPConstants[DenseMapAPFloatKeyInfo::KeyTy(V)];
+ ConstantFP *&Slot = pImpl->FPConstants[V];
if (!Slot) {
Type *Ty;
OpenPOWER on IntegriCloud