diff options
author | Chris Lattner <sabre@nondot.org> | 2003-05-21 17:49:25 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2003-05-21 17:49:25 +0000 |
commit | f31f583b153dacac9f91d6109cdfad140ad0cec1 (patch) | |
tree | 9c0b4c581994a9a94735c658a5ececece48e740c /lib/VMCore | |
parent | 67d8e1aabc1fc9d5a7d3bb575aa4180ed1fe399b (diff) | |
download | llvm-f31f583b153dacac9f91d6109cdfad140ad0cec1.tar.gz llvm-f31f583b153dacac9f91d6109cdfad140ad0cec1.tar.bz2 llvm-f31f583b153dacac9f91d6109cdfad140ad0cec1.tar.xz |
Add support for shift constant expressions
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@6260 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore')
-rw-r--r-- | lib/VMCore/Constants.cpp | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index 9efc313be7..273ab07293 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -649,6 +649,12 @@ Constant *ConstantExpr::getCast(Constant *C, const Type *Ty) { } Constant *ConstantExpr::get(unsigned Opcode, Constant *C1, Constant *C2) { + // Check the operands for consistency first + assert((Opcode >= Instruction::BinaryOpsBegin && + Opcode < Instruction::BinaryOpsEnd) && + "Invalid opcode in binary constant expression"); + assert(C1->getType() == C2->getType() && + "Operand types in binary constant expression should match"); if (Constant *FC = ConstantFoldBinaryInstruction(Opcode, C1, C2)) return FC; // Fold a few common cases... @@ -659,20 +665,37 @@ Constant *ConstantExpr::get(unsigned Opcode, Constant *C1, Constant *C2) { ConstantExpr *Result = ExprConstants.get(C1->getType(), Key); if (Result) return Result; - // Its not in the table so create a new one and put it in the table. + // It's not in the table so create a new one and put it in the table. + Result = new ConstantExpr(Opcode, C1, C2); + ExprConstants.add(C1->getType(), Key, Result); + return Result; +} + +/// getShift - Return a shift left or shift right constant expr +Constant *ConstantExpr::getShift(unsigned Opcode, Constant *C1, Constant *C2) { // Check the operands for consistency first - assert((Opcode >= Instruction::BinaryOpsBegin && - Opcode < Instruction::BinaryOpsEnd) && + assert((Opcode == Instruction::Shl || + Opcode == Instruction::Shr) && "Invalid opcode in binary constant expression"); + assert(C1->getType()->isIntegral() && C2->getType() == Type::UByteTy && + "Invalid operand types for Shift constant expr!"); - assert(C1->getType() == C2->getType() && - "Operand types in binary constant expression should match"); + if (Constant *FC = ConstantFoldShiftInstruction(Opcode, C1, C2)) + return FC; // Fold a few common cases... + + // Look up the constant in the table first to ensure uniqueness + std::vector<Constant*> argVec(1, C1); argVec.push_back(C2); + const ExprMapKeyType &Key = std::make_pair(Opcode, argVec); + ConstantExpr *Result = ExprConstants.get(C1->getType(), Key); + if (Result) return Result; + // It's not in the table so create a new one and put it in the table. Result = new ConstantExpr(Opcode, C1, C2); ExprConstants.add(C1->getType(), Key, Result); return Result; } + Constant *ConstantExpr::getGetElementPtr(Constant *C, const std::vector<Constant*> &IdxList){ if (Constant *FC = ConstantFoldGetElementPtr(C, IdxList)) |