Go to the documentation of this file.
14 #ifndef LLVM_IR_INSTRUCTION_H
15 #define LLVM_IR_INSTRUCTION_H
52 mutable unsigned Order = 0;
64 template <
unsigned Offset>
69 template <
unsigned Offset>
72 template <
unsigned Offset>
104 return const_cast<Module *
>(
180 return OpCode >= TermOpsBegin && OpCode < TermOpsEnd;
184 return Opcode >= UnaryOpsBegin && Opcode < UnaryOpsEnd;
187 return Opcode >= BinaryOpsBegin && Opcode < BinaryOpsEnd;
191 return Opcode == UDiv || Opcode == SDiv || Opcode == URem || Opcode == SRem;
196 return Opcode >= Shl && Opcode <= AShr;
211 return Opcode ==
And || Opcode ==
Or || Opcode ==
Xor;
220 static inline bool isCast(
unsigned OpCode) {
221 return OpCode >= CastOpsBegin && OpCode < CastOpsEnd;
226 return OpCode >= FuncletPadOpsBegin && OpCode < FuncletPadOpsEnd;
232 case Instruction::CatchSwitch:
233 case Instruction::CatchRet:
234 case Instruction::CleanupRet:
235 case Instruction::Invoke:
236 case Instruction::Resume:
246 case Instruction::IndirectBr:
247 case Instruction::CallBr:
279 return getMetadataImpl(KindID);
286 return getMetadataImpl(
Kind);
295 getAllMetadataImpl(MDs);
338 unsigned IDs[] = {ID1, ID2};
513 MDNode *getMetadataImpl(
unsigned KindID)
const;
516 getAllMetadataImpl(
SmallVectorImpl<std::pair<unsigned, MDNode *>> &)
const;
531 return Opcode ==
And || Opcode ==
Or || Opcode ==
Xor ||
532 Opcode == Add || Opcode ==
Mul;
562 return Opcode ==
And || Opcode ==
Or;
576 return Opcode ==
Xor;
611 case Instruction::Fence:
612 case Instruction::CatchPad:
613 case Instruction::CatchRet:
615 case Instruction::Invoke:
643 case Instruction::CatchSwitch:
644 case Instruction::CatchPad:
645 case Instruction::CleanupPad:
646 case Instruction::LandingPad:
741 return V->
getValueID() >= Value::InstructionVal;
748 #define FIRST_TERM_INST(N) TermOpsBegin = N,
749 #define HANDLE_TERM_INST(N, OPC, CLASS) OPC = N,
750 #define LAST_TERM_INST(N) TermOpsEnd = N+1
751 #include "llvm/IR/Instruction.def"
755 #define FIRST_UNARY_INST(N) UnaryOpsBegin = N,
756 #define HANDLE_UNARY_INST(N, OPC, CLASS) OPC = N,
757 #define LAST_UNARY_INST(N) UnaryOpsEnd = N+1
758 #include "llvm/IR/Instruction.def"
762 #define FIRST_BINARY_INST(N) BinaryOpsBegin = N,
763 #define HANDLE_BINARY_INST(N, OPC, CLASS) OPC = N,
764 #define LAST_BINARY_INST(N) BinaryOpsEnd = N+1
765 #include "llvm/IR/Instruction.def"
769 #define FIRST_MEMORY_INST(N) MemoryOpsBegin = N,
770 #define HANDLE_MEMORY_INST(N, OPC, CLASS) OPC = N,
771 #define LAST_MEMORY_INST(N) MemoryOpsEnd = N+1
772 #include "llvm/IR/Instruction.def"
776 #define FIRST_CAST_INST(N) CastOpsBegin = N,
777 #define HANDLE_CAST_INST(N, OPC, CLASS) OPC = N,
778 #define LAST_CAST_INST(N) CastOpsEnd = N+1
779 #include "llvm/IR/Instruction.def"
783 #define FIRST_FUNCLETPAD_INST(N) FuncletPadOpsBegin = N,
784 #define HANDLE_FUNCLETPAD_INST(N, OPC, CLASS) OPC = N,
785 #define LAST_FUNCLETPAD_INST(N) FuncletPadOpsEnd = N+1
786 #include "llvm/IR/Instruction.def"
790 #define FIRST_OTHER_INST(N) OtherOpsBegin = N,
791 #define HANDLE_OTHER_INST(N, OPC, CLASS) OPC = N,
792 #define LAST_OTHER_INST(N) OtherOpsEnd = N+1
793 #include "llvm/IR/Instruction.def"
802 void setValueSubclassData(
unsigned short D) {
806 unsigned short getSubclassDataFromValue()
const {
816 template <
typename BitfieldElement>
819 std::is_same<BitfieldElement, HasMetadataField>::value ||
820 !Bitfield::isOverlapping<BitfieldElement, HasMetadataField>(),
821 "Must not overlap with the metadata bit");
822 return Bitfield::get<BitfieldElement>(getSubclassDataFromValue());
825 template <
typename BitfieldElement>
828 std::is_same<BitfieldElement, HasMetadataField>::value ||
829 !Bitfield::isOverlapping<BitfieldElement, HasMetadataField>(),
830 "Must not overlap with the metadata bit");
831 auto Storage = getSubclassDataFromValue();
832 Bitfield::set<BitfieldElement>(Storage,
Value);
833 setValueSubclassData(Storage);
852 #endif // LLVM_IR_INSTRUCTION_H
const Instruction * getPrevNonDebugInstruction(bool SkipPseudoOp=false) const
Return a pointer to the previous non-debug instruction in the same basic block as 'this',...
bool isTerminator() const
bool isAssociative() const LLVM_READONLY
Return true if the instruction is associative:
Instruction * getNextNonDebugInstruction(bool SkipPseudoOp=false)
This class represents lattice values for constants.
void replaceSuccessorWith(BasicBlock *OldBB, BasicBlock *NewBB)
Replace specified successor OldBB to point at the provided block.
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
@ Or
Bitwise or logical OR of integers.
static bool isBitwiseLogicOp(unsigned Opcode)
Determine if the Opcode is and/or/xor.
static bool isExceptionalTerminator(unsigned OpCode)
Returns true if the OpCode is a terminator related to exception handling.
const Instruction * getNextNonDebugInstruction(bool SkipPseudoOp=false) const
Return a pointer to the next non-debug instruction in the same basic block as 'this',...
unsigned short getSubclassDataFromValue() const
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
static bool isNilpotent(unsigned Opcode)
void getAllMetadataOtherThanDebugLoc(SmallVectorImpl< std::pair< unsigned, MDNode * >> &MDs) const
This does the same thing as getAllMetadata, except that it filters out the debug location.
void setHasAllowContract(bool B)
Set or clear the allow-contract flag on this instruction, which must be an operator which supports th...
An ilist node that can access its parent list.
BitfieldElement::Type getSubclassData() const
bool hasNoUnsignedWrap() const
Determine whether the no unsigned wrap flag is set.
void insertBefore(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified instruction.
bool hasAllowReciprocal() const
Determine whether the allow-reciprocal flag is set.
static bool isIndirectTerminator(unsigned OpCode)
Returns true if the OpCode is a terminator with indirect targets.
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
void dropUnknownNonDebugMetadata(unsigned ID1)
The instances of the Type class are immutable: once they are created, they are never changed.
Instruction * getPrevNonDebugInstruction(bool SkipPseudoOp=false)
void setSubclassData(typename BitfieldElement::Type Value)
bool hasApproxFunc() const
Determine whether the approximate-math-functions 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...
typename Bitfield::Element< unsigned, Offset, 5, Value::MaxAlignmentExponent > AlignmentBitfieldElementT
void setHasNoUnsignedWrap(bool b=true)
Set or clear the nuw flag on this instruction, which must be an operator which supports this flag.
bool mayThrow() const
Return true if this instruction may throw an exception.
user_iterator user_begin()
void copyMetadata(const Instruction &SrcInst, ArrayRef< unsigned > WL=ArrayRef< unsigned >())
Copy metadata from SrcInst to this instruction.
void setValueSubclassData(unsigned short D)
Convenience struct for specifying and reasoning about fast-math flags.
void setIsExact(bool b=true)
Set or clear the exact flag on this instruction, which must be an operator which supports this flag.
void dropUnknownNonDebugMetadata()
bool isExceptionalTerminator() const
bool hasMetadata(StringRef Kind) const
Return true if this instruction has the given type of metadata attached.
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
LLVM Basic Block Representation.
unsigned getNumSuccessors() const
Return the number of successors that this instruction has.
void insertAfter(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately after the specified instruction.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
bool willReturn() const
Return true if the instruction will return (unwinding is considered as a form of returning control fl...
bool extractProfTotalWeight(uint64_t &TotalVal) const
Retrieve total raw weight values of a branch.
bool isArithmeticShift() const
Return true if this is an arithmetic shift right.
@ And
Bitwise or logical AND of integers.
bool mayReadOrWriteMemory() const
Return true if this instruction may read or write memory.
void getAAMetadata(AAMDNodes &N, bool Merge=false) const
Fills the AAMDNodes structure with AA metadata from this instruction.
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< bool, Offset, 1 > BoolBitfieldElementT
bool isIdenticalToWhenDefined(const Instruction *I) const
This is like isIdenticalTo, except that it ignores the SubclassOptionalData flags,...
the resulting code requires compare and branches when and if the revised code is with conditional branches instead of More there is a byte word extend before each where there should be only and the condition codes are not remembered when the same two values are compared twice More LSR enhancements i8 and i32 load store addressing modes are identical int b
void applyMergedLocation(const DILocation *LocA, const DILocation *LocB)
Merge 2 debug locations and apply it to the Instruction.
static bool isShift(unsigned Opcode)
Determine if the Opcode is one of the shift instructions.
bool isNilpotent() const
Return true if the instruction is nilpotent:
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
unsigned getValueID() const
Return an ID for the concrete type of this object.
const char * getOpcodeName() const
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
void getAllMetadata(SmallVectorImpl< std::pair< unsigned, MDNode * >> &MDs) const
Get all metadata attached to this Instruction.
bool hasMetadata(unsigned KindID) const
Return true if this instruction has the given type of metadata attached.
BasicBlock * getSuccessor(unsigned Idx) const
Return the specified successor. This instruction must be a terminator.
void removeFromParent()
This method unlinks 'this' from the containing basic block, but does not delete it.
bool isSafeToRemove() const
Return true if the instruction can be removed if the result is unused.
bool mayWriteToMemory() const
Return true if this instruction may modify memory.
bool isLifetimeStartOrEnd() const
Return true if the instruction is a llvm.lifetime.start or llvm.lifetime.end marker.
bool extractProfMetadata(uint64_t &TrueVal, uint64_t &FalseVal) const
Retrieve the raw weight values of a conditional branch or select.
OperationEquivalenceFlags
When checking for operation equivalence (using isSameOperationAs) it is sometimes useful to ignore ce...
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
bool isCommutative() const LLVM_READONLY
Return true if the instruction is commutative:
void setHasNoNaNs(bool B)
Set or clear the no-nans flag on this instruction, which must be an operator which supports this flag...
bool hasAtomicLoad() const
Return true if this atomic instruction loads from memory.
typename Bitfield::Element< AtomicOrdering, Offset, 3, AtomicOrdering::LAST > AtomicOrderingBitfieldElementT
void andIRFlags(const Value *V)
Logical 'and' of any supported wrapping, exact, and fast-math flags of V and this instruction.
AtomicOrdering
Atomic ordering for LLVM's memory model.
static bool isTerminator(unsigned OpCode)
void addAnnotationMetadata(StringRef Annotation)
Adds an !annotation metadata node with Annotation to this instruction.
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
bool isLogicalShift() const
Return true if this is a logical shift left or a logical shift right.
void setFast(bool B)
Set or clear all fast-math-flags on this instruction, which must be an operator which supports this f...
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
bool hasAllowContract() const
Determine whether the allow-contract flag is set.
Instruction * user_back()
Specialize the methods defined in Value, as we know that an instruction can only be used by other ins...
bool isIdenticalTo(const Instruction *I) const
Return true if the specified instruction is exactly identical to the current one.
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
void moveAfter(Instruction *MovePos)
Unlink this instruction from its current basic block and insert it into the basic block that MovePos ...
bool isFenceLike() const
Return true if this instruction behaves like a memory fence: it can load or store to memory location ...
bool hasAtomicStore() const
Return true if this atomic instruction stores to memory.
Use delete by default for iplist and ilist.
void updateLocationAfterHoist()
Updates the debug location given that the instruction has been hoisted from a block to a predecessor ...
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
bool isIdempotent() const
Return true if the instruction is idempotent:
void dropLocation()
Drop the instruction's debug location.
bool mayHaveSideEffects() const
Return true if the instruction may have side effects.
bool hasMetadata() const
Return true if this instruction has any metadata attached to it.
bool isFast() const
Determine whether all fast-math-flags are set.
@ BasicBlock
Various leaf nodes.
A Module instance is used to store all the information related to an LLVM module.
Instruction * clone() const
Create a copy of 'this' instruction that is identical in all ways except the following:
FastMathFlags getFastMathFlags() const
Convenience function for getting all the fast-math flags, which must be an operator which supports th...
List that automatically updates parent links and symbol tables.
StringRef - Represent a constant reference to a string, i.e.
void setSuccessor(unsigned Idx, BasicBlock *BB)
Update the specified successor to point at the provided block.
const Function * getFunction() const
Return the function this instruction belongs to.
bool isExact() const
Determine whether the exact flag is set.
@ Mul
Product of integers.
Machine Check Debug Module
void copyFastMathFlags(FastMathFlags FMF)
Convenience function for transferring all fast-math flag values to this instruction,...
const Instruction * user_back() const
bool mayReadFromMemory() const
Return true if this instruction may read memory.
Instruction & operator=(const Instruction &)=delete
static bool isBinaryOp(unsigned Opcode)
void setFastMathFlags(FastMathFlags FMF)
Convenience function for setting multiple fast-math flags on this instruction, which must be an opera...
bool isAtomic() const
Return true if this instruction has an AtomicOrdering of unordered or higher.
static bool isFuncletPad(unsigned OpCode)
Determine if the OpCode is one of the FuncletPadInst instructions.
void setHasApproxFunc(bool B)
Set or clear the approximate-math-functions flag on this instruction, which must be an operator which...
@ CompareIgnoringAlignment
Check for equivalence ignoring load/store alignment.
Instruction(const Instruction &)=delete
bool isUsedOutsideOfBlock(const BasicBlock *BB) const
Return true if there are any uses of this instruction in blocks other than the specified block.
bool isFuncletPad() const
void dropUnknownNonDebugMetadata(unsigned ID1, unsigned ID2)
static const unsigned MaxAlignmentExponent
The maximum alignment for instructions.
void setAAMetadata(const AAMDNodes &N)
Sets the metadata on this instruction from the AAMDNodes structure.
static bool isIntDivRem(unsigned Opcode)
bool isEHPad() const
Return true if the instruction is a variety of EH-block.
Describes an element of a Bitfield.
static bool isUnaryOp(unsigned Opcode)
bool isBitwiseLogicOp() const
Return true if this is and/or/xor.
bool hasAllowReassoc() const
Determine whether the allow-reassociation flag is set.
bool isDebugOrPseudoInst() const
Return true if the instruction is a DbgInfoIntrinsic or PseudoProbeInst.
bool hasNoNaNs() const
Determine whether the no-NaNs flag is set.
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
void setHasAllowReciprocal(bool B)
Set or clear the allow-reciprocal flag on this instruction, which must be an operator which supports ...
MDNode * getMetadata(StringRef Kind) const
Get the metadata of given kind attached to this Instruction.
static bool isIdempotent(unsigned Opcode)
void setHasNoInfs(bool B)
Set or clear the no-infs flag on this instruction, which must be an operator which supports this flag...
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
static void deleteNode(NodeTy *V)
void setHasNoSignedZeros(bool B)
Set or clear the no-signed-zeros flag on this instruction, which must be an operator which supports t...
bool hasNoSignedWrap() const
Determine whether the no signed wrap flag is set.
const BasicBlock * getParent() const
void deleteValue()
Delete a pointer to a generic Value.
@ CompareUsingScalarTypes
Check for equivalence treating a type and a vector of that type as equivalent.
void swapProfMetadata()
If the instruction has "branch_weights" MD_prof metadata and the MDNode has three operands (including...
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 getAllMetadata(SmallVectorImpl< std::pair< unsigned, MDNode * >> &MDs) const
Appends all metadata attached to this value to MDs, sorting by KindID.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Type
MessagePack types as defined in the standard, with the exception of Integer being divided into a sign...
bool hasNoInfs() const
Determine whether the no-infs flag is set.
bool hasNoSignedZeros() const
Determine whether the no-signed-zeros flag is set.
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM BB
bool isSameOperationAs(const Instruction *I, unsigned flags=0) const
This function determines if the specified instruction executes the same operation as the current one.
bool hasMetadata() const
Return true if this value has any metadata attached to it.
LLVM Value Representation.
void setHasAllowReassoc(bool B)
Set or clear the reassociation flag on this instruction, which must be an operator which supports thi...
void dropPoisonGeneratingFlags()
Drops flags that may cause this instruction to evaluate to poison despite having non-poison inputs.
bool isIndirectTerminator() const
friend class BasicBlock
Various leaf nodes.
@ Xor
Bitwise or logical XOR of integers.
void moveBefore(Instruction *MovePos)
Unlink this instruction from its current basic block and insert it into the basic block that MovePos ...
A Use represents the edge between a Value definition and its users.
bool hasMetadataOtherThanDebugLoc() const
Return true if this instruction has metadata attached to it other than a debug location.
static bool isCast(unsigned OpCode)
Determine if the OpCode is one of the CastInst instructions.