aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-04-04 23:20:30 +0000
committerChris Lattner <sabre@nondot.org>2004-04-04 23:20:30 +0000
commitd144f42a5aa0e9c41b0bf478ea20742c09e9a015 (patch)
tree8e24b977791d26baf8db797b64c1b7bb8f4be4d7
parent97220b7338f0931d748ed1da8c006f47e4a30798 (diff)
downloadexternal_llvm-d144f42a5aa0e9c41b0bf478ea20742c09e9a015.tar.gz
external_llvm-d144f42a5aa0e9c41b0bf478ea20742c09e9a015.tar.bz2
external_llvm-d144f42a5aa0e9c41b0bf478ea20742c09e9a015.zip
Add ConstantExpr::get(Sign|Zero)Extend methods
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12648 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/Constants.h2
-rw-r--r--lib/VMCore/Constants.cpp16
2 files changed, 18 insertions, 0 deletions
diff --git a/include/llvm/Constants.h b/include/llvm/Constants.h
index 2e471cb5dd..b5ba1b9671 100644
--- a/include/llvm/Constants.h
+++ b/include/llvm/Constants.h
@@ -544,6 +544,8 @@ public:
/// Cast constant expr
///
static Constant *getCast(Constant *C, const Type *Ty);
+ static Constant *getSignExtend(Constant *C, const Type *Ty);
+ static Constant *getZeroExtend(Constant *C, const Type *Ty);
/// Select constant expr
///
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp
index 6c6557dccd..3ed70089c1 100644
--- a/lib/VMCore/Constants.cpp
+++ b/lib/VMCore/Constants.cpp
@@ -1131,6 +1131,22 @@ Constant *ConstantExpr::getCast(Constant *C, const Type *Ty) {
return ExprConstants.getOrCreate(Ty, Key);
}
+Constant *ConstantExpr::getSignExtend(Constant *C, const Type *Ty) {
+ assert(C->getType()->isInteger() && Ty->isInteger() &&
+ C->getType()->getPrimitiveSize() <= Ty->getPrimitiveSize() &&
+ "This is an illegal sign extension!");
+ C = ConstantExpr::getCast(C, C->getType()->getSignedVersion());
+ return ConstantExpr::getCast(C, Ty);
+}
+
+Constant *ConstantExpr::getZeroExtend(Constant *C, const Type *Ty) {
+ assert(C->getType()->isInteger() && Ty->isInteger() &&
+ C->getType()->getPrimitiveSize() <= Ty->getPrimitiveSize() &&
+ "This is an illegal zero extension!");
+ C = ConstantExpr::getCast(C, C->getType()->getUnsignedVersion());
+ return ConstantExpr::getCast(C, Ty);
+}
+
Constant *ConstantExpr::getTy(const Type *ReqTy, unsigned Opcode,
Constant *C1, Constant *C2) {
if (Opcode == Instruction::Shl || Opcode == Instruction::Shr)