Factor several methods, including getInversePredicate and

getSwappedPredicate, from ICmpInst and FCmpInst into common
methods in CmpInst. This allows CmpInsts to be manipulated
generically.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@51810 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Dan Gohman 2008-05-31 02:47:54 +00:00
parent e4c67cdab4
commit 7e2dd6628e
3 changed files with 63 additions and 115 deletions

View File

@ -656,17 +656,41 @@ public:
return static_cast<OtherOps>(Instruction::getOpcode());
}
/// The predicate for CmpInst is defined by the subclasses but stored in
/// the SubclassData field (see Value.h). We allow it to be fetched here
/// as the predicate but there is no enum type for it, just the raw unsigned
/// short. This facilitates comparison of CmpInst instances without delving
/// into the subclasses since predicate values are distinct between the
/// CmpInst subclasses.
/// @brief Return the predicate for this instruction.
unsigned short getPredicate() const {
return SubclassData;
Predicate getPredicate() const { return Predicate(SubclassData); }
/// @brief Set the predicate for this instruction to the specified value.
void setPredicate(Predicate P) { SubclassData = P; }
/// For example, EQ -> NE, UGT -> ULE, SLT -> SGE,
/// OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
/// @returns the inverse predicate for the instruction's current predicate.
/// @brief Return the inverse of the instruction's predicate.
Predicate getInversePredicate() const {
return getInversePredicate(getPredicate());
}
/// For example, EQ -> NE, UGT -> ULE, SLT -> SGE,
/// OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
/// @returns the inverse predicate for predicate provided in \p pred.
/// @brief Return the inverse of a given predicate
static Predicate getInversePredicate(Predicate pred);
/// For example, EQ->EQ, SLE->SGE, ULT->UGT,
/// OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
/// @returns the predicate that would be the result of exchanging the two
/// operands of the CmpInst instruction without changing the result
/// produced.
/// @brief Return the predicate as if the operands were swapped
Predicate getSwappedPredicate() const {
return getSwappedPredicate(getPredicate());
}
/// This is a static version that you can use without an instruction
/// available.
/// @brief Return the predicate as if the operands were swapped.
static Predicate getSwappedPredicate(Predicate pred);
/// @brief Provide more efficient getOperand methods.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);

View File

@ -650,38 +650,6 @@ public:
"Invalid operand types for ICmp instruction");
}
/// @brief Return the predicate for this instruction.
Predicate getPredicate() const { return Predicate(SubclassData); }
/// @brief Set the predicate for this instruction to the specified value.
void setPredicate(Predicate P) { SubclassData = P; }
/// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc.
/// @returns the inverse predicate for the instruction's current predicate.
/// @brief Return the inverse of the instruction's predicate.
Predicate getInversePredicate() const {
return getInversePredicate(getPredicate());
}
/// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc.
/// @returns the inverse predicate for predicate provided in \p pred.
/// @brief Return the inverse of a given predicate
static Predicate getInversePredicate(Predicate pred);
/// For example, EQ->EQ, SLE->SGE, ULT->UGT, etc.
/// @returns the predicate that would be the result of exchanging the two
/// operands of the ICmpInst instruction without changing the result
/// produced.
/// @brief Return the predicate as if the operands were swapped
Predicate getSwappedPredicate() const {
return getSwappedPredicate(getPredicate());
}
/// This is a static version that you can use without an instruction
/// available.
/// @brief Return the predicate as if the operands were swapped.
static Predicate getSwappedPredicate(Predicate pred);
/// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
/// @returns the predicate that would be the result if the operand were
/// regarded as signed.
@ -830,38 +798,6 @@ public:
"Invalid operand types for FCmp instruction");
}
/// @brief Return the predicate for this instruction.
Predicate getPredicate() const { return Predicate(SubclassData); }
/// @brief Set the predicate for this instruction to the specified value.
void setPredicate(Predicate P) { SubclassData = P; }
/// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
/// @returns the inverse predicate for the instructions current predicate.
/// @brief Return the inverse of the predicate
Predicate getInversePredicate() const {
return getInversePredicate(getPredicate());
}
/// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
/// @returns the inverse predicate for \p pred.
/// @brief Return the inverse of a given predicate
static Predicate getInversePredicate(Predicate pred);
/// For example, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
/// @returns the predicate that would be the result of exchanging the two
/// operands of the ICmpInst instruction without changing the result
/// produced.
/// @brief Return the predicate as if the operands were swapped
Predicate getSwappedPredicate() const {
return getSwappedPredicate(getPredicate());
}
/// This is a static version that you can use without an instruction
/// available.
/// @brief Return the predicate as if the operands were swapped.
static Predicate getSwappedPredicate(Predicate Opcode);
/// This also tests for commutativity. If isEquality() returns true then
/// the predicate is also commutative. Only the equality predicates are
/// commutative.

View File

@ -2497,10 +2497,9 @@ bool CmpInst::isEquality() {
}
ICmpInst::Predicate ICmpInst::getInversePredicate(Predicate pred) {
CmpInst::Predicate CmpInst::getInversePredicate(Predicate pred) {
switch (pred) {
default:
assert(!"Unknown icmp predicate!");
default: assert(!"Unknown cmp predicate!");
case ICMP_EQ: return ICMP_NE;
case ICMP_NE: return ICMP_EQ;
case ICMP_UGT: return ICMP_ULE;
@ -2511,22 +2510,23 @@ ICmpInst::Predicate ICmpInst::getInversePredicate(Predicate pred) {
case ICMP_SLT: return ICMP_SGE;
case ICMP_SGE: return ICMP_SLT;
case ICMP_SLE: return ICMP_SGT;
}
}
ICmpInst::Predicate ICmpInst::getSwappedPredicate(Predicate pred) {
switch (pred) {
default: assert(! "Unknown icmp predicate!");
case ICMP_EQ: case ICMP_NE:
return pred;
case ICMP_SGT: return ICMP_SLT;
case ICMP_SLT: return ICMP_SGT;
case ICMP_SGE: return ICMP_SLE;
case ICMP_SLE: return ICMP_SGE;
case ICMP_UGT: return ICMP_ULT;
case ICMP_ULT: return ICMP_UGT;
case ICMP_UGE: return ICMP_ULE;
case ICMP_ULE: return ICMP_UGE;
case FCMP_OEQ: return FCMP_UNE;
case FCMP_ONE: return FCMP_UEQ;
case FCMP_OGT: return FCMP_ULE;
case FCMP_OLT: return FCMP_UGE;
case FCMP_OGE: return FCMP_ULT;
case FCMP_OLE: return FCMP_UGT;
case FCMP_UEQ: return FCMP_ONE;
case FCMP_UNE: return FCMP_OEQ;
case FCMP_UGT: return FCMP_OLE;
case FCMP_ULT: return FCMP_OGE;
case FCMP_UGE: return FCMP_OLT;
case FCMP_ULE: return FCMP_OGT;
case FCMP_ORD: return FCMP_UNO;
case FCMP_UNO: return FCMP_ORD;
case FCMP_TRUE: return FCMP_FALSE;
case FCMP_FALSE: return FCMP_TRUE;
}
}
@ -2602,32 +2602,20 @@ ICmpInst::makeConstantRange(Predicate pred, const APInt &C) {
return ConstantRange(Lower, Upper);
}
FCmpInst::Predicate FCmpInst::getInversePredicate(Predicate pred) {
CmpInst::Predicate CmpInst::getSwappedPredicate(Predicate pred) {
switch (pred) {
default:
assert(!"Unknown icmp predicate!");
case FCMP_OEQ: return FCMP_UNE;
case FCMP_ONE: return FCMP_UEQ;
case FCMP_OGT: return FCMP_ULE;
case FCMP_OLT: return FCMP_UGE;
case FCMP_OGE: return FCMP_ULT;
case FCMP_OLE: return FCMP_UGT;
case FCMP_UEQ: return FCMP_ONE;
case FCMP_UNE: return FCMP_OEQ;
case FCMP_UGT: return FCMP_OLE;
case FCMP_ULT: return FCMP_OGE;
case FCMP_UGE: return FCMP_OLT;
case FCMP_ULE: return FCMP_OGT;
case FCMP_ORD: return FCMP_UNO;
case FCMP_UNO: return FCMP_ORD;
case FCMP_TRUE: return FCMP_FALSE;
case FCMP_FALSE: return FCMP_TRUE;
}
}
FCmpInst::Predicate FCmpInst::getSwappedPredicate(Predicate pred) {
switch (pred) {
default: assert(!"Unknown fcmp predicate!");
default: assert(!"Unknown cmp predicate!");
case ICMP_EQ: case ICMP_NE:
return pred;
case ICMP_SGT: return ICMP_SLT;
case ICMP_SLT: return ICMP_SGT;
case ICMP_SGE: return ICMP_SLE;
case ICMP_SLE: return ICMP_SGE;
case ICMP_UGT: return ICMP_ULT;
case ICMP_ULT: return ICMP_UGT;
case ICMP_UGE: return ICMP_ULE;
case ICMP_ULE: return ICMP_UGE;
case FCMP_FALSE: case FCMP_TRUE:
case FCMP_OEQ: case FCMP_ONE:
case FCMP_UEQ: case FCMP_UNE: