15 #ifndef LLVM_IR_INSTRUCTION_H
16 #define LLVM_IR_INSTRUCTION_H
47 HasMetadataBit = 1 << 15
123 return OpCode >= TermOpsBegin && OpCode < TermOpsEnd;
127 return Opcode >= BinaryOpsBegin && Opcode < BinaryOpsEnd;
132 return Opcode >= Shl && Opcode <= AShr;
151 static inline bool isCast(
unsigned OpCode) {
152 return OpCode >= CastOpsBegin && OpCode < CastOpsEnd;
157 return OpCode >= FuncletPadOpsBegin && OpCode < FuncletPadOpsEnd;
165 bool hasMetadata()
const {
return DbgLoc || hasMetadataHashEntry(); }
170 return hasMetadataHashEntry();
177 return getMetadataImpl(KindID);
184 return getMetadataImpl(Kind);
193 getAllMetadataImpl(MDs);
201 getAllMetadataOtherThanDebugLocImpl(MDs);
237 unsigned IDs[] = {ID1, ID2};
350 bool hasMetadataHashEntry()
const {
351 return (getSubclassDataFromValue() & HasMetadataBit) != 0;
355 MDNode *getMetadataImpl(
unsigned KindID)
const;
356 MDNode *getMetadataImpl(StringRef
Kind)
const;
358 getAllMetadataImpl(SmallVectorImpl<std::pair<unsigned, MDNode *>> &)
const;
359 void getAllMetadataOtherThanDebugLocImpl(
360 SmallVectorImpl<std::pair<unsigned, MDNode *>> &)
const;
362 void clearMetadataHashEntries();
435 case Instruction::Fence:
436 case Instruction::CatchPad:
437 case Instruction::CatchRet:
439 case Instruction::Invoke:
455 case Instruction::CatchSwitch:
456 case Instruction::CatchPad:
457 case Instruction::CleanupPad:
458 case Instruction::LandingPad:
510 return V->
getValueID() >= Value::InstructionVal;
517 #define FIRST_TERM_INST(N) TermOpsBegin = N,
518 #define HANDLE_TERM_INST(N, OPC, CLASS) OPC = N,
519 #define LAST_TERM_INST(N) TermOpsEnd = N+1
520 #include "llvm/IR/Instruction.def"
524 #define FIRST_BINARY_INST(N) BinaryOpsBegin = N,
525 #define HANDLE_BINARY_INST(N, OPC, CLASS) OPC = N,
526 #define LAST_BINARY_INST(N) BinaryOpsEnd = N+1
527 #include "llvm/IR/Instruction.def"
531 #define FIRST_MEMORY_INST(N) MemoryOpsBegin = N,
532 #define HANDLE_MEMORY_INST(N, OPC, CLASS) OPC = N,
533 #define LAST_MEMORY_INST(N) MemoryOpsEnd = N+1
534 #include "llvm/IR/Instruction.def"
538 #define FIRST_CAST_INST(N) CastOpsBegin = N,
539 #define HANDLE_CAST_INST(N, OPC, CLASS) OPC = N,
540 #define LAST_CAST_INST(N) CastOpsEnd = N+1
541 #include "llvm/IR/Instruction.def"
545 #define FIRST_FUNCLETPAD_INST(N) FuncletPadOpsBegin = N,
546 #define HANDLE_FUNCLETPAD_INST(N, OPC, CLASS) OPC = N,
547 #define LAST_FUNCLETPAD_INST(N) FuncletPadOpsEnd = N+1
548 #include "llvm/IR/Instruction.def"
552 #define FIRST_OTHER_INST(N) OtherOpsBegin = N,
553 #define HANDLE_OTHER_INST(N, OPC, CLASS) OPC = N,
554 #define LAST_OTHER_INST(N) OtherOpsEnd = N+1
555 #include "llvm/IR/Instruction.def"
563 void setValueSubclassData(
unsigned short D) {
567 unsigned short getSubclassDataFromValue()
const {
571 void setHasMetadataHashEntry(
bool V) {
572 setValueSubclassData((getSubclassDataFromValue() & ~HasMetadataBit) |
573 (V ? HasMetadataBit : 0));
584 assert((D & HasMetadataBit) == 0 &&
"Out of range value put into field");
585 setValueSubclassData((getSubclassDataFromValue() & HasMetadataBit) | D);
589 return getSubclassDataFromValue() & ~HasMetadataBit;
604 #endif // LLVM_IR_INSTRUCTION_H
bool isArithmeticShift() const
Return true if this is an arithmetic shift right.
bool isNilpotent() const
Return true if the instruction is nilpotent:
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
void copyFastMathFlags(FastMathFlags FMF)
Convenience function for transferring all fast-math flag values to this instruction, which must be an operator which supports these flags.
void setFastMathFlags(FastMathFlags FMF)
Convenience function for setting multiple fast-math flags on this instruction, which must be an opera...
bool isFenceLike() const
Return true if this instruction behaves like a memory fence: it can load or store to memory location ...
A Module instance is used to store all the information related to an LLVM module. ...
void setHasNoNaNs(bool B)
Set or clear the no-nans flag on this instruction, which must be an operator which supports this flag...
bool isUsedOutsideOfBlock(const BasicBlock *BB) const
Return true if there are any uses of this instruction in blocks other than the specified block...
bool mayHaveSideEffects() const
Return true if the instruction may have side effects.
FastMathFlags getFastMathFlags() const
Convenience function for getting all the fast-math flags, which must be an operator which supports th...
void getAllMetadata(SmallVectorImpl< std::pair< unsigned, MDNode * >> &MDs) const
Get all metadata attached to this Instruction.
void copyIRFlags(const Value *V)
Convenience method to copy supported wrapping, exact, and fast-math flags from V to this instruction...
bool hasNoNaNs() const
Determine whether the no-NaNs flag is set.
static bool isShift(unsigned Opcode)
Determine if the Opcode is one of the shift instructions.
unsigned getSubclassDataFromInstruction() const
bool isIdenticalTo(const Instruction *I) const
Return true if the specified instruction is exactly identical to the current one. ...
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
A Use represents the edge between a Value definition and its users.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
static GCRegistry::Add< StatepointGC > D("statepoint-example","an example strategy for statepoint")
bool hasAllowReciprocal() const
Determine whether the allow-reciprocal flag is set.
Check for equivalence ignoring load/store alignment.
void dropUnknownNonDebugMetadata(unsigned ID1)
Instruction * clone() const
Create a copy of 'this' instruction that is identical in all ways except the following: ...
OperationEquivalenceFlags
When checking for operation equivalence (using isSameOperationAs) it is sometimes useful to ignore ce...
void setIsExact(bool b=true)
Set or clear the exact flag on this instruction, which must be an operator which supports this flag...
Check for equivalence treating a type and a vector of that type as equivalent.
bool mayReadFromMemory() const
Return true if this instruction may read memory.
void dropUnknownNonDebugMetadata()
bool isAssociative() const
Return true if the instruction is associative:
void andIRFlags(const Value *V)
Logical 'and' of any supported wrapping, exact, and fast-math flags of V and this instruction...
void setHasUnsafeAlgebra(bool B)
Set or clear the unsafe-algebra flag on this instruction, which must be an operator which supports th...
bool hasUnsafeAlgebra() const
Determine whether the unsafe-algebra flag is set.
static bool isBinaryOp(unsigned Opcode)
bool isLogicalShift() const
Return true if this is a logical shift left or a logical shift right.
static GCRegistry::Add< OcamlGC > B("ocaml","ocaml 3.10-compatible GC")
void setInstructionSubclassData(unsigned short D)
const Function * getFunction() const
Return the function this instruction belongs to.
const char * getOpcodeName() const
bool isAtomic() const
Return true if this instruction has an AtomicOrdering of unordered or higher.
bool mayReadOrWriteMemory() const
Return true if this instruction may read or write memory.
static bool isTerminator(unsigned OpCode)
An ilist node that can access its parent list.
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
bool isIdenticalToWhenDefined(const Instruction *I) const
This is like isIdenticalTo, except that it ignores the SubclassOptionalData flags, which may specify conditions under which the instruction's result is undefined.
void insertBefore(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified instruction...
void setAAMetadata(const AAMDNodes &N)
Sets the metadata on this instruction from the AAMDNodes structure.
LLVM Basic Block Representation.
bool isExact() const
Determine whether the exact flag is set.
The instances of the Type class are immutable: once they are created, they are never changed...
void getAllMetadataOtherThanDebugLoc(SmallVectorImpl< std::pair< unsigned, MDNode * >> &MDs) const
This does the same thing as getAllMetadata, except that it filters out the debug location.
APInt Or(const APInt &LHS, const APInt &RHS)
Bitwise OR function for APInt.
bool hasNoSignedWrap() const
Determine whether the no signed wrap flag is set.
APInt Xor(const APInt &LHS, const APInt &RHS)
Bitwise XOR function for APInt.
bool hasMetadata() const
Return true if this instruction has any metadata attached to it.
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
bool extractProfMetadata(uint64_t &TrueVal, uint64_t &FalseVal) const
Retrieve the raw weight values of a conditional branch or select.
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
unsigned getValueID() const
Return an ID for the concrete type of this object.
bool isCommutative() const
Return true if the instruction is commutative:
void setHasNoInfs(bool B)
Set or clear the no-infs flag on this instruction, which must be an operator which supports this flag...
void swapProfMetadata()
If the instruction has "branch_weights" MD_prof metadata and the MDNode has three operands (including...
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
bool mayWriteToMemory() const
Return true if this instruction may modify memory.
bool isTerminator() const
bool extractProfTotalWeight(uint64_t &TotalVal) const
Retrieve total raw weight values of a branch.
void setHasNoSignedWrap(bool b=true)
Set or clear the nsw flag on this instruction, which must be an operator which supports this flag...
static void Merge(const std::string &Input, const std::vector< std::string > Result, size_t NumNewFeatures)
bool hasNoUnsignedWrap() const
Determine whether the no unsigned wrap flag is set.
MDNode * getMetadata(StringRef Kind) const
Get the metadata of given kind attached to this Instruction.
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
Instruction * user_back()
Specialize the methods defined in Value, as we know that an instruction can only be used by other ins...
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
const Instruction * user_back() const
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
static bool isCast(unsigned OpCode)
Determine if the OpCode is one of the CastInst instructions.
void dropUnknownNonDebugMetadata(unsigned ID1, unsigned ID2)
void setValueSubclassData(unsigned short D)
APInt And(const APInt &LHS, const APInt &RHS)
Bitwise AND function for APInt.
void removeFromParent()
This method unlinks 'this' from the containing basic block, but does not delete it.
bool mayThrow() const
Return true if this instruction may throw an exception.
bool isEHPad() const
Return true if the instruction is a variety of EH-block.
bool isFuncletPad() const
List that automatically updates parent links and symbol tables.
unsigned short getSubclassDataFromValue() const
void getAAMetadata(AAMDNodes &N, bool Merge=false) const
Fills the AAMDNodes structure with AA metadata from this instruction.
bool isIdempotent() const
Return true if the instruction is idempotent:
void insertAfter(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately after the specified instruction...
bool hasNoInfs() const
Determine whether the no-infs flag is set.
bool hasNoSignedZeros() const
Determine whether the no-signed-zeros flag is set.
Instruction & operator=(const Instruction &)=delete
static bool isFuncletPad(unsigned OpCode)
Determine if the OpCode is one of the FuncletPadInst instructions.
Instruction(const Instruction &)=delete
bool hasMetadataOtherThanDebugLoc() const
Return true if this instruction has metadata attached to it other than a debug location.
void setHasNoUnsignedWrap(bool b=true)
Set or clear the nsw flag on this instruction, which must be an operator which supports this flag...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
user_iterator user_begin()
LLVM Value Representation.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
void copyMetadata(const Instruction &SrcInst, ArrayRef< unsigned > WL=ArrayRef< unsigned >())
Copy metadata from SrcInst to this instruction.
void moveBefore(Instruction *MovePos)
Unlink this instruction from its current basic block and insert it into the basic block that MovePos ...
Convenience struct for specifying and reasoning about fast-math flags.
StringRef - Represent a constant reference to a string, i.e.
bool isSameOperationAs(const Instruction *I, unsigned flags=0) const
This function determines if the specified instruction executes the same operation as the current one...
void setHasNoSignedZeros(bool B)
Set or clear the no-signed-zeros flag on this instruction, which must be an operator which supports t...
bool isBitwiseLogicOp() const
Return true if this is and/or/xor.
void setHasAllowReciprocal(bool B)
Set or clear the allow-reciprocal flag on this instruction, which must be an operator which supports ...
const BasicBlock * getParent() const