From cf09f51bb98a1658c2357f39d12d3e0ed4fa6133 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 17 Nov 2003 19:19:32 +0000 Subject: [PATCH] Eliminate use of the ConstantPointer class git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10053 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/VMCore/ConstantFold.cpp | 58 +++++++++++++++---------------------- 1 file changed, 23 insertions(+), 35 deletions(-) diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp index aca7df25893..0b1b1233520 100644 --- a/lib/VMCore/ConstantFold.cpp +++ b/lib/VMCore/ConstantFold.cpp @@ -389,64 +389,51 @@ struct BoolRules : public TemplateRules { //===----------------------------------------------------------------------===// -// PointerRules Class +// NullPointerRules Class //===----------------------------------------------------------------------===// // -// PointerRules provides a concrete base class of ConstRules for pointer types +// NullPointerRules provides a concrete base class of ConstRules for null +// pointers. // -struct PointerRules : public TemplateRules { +struct NullPointerRules : public TemplateRules { static ConstantBool *CastToBool (const Constant *V) { - if (V->isNullValue()) return ConstantBool::False; - return 0; // Can't const prop other types of pointers + return ConstantBool::False; } static ConstantSInt *CastToSByte (const Constant *V) { - if (V->isNullValue()) return ConstantSInt::get(Type::SByteTy, 0); - return 0; // Can't const prop other types of pointers + return ConstantSInt::get(Type::SByteTy, 0); } static ConstantUInt *CastToUByte (const Constant *V) { - if (V->isNullValue()) return ConstantUInt::get(Type::UByteTy, 0); - return 0; // Can't const prop other types of pointers + return ConstantUInt::get(Type::UByteTy, 0); } static ConstantSInt *CastToShort (const Constant *V) { - if (V->isNullValue()) return ConstantSInt::get(Type::ShortTy, 0); - return 0; // Can't const prop other types of pointers + return ConstantSInt::get(Type::ShortTy, 0); } static ConstantUInt *CastToUShort(const Constant *V) { - if (V->isNullValue()) return ConstantUInt::get(Type::UShortTy, 0); - return 0; // Can't const prop other types of pointers + return ConstantUInt::get(Type::UShortTy, 0); } static ConstantSInt *CastToInt (const Constant *V) { - if (V->isNullValue()) return ConstantSInt::get(Type::IntTy, 0); - return 0; // Can't const prop other types of pointers + return ConstantSInt::get(Type::IntTy, 0); } static ConstantUInt *CastToUInt (const Constant *V) { - if (V->isNullValue()) return ConstantUInt::get(Type::UIntTy, 0); - return 0; // Can't const prop other types of pointers + return ConstantUInt::get(Type::UIntTy, 0); } static ConstantSInt *CastToLong (const Constant *V) { - if (V->isNullValue()) return ConstantSInt::get(Type::LongTy, 0); - return 0; // Can't const prop other types of pointers + return ConstantSInt::get(Type::LongTy, 0); } static ConstantUInt *CastToULong (const Constant *V) { - if (V->isNullValue()) return ConstantUInt::get(Type::ULongTy, 0); - return 0; // Can't const prop other types of pointers + return ConstantUInt::get(Type::ULongTy, 0); } static ConstantFP *CastToFloat (const Constant *V) { - if (V->isNullValue()) return ConstantFP::get(Type::FloatTy, 0); - return 0; // Can't const prop other types of pointers + return ConstantFP::get(Type::FloatTy, 0); } static ConstantFP *CastToDouble(const Constant *V) { - if (V->isNullValue()) return ConstantFP::get(Type::DoubleTy, 0); - return 0; // Can't const prop other types of pointers + return ConstantFP::get(Type::DoubleTy, 0); } static Constant *CastToPointer(const ConstantPointer *V, const PointerType *PTy) { - if (V->getType() == PTy) - return const_cast(V); // Allow cast %PTy %ptr to %PTy - if (V->isNullValue()) - return ConstantPointerNull::get(PTy); - return 0; // Can't const prop other types of pointers + return ConstantPointerNull::get(PTy); } }; @@ -592,9 +579,9 @@ struct DirectFPRules }; ConstRules &ConstRules::get(const Constant &V1, const Constant &V2) { - static EmptyRules EmptyR; - static BoolRules BoolR; - static PointerRules PointerR; + static EmptyRules EmptyR; + static BoolRules BoolR; + static NullPointerRules NullPointerR; static DirectIntRules SByteR; static DirectIntRules UByteR; static DirectIntRules ShortR; @@ -606,7 +593,8 @@ ConstRules &ConstRules::get(const Constant &V1, const Constant &V2) { static DirectFPRules FloatR; static DirectFPRules DoubleR; - if (isa(V1) || isa(V2)) + if (isa(V1) || isa(V2) || + isa(V1) || isa(V2)) return EmptyR; // FIXME: This assert doesn't work because shifts pass both operands in to @@ -616,7 +604,7 @@ ConstRules &ConstRules::get(const Constant &V1, const Constant &V2) { switch (V1.getType()->getPrimitiveID()) { default: assert(0 && "Unknown value type for constant folding!"); case Type::BoolTyID: return BoolR; - case Type::PointerTyID: return PointerR; + case Type::PointerTyID: return NullPointerR; case Type::SByteTyID: return SByteR; case Type::UByteTyID: return UByteR; case Type::ShortTyID: return ShortR; -- 2.34.1