summaryrefslogtreecommitdiffstats
path: root/llvm/lib/VMCore/ConstantHandling.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
commitcea4d8c2f5ebb81202740cf2090ffeba20ba80b9 (patch)
tree4f94499ef509f1ea8e1d5c507a74b71de231b6f0 /llvm/lib/VMCore/ConstantHandling.cpp
parent35364c84085533db6c429289e60fb63fd7bce5e5 (diff)
downloadbcm5719-llvm-cea4d8c2f5ebb81202740cf2090ffeba20ba80b9.tar.gz
bcm5719-llvm-cea4d8c2f5ebb81202740cf2090ffeba20ba80b9.zip
Implement constant folding of casts from boolean constants to other values
llvm-svn: 7812
Diffstat (limited to 'llvm/lib/VMCore/ConstantHandling.cpp')
-rw-r--r--llvm/lib/VMCore/ConstantHandling.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/llvm/lib/VMCore/ConstantHandling.cpp b/llvm/lib/VMCore/ConstantHandling.cpp
index 0edf6a76a62..e8dd243c159 100644
--- a/llvm/lib/VMCore/ConstantHandling.cpp
+++ b/llvm/lib/VMCore/ConstantHandling.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
};
OpenPOWER on IntegriCloud