14#ifndef LLVM_IR_INSTRUCTION_H
15#define LLVM_IR_INSTRUCTION_H
60 bool isValid()
const {
return InsertAt.isValid(); }
66 ilist_iterator_bits<true>,
67 ilist_parent<BasicBlock>> {
77 std::random_access_iterator_tag, BasicBlock *,
78 ptrdiff_t, BasicBlock *, BasicBlock *> {
91 std::random_access_iterator_tag,
92 const BasicBlock *, ptrdiff_t, const BasicBlock *,
109 unsigned MetadataIndex = 0;
113 mutable unsigned Order = 0;
136 bool InsertAtHead =
false);
146 LLVM_ABI std::optional<simple_ilist<DbgRecord>::iterator>
147 getDbgReinsertionPosition();
150 LLVM_ABI bool hasDbgRecords()
const;
166 LLVM_ABI void handleMarkerRemoval();
178 template <
unsigned Offset>
183 template <
unsigned Offset>
186 template <
unsigned Offset>
210 return const_cast<Module *
>(
211 static_cast<const Instruction *
>(
this)->getModule());
221 static_cast<const Instruction *
>(
this)->getFunction());
236 LLVM_ABI InstListType::iterator eraseFromParent();
240 LLVM_ABI void insertBefore(InstListType::iterator InsertPos);
248 LLVM_ABI void insertAfter(InstListType::iterator InsertPos);
253 InstListType::iterator It);
259 LLVM_ABI void moveBefore(InstListType::iterator InsertPos);
264 LLVM_ABI void moveBeforePreserving(InstListType::iterator MovePos);
274 void moveBeforeImpl(
BasicBlock &BB, InstListType::iterator
I,
bool Preserve);
288 LLVM_ABI void moveAfter(InstListType::iterator MovePos);
305 LLVM_ABI std::optional<InstListType::iterator> getInsertionPointAfterDef();
327 LLVM_ABI bool isOnlyUserOfAnyOperand();
332 return Opcode >= TermOpsBegin && Opcode < TermOpsEnd;
336 return Opcode >= UnaryOpsBegin && Opcode < UnaryOpsEnd;
339 return Opcode >= BinaryOpsBegin && Opcode < BinaryOpsEnd;
343 return Opcode == UDiv || Opcode == SDiv || Opcode == URem || Opcode == SRem;
347 return Opcode == FDiv || Opcode == FRem;
352 return Opcode >= Shl && Opcode <= AShr;
367 return Opcode ==
And || Opcode ==
Or || Opcode ==
Xor;
376 static inline bool isCast(
unsigned Opcode) {
377 return Opcode >= CastOpsBegin && Opcode < CastOpsEnd;
382 return Opcode >= FuncletPadOpsBegin && Opcode < FuncletPadOpsEnd;
389 case Instruction::CatchSwitch:
390 case Instruction::CatchRet:
391 case Instruction::CleanupRet:
392 case Instruction::Invoke:
393 case Instruction::Resume:
394 case Instruction::CallBr:
410 LLVM_ABI bool hasNonDebugLocLoopMetadata()
const;
430 if (KindID == LLVMContext::MD_dbg)
431 return DbgLoc.getAsMDNode();
440 return getMetadataImpl(Kind);
449 getAllMetadataImpl(MDs);
495 LLVM_ABI void addAnnotationMetadata(StringRef Annotation);
500 LLVM_ABI void addAnnotationMetadata(SmallVector<StringRef> Annotations);
502 LLVM_ABI AAMDNodes getAAMetadata()
const;
505 LLVM_ABI void setAAMetadata(
const AAMDNodes &
N);
508 LLVM_ABI void setNoSanitizeMetadata();
527 LLVM_ABI void setHasNoUnsignedWrap(
bool b =
true);
531 LLVM_ABI void setHasNoSignedWrap(
bool b =
true);
535 LLVM_ABI void setIsExact(
bool b =
true);
539 LLVM_ABI void setNonNeg(
bool b =
true);
556 LLVM_ABI void dropPoisonGeneratingFlags();
562 LLVM_ABI void dropPoisonGeneratingMetadata();
568 LLVM_ABI void dropPoisonGeneratingAttributes();
595 LLVM_ABI void dropUBImplyingAttrsAndMetadata(ArrayRef<unsigned> Keep = {});
612 LLVM_ABI void setHasAllowReassoc(
bool B);
627 LLVM_ABI void setHasNoSignedZeros(
bool B);
632 LLVM_ABI void setHasAllowReciprocal(
bool B);
637 LLVM_ABI void setHasAllowContract(
bool B);
647 LLVM_ABI void setFastMathFlags(FastMathFlags FMF);
652 LLVM_ABI void copyFastMathFlags(FastMathFlags FMF);
711 LLVM_ABI void applyMergedLocation(DebugLoc LocA, DebugLoc LocB);
717 LLVM_ABI void updateLocationAfterHoist();
737 mergeDIAssignID(ArrayRef<
const Instruction *> SourceInstructions);
743 getAllMetadataImpl(SmallVectorImpl<std::pair<
unsigned, MDNode *>> &)
const;
747 void updateDIAssignIDMapping(DIAssignID *ID);
762 return Opcode ==
And || Opcode ==
Or || Opcode ==
Xor ||
763 Opcode ==
Add || Opcode ==
Mul;
799 return Opcode ==
And || Opcode ==
Or;
813 return Opcode ==
Xor;
867 case Instruction::Fence:
868 case Instruction::CatchPad:
869 case Instruction::CatchRet:
870 case Instruction::Call:
871 case Instruction::Invoke:
904 case Instruction::CatchSwitch:
905 case Instruction::CatchPad:
906 case Instruction::CleanupPad:
907 case Instruction::LandingPad:
998 Use *Begin =
const_cast<Use *
>(
Ops.begin().getUse());
999 Use *End =
const_cast<Use *
>(
Ops.end().getUse());
1009 return V->getValueID() >= Value::InstructionVal;
1016#define FIRST_TERM_INST(N) TermOpsBegin = N,
1017#define HANDLE_TERM_INST(N, OPC, CLASS) OPC = N,
1018#define LAST_TERM_INST(N) TermOpsEnd = N+1
1019#include "llvm/IR/Instruction.def"
1023#define FIRST_UNARY_INST(N) UnaryOpsBegin = N,
1024#define HANDLE_UNARY_INST(N, OPC, CLASS) OPC = N,
1025#define LAST_UNARY_INST(N) UnaryOpsEnd = N+1
1026#include "llvm/IR/Instruction.def"
1030#define FIRST_BINARY_INST(N) BinaryOpsBegin = N,
1031#define HANDLE_BINARY_INST(N, OPC, CLASS) OPC = N,
1032#define LAST_BINARY_INST(N) BinaryOpsEnd = N+1
1033#include "llvm/IR/Instruction.def"
1037#define FIRST_MEMORY_INST(N) MemoryOpsBegin = N,
1038#define HANDLE_MEMORY_INST(N, OPC, CLASS) OPC = N,
1039#define LAST_MEMORY_INST(N) MemoryOpsEnd = N+1
1040#include "llvm/IR/Instruction.def"
1044#define FIRST_CAST_INST(N) CastOpsBegin = N,
1045#define HANDLE_CAST_INST(N, OPC, CLASS) OPC = N,
1046#define LAST_CAST_INST(N) CastOpsEnd = N+1
1047#include "llvm/IR/Instruction.def"
1051#define FIRST_FUNCLETPAD_INST(N) FuncletPadOpsBegin = N,
1052#define HANDLE_FUNCLETPAD_INST(N, OPC, CLASS) OPC = N,
1053#define LAST_FUNCLETPAD_INST(N) FuncletPadOpsEnd = N+1
1054#include "llvm/IR/Instruction.def"
1058#define FIRST_OTHER_INST(N) OtherOpsBegin = N,
1059#define HANDLE_OTHER_INST(N, OPC, CLASS) OPC = N,
1060#define LAST_OTHER_INST(N) OtherOpsEnd = N+1
1061#include "llvm/IR/Instruction.def"
1065 friend class SymbolTableListTraits<
Instruction, ilist_iterator_bits<
true>,
1071 void setValueSubclassData(
unsigned short D) {
1075 unsigned short getSubclassDataFromValue()
const {
1083 template <
typename BitfieldElement>
1088 template <
typename BitfieldElement>
1090 auto Storage = getSubclassDataFromValue();
1092 setValueSubclassData(Storage);
Atomic ordering constants.
This file implements methods to test, set and extract typed bits from packed unsigned integers.
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static StringRef getOpcodeName(uint8_t Opcode, uint8_t OpcodeBase)
static bool hasNoSignedWrap(BinaryOperator &I)
static bool hasNoUnsignedWrap(BinaryOperator &I)
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
static MemAccessTy getAccessType(const TargetTransformInfo &TTI, Instruction *Inst, Value *OperandVal)
Return the type of the memory being accessed.
static bool mayHaveSideEffects(MachineInstr &MI)
static unsigned getFastMathFlags(const MachineInstr &I, const SPIRVSubtarget &ST)
static Function * getFunction(FunctionType *Ty, const Twine &Name, Module *M)
static bool isAssociative(const COFFSection &Section)
Represent a constant reference to an array (0 or more elements consecutively in memory),...
LLVM Basic Block Representation.
A parsed version of the target data layout string in and methods for querying it.
Per-instruction record of debug-info.
Base class for non-instruction debug metadata records that have positions within IR.
Convenience struct for specifying and reasoning about fast-math flags.
InsertPosition(InstListType::iterator InsertAt)
BasicBlock * getBasicBlock()
InsertPosition(std::nullptr_t)
DbgMarker * DebugMarker
Optional marker recording the position for debugging information that takes effect immediately before...
BitfieldElement::Type getSubclassData() const
typename Bitfield::Element< unsigned, Offset, 6, Value::MaxAlignmentExponent > AlignmentBitfieldElementT
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.
typename Bitfield::Element< AtomicOrdering, Offset, 3, AtomicOrdering::LAST > AtomicOrderingBitfieldElementT
LLVM_ABI bool hasPoisonGeneratingAttributes() const LLVM_READONLY
Return true if this instruction has poison-generating attribute.
bool hasMetadata(StringRef Kind) const
Return true if this instruction has the given type of metadata attached.
static bool isFPDivRem(unsigned Opcode)
LLVM_ABI iterator_range< simple_ilist< DbgRecord >::iterator > cloneDebugInfoFrom(const Instruction *From, std::optional< simple_ilist< DbgRecord >::iterator > FromHere=std::nullopt, bool InsertAtHead=false)
Clone any debug-info attached to From onto this instruction.
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.
static bool isShift(unsigned Opcode)
Determine if the Opcode is one of the shift instructions.
LLVM_ABI bool mayWriteToMemory() const LLVM_READONLY
Return true if this instruction may modify memory.
static bool isSpecialTerminator(unsigned Opcode)
Returns true if the Opcode is a "special" terminator that does more than branch to a successor (e....
iterator_range< simple_ilist< DbgRecord >::iterator > getDbgRecordRange() const
Return a range over the DbgRecords attached to this instruction.
static bool isCast(unsigned Opcode)
Determine if the Opcode is one of the CastInst instructions.
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
LLVM_ABI bool isAssociative() const LLVM_READONLY
Return true if the instruction is associative:
Instruction & operator=(const Instruction &)=delete
bool hasMetadataOtherThanDebugLoc() const
Return true if this instruction has metadata attached to it other than a debug location.
LLVM_ABI 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 isEHPad() const
Return true if the instruction is a variety of EH-block.
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
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)
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
bool isFuncletPad() const
bool isTerminator() const
bool hasPoisonGeneratingAnnotations() const
Return true if this instruction has poison-generating flags, attributes or metadata.
LLVM_ABI 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:
LLVM_ABI bool mayReadFromMemory() const LLVM_READONLY
Return true if this instruction may read memory.
LLVM_ABI iterator_range< const_succ_iterator > successors() const LLVM_READONLY
void dropPoisonGeneratingAnnotations()
Drops flags, attributes and metadata that may generate poison.
const char * getOpcodeName() const
const Instruction * user_back() const
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.
@ CompareUsingIntersectedAttrs
Check for equivalence with intersected callbase attrs.
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 isLogicalShift() const
Return true if this is a logical shift left or a logical shift right.
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.
static bool isNilpotent(unsigned Opcode)
LLVM_ABI void dropPoisonGeneratingMetadata()
Drops metadata that may generate poison.
bool isBitwiseLogicOp() const
Return true if this is and/or/xor.
static bool isTerminator(unsigned Opcode)
bool isFenceLike() const
Return true if this instruction behaves like a memory fence: it can load or store to memory location ...
LLVM_ABI void dropPoisonGeneratingFlags()
Drops flags that may cause this instruction to evaluate to poison despite having non-poison inputs.
LLVM_ABI void dropPoisonGeneratingAttributes()
Drops attributes that may generate poison.
Bitfield::Element< uint16_t, 0, 16 > OpaqueField
LLVM_ABI bool hasPoisonGeneratingMetadata() const LLVM_READONLY
Return true if this instruction has poison-generating metadata.
Instruction(const Instruction &)=delete
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
static bool isIntDivRem(unsigned Opcode)
bool isIdempotent() const
Return true if the instruction is idempotent:
friend class BasicBlock
Various leaf nodes.
SymbolTableList< Instruction, ilist_iterator_bits< true >, ilist_parent< BasicBlock > > InstListType
void setSubclassData(typename BitfieldElement::Type Value)
bool isSpecialTerminator() const
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...
Represent a constant reference to a string, i.e.
List that automatically updates parent links and symbol tables.
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.
User(Type *ty, unsigned vty, AllocInfo AllocInfo)
const Use * const_op_iterator
unsigned short getSubclassDataFromValue() const
user_iterator user_begin()
LLVM_ABI 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.
LLVM_ABI MDNode * getMetadataImpl(unsigned KindID) const LLVM_READONLY
Get metadata for the given kind, if any.
void setValueSubclassData(unsigned short D)
static constexpr unsigned MaxAlignmentExponent
The maximum alignment for instructions.
An efficient, type-erasing, non-owning reference to a callable.
ilist_node_with_parent()=default
typename base_list_type::iterator iterator
iterator_adaptor_base()=default
A range adaptor for a pair of iterators.
ilist_select_iterator_type< OptionsT, false, false > iterator
This file defines the ilist_node class template, which is a convenient base class for creating classe...
@ BasicBlock
Various leaf nodes.
friend class Instruction
Iterator for Instructions in a `BasicBlock.
This is an optimization pass for GlobalISel generic memory operations.
auto successors(const MachineBasicBlock *BB)
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
MemoryEffectsBase< IRMemLocation > MemoryEffects
Summary of how a function affects memory in the program.
iterator_range< simple_ilist< DbgRecord >::iterator > getDbgRecordRange(DbgMarker *DebugMarker)
Inline helper to return a range of DbgRecords attached to a marker.
AtomicOrdering
Atomic ordering for LLVM's memory model.
@ Mul
Product of integers.
@ Xor
Bitwise or logical XOR of integers.
DWARFExpression::Operation Op
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Instruction::const_succ_iterator const_succ_iterator
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
Summary of memprof metadata on allocations.
Describes an element of a Bitfield.
static Bitfield::Type get(StorageType Packed)
Unpacks the field from the Packed value.
static void set(StorageType &Packed, typename Bitfield::Type Value)
Sets the typed value in the provided Packed value.
const BasicBlock * operator->() const
const_succ_iterator()=default
const BasicBlock * operator*() const
const_succ_iterator(const_op_iterator I)
const_op_iterator getUse() const
Iterator type that casts an operand to a basic block.
BasicBlock * operator->() const
succ_iterator(op_iterator I)
op_iterator getUse() const
BasicBlock * operator*() const
Use delete by default for iplist and ilist.
static void deleteNode(NodeTy *V)
Option to add a pointer to this list's owner in every node.