15 #ifndef LLVM_IR_INSTRUCTION_H
16 #define LLVM_IR_INSTRUCTION_H
51 HasMetadataBit = 1 << 15
76 return const_cast<Module *
>(
133 return OpCode >= TermOpsBegin && OpCode < TermOpsEnd;
137 return Opcode >= BinaryOpsBegin && Opcode < BinaryOpsEnd;
142 return Opcode >= Shl && Opcode <= AShr;
157 return Opcode == And || Opcode == Or || Opcode == Xor;
166 static inline bool isCast(
unsigned OpCode) {
167 return OpCode >= CastOpsBegin && OpCode < CastOpsEnd;
172 return OpCode >= FuncletPadOpsBegin && OpCode < FuncletPadOpsEnd;
180 bool hasMetadata()
const {
return DbgLoc || hasMetadataHashEntry(); }
185 return hasMetadataHashEntry();
192 return getMetadataImpl(KindID);
199 return getMetadataImpl(Kind);
208 getAllMetadataImpl(MDs);
216 getAllMetadataOtherThanDebugLocImpl(MDs);
252 unsigned IDs[] = {ID1, ID2};
378 bool hasMetadataHashEntry()
const {
379 return (getSubclassDataFromValue() & HasMetadataBit) != 0;
383 MDNode *getMetadataImpl(
unsigned KindID)
const;
384 MDNode *getMetadataImpl(StringRef
Kind)
const;
386 getAllMetadataImpl(SmallVectorImpl<std::pair<unsigned, MDNode *>> &)
const;
387 void getAllMetadataOtherThanDebugLocImpl(
388 SmallVectorImpl<std::pair<unsigned, MDNode *>> &)
const;
390 void clearMetadataHashEntries();
405 return Opcode == And || Opcode == Or || Opcode == Xor ||
406 Opcode ==
Add || Opcode == Mul;
421 case And:
case Or:
case Xor:
436 return Opcode == And || Opcode == Or;
450 return Opcode == Xor;
485 case Instruction::Fence:
486 case Instruction::CatchPad:
487 case Instruction::CatchRet:
489 case Instruction::Invoke:
505 case Instruction::CatchSwitch:
506 case Instruction::CatchPad:
507 case Instruction::CleanupPad:
508 case Instruction::LandingPad:
560 return V->
getValueID() >= Value::InstructionVal;
567 #define FIRST_TERM_INST(N) TermOpsBegin = N,
568 #define HANDLE_TERM_INST(N, OPC, CLASS) OPC = N,
569 #define LAST_TERM_INST(N) TermOpsEnd = N+1
570 #include "llvm/IR/Instruction.def"
574 #define FIRST_BINARY_INST(N) BinaryOpsBegin = N,
575 #define HANDLE_BINARY_INST(N, OPC, CLASS) OPC = N,
576 #define LAST_BINARY_INST(N) BinaryOpsEnd = N+1
577 #include "llvm/IR/Instruction.def"
581 #define FIRST_MEMORY_INST(N) MemoryOpsBegin = N,
582 #define HANDLE_MEMORY_INST(N, OPC, CLASS) OPC = N,
583 #define LAST_MEMORY_INST(N) MemoryOpsEnd = N+1
584 #include "llvm/IR/Instruction.def"
588 #define FIRST_CAST_INST(N) CastOpsBegin = N,
589 #define HANDLE_CAST_INST(N, OPC, CLASS) OPC = N,
590 #define LAST_CAST_INST(N) CastOpsEnd = N+1
591 #include "llvm/IR/Instruction.def"
595 #define FIRST_FUNCLETPAD_INST(N) FuncletPadOpsBegin = N,
596 #define HANDLE_FUNCLETPAD_INST(N, OPC, CLASS) OPC = N,
597 #define LAST_FUNCLETPAD_INST(N) FuncletPadOpsEnd = N+1
598 #include "llvm/IR/Instruction.def"
602 #define FIRST_OTHER_INST(N) OtherOpsBegin = N,
603 #define HANDLE_OTHER_INST(N, OPC, CLASS) OPC = N,
604 #define LAST_OTHER_INST(N) OtherOpsEnd = N+1
605 #include "llvm/IR/Instruction.def"
613 void setValueSubclassData(
unsigned short D) {
617 unsigned short getSubclassDataFromValue()
const {
621 void setHasMetadataHashEntry(
bool V) {
622 setValueSubclassData((getSubclassDataFromValue() & ~HasMetadataBit) |
623 (V ? HasMetadataBit : 0));
634 assert((D & HasMetadataBit) == 0 &&
"Out of range value put into field");
635 setValueSubclassData((getSubclassDataFromValue() & HasMetadataBit) | D);
639 return getSubclassDataFromValue() & ~HasMetadataBit;
658 #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 setProfWeight(uint64_t W)
Sets the branch_weights metadata to W for CallInst.
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.
void deleteValue()
Delete a pointer to a generic Value.
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, bool IncludeWrapFlags=true)
Convenience method to copy supported exact, fast-math, and (optionally) wrapping flags from V to this...
static bool isBitwiseLogicOp(unsigned Opcode)
Determine if the Opcode is and/or/xor.
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. ...
static bool isCommutative(unsigned Opcode)
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...
void dropPoisonGeneratingFlags()
Drops flags that may cause this instruction to evaluate to poison despite having non-poison inputs...
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 hasAllowContract() const
Determine whether the allow-contract flag is set.
bool hasAtomicLoad() const
Return true if this atomic instruction loads from memory.
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.
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)
Use delete by default for iplist and ilist.
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.
bool hasNoSignedWrap() const
Determine whether the no signed wrap flag is set.
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.
bool isAssociative() const LLVM_READONLY
Return true if the instruction is associative:
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)
static void deleteNode(NodeTy *V)
void setValueSubclassData(unsigned short D)
bool hasAtomicStore() const
Return true if this atomic instruction stores to memory.
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.
void updateProfWeight(uint64_t S, uint64_t T)
Updates branch_weights metadata by scaling it by S / T.
unsigned short getSubclassDataFromValue() const
static bool isNilpotent(unsigned Opcode)
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.
static bool isIdempotent(unsigned Opcode)
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