aboutsummaryrefslogtreecommitdiffstats
path: root/lib/VMCore
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-10-03 19:34:51 +0000
committerChris Lattner <sabre@nondot.org>2003-10-03 19:34:51 +0000
commit70b06fc717b65734daaa5e442a99fdc231835a84 (patch)
treeeb6aaaae3b8e670d9a2096bfeb4ac010e60558a6 /lib/VMCore
parent23c3288ce9339df174823a8e833d8f68ff2d8bdd (diff)
downloadexternal_llvm-70b06fc717b65734daaa5e442a99fdc231835a84.zip
external_llvm-70b06fc717b65734daaa5e442a99fdc231835a84.tar.gz
external_llvm-70b06fc717b65734daaa5e442a99fdc231835a84.tar.bz2
Minor random speedup: make Constant::getNullValue only call ConstantFOO::get
once! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8845 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore')
-rw-r--r--lib/VMCore/Constants.cpp58
1 files changed, 45 insertions, 13 deletions
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp
index c252247..8fb665a 100644
--- a/lib/VMCore/Constants.cpp
+++ b/lib/VMCore/Constants.cpp
@@ -59,25 +59,57 @@ void Constant::destroyConstantImpl() {
// Static constructor to create a '0' constant of arbitrary type...
Constant *Constant::getNullValue(const Type *Ty) {
switch (Ty->getPrimitiveID()) {
- case Type::BoolTyID: return ConstantBool::get(false);
- case Type::SByteTyID:
- case Type::ShortTyID:
- case Type::IntTyID:
- case Type::LongTyID: return ConstantSInt::get(Ty, 0);
-
- case Type::UByteTyID:
- case Type::UShortTyID:
- case Type::UIntTyID:
- case Type::ULongTyID: return ConstantUInt::get(Ty, 0);
+ case Type::BoolTyID: {
+ static Constant *NullBool = ConstantBool::get(false);
+ return NullBool;
+ }
+ case Type::SByteTyID: {
+ static Constant *NullSByte = ConstantSInt::get(Type::SByteTy, 0);
+ return NullSByte;
+ }
+ case Type::UByteTyID: {
+ static Constant *NullUByte = ConstantUInt::get(Type::UByteTy, 0);
+ return NullUByte;
+ }
+ case Type::ShortTyID: {
+ static Constant *NullShort = ConstantSInt::get(Type::ShortTy, 0);
+ return NullShort;
+ }
+ case Type::UShortTyID: {
+ static Constant *NullUShort = ConstantUInt::get(Type::UShortTy, 0);
+ return NullUShort;
+ }
+ case Type::IntTyID: {
+ static Constant *NullInt = ConstantSInt::get(Type::IntTy, 0);
+ return NullInt;
+ }
+ case Type::UIntTyID: {
+ static Constant *NullUInt = ConstantUInt::get(Type::UIntTy, 0);
+ return NullUInt;
+ }
+ case Type::LongTyID: {
+ static Constant *NullLong = ConstantSInt::get(Type::LongTy, 0);
+ return NullLong;
+ }
+ case Type::ULongTyID: {
+ static Constant *NullULong = ConstantUInt::get(Type::ULongTy, 0);
+ return NullULong;
+ }
- case Type::FloatTyID:
- case Type::DoubleTyID: return ConstantFP::get(Ty, 0);
+ case Type::FloatTyID: {
+ static Constant *NullFloat = ConstantFP::get(Type::FloatTy, 0);
+ return NullFloat;
+ }
+ case Type::DoubleTyID: {
+ static Constant *NullDouble = ConstantFP::get(Type::DoubleTy, 0);
+ return NullDouble;
+ }
case Type::PointerTyID:
return ConstantPointerNull::get(cast<PointerType>(Ty));
+
case Type::StructTyID: {
const StructType *ST = cast<StructType>(Ty);
-
const StructType::ElementTypes &ETs = ST->getElementTypes();
std::vector<Constant*> Elements;
Elements.resize(ETs.size());