LLVM API Documentation

llvm::CmpInst Class Reference

Abstract base class of comparison instructions. More...

#include <InstrTypes.h>

Inheritance diagram for llvm::CmpInst:
[legend]
Collaboration diagram for llvm::CmpInst:
[legend]

List of all members.

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.
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 ()
 Determine if this CmpInst is commutative.
bool isEquality ()
 Determine if this is an equals/not equals predicate.

Static Public Member Functions

static CmpInst * Create (OtherOps Op, unsigned short predicate, Value *S1, Value *S2, const std::string &Name="", Instruction *InsertBefore=0)
 Create a CmpInst.
static CmpInst * Create (OtherOps Op, unsigned short predicate, Value *S1, Value *S2, const std::string &Name, BasicBlock *InsertAtEnd)
 Create a CmpInst.
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 classof (const CmpInst *)
 Methods for support type inquiry through isa, cast, and dyn_cast:.
static bool classof (const Instruction *I)
 Methods for support type inquiry through isa, cast, and dyn_cast:.
static bool classof (const Value *V)
static const Type * makeCmpResultType (const Type *opnd_type)
 Create a result type for fcmp/icmp (but not vicmp/vfcmp).

Protected Member Functions

 CmpInst (const Type *ty, Instruction::OtherOps op, unsigned short pred, Value *LHS, Value *RHS, const std::string &Name="", Instruction *InsertBefore=0)
 CmpInst (const Type *ty, Instruction::OtherOps op, unsigned short pred, Value *LHS, Value *RHS, const std::string &Name, BasicBlock *InsertAtEnd)


Detailed Description

Abstract base class of comparison instructions.

This class is the base class for the comparison instructions.

Definition at line 1085 of file InstrTypes.h.


Member Enumeration Documentation

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.

Enumerator:
FCMP_FALSE 
FCMP_OEQ  0 0 0 0 Always false (always folded)
FCMP_OGT  0 0 0 1 True if ordered and equal
FCMP_OGE  0 0 1 0 True if ordered and greater than
FCMP_OLT  0 0 1 1 True if ordered and greater than or equal
FCMP_OLE  0 1 0 0 True if ordered and less than
FCMP_ONE  0 1 0 1 True if ordered and less than or equal
FCMP_ORD  0 1 1 0 True if ordered and operands are unequal
FCMP_UNO  0 1 1 1 True if ordered (no nans)
FCMP_UEQ  1 0 0 0 True if unordered: isnan(X) | isnan(Y)
FCMP_UGT  1 0 0 1 True if unordered or equal
FCMP_UGE  1 0 1 0 True if unordered or greater than
FCMP_ULT  1 0 1 1 True if unordered, greater than, or equal
FCMP_ULE  1 1 0 0 True if unordered or less than
FCMP_UNE  1 1 0 1 True if unordered, less than, or equal
FCMP_TRUE  1 1 1 0 True if unordered or not equal
FIRST_FCMP_PREDICATE  1 1 1 1 Always true (always folded)
LAST_FCMP_PREDICATE 
BAD_FCMP_PREDICATE 
ICMP_EQ 
ICMP_NE  equal
ICMP_UGT  not equal
ICMP_UGE  unsigned greater than
ICMP_ULT  unsigned greater or equal
ICMP_ULE  unsigned less than
ICMP_SGT  unsigned less or equal
ICMP_SGE  signed greater than
ICMP_SLT  signed greater or equal
ICMP_SLE  signed less than
FIRST_ICMP_PREDICATE  signed less or equal
LAST_ICMP_PREDICATE 
BAD_ICMP_PREDICATE 

Definition at line 1102 of file InstrTypes.h.


Constructor & Destructor Documentation

CmpInst::CmpInst ( const Type *  ty,
Instruction::OtherOps  op,
unsigned short  pred,
Value *  LHS,
Value *  RHS,
const std::string &  Name = "",
Instruction *  InsertBefore = 0 
) [protected]

Definition at line 2469 of file Instructions.cpp.

References llvm::Value::setName().

CmpInst::CmpInst ( const Type *  ty,
Instruction::OtherOps  op,
unsigned short  pred,
Value *  LHS,
Value *  RHS,
const std::string &  Name,
BasicBlock *  InsertAtEnd 
) [protected]

Definition at line 2482 of file Instructions.cpp.

References llvm::Value::setName().


Member Function Documentation

void* llvm::CmpInst::operator new ( size_t  s  )  [inline]

Reimplemented from llvm::User.

Definition at line 1139 of file InstrTypes.h.

CmpInst * CmpInst::Create ( OtherOps  Op,
unsigned short  predicate,
Value *  S1,
Value *  S2,
const std::string &  Name = "",
Instruction *  InsertBefore = 0 
) [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 2496 of file Instructions.cpp.

References FCmp, and VICmp.

Referenced by OptimizeCmpExpression().

CmpInst * CmpInst::Create ( OtherOps  Op,
unsigned short  predicate,
Value *  S1,
Value *  S2,
const std::string &  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 2515 of file Instructions.cpp.

References FCmp, and VICmp.

OtherOps llvm::CmpInst::getOpcode (  )  const [inline]

Get the opcode casted to the right type.

Reimplemented from llvm::Instruction.

Definition at line 1160 of file InstrTypes.h.

Referenced by dyn_castFoldableMul(), getOpcode(), and OptimizeCmpExpression().

Predicate llvm::CmpInst::getPredicate (  )  const [inline]

void llvm::CmpInst::setPredicate ( Predicate  P  )  [inline]

Set the predicate for this instruction to the specified value.

Definition at line 1168 of file InstrTypes.h.

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.

Returns:
the inverse predicate for the instruction's current predicate.

Definition at line 1174 of file InstrTypes.h.

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.

Returns:
the inverse predicate for predicate provided in pred.

Definition at line 2553 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, and ICMP_ULT.

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.

Returns:
the predicate that would be the result of exchanging the two operands of the CmpInst instruction without changing the result produced.

Definition at line 1190 of file InstrTypes.h.

Referenced by llvm::ConstantFoldCompareInstruction(), evaluateFCmpRelation(), and evaluateICmpRelation().

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 2658 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, and ICMP_ULT.

llvm::CmpInst::DECLARE_TRANSPARENT_OPERAND_ACCESSORS ( Value   ) 

Provide more efficient getOperand methods.

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::ICmpInst, and llvm::FCmpInst.

Definition at line 2533 of file Instructions.cpp.

References IC.

bool CmpInst::isCommutative (  ) 

Determine if this CmpInst is commutative.

This is just a convenience that dispatches to the subclasses.

Definition at line 2540 of file Instructions.cpp.

References IC.

bool CmpInst::isEquality (  ) 

Determine if this is an equals/not equals predicate.

This is just a convenience that dispatches to the subclasses.

Definition at line 2546 of file Instructions.cpp.

References IC.

bool CmpInst::isUnsigned ( unsigned short  predicate  )  [static]

Determine if the predicate is an unsigned operation.

Returns:
true if the predicate is unsigned, false otherwise.

Definition at line 2688 of file Instructions.cpp.

References ICMP_UGE, ICMP_UGT, ICMP_ULE, and ICMP_ULT.

bool CmpInst::isSigned ( unsigned short  predicate  )  [static]

Determine if the predicate is an signed operation.

Returns:
true if the predicate is signed, false otherwise.

Definition at line 2696 of file Instructions.cpp.

References ICMP_SGE, ICMP_SGT, ICMP_SLE, and ICMP_SLT.

Referenced by llvm::ConstantFoldCompareInstruction().

bool CmpInst::isOrdered ( unsigned short  predicate  )  [static]

Determine if the predicate is an ordered operation.

Definition at line 2704 of file Instructions.cpp.

References FCMP_OEQ, FCMP_OGE, FCMP_OGT, FCMP_OLE, FCMP_OLT, FCMP_ONE, and FCMP_ORD.

bool CmpInst::isUnordered ( unsigned short  predicate  )  [static]

Determine if the predicate is an unordered operation.

Definition at line 2713 of file Instructions.cpp.

References FCMP_UEQ, FCMP_UGE, FCMP_UGT, FCMP_ULE, FCMP_ULT, FCMP_UNE, and FCMP_UNO.

static bool llvm::CmpInst::classof ( const CmpInst *   )  [inline, static]

Methods for support type inquiry through isa, cast, and dyn_cast:.

Definition at line 1230 of file InstrTypes.h.

static bool llvm::CmpInst::classof ( const Instruction *   )  [inline, static]

Methods for support type inquiry through isa, cast, and dyn_cast:.

Reimplemented from llvm::Instruction.

Reimplemented in llvm::ICmpInst, llvm::FCmpInst, llvm::VICmpInst, and llvm::VFCmpInst.

Definition at line 1231 of file InstrTypes.h.

static bool llvm::CmpInst::classof ( const Value *  V  )  [inline, static]

Reimplemented from llvm::Instruction.

Reimplemented in llvm::ICmpInst, llvm::FCmpInst, llvm::VICmpInst, and llvm::VFCmpInst.

Definition at line 1237 of file InstrTypes.h.

static const Type* llvm::CmpInst::makeCmpResultType ( const Type *  opnd_type  )  [inline, static]

Create a result type for fcmp/icmp (but not vicmp/vfcmp).

Definition at line 1241 of file InstrTypes.h.


The documentation for this class was generated from the following files: