summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-02-15 02:46:46 +0000
committerChris Lattner <sabre@nondot.org>2004-02-15 02:46:46 +0000
commit5d56c478bac04bfa17b6a8222915031a81f48b87 (patch)
tree4a6f19767555ec83e2ef8c4d2b7d21bffaa0eed1 /llvm/lib
parent0836c1005253f955642862406b2148473649e1c4 (diff)
downloadbcm5719-llvm-5d56c478bac04bfa17b6a8222915031a81f48b87.tar.gz
bcm5719-llvm-5d56c478bac04bfa17b6a8222915031a81f48b87.zip
Keep a cache of non-abstract null arrays and structs. This speeds up llvm-dis
from 16.57 -> 13.46s on 129.compress. llvm-svn: 11462
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/VMCore/Constants.cpp21
1 files changed, 19 insertions, 2 deletions
diff --git a/llvm/lib/VMCore/Constants.cpp b/llvm/lib/VMCore/Constants.cpp
index 2500ec46e80..f86fcc1a23b 100644
--- a/llvm/lib/VMCore/Constants.cpp
+++ b/llvm/lib/VMCore/Constants.cpp
@@ -64,6 +64,8 @@ void Constant::destroyConstantImpl() {
delete this;
}
+static std::map<const Type *, Constant*> NullValues;
+
// Static constructor to create a '0' constant of arbitrary type...
Constant *Constant::getNullValue(const Type *Ty) {
switch (Ty->getPrimitiveID()) {
@@ -117,18 +119,33 @@ Constant *Constant::getNullValue(const Type *Ty) {
return ConstantPointerNull::get(cast<PointerType>(Ty));
case Type::StructTyID: {
+ if (!Ty->isAbstract())
+ if (Constant *V = NullValues[Ty])
+ return V;
+
const StructType *ST = cast<StructType>(Ty);
std::vector<Constant*> Elements;
Elements.resize(ST->getNumElements());
for (unsigned i = 0, e = ST->getNumElements(); i != e; ++i)
Elements[i] = Constant::getNullValue(ST->getElementType(i));
- return ConstantStruct::get(ST, Elements);
+ Constant *Ret = ConstantStruct::get(ST, Elements);
+ if (!Ty->isAbstract())
+ NullValues[Ty] = Ret;
+ return Ret;
}
case Type::ArrayTyID: {
+ if (!Ty->isAbstract())
+ if (Constant *V = NullValues[Ty])
+ return V;
+
const ArrayType *AT = cast<ArrayType>(Ty);
Constant *El = Constant::getNullValue(AT->getElementType());
unsigned NumElements = AT->getNumElements();
- return ConstantArray::get(AT, std::vector<Constant*>(NumElements, El));
+ Constant *Ret = ConstantArray::get(AT,
+ std::vector<Constant*>(NumElements, El));
+ if (!Ty->isAbstract())
+ NullValues[Ty] = Ret;
+ return Ret;
}
default:
// Function, Type, Label, or Opaque type?
OpenPOWER on IntegriCloud