From dd2847461034684b8eed3b3449cfa174ecfff961 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 4 Apr 2004 23:20:30 +0000 Subject: [PATCH] Add ConstantExpr::get(Sign|Zero)Extend methods llvm-svn: 12648 --- llvm/include/llvm/Constants.h | 2 ++ llvm/lib/VMCore/Constants.cpp | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/llvm/include/llvm/Constants.h b/llvm/include/llvm/Constants.h index 2e471cb5dd3d..b5ba1b96713d 100644 --- a/llvm/include/llvm/Constants.h +++ b/llvm/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/llvm/lib/VMCore/Constants.cpp b/llvm/lib/VMCore/Constants.cpp index 6c6557dccde3..3ed70089c1af 100644 --- a/llvm/lib/VMCore/Constants.cpp +++ b/llvm/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)