Add ConstantExpr::get(Sign|Zero)Extend methods

llvm-svn: 12648
This commit is contained in:
Chris Lattner 2004-04-04 23:20:30 +00:00
parent dfcf8e34cf
commit dd28474610
2 changed files with 18 additions and 0 deletions

View File

@ -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
///

View File

@ -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)