delete [] OperandList;
}
-static bool isSetCC(unsigned Opcode) {
- return Opcode == Instruction::SetEQ || Opcode == Instruction::SetNE ||
- Opcode == Instruction::SetLT || Opcode == Instruction::SetGT ||
- Opcode == Instruction::SetLE || Opcode == Instruction::SetGE;
-}
-
// We declare several classes private to this file, so use an anonymous
// namespace
namespace {
Use Ops[2];
public:
BinaryConstantExpr(unsigned Opcode, Constant *C1, Constant *C2)
- : ConstantExpr(isSetCC(Opcode) ? Type::BoolTy : C1->getType(),
- Opcode, Ops, 2) {
+ : ConstantExpr(C1->getType(), Opcode, Ops, 2) {
Ops[0].init(C1, this);
Ops[1].init(C2, this);
}
Constant *ConstantExpr::getXor(Constant *C1, Constant *C2) {
return get(Instruction::Xor, C1, C2);
}
-Constant *ConstantExpr::getSetEQ(Constant *C1, Constant *C2) {
- return get(Instruction::SetEQ, C1, C2);
-}
-Constant *ConstantExpr::getSetNE(Constant *C1, Constant *C2) {
- return get(Instruction::SetNE, C1, C2);
-}
-Constant *ConstantExpr::getSetLT(Constant *C1, Constant *C2) {
- return get(Instruction::SetLT, C1, C2);
-}
-Constant *ConstantExpr::getSetGT(Constant *C1, Constant *C2) {
- return get(Instruction::SetGT, C1, C2);
-}
-Constant *ConstantExpr::getSetLE(Constant *C1, Constant *C2) {
- return get(Instruction::SetLE, C1, C2);
-}
-Constant *ConstantExpr::getSetGE(Constant *C1, Constant *C2) {
- return get(Instruction::SetGE, C1, C2);
-}
unsigned ConstantExpr::getPredicate() const {
assert(getOpcode() == Instruction::FCmp || getOpcode() == Instruction::ICmp);
return dynamic_cast<const CompareConstantExpr*>(this)->predicate;
std::vector<Constant*> ActualOps(Ops.begin()+1, Ops.end());
return ConstantExpr::getGetElementPtr(Ops[0], ActualOps);
}
+ case Instruction::ICmp:
+ case Instruction::FCmp:
+ return ConstantExpr::getCompare(getPredicate(), Ops[0], Ops[1]);
default:
assert(getNumOperands() == 2 && "Must be binary operator?");
return ConstantExpr::get(getOpcode(), Ops[0], Ops[1]);
assert(C1->getType() == C2->getType() &&
"Operand types in binary constant expression should match");
- if (ReqTy == C1->getType() || (Instruction::isComparison(Opcode) &&
- ReqTy == Type::BoolTy))
+ if (ReqTy == C1->getType() || ReqTy == Type::BoolTy)
if (Constant *FC = ConstantFoldBinaryInstruction(Opcode, C1, C2))
return FC; // Fold a few common cases...
return ExprConstants->getOrCreate(ReqTy, Key);
}
-Constant *ConstantExpr::getCompareTy(unsigned Opcode, unsigned short predicate,
+Constant *ConstantExpr::getCompareTy(unsigned short predicate,
Constant *C1, Constant *C2) {
- if (Opcode == Instruction::ICmp)
- return getICmp(predicate, C1, C2);
- return getFCmp(predicate, C1, C2);
+ switch (predicate) {
+ default: assert(0 && "Invalid CmpInst predicate");
+ case FCmpInst::FCMP_FALSE: case FCmpInst::FCMP_OEQ: case FCmpInst::FCMP_OGT:
+ case FCmpInst::FCMP_OGE: case FCmpInst::FCMP_OLT: case FCmpInst::FCMP_OLE:
+ case FCmpInst::FCMP_ONE: case FCmpInst::FCMP_ORD: case FCmpInst::FCMP_UNO:
+ case FCmpInst::FCMP_UEQ: case FCmpInst::FCMP_UGT: case FCmpInst::FCMP_UGE:
+ case FCmpInst::FCMP_ULT: case FCmpInst::FCMP_ULE: case FCmpInst::FCMP_UNE:
+ case FCmpInst::FCMP_TRUE:
+ return getFCmp(predicate, C1, C2);
+ case ICmpInst::ICMP_EQ: case ICmpInst::ICMP_NE: case ICmpInst::ICMP_UGT:
+ case ICmpInst::ICMP_UGE: case ICmpInst::ICMP_ULT: case ICmpInst::ICMP_ULE:
+ case ICmpInst::ICMP_SGT: case ICmpInst::ICMP_SGE: case ICmpInst::ICMP_SLT:
+ case ICmpInst::ICMP_SLE:
+ return getICmp(predicate, C1, C2);
+ }
}
Constant *ConstantExpr::get(unsigned Opcode, Constant *C1, Constant *C2) {
assert((C1->getType()->isIntegral() || isa<PackedType>(C1->getType())) &&
"Tried to create a logical operation on a non-integral type!");
break;
- case Instruction::SetLT: case Instruction::SetGT: case Instruction::SetLE:
- case Instruction::SetGE: case Instruction::SetEQ: case Instruction::SetNE:
- assert(C1->getType() == C2->getType() && "Op types should be identical!");
- break;
case Instruction::Shl:
case Instruction::LShr:
case Instruction::AShr:
return getTy(C1->getType(), Opcode, C1, C2);
}
-Constant *ConstantExpr::getCompare(unsigned Opcode, unsigned short pred,
+Constant *ConstantExpr::getCompare(unsigned short pred,
Constant *C1, Constant *C2) {
assert(C1->getType() == C2->getType() && "Op types should be identical!");
- return getCompareTy(Opcode, pred, C1, C2);
+ return getCompareTy(pred, C1, C2);
}
Constant *ConstantExpr::getSelectTy(const Type *ReqTy, Constant *C,
assert(pred >= ICmpInst::FIRST_ICMP_PREDICATE &&
pred <= ICmpInst::LAST_ICMP_PREDICATE && "Invalid ICmp Predicate");
- if (Constant *FC = ConstantFoldCompare(Instruction::ICmp, LHS, RHS, pred))
+ if (Constant *FC = ConstantFoldCompareInstruction(pred, LHS, RHS))
return FC; // Fold a few common cases...
// Look up the constant in the table first to ensure uniqueness
assert(LHS->getType() == RHS->getType());
assert(pred <= FCmpInst::LAST_FCMP_PREDICATE && "Invalid FCmp Predicate");
- if (Constant *FC = ConstantFoldCompare(Instruction::FCmp, LHS, RHS, pred))
+ if (Constant *FC = ConstantFoldCompareInstruction(pred, LHS, RHS))
return FC; // Fold a few common cases...
// Look up the constant in the table first to ensure uniqueness