16 #ifndef LLVM_IR_INSTRTYPES_H
17 #define LLVM_IR_INSTRTYPES_H
38 Use *Ops,
unsigned NumOps,
40 :
Instruction(Ty, iType, Ops, NumOps, InsertBefore) {}
44 :
Instruction(Ty, iType, Ops, NumOps, InsertAtEnd) {}
76 return isa<Instruction>(V) &&
classof(cast<Instruction>(V));
86 void *
operator new(size_t,
unsigned) =
delete;
100 void *
operator new(
size_t s) {
101 return User::operator
new(s, 1);
112 return I->
getOpcode() == Instruction::Alloca ||
115 I->
getOpcode() == Instruction::ExtractValue ||
119 return isa<Instruction>(V) &&
classof(cast<Instruction>(V));
135 void *
operator new(size_t,
unsigned) =
delete;
139 const Twine &
Name, Instruction *InsertBefore);
144 friend class Instruction;
149 void *
operator new(
size_t s) {
150 return User::operator
new(s, 2);
163 Instruction *InsertBefore =
nullptr);
175 #define HANDLE_BINARY_INST(N, OPC, CLASS) \
176 static BinaryOperator *Create##OPC(Value *V1, Value *V2, \
177 const Twine &Name = "") {\
178 return Create(Instruction::OPC, V1, V2, Name);\
180 #include "llvm/IR/Instruction.def"
181 #define HANDLE_BINARY_INST(N, OPC, CLASS) \
182 static BinaryOperator *Create##OPC(Value *V1, Value *V2, \
183 const Twine &Name, BasicBlock *BB) {\
184 return Create(Instruction::OPC, V1, V2, Name, BB);\
186 #include "llvm/IR/Instruction.def"
187 #define HANDLE_BINARY_INST(N, OPC, CLASS) \
188 static BinaryOperator *Create##OPC(Value *V1, Value *V2, \
189 const Twine &Name, Instruction *I) {\
190 return Create(Instruction::OPC, V1, V2, Name, I);\
192 #include "llvm/IR/Instruction.def"
195 const Twine &Name =
"") {
207 const Twine &Name, Instruction *
I) {
214 const Twine &Name =
"") {
226 const Twine &Name, Instruction *
I) {
233 const Twine &Name =
"") {
245 const Twine &Name, Instruction *
I) {
251 #define DEFINE_HELPERS(OPC, NUWNSWEXACT) \
252 static BinaryOperator *Create ## NUWNSWEXACT ## OPC \
253 (Value *V1, Value *V2, const Twine &Name = "") { \
254 return Create ## NUWNSWEXACT(Instruction::OPC, V1, V2, Name); \
256 static BinaryOperator *Create ## NUWNSWEXACT ## OPC \
257 (Value *V1, Value *V2, const Twine &Name, BasicBlock *BB) { \
258 return Create ## NUWNSWEXACT(Instruction::OPC, V1, V2, Name, BB); \
260 static BinaryOperator *Create ## NUWNSWEXACT ## OPC \
261 (Value *V1, Value *V2, const Twine &Name, Instruction *I) { \
262 return Create ## NUWNSWEXACT(Instruction::OPC, V1, V2, Name, I); \
279 #undef DEFINE_HELPERS
286 static BinaryOperator *
CreateNeg(Value *Op,
const Twine &Name =
"",
287 Instruction *InsertBefore =
nullptr);
288 static BinaryOperator *
CreateNeg(Value *Op,
const Twine &Name,
290 static BinaryOperator *CreateNSWNeg(Value *Op,
const Twine &Name =
"",
291 Instruction *InsertBefore =
nullptr);
292 static BinaryOperator *CreateNSWNeg(Value *Op,
const Twine &Name,
294 static BinaryOperator *CreateNUWNeg(Value *Op,
const Twine &Name =
"",
295 Instruction *InsertBefore =
nullptr);
296 static BinaryOperator *CreateNUWNeg(Value *Op,
const Twine &Name,
298 static BinaryOperator *CreateFNeg(Value *Op,
const Twine &Name =
"",
299 Instruction *InsertBefore =
nullptr);
300 static BinaryOperator *CreateFNeg(Value *Op,
const Twine &Name,
302 static BinaryOperator *CreateNot(Value *Op,
const Twine &Name =
"",
303 Instruction *InsertBefore =
nullptr);
304 static BinaryOperator *CreateNot(Value *Op,
const Twine &Name,
309 static bool isNeg(
const Value *V);
310 static bool isFNeg(
const Value *V,
bool IgnoreZeroSign=
false);
311 static bool isNot(
const Value *V);
316 static const Value *getNegArgument(
const Value *BinOp);
317 static Value *getNegArgument( Value *BinOp);
318 static const Value *getFNegArgument(
const Value *BinOp);
319 static Value *getFNegArgument( Value *BinOp);
320 static const Value *getNotArgument(
const Value *BinOp);
321 static Value *getNotArgument( Value *BinOp);
336 void setHasNoUnsignedWrap(
bool b =
true);
340 void setHasNoSignedWrap(
bool b =
true);
344 void setIsExact(
bool b =
true);
347 bool hasNoUnsignedWrap()
const;
350 bool hasNoSignedWrap()
const;
353 bool isExact()
const;
357 void copyIRFlags(
const Value *V);
361 void andIRFlags(
const Value *V);
368 return isa<Instruction>(V) && classof(cast<Instruction>(V));
390 void anchor()
override;
394 const Twine &NameStr =
"", Instruction *InsertBefore =
nullptr)
395 : UnaryInstruction(Ty, iType, S, InsertBefore) {
401 : UnaryInstruction(Ty, iType, S, InsertAtEnd) {
415 const Twine &Name =
"",
416 Instruction *InsertBefore =
nullptr
433 static CastInst *CreateZExtOrBitCast(
436 const Twine &Name =
"",
437 Instruction *InsertBefore =
nullptr
441 static CastInst *CreateZExtOrBitCast(
449 static CastInst *CreateSExtOrBitCast(
452 const Twine &Name =
"",
453 Instruction *InsertBefore =
nullptr
457 static CastInst *CreateSExtOrBitCast(
476 const Twine &Name =
"",
477 Instruction *InsertBefore =
nullptr
481 static CastInst *CreatePointerBitCastOrAddrSpaceCast(
489 static CastInst *CreatePointerBitCastOrAddrSpaceCast(
492 const Twine &Name =
"",
493 Instruction *InsertBefore = 0
502 static CastInst *CreateBitOrPointerCast(
505 const Twine &Name =
"",
506 Instruction *InsertBefore = 0
514 const Twine &Name =
"",
515 Instruction *InsertBefore =
nullptr
531 const Twine &Name =
"",
532 Instruction *InsertBefore =
nullptr
544 static CastInst *CreateTruncOrBitCast(
547 const Twine &Name =
"",
548 Instruction *InsertBefore =
nullptr
552 static CastInst *CreateTruncOrBitCast(
560 static bool isCastable(
566 static bool isBitCastable(
576 static bool isBitOrNoopPointerCastable(
596 bool isIntegerCast()
const;
603 bool isLosslessCast()
const;
614 static bool isNoopCast(
669 return isa<Instruction>(V) && classof(cast<Instruction>(V));
680 void *
operator new(size_t,
unsigned) =
delete;
685 Instruction *InsertBefore =
nullptr);
734 void *
operator new(
size_t s) {
735 return User::operator
new(s, 2);
743 unsigned short predicate,
Value *S1,
745 Instruction *InsertBefore =
nullptr);
850 static bool isUnsigned(
unsigned short predicate);
854 static bool isSigned(
unsigned short predicate);
857 static bool isOrdered(
unsigned short predicate);
870 return I->
getOpcode() == Instruction::ICmp ||
874 return isa<Instruction>(V) &&
classof(cast<Instruction>(V));
879 if (
VectorType* vt = dyn_cast<VectorType>(opnd_type)) {
881 vt->getNumElements());
888 void setValueSubclassData(
unsigned short D) {
TerminatorInst(Type *Ty, Instruction::TermOps iType, Use *Ops, unsigned NumOps, Instruction *InsertBefore=nullptr)
A parsed version of the target data layout string in and methods for querying it. ...
Instruction::CastOps getOpcode() const
Return the opcode of this CastInst.
void setHasNoSignedWrap(bool b=true)
Set or clear the nsw flag on this instruction, which must be an operator which supports this flag...
This class is the base class for the comparison instructions.
static bool classof(const Instruction *I)
static IntegerType * getInt1Ty(LLVMContext &C)
static Type * makeCmpResultType(Type *opnd_type)
Create a result type for fcmp/icmp.
static BinaryOperator * CreateNUW(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name, Instruction *I)
static BinaryOperator * CreateExact(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name="")
static BinaryOperator * CreateNSW(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name, BasicBlock *BB)
UnaryInstruction(Type *Ty, unsigned iType, Value *V, BasicBlock *IAE)
static bool isOrdered(unsigned short predicate)
Determine if the predicate is an ordered operation.
Predicate getInversePredicate() const
For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Provide more efficient getOperand methods.
bool isSigned() const
Determine if this instruction is using a signed comparison.
0 1 0 0 True if ordered and less than
virtual unsigned getNumSuccessorsV() const =0
1 1 1 0 True if unordered or not equal
static bool classof(const Value *V)
FunctionType * getType(LLVMContext &Context, ID id, ArrayRef< Type * > Tys=None)
Return the function type for an intrinsic.
UnaryInstruction(Type *Ty, unsigned iType, Value *V, Instruction *IB=nullptr)
bool isEquality() const
This is just a convenience that dispatches to the subclasses.
static BinaryOperator * CreateNSW(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name, Instruction *I)
static BinaryOperator * CreateNSW(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name="")
1 0 0 1 True if unordered or equal
1 0 0 0 True if unordered: isnan(X) | isnan(Y)
unsigned getSubclassDataFromInstruction() const
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
This is the base class for all instructions that perform data casts.
static Instruction::CastOps isEliminableCastPair(const CastInst *CI, unsigned opcode, Type *DstTy, const DataLayout &DL)
This function is a wrapper around CastInst::isEliminableCastPair.
CastInst(Type *Ty, unsigned iType, Value *S, const Twine &NameStr, BasicBlock *InsertAtEnd)
Constructor with insert-at-end-of-block semantics for subclasses.
A Use represents the edge between a Value definition and its users.
void setHasNoUnsignedWrap(bool b=true)
Set or clear the nsw flag on this instruction, which must be an operator which supports this flag...
0 1 0 1 True if ordered and less than or equal
#define DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CLASS, VALUECLASS)
Macro for generating out-of-class operand accessor definitions.
LLVMContext & getContext() const
getContext - Return the LLVMContext in which this type was uniqued.
void setSuccessor(unsigned idx, BasicBlock *B)
Update the specified successor to point at the provided block.
void setInstructionSubclassData(unsigned short D)
virtual void setSuccessorV(unsigned idx, BasicBlock *B)=0
unsigned getNumSuccessors() const
Return the number of successors that this terminator has.
static bool classof(const Instruction *I)
Methods for support type inquiry through isa, cast, and dyn_cast:
initializer< Ty > init(const Ty &Val)
static bool isIntPredicate(Predicate P)
static CmpInst * Create(OtherOps Op, unsigned short predicate, Value *S1, Value *S2, const Twine &Name="", Instruction *InsertBefore=nullptr)
Construct a compare instruction, given the opcode, the predicate and the two operands.
Subclasses of this class are all able to terminate a basic block.
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
BasicBlock * getSuccessor(unsigned idx) const
Return the specified successor.
static BinaryOperator * CreateNUW(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name="")
bool isIntPredicate() const
~TerminatorInst() override
static BinaryOperator * CreateNUW(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name, BasicBlock *BB)
bool isFalseWhenEqual() const
This is just a convenience.
static BinaryOperator * CreateExact(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name, BasicBlock *BB)
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
0 1 1 1 True if ordered (no nans)
static bool classof(const Value *V)
Type * getSrcTy() const
Return the source type, as a convenience.
Predicate getPredicate() const
Return the predicate for this instruction.
static bool classof(const Instruction *I)
1 1 1 1 Always true (always folded)
#define DECLARE_TRANSPARENT_OPERAND_ACCESSORS(VALUECLASS)
Macro for generating in-class operand accessor declarations.
bool isCommutative() const
This is just a convenience that dispatches to the subclasses.
~UnaryInstruction() override
1 1 0 1 True if unordered, less than, or equal
void swapOperands()
This is just a convenience that dispatches to the subclasses.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
virtual BasicBlock * getSuccessorV(unsigned idx) const =0
Virtual methods - Terminators should overload these and provide inline overrides of non-V methods...
void setIsExact(bool b=true)
Set or clear the exact flag on this instruction, which must be an operator which supports this flag...
bool isTerminator() const
0 0 1 0 True if ordered and greater than
BinaryOps getOpcode() const
TerminatorInst(Type *Ty, Instruction::TermOps iType, Use *Ops, unsigned NumOps, BasicBlock *InsertAtEnd)
1 1 0 0 True if unordered or less than
CastInst(Type *Ty, unsigned iType, Value *S, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructor with insert-before-instruction semantics for subclasses.
bool isTrueWhenEqual() const
This is just a convenience.
Type * getDestTy() const
Return the destination type, as a convenience.
#define DEFINE_HELPERS(OPC, NUWNSWEXACT)
Predicate getSwappedPredicate() const
For example, EQ->EQ, SLE->SGE, ULT->UGT, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
void setValueSubclassData(unsigned short D)
void setPredicate(Predicate P)
Set the predicate for this instruction to the specified value.
VectorType - Class to represent vector types.
static bool isFPPredicate(Predicate P)
static BinaryOperator * CreateExact(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name, Instruction *I)
bool isFPPredicate() const
unsigned greater or equal
static bool classof(const Value *V)
0 1 1 0 True if ordered and operands are unequal
Compile-time customization of User operands.
static BinaryOperator * CreateNeg(Value *S1, const Twine &Name, Instruction *InsertBefore, Value *FlagsOp)
1 0 1 0 True if unordered or greater than
OtherOps getOpcode() const
Get the opcode casted to the right type.
static bool classof(const Value *V)
bool isUnsigned() const
Determine if this instruction is using an unsigned comparison.
0 0 0 1 True if ordered and equal
LLVM Value Representation.
1 0 1 1 True if unordered, greater than, or equal
unsigned getOpcode() const
getOpcode() returns a member of one of the enums like Instruction::Add.
static bool classof(const Value *V)
static VectorType * get(Type *ElementType, unsigned NumElements)
VectorType::get - This static method is the primary way to construct an VectorType.
static bool isUnordered(unsigned short predicate)
Determine if the predicate is an unordered operation.
FixedNumOperandTraits - determine the allocation regime of the Use array when it is a prefix to the U...
static bool classof(const Instruction *I)
0 0 1 1 True if ordered and greater than or equal
static bool classof(const Instruction *I)
Methods for support type inquiry through isa, cast, and dyn_cast:
0 0 0 0 Always false (always folded)