aboutsummaryrefslogtreecommitdiff
path: root/lib/VMCore/ConstantFold.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-08-13 15:52:25 +0000
committerChris Lattner <sabre@nondot.org>2003-08-13 15:52:25 +0000
commit3ccd0fd7568ab3f671c00cc2b7defc616d9d213a (patch)
treed28d9b64825622e415620b93fc6261119d7cf889 /lib/VMCore/ConstantFold.cpp
parent478b3a9682c888d17abef1b19f779852ebba213b (diff)
Implement constant folding of casts from boolean constants to other values
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7812 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/ConstantFold.cpp')
-rw-r--r--lib/VMCore/ConstantFold.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp
index 0edf6a76a6..e8dd243c15 100644
--- a/lib/VMCore/ConstantFold.cpp
+++ b/lib/VMCore/ConstantFold.cpp
@@ -344,6 +344,25 @@ struct BoolRules : public TemplateRules<ConstantBool, BoolRules> {
static Constant *Xor(const ConstantBool *V1, const ConstantBool *V2) {
return ConstantBool::get(V1->getValue() ^ V2->getValue());
}
+
+ // Casting operators. ick
+#define DEF_CAST(TYPE, CLASS, CTYPE) \
+ static CLASS *CastTo##TYPE (const ConstantBool *V) { \
+ return CLASS::get(Type::TYPE##Ty, (CTYPE)(bool)V->getValue()); \
+ }
+
+ DEF_CAST(Bool , ConstantBool, bool)
+ DEF_CAST(SByte , ConstantSInt, signed char)
+ DEF_CAST(UByte , ConstantUInt, unsigned char)
+ DEF_CAST(Short , ConstantSInt, signed short)
+ DEF_CAST(UShort, ConstantUInt, unsigned short)
+ DEF_CAST(Int , ConstantSInt, signed int)
+ DEF_CAST(UInt , ConstantUInt, unsigned int)
+ DEF_CAST(Long , ConstantSInt, int64_t)
+ DEF_CAST(ULong , ConstantUInt, uint64_t)
+ DEF_CAST(Float , ConstantFP , float)
+ DEF_CAST(Double, ConstantFP , double)
+#undef DEF_CAST
};