LLVM API Documentation
Abstract base class of comparison instructions. More...
#include <InstrTypes.h>
Public Types | |
enum | Predicate { FCMP_FALSE = 0, FCMP_OEQ = 1, FCMP_OGT = 2, FCMP_OGE = 3, FCMP_OLT = 4, FCMP_OLE = 5, FCMP_ONE = 6, FCMP_ORD = 7, FCMP_UNO = 8, FCMP_UEQ = 9, FCMP_UGT = 10, FCMP_UGE = 11, FCMP_ULT = 12, FCMP_ULE = 13, FCMP_UNE = 14, FCMP_TRUE = 15, FIRST_FCMP_PREDICATE = FCMP_FALSE, LAST_FCMP_PREDICATE = FCMP_TRUE, BAD_FCMP_PREDICATE = FCMP_TRUE + 1, ICMP_EQ = 32, ICMP_NE = 33, ICMP_UGT = 34, ICMP_UGE = 35, ICMP_ULT = 36, ICMP_ULE = 37, ICMP_SGT = 38, ICMP_SGE = 39, ICMP_SLT = 40, ICMP_SLE = 41, FIRST_ICMP_PREDICATE = ICMP_EQ, LAST_ICMP_PREDICATE = ICMP_SLE, BAD_ICMP_PREDICATE = ICMP_SLE + 1 } |
Public Member Functions | |
void * | operator new (size_t s) |
OtherOps | getOpcode () const |
Get the opcode casted to the right type. | |
Predicate | getPredicate () const |
Return the predicate for this instruction. | |
void | setPredicate (Predicate P) |
Set the predicate for this instruction to the specified value. | |
bool | isFPPredicate () const |
bool | isIntPredicate () const |
Predicate | getInversePredicate () const |
Return the inverse of the instruction's predicate. | |
Predicate | getSwappedPredicate () const |
Return the predicate as if the operands were swapped. | |
DECLARE_TRANSPARENT_OPERAND_ACCESSORS (Value) | |
Provide more efficient getOperand methods. | |
void | swapOperands () |
Swap the operands and adjust predicate accordingly to retain the same comparison. | |
bool | isCommutative () const |
Determine if this CmpInst is commutative. | |
bool | isEquality () const |
Determine if this is an equals/not equals predicate. | |
bool | isSigned () const |
Determine if this instruction is using a signed comparison. | |
bool | isUnsigned () const |
Determine if this instruction is using an unsigned comparison. | |
bool | isTrueWhenEqual () const |
Determine if this is true when both operands are the same. | |
bool | isFalseWhenEqual () const |
Determine if this is false when both operands are the same. | |
Static Public Member Functions | |
static CmpInst * | Create (OtherOps Op, unsigned short predicate, Value *S1, Value *S2, const Twine &Name="", Instruction *InsertBefore=nullptr) |
Create a CmpInst. | |
static CmpInst * | Create (OtherOps Op, unsigned short predicate, Value *S1, Value *S2, const Twine &Name, BasicBlock *InsertAtEnd) |
Create a CmpInst. | |
static bool | isFPPredicate (Predicate P) |
static bool | isIntPredicate (Predicate P) |
static Predicate | getInversePredicate (Predicate pred) |
Return the inverse of a given predicate. | |
static Predicate | getSwappedPredicate (Predicate pred) |
Return the predicate as if the operands were swapped. | |
static bool | isUnsigned (unsigned short predicate) |
Determine if the predicate is an unsigned operation. | |
static bool | isSigned (unsigned short predicate) |
Determine if the predicate is an signed operation. | |
static bool | isOrdered (unsigned short predicate) |
Determine if the predicate is an ordered operation. | |
static bool | isUnordered (unsigned short predicate) |
Determine if the predicate is an unordered operation. | |
static bool | isTrueWhenEqual (unsigned short predicate) |
Determine if the predicate is true when comparing a value with itself. | |
static bool | isFalseWhenEqual (unsigned short predicate) |
Determine if the predicate is false when comparing a value with itself. | |
static bool | classof (const Instruction *I) |
Methods for support type inquiry through isa, cast, and dyn_cast: | |
static bool | classof (const Value *V) |
Methods for support type inquiry through isa, cast, and dyn_cast: | |
static Type * | makeCmpResultType (Type *opnd_type) |
Create a result type for fcmp/icmp. | |
Protected Member Functions | |
CmpInst (Type *ty, Instruction::OtherOps op, unsigned short pred, Value *LHS, Value *RHS, const Twine &Name="", Instruction *InsertBefore=nullptr) | |
CmpInst (Type *ty, Instruction::OtherOps op, unsigned short pred, Value *LHS, Value *RHS, const Twine &Name, BasicBlock *InsertAtEnd) | |
void | anchor () override |
Abstract base class of comparison instructions.
This class is the base class for the comparison instructions.
Definition at line 653 of file InstrTypes.h.
This enumeration lists the possible predicates for CmpInst subclasses. Values in the range 0-31 are reserved for FCmpInst, while values in the range 32-64 are reserved for ICmpInst. This is necessary to ensure the predicate values are not overlapping between the classes.
Definition at line 671 of file InstrTypes.h.
CmpInst::CmpInst | ( | Type * | ty, |
Instruction::OtherOps | op, | ||
unsigned short | pred, | ||
Value * | LHS, | ||
Value * | RHS, | ||
const Twine & | Name = "" , |
||
Instruction * | InsertBefore = nullptr |
||
) | [protected] |
Definition at line 3110 of file Instructions.cpp.
References llvm::Value::setName(), and setPredicate().
CmpInst::CmpInst | ( | Type * | ty, |
Instruction::OtherOps | op, | ||
unsigned short | pred, | ||
Value * | LHS, | ||
Value * | RHS, | ||
const Twine & | Name, | ||
BasicBlock * | InsertAtEnd | ||
) | [protected] |
Definition at line 3123 of file Instructions.cpp.
References llvm::Value::setName(), and setPredicate().
void CmpInst::anchor | ( | ) | [override, protected, virtual] |
Reimplemented from llvm::User.
Definition at line 3108 of file Instructions.cpp.
static bool llvm::CmpInst::classof | ( | const Instruction * | I | ) | [inline, static] |
Methods for support type inquiry through isa, cast, and dyn_cast:
Reimplemented in llvm::FCmpInst, and llvm::ICmpInst.
Definition at line 843 of file InstrTypes.h.
References llvm::FCmp, and llvm::Instruction::getOpcode().
Referenced by classof().
static bool llvm::CmpInst::classof | ( | const Value * | V | ) | [inline, static] |
Methods for support type inquiry through isa, cast, and dyn_cast:
Reimplemented from llvm::Instruction.
Reimplemented in llvm::FCmpInst, and llvm::ICmpInst.
Definition at line 847 of file InstrTypes.h.
References classof().
CmpInst * CmpInst::Create | ( | OtherOps | Op, |
unsigned short | predicate, | ||
Value * | S1, | ||
Value * | S2, | ||
const Twine & | Name = "" , |
||
Instruction * | InsertBefore = nullptr |
||
) | [static] |
Create a CmpInst.
Construct a compare instruction, given the opcode, the predicate and the two operands. Optionally (if InstBefore is specified) insert the instruction into a BasicBlock right before the specified instruction. The specified Instruction is allowed to be a dereferenced end iterator.
Definition at line 3137 of file Instructions.cpp.
Referenced by llvm::ConstantExpr::getAsInstruction(), OptimizeCmpExpression(), llvm::InstCombiner::visitICmpInst(), and llvm::InstCombiner::visitXor().
CmpInst * CmpInst::Create | ( | OtherOps | Op, |
unsigned short | predicate, | ||
Value * | S1, | ||
Value * | S2, | ||
const Twine & | Name, | ||
BasicBlock * | InsertAtEnd | ||
) | [static] |
Create a CmpInst.
Construct a compare instruction, given the opcode, the predicate and the two operands. Also automatically insert this instruction to the end of the BasicBlock specified.
Definition at line 3158 of file Instructions.cpp.
Provide more efficient getOperand methods.
Predicate llvm::CmpInst::getInversePredicate | ( | ) | const [inline] |
Return the inverse of the instruction's predicate.
For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
Definition at line 757 of file InstrTypes.h.
References getPredicate().
Referenced by llvm::ConstantFoldBinaryInstruction(), llvm::FoldBranchToCommonDest(), llvm::InstCombiner::FoldICmpCstShrCst(), llvm::getICmpCode(), SimplifyICmpInst(), llvm::InstCombiner::visitBranchInst(), and llvm::InstCombiner::visitICmpInst().
CmpInst::Predicate CmpInst::getInversePredicate | ( | Predicate | pred | ) | [static] |
Return the inverse of a given predicate.
For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
pred
. Definition at line 3188 of file Instructions.cpp.
References FCMP_FALSE, FCMP_OEQ, FCMP_OGE, FCMP_OGT, FCMP_OLE, FCMP_OLT, FCMP_ONE, FCMP_ORD, FCMP_TRUE, FCMP_UEQ, FCMP_UGE, FCMP_UGT, FCMP_ULE, FCMP_ULT, FCMP_UNE, FCMP_UNO, ICMP_EQ, ICMP_NE, ICMP_SGE, ICMP_SGT, ICMP_SLE, ICMP_SLT, ICMP_UGE, ICMP_UGT, ICMP_ULE, ICMP_ULT, and llvm_unreachable.
OtherOps llvm::CmpInst::getOpcode | ( | ) | const [inline] |
Get the opcode casted to the right type.
Reimplemented from llvm::Instruction.
Definition at line 729 of file InstrTypes.h.
Referenced by OptimizeCmpExpression(), and llvm::InstCombiner::visitXor().
Predicate llvm::CmpInst::getPredicate | ( | ) | const [inline] |
Return the predicate for this instruction.
Definition at line 734 of file InstrTypes.h.
References llvm::Instruction::getSubclassDataFromInstruction().
Referenced by canFoldZeroCheckIntoBranch(), llvm::ICmpInst::clone_impl(), llvm::FCmpInst::clone_impl(), decomposeBitTestICmp(), DemandedBitsLHSMask(), ExtractEquivalentCondition(), llvm::InstCombiner::FoldAndOfFCmps(), llvm::InstCombiner::FoldAndOfICmps(), llvm::InstCombiner::FoldCmpLoadFromIndexedGlobal(), llvm::InstCombiner::FoldFCmp_IntToFP_Cst(), llvm::InstCombiner::FoldICmpCstShrCst(), llvm::InstCombiner::FoldICmpDivCst(), llvm::InstCombiner::FoldICmpShrCst(), foldLogOpOfMaskedICmps(), llvm::InstCombiner::FoldOrOfFCmps(), llvm::InstCombiner::FoldOrOfICmps(), foldSelectICmpAnd(), foldSelectICmpAndOr(), llvm::getICmpCode(), getInversePredicate(), getSwappedPredicate(), getValueFromFromCondition(), llvm::FCmpInst::isCommutative(), llvm::FCmpInst::isEquality(), isFalseWhenEqual(), isFPPredicate(), isIntPredicate(), isSameCompare(), isSigned(), isTrueWhenEqual(), isUnsigned(), MatchSelectPattern(), needsLFTR(), OptimizeCmpExpression(), llvm::FastISel::optimizeCmpPredicate(), OptimizeGlobalAddressOfMalloc(), ProcessUMulZExtIdiom(), TryToSimplifyUncondBranchWithICmpInIt(), llvm::Interpreter::visitFCmpInst(), llvm::InstCombiner::visitFCmpInst(), llvm::Interpreter::visitICmpInst(), llvm::InstCombiner::visitICmpInst(), llvm::InstCombiner::visitICmpInstWithCastAndCast(), llvm::InstCombiner::visitICmpInstWithInstAndIntCst(), and llvm::InstCombiner::visitSelectInstWithICmp().
Predicate llvm::CmpInst::getSwappedPredicate | ( | ) | const [inline] |
Return the predicate as if the operands were swapped.
For example, EQ->EQ, SLE->SGE, ULT->UGT, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
Definition at line 773 of file InstrTypes.h.
References getPredicate().
Referenced by llvm::ConstantFoldCompareInstruction(), evaluateFCmpRelation(), evaluateICmpRelation(), ExtractEquivalentCondition(), llvm::FCmpInst::swapOperands(), llvm::InstCombiner::visitFCmpInst(), llvm::InstCombiner::visitICmpInst(), and llvm::InstCombiner::visitICmpInstWithInstAndIntCst().
CmpInst::Predicate CmpInst::getSwappedPredicate | ( | Predicate | pred | ) | [static] |
Return the predicate as if the operands were swapped.
This is a static version that you can use without an instruction available.
Definition at line 3310 of file Instructions.cpp.
References FCMP_FALSE, FCMP_OEQ, FCMP_OGE, FCMP_OGT, FCMP_OLE, FCMP_OLT, FCMP_ONE, FCMP_ORD, FCMP_TRUE, FCMP_UEQ, FCMP_UGE, FCMP_UGT, FCMP_ULE, FCMP_ULT, FCMP_UNE, FCMP_UNO, ICMP_EQ, ICMP_NE, ICMP_SGE, ICMP_SGT, ICMP_SLE, ICMP_SLT, ICMP_UGE, ICMP_UGT, ICMP_ULE, ICMP_ULT, and llvm_unreachable.
bool CmpInst::isCommutative | ( | ) | const |
Determine if this CmpInst is commutative.
This is just a convenience that dispatches to the subclasses.
Reimplemented from llvm::Instruction.
Reimplemented in llvm::FCmpInst, and llvm::ICmpInst.
Definition at line 3175 of file Instructions.cpp.
bool CmpInst::isEquality | ( | ) | const |
Determine if this is an equals/not equals predicate.
This is just a convenience that dispatches to the subclasses.
Reimplemented in llvm::FCmpInst, and llvm::ICmpInst.
Definition at line 3181 of file Instructions.cpp.
bool llvm::CmpInst::isFalseWhenEqual | ( | ) | const [inline] |
Determine if this is false when both operands are the same.
This is just a convenience.
Definition at line 818 of file InstrTypes.h.
References getPredicate().
Referenced by SimplifyFCmpInst(), and llvm::ScalarEvolution::SimplifyICmpOperands().
bool CmpInst::isFalseWhenEqual | ( | unsigned short | predicate | ) | [static] |
static bool llvm::CmpInst::isFPPredicate | ( | Predicate | P | ) | [inline, static] |
Definition at line 741 of file InstrTypes.h.
References FIRST_FCMP_PREDICATE, and LAST_FCMP_PREDICATE.
bool llvm::CmpInst::isFPPredicate | ( | ) | const [inline] |
Definition at line 749 of file InstrTypes.h.
References getPredicate(), and isFPPredicate().
Referenced by isFPPredicate(), and SimplifyFCmpInst().
static bool llvm::CmpInst::isIntPredicate | ( | Predicate | P | ) | [inline, static] |
Definition at line 745 of file InstrTypes.h.
References FIRST_ICMP_PREDICATE, and LAST_ICMP_PREDICATE.
bool llvm::CmpInst::isIntPredicate | ( | ) | const [inline] |
Definition at line 750 of file InstrTypes.h.
References getPredicate(), and isIntPredicate().
Referenced by isIntPredicate(), SimplifyCmpInst(), and SimplifyICmpInst().
bool CmpInst::isOrdered | ( | unsigned short | predicate | ) | [static] |
Determine if the predicate is an ordered operation.
Definition at line 3356 of file Instructions.cpp.
References FCMP_OEQ, FCMP_OGE, FCMP_OGT, FCMP_OLE, FCMP_OLT, FCMP_ONE, and FCMP_ORD.
Referenced by SimplifyFCmpInst().
bool llvm::CmpInst::isSigned | ( | ) | const [inline] |
Determine if this instruction is using a signed comparison.
Definition at line 800 of file InstrTypes.h.
References getPredicate().
Referenced by llvm::ConstantFoldCompareInstruction(), llvm::InstCombiner::FoldAndOfICmps(), llvm::InstCombiner::FoldGEPICmp(), llvm::InstCombiner::FoldICmpDivCst(), llvm::InstCombiner::FoldICmpShrCst(), llvm::InstCombiner::FoldOrOfICmps(), isSignTest(), llvm::PredicatesFoldable(), SimplifyICmpInst(), llvm::InstCombiner::visitICmpInst(), llvm::InstCombiner::visitICmpInstWithCastAndCast(), and llvm::InstCombiner::visitICmpInstWithInstAndIntCst().
bool CmpInst::isSigned | ( | unsigned short | predicate | ) | [static] |
bool llvm::CmpInst::isTrueWhenEqual | ( | ) | const [inline] |
Determine if this is true when both operands are the same.
This is just a convenience.
Definition at line 812 of file InstrTypes.h.
References getPredicate().
Referenced by computePointerICmp(), llvm::ConstantFoldCompareInstruction(), llvm::InstCombiner::FoldGEPICmp(), SimplifyFCmpInst(), SimplifyICmpInst(), and llvm::ScalarEvolution::SimplifyICmpOperands().
bool CmpInst::isTrueWhenEqual | ( | unsigned short | predicate | ) | [static] |
bool CmpInst::isUnordered | ( | unsigned short | predicate | ) | [static] |
Determine if the predicate is an unordered operation.
Definition at line 3365 of file Instructions.cpp.
References FCMP_UEQ, FCMP_UGE, FCMP_UGT, FCMP_ULE, FCMP_ULT, FCMP_UNE, and FCMP_UNO.
Referenced by SimplifyFCmpInst().
bool llvm::CmpInst::isUnsigned | ( | ) | const [inline] |
Determine if this instruction is using an unsigned comparison.
Definition at line 806 of file InstrTypes.h.
References getPredicate().
Referenced by SimplifyICmpInst(), llvm::InstCombiner::visitICmpInst(), llvm::InstCombiner::visitICmpInstWithInstAndIntCst(), and llvm::InstCombiner::visitSelectInstWithICmp().
bool CmpInst::isUnsigned | ( | unsigned short | predicate | ) | [static] |
static Type* llvm::CmpInst::makeCmpResultType | ( | Type * | opnd_type | ) | [inline, static] |
Create a result type for fcmp/icmp.
Definition at line 852 of file InstrTypes.h.
References llvm::VectorType::get(), llvm::Type::getContext(), and llvm::Type::getInt1Ty().
Referenced by llvm::InstCombiner::FoldAndOfFCmps(), llvm::InstCombiner::FoldAndOfICmps(), llvm::InstCombiner::FoldOrOfFCmps(), GetCompareTy(), and llvm::getICmpValue().
void* llvm::CmpInst::operator new | ( | size_t | s | ) | [inline] |
Reimplemented from llvm::User.
Definition at line 708 of file InstrTypes.h.
void llvm::CmpInst::setPredicate | ( | Predicate | P | ) | [inline] |
Set the predicate for this instruction to the specified value.
Definition at line 739 of file InstrTypes.h.
References llvm::Instruction::setInstructionSubclassData().
Referenced by CmpInst(), llvm::FoldBranchToCommonDest(), llvm::FCmpInst::swapOperands(), llvm::InstCombiner::visitBranchInst(), llvm::InstCombiner::visitFCmpInst(), and llvm::InstCombiner::visitSelectInstWithICmp().
void CmpInst::swapOperands | ( | ) |
Swap the operands and adjust predicate accordingly to retain the same comparison.
This is just a convenience that dispatches to the subclasses.
Reimplemented in llvm::FCmpInst, and llvm::ICmpInst.
Definition at line 3168 of file Instructions.cpp.