From aab54da21c8c9d38430d8681c63b633b7e7bf71c Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 15 Feb 2004 02:46:46 +0000 Subject: [PATCH] Keep a cache of non-abstract null arrays and structs. This speeds up llvm-dis from 16.57 -> 13.46s on 129.compress. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11462 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/VMCore/Constants.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index 2500ec46e80..f86fcc1a23b 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -64,6 +64,8 @@ void Constant::destroyConstantImpl() { delete this; } +static std::map 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(Ty)); case Type::StructTyID: { + if (!Ty->isAbstract()) + if (Constant *V = NullValues[Ty]) + return V; + const StructType *ST = cast(Ty); std::vector 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(Ty); Constant *El = Constant::getNullValue(AT->getElementType()); unsigned NumElements = AT->getNumElements(); - return ConstantArray::get(AT, std::vector(NumElements, El)); + Constant *Ret = ConstantArray::get(AT, + std::vector(NumElements, El)); + if (!Ty->isAbstract()) + NullValues[Ty] = Ret; + return Ret; } default: // Function, Type, Label, or Opaque type? -- 2.34.1