14#ifndef LLVM_IR_INSTRUCTION_H
15#define LLVM_IR_INSTRUCTION_H
48 mutable unsigned Order = 0;
60 template <
unsigned Offset>
65 template <
unsigned Offset>
68 template <
unsigned Offset>
100 return const_cast<Module *
>(
189 return Opcode >= TermOpsBegin && Opcode < TermOpsEnd;
193 return Opcode >= UnaryOpsBegin && Opcode < UnaryOpsEnd;
196 return Opcode >= BinaryOpsBegin && Opcode < BinaryOpsEnd;
200 return Opcode == UDiv || Opcode == SDiv || Opcode == URem || Opcode == SRem;
205 return Opcode >= Shl && Opcode <= AShr;
220 return Opcode ==
And || Opcode ==
Or || Opcode ==
Xor;
229 static inline bool isCast(
unsigned Opcode) {
230 return Opcode >= CastOpsBegin && Opcode < CastOpsEnd;
235 return Opcode >= FuncletPadOpsBegin && Opcode < FuncletPadOpsEnd;
241 case Instruction::CatchSwitch:
242 case Instruction::CatchRet:
243 case Instruction::CleanupRet:
244 case Instruction::Invoke:
245 case Instruction::Resume:
277 return getMetadataImpl(KindID);
284 return getMetadataImpl(Kind);
293 getAllMetadataImpl(MDs);
333 unsigned IDs[] = {ID1, ID2};
556 MDNode *getMetadataImpl(
unsigned KindID)
const;
557 MDNode *getMetadataImpl(StringRef Kind)
const;
559 getAllMetadataImpl(SmallVectorImpl<
std::pair<
unsigned, MDNode *>> &)
const;
563 void updateDIAssignIDMapping(DIAssignID *
ID);
578 return Opcode ==
And || Opcode ==
Or || Opcode ==
Xor ||
579 Opcode ==
Add || Opcode ==
Mul;
609 return Opcode ==
And || Opcode ==
Or;
623 return Opcode ==
Xor;
665 case Instruction::Fence:
666 case Instruction::CatchPad:
667 case Instruction::CatchRet:
668 case Instruction::Call:
669 case Instruction::Invoke:
702 case Instruction::CatchSwitch:
703 case Instruction::CatchPad:
704 case Instruction::CleanupPad:
705 case Instruction::LandingPad:
815 return V->getValueID() >= Value::InstructionVal;
822#define FIRST_TERM_INST(N) TermOpsBegin = N,
823#define HANDLE_TERM_INST(N, OPC, CLASS) OPC = N,
824#define LAST_TERM_INST(N) TermOpsEnd = N+1
825#include "llvm/IR/Instruction.def"
829#define FIRST_UNARY_INST(N) UnaryOpsBegin = N,
830#define HANDLE_UNARY_INST(N, OPC, CLASS) OPC = N,
831#define LAST_UNARY_INST(N) UnaryOpsEnd = N+1
832#include "llvm/IR/Instruction.def"
836#define FIRST_BINARY_INST(N) BinaryOpsBegin = N,
837#define HANDLE_BINARY_INST(N, OPC, CLASS) OPC = N,
838#define LAST_BINARY_INST(N) BinaryOpsEnd = N+1
839#include "llvm/IR/Instruction.def"
843#define FIRST_MEMORY_INST(N) MemoryOpsBegin = N,
844#define HANDLE_MEMORY_INST(N, OPC, CLASS) OPC = N,
845#define LAST_MEMORY_INST(N) MemoryOpsEnd = N+1
846#include "llvm/IR/Instruction.def"
850#define FIRST_CAST_INST(N) CastOpsBegin = N,
851#define HANDLE_CAST_INST(N, OPC, CLASS) OPC = N,
852#define LAST_CAST_INST(N) CastOpsEnd = N+1
853#include "llvm/IR/Instruction.def"
857#define FIRST_FUNCLETPAD_INST(N) FuncletPadOpsBegin = N,
858#define HANDLE_FUNCLETPAD_INST(N, OPC, CLASS) OPC = N,
859#define LAST_FUNCLETPAD_INST(N) FuncletPadOpsEnd = N+1
860#include "llvm/IR/Instruction.def"
864#define FIRST_OTHER_INST(N) OtherOpsBegin = N,
865#define HANDLE_OTHER_INST(N, OPC, CLASS) OPC = N,
866#define LAST_OTHER_INST(N) OtherOpsEnd = N+1
867#include "llvm/IR/Instruction.def"
876 void setValueSubclassData(
unsigned short D) {
880 unsigned short getSubclassDataFromValue()
const {
890 template <
typename BitfieldElement>
893 std::is_same<BitfieldElement, HasMetadataField>::value ||
894 !Bitfield::isOverlapping<BitfieldElement, HasMetadataField>(),
895 "Must not overlap with the metadata bit");
896 return Bitfield::get<BitfieldElement>(getSubclassDataFromValue());
899 template <
typename BitfieldElement>
902 std::is_same<BitfieldElement, HasMetadataField>::value ||
903 !Bitfield::isOverlapping<BitfieldElement, HasMetadataField>(),
904 "Must not overlap with the metadata bit");
905 auto Storage = getSubclassDataFromValue();
906 Bitfield::set<BitfieldElement>(Storage,
Value);
907 setValueSubclassData(Storage);
Atomic ordering constants.
This file implements methods to test, set and extract typed bits from packed unsigned integers.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
Machine Check Debug Module
Annotations lets you mark points and ranges inside source code, for tests:
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
LLVM Basic Block Representation.
BitfieldElement::Type getSubclassData() const
bool mayThrow(bool IncludePhaseOneUnwind=false) const LLVM_READONLY
Return true if this instruction may throw an exception.
Instruction * clone() const
Create a copy of 'this' instruction that is identical in all ways except the following:
void setHasNoUnsignedWrap(bool b=true)
Set or clear the nuw flag on this instruction, which must be an operator which supports this flag.
bool hasNoNaNs() const LLVM_READONLY
Determine whether the no-NaNs flag is set.
void removeFromParent()
This method unlinks 'this' from the containing basic block, but does not delete it.
bool hasNoUnsignedWrap() const LLVM_READONLY
Determine whether the no unsigned wrap flag is set.
bool hasNoInfs() const LLVM_READONLY
Determine whether the no-infs flag is set.
bool isLifetimeStartOrEnd() const LLVM_READONLY
Return true if the instruction is a llvm.lifetime.start or llvm.lifetime.end marker.
bool hasMetadata(unsigned KindID) const
Return true if this instruction has the given type of metadata attached.
static bool isBinaryOp(unsigned Opcode)
bool isArithmeticShift() const
Return true if this is an arithmetic shift right.
bool hasMetadata(StringRef Kind) const
Return true if this instruction has the given type of metadata attached.
void copyFastMathFlags(FastMathFlags FMF)
Convenience function for transferring all fast-math flag values to this instruction,...
bool isSameOperationAs(const Instruction *I, unsigned flags=0) const LLVM_READONLY
This function determines if the specified instruction executes the same operation as the current one.
void mergeDIAssignID(ArrayRef< const Instruction * > SourceInstructions)
Merge the DIAssignID metadata from this instruction and those attached to instructions in SourceInstr...
void setHasNoSignedZeros(bool B)
Set or clear the no-signed-zeros flag on this instruction, which must be an operator which supports t...
bool hasNoSignedZeros() const LLVM_READONLY
Determine whether the no-signed-zeros flag is set.
static bool isBitwiseLogicOp(unsigned Opcode)
Determine if the Opcode is and/or/xor.
bool mayReadOrWriteMemory() const
Return true if this instruction may read or write memory.
bool isDebugOrPseudoInst() const LLVM_READONLY
Return true if the instruction is a DbgInfoIntrinsic or PseudoProbeInst.
unsigned getNumSuccessors() const LLVM_READONLY
Return the number of successors that this instruction has.
static bool isShift(unsigned Opcode)
Determine if the Opcode is one of the shift instructions.
bool hasNoSignedWrap() const LLVM_READONLY
Determine whether the no signed wrap flag is set.
bool mayWriteToMemory() const LLVM_READONLY
Return true if this instruction may modify memory.
static bool isExceptionalTerminator(unsigned Opcode)
Returns true if the Opcode is a terminator related to exception handling.
void copyIRFlags(const Value *V, bool IncludeWrapFlags=true)
Convenience method to copy supported exact, fast-math, and (optionally) wrapping flags from V to this...
void setHasAllowContract(bool B)
Set or clear the allow-contract flag on this instruction, which must be an operator which supports th...
bool hasAtomicStore() const LLVM_READONLY
Return true if this atomic instruction stores to memory.
void setHasNoSignedWrap(bool b=true)
Set or clear the nsw flag on this instruction, which must be an operator which supports this flag.
typename Bitfield::Element< AtomicOrdering, Offset, 3, AtomicOrdering::LAST > AtomicOrderingBitfieldElementT
bool isOnlyUserOfAnyOperand()
It checks if this instruction is the only user of at least one of its operands.
void dropLocation()
Drop the instruction's debug location.
static bool isCast(unsigned Opcode)
Determine if the Opcode is one of the CastInst instructions.
void insertBefore(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified instruction.
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
void setAAMetadata(const AAMDNodes &N)
Sets the AA metadata on this instruction from the AAMDNodes structure.
void andIRFlags(const Value *V)
Logical 'and' of any supported wrapping, exact, and fast-math flags of V and this instruction.
void setHasNoNaNs(bool B)
Set or clear the no-nans flag on this instruction, which must be an operator which supports this flag...
bool isAssociative() const LLVM_READONLY
Return true if the instruction is associative:
const Instruction * getPrevNonDebugInstruction(bool SkipPseudoOp=false) const
Return a pointer to the previous non-debug instruction in the same basic block as 'this',...
bool extractProfTotalWeight(uint64_t &TotalVal) const
Retrieve total raw weight values of a branch.
Instruction & operator=(const Instruction &)=delete
void setHasApproxFunc(bool B)
Set or clear the approximate-math-functions flag on this instruction, which must be an operator which...
void moveAfter(Instruction *MovePos)
Unlink this instruction from its current basic block and insert it into the basic block that MovePos ...
bool hasMetadataOtherThanDebugLoc() const
Return true if this instruction has metadata attached to it other than a debug location.
bool isCommutative() const LLVM_READONLY
Return true if the instruction is commutative:
typename Bitfield::Element< bool, Offset, 1 > BoolBitfieldElementT
bool hasMetadata() const
Return true if this instruction has any metadata attached to it.
bool isAtomic() const LLVM_READONLY
Return true if this instruction has an AtomicOrdering of unordered or higher.
void setHasAllowReassoc(bool B)
Set or clear the reassociation flag on this instruction, which must be an operator which supports thi...
void setFastMathFlags(FastMathFlags FMF)
Convenience function for setting multiple fast-math flags on this instruction, which must be an opera...
bool isEHPad() const
Return true if the instruction is a variety of EH-block.
const BasicBlock * getParent() const
bool isFast() const LLVM_READONLY
Determine whether all fast-math-flags are set.
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
void replaceSuccessorWith(BasicBlock *OldBB, BasicBlock *NewBB)
Replace specified successor OldBB to point at the provided block.
Instruction * user_back()
Specialize the methods defined in Value, as we know that an instruction can only be used by other ins...
static bool isIdempotent(unsigned Opcode)
void addAnnotationMetadata(StringRef Annotation)
Adds an !annotation metadata node with Annotation to this instruction.
bool isExact() const LLVM_READONLY
Determine whether the exact flag is set.
bool isIdenticalToWhenDefined(const Instruction *I) const LLVM_READONLY
This is like isIdenticalTo, except that it ignores the SubclassOptionalData flags,...
const Function * getFunction() const
Return the function this instruction belongs to.
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
void swapProfMetadata()
If the instruction has "branch_weights" MD_prof metadata and the MDNode has three operands (including...
BasicBlock * getSuccessor(unsigned Idx) const LLVM_READONLY
Return the specified successor. This instruction must be a terminator.
bool mayHaveSideEffects() const LLVM_READONLY
Return true if the instruction may have side effects.
bool isFuncletPad() const
bool isTerminator() const
bool hasSameSpecialState(const Instruction *I2, bool IgnoreAlignment=false) const LLVM_READONLY
This function determines if the speficied instruction has the same "special" characteristics as the c...
bool hasAllowReciprocal() const LLVM_READONLY
Determine whether the allow-reciprocal flag is set.
bool comesBefore(const Instruction *Other) const
Given an instruction Other in the same basic block as this instruction, return true if this instructi...
void dropUBImplyingAttrsAndMetadata()
Drop any attributes or metadata that can cause immediate undefined behavior.
typename Bitfield::Element< unsigned, Offset, 6, Value::MaxAlignmentExponent > AlignmentBitfieldElementT
void dropUnknownNonDebugMetadata(unsigned ID1, unsigned ID2)
Instruction * getPrevNonDebugInstruction(bool SkipPseudoOp=false)
bool hasPoisonGeneratingFlags() const LLVM_READONLY
Return true if this operator has flags which may cause this instruction to evaluate to poison despite...
bool isNilpotent() const
Return true if the instruction is nilpotent:
bool mayReadFromMemory() const LLVM_READONLY
Return true if this instruction may read memory.
const Instruction * getNextNonDebugInstruction(bool SkipPseudoOp=false) const
Return a pointer to the next non-debug instruction in the same basic block as 'this',...
bool isUsedOutsideOfBlock(const BasicBlock *BB) const LLVM_READONLY
Return true if there are any uses of this instruction in blocks other than the specified block.
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
bool isVolatile() const LLVM_READONLY
Return true if this instruction has a volatile memory access.
void setHasNoInfs(bool B)
Set or clear the no-infs flag on this instruction, which must be an operator which supports this flag...
void setNoSanitizeMetadata()
Sets the nosanitize metadata on this instruction.
FastMathFlags getFastMathFlags() const LLVM_READONLY
Convenience function for getting all the fast-math flags, which must be an operator which supports th...
const char * getOpcodeName() const
const Instruction * user_back() const
void dropPoisonGeneratingFlagsAndMetadata()
Drops flags and metadata that may generate poison.
bool willReturn() const LLVM_READONLY
Return true if the instruction will return (unwinding is considered as a form of returning control fl...
bool hasApproxFunc() const LLVM_READONLY
Determine whether the approximate-math-functions flag is set.
OperationEquivalenceFlags
When checking for operation equivalence (using isSameOperationAs) it is sometimes useful to ignore ce...
@ CompareIgnoringAlignment
Check for equivalence ignoring load/store alignment.
@ CompareUsingScalarTypes
Check for equivalence treating a type and a vector of that type as equivalent.
MDNode * getMetadata(StringRef Kind) const
Get the metadata of given kind attached to this Instruction.
void getAllMetadata(SmallVectorImpl< std::pair< unsigned, MDNode * > > &MDs) const
Get all metadata attached to this Instruction.
bool isExceptionalTerminator() const
bool isLogicalShift() const
Return true if this is a logical shift left or a logical shift right.
AAMDNodes getAAMetadata() const
Returns the AA metadata for this instruction.
void getAllMetadataOtherThanDebugLoc(SmallVectorImpl< std::pair< unsigned, MDNode * > > &MDs) const
This does the same thing as getAllMetadata, except that it filters out the debug location.
static bool isFuncletPad(unsigned Opcode)
Determine if the Opcode is one of the FuncletPadInst instructions.
static bool isUnaryOp(unsigned Opcode)
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
bool hasAtomicLoad() const LLVM_READONLY
Return true if this atomic instruction loads from memory.
static bool isNilpotent(unsigned Opcode)
bool hasPoisonGeneratingFlagsOrMetadata() const
Return true if this instruction has poison-generating flags or metadata.
void dropUnknownNonDebugMetadata()
void setIsExact(bool b=true)
Set or clear the exact flag on this instruction, which must be an operator which supports this flag.
void dropPoisonGeneratingMetadata()
Drops metadata that may generate poison.
bool isBitwiseLogicOp() const
Return true if this is and/or/xor.
static bool isTerminator(unsigned Opcode)
Instruction * getInsertionPointAfterDef()
Get the first insertion point at which the result of this instruction is defined.
void setHasAllowReciprocal(bool B)
Set or clear the allow-reciprocal flag on this instruction, which must be an operator which supports ...
bool isFenceLike() const
Return true if this instruction behaves like a memory fence: it can load or store to memory location ...
void dropPoisonGeneratingFlags()
Drops flags that may cause this instruction to evaluate to poison despite having non-poison inputs.
void dropUBImplyingAttrsAndUnknownMetadata(ArrayRef< unsigned > KnownIDs={})
This function drops non-debug unknown metadata (through dropUnknownNonDebugMetadata).
bool isIdenticalTo(const Instruction *I) const LLVM_READONLY
Return true if the specified instruction is exactly identical to the current one.
SymbolTableList< Instruction >::iterator insertInto(BasicBlock *ParentBB, SymbolTableList< Instruction >::iterator It)
Inserts an unlinked instruction into ParentBB at position It and returns the iterator of the inserted...
bool isLaunderOrStripInvariantGroup() const LLVM_READONLY
Return true if the instruction is a llvm.launder.invariant.group or llvm.strip.invariant....
bool hasAllowContract() const LLVM_READONLY
Determine whether the allow-contract flag is set.
void updateLocationAfterHoist()
Updates the debug location given that the instruction has been hoisted from a block to a predecessor ...
bool hasPoisonGeneratingMetadata() const LLVM_READONLY
Return true if this instruction has poison-generating metadata.
void dropUnknownNonDebugMetadata(unsigned ID1)
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
Instruction(const Instruction &)=delete
void applyMergedLocation(DILocation *LocA, DILocation *LocB)
Merge 2 debug locations and apply it to the Instruction.
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
void setSuccessor(unsigned Idx, BasicBlock *BB)
Update the specified successor to point at the provided block.
static bool isIntDivRem(unsigned Opcode)
bool isIdempotent() const
Return true if the instruction is idempotent:
void copyMetadata(const Instruction &SrcInst, ArrayRef< unsigned > WL=ArrayRef< unsigned >())
Copy metadata from SrcInst to this instruction.
void setFast(bool B)
Set or clear all fast-math-flags on this instruction, which must be an operator which supports this f...
bool hasAllowReassoc() const LLVM_READONLY
Determine whether the allow-reassociation flag is set.
void insertAfter(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately after the specified instruction.
friend class BasicBlock
Various leaf nodes.
void moveBefore(Instruction *MovePos)
Unlink this instruction from its current basic block and insert it into the basic block that MovePos ...
bool isSafeToRemove() const LLVM_READONLY
Return true if the instruction can be removed if the result is unused.
void setSubclassData(typename BitfieldElement::Type Value)
A Module instance is used to store all the information related to an LLVM module.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
The instances of the Type class are immutable: once they are created, they are never changed.
A Use represents the edge between a Value definition and its users.
LLVM Value Representation.
unsigned short getSubclassDataFromValue() const
user_iterator user_begin()
bool hasMetadata() const
Return true if this value has any metadata attached to it.
void getAllMetadata(SmallVectorImpl< std::pair< unsigned, MDNode * > > &MDs) const
Appends all metadata attached to this value to MDs, sorting by KindID.
unsigned getValueID() const
Return an ID for the concrete type of this object.
void setValueSubclassData(unsigned short D)
static constexpr unsigned MaxAlignmentExponent
The maximum alignment for instructions.
Iterator for intrusive lists based on ilist_node.
An ilist node that can access its parent list.
This file defines the ilist_node class template, which is a convenient base class for creating classe...
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ BasicBlock
Various leaf nodes.
This is an optimization pass for GlobalISel generic memory operations.
AtomicOrdering
Atomic ordering for LLVM's memory model.
@ Or
Bitwise or logical OR of integers.
@ Mul
Product of integers.
@ Xor
Bitwise or logical XOR of integers.
@ And
Bitwise or logical AND of integers.
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
Describes an element of a Bitfield.
Use delete by default for iplist and ilist.
static void deleteNode(NodeTy *V)