14#ifndef LLVM_IR_INSTRUCTION_H
15#define LLVM_IR_INSTRUCTION_H
59 bool isValid()
const {
return InsertAt.isValid(); }
65 ilist_iterator_bits<true>,
66 ilist_parent<BasicBlock>> {
76 std::random_access_iterator_tag, BasicBlock *,
77 ptrdiff_t, BasicBlock *, BasicBlock *> {
90 std::random_access_iterator_tag,
91 const BasicBlock *, ptrdiff_t, const BasicBlock *,
108 unsigned MetadataIndex = 0;
112 mutable unsigned Order = 0;
137 bool InsertAtHead =
false);
147 LLVM_ABI std::optional<simple_ilist<DbgRecord>::iterator>
148 getDbgReinsertionPosition();
151 LLVM_ABI bool hasDbgRecords()
const;
167 LLVM_ABI void handleMarkerRemoval();
179 template <
unsigned Offset>
184 template <
unsigned Offset>
187 template <
unsigned Offset>
246 return const_cast<Module *
>(
247 static_cast<const Instruction *
>(
this)->getModule());
257 static_cast<const Instruction *
>(
this)->getFunction());
272 LLVM_ABI InstListType::iterator eraseFromParent();
276 LLVM_ABI void insertBefore(InstListType::iterator InsertPos);
284 LLVM_ABI void insertAfter(InstListType::iterator InsertPos);
289 InstListType::iterator It);
295 LLVM_ABI void moveBefore(InstListType::iterator InsertPos);
300 LLVM_ABI void moveBeforePreserving(InstListType::iterator MovePos);
310 void moveBeforeImpl(
BasicBlock &BB, InstListType::iterator
I,
bool Preserve);
324 LLVM_ABI void moveAfter(InstListType::iterator MovePos);
341 LLVM_ABI std::optional<InstListType::iterator> getInsertionPointAfterDef();
363 LLVM_ABI bool isOnlyUserOfAnyOperand();
368 return Opcode >= TermOpsBegin && Opcode < TermOpsEnd;
372 return Opcode >= UnaryOpsBegin && Opcode < UnaryOpsEnd;
375 return Opcode >= BinaryOpsBegin && Opcode < BinaryOpsEnd;
379 return Opcode == UDiv || Opcode == SDiv || Opcode == URem || Opcode == SRem;
383 return Opcode == FDiv || Opcode == FRem;
388 return Opcode >= Shl && Opcode <= AShr;
403 return Opcode ==
And || Opcode ==
Or || Opcode ==
Xor;
412 static inline bool isCast(
unsigned Opcode) {
413 return Opcode >= CastOpsBegin && Opcode < CastOpsEnd;
418 return Opcode >= FuncletPadOpsBegin && Opcode < FuncletPadOpsEnd;
425 case Instruction::CatchSwitch:
426 case Instruction::CatchRet:
427 case Instruction::CleanupRet:
428 case Instruction::Invoke:
429 case Instruction::Resume:
430 case Instruction::CallBr:
446 LLVM_ABI bool hasNonDebugLocLoopMetadata()
const;
466 if (KindID == LLVMContext::MD_dbg)
467 return DbgLoc.getAsMDNode();
476 return getMetadataImpl(Kind);
485 getAllMetadataImpl(MDs);
531 LLVM_ABI void addAnnotationMetadata(StringRef Annotation);
536 LLVM_ABI void addAnnotationMetadata(SmallVector<StringRef> Annotations);
538 LLVM_ABI AAMDNodes getAAMetadata()
const;
541 LLVM_ABI void setAAMetadata(
const AAMDNodes &
N);
544 LLVM_ABI void setNoSanitizeMetadata();
563 LLVM_ABI void setHasNoUnsignedWrap(
bool b =
true);
567 LLVM_ABI void setHasNoSignedWrap(
bool b =
true);
571 LLVM_ABI void setIsExact(
bool b =
true);
575 LLVM_ABI void setNonNeg(
bool b =
true);
592 LLVM_ABI void dropPoisonGeneratingFlags();
598 LLVM_ABI void dropPoisonGeneratingMetadata();
604 LLVM_ABI void dropPoisonGeneratingAttributes();
631 LLVM_ABI void dropUBImplyingAttrsAndMetadata(ArrayRef<unsigned> Keep = {});
648 LLVM_ABI void setHasAllowReassoc(
bool B);
663 LLVM_ABI void setHasNoSignedZeros(
bool B);
668 LLVM_ABI void setHasAllowReciprocal(
bool B);
673 LLVM_ABI void setHasAllowContract(
bool B);
683 LLVM_ABI void setFastMathFlags(FastMathFlags FMF);
688 LLVM_ABI void copyFastMathFlags(FastMathFlags FMF);
747 LLVM_ABI void applyMergedLocation(DebugLoc LocA, DebugLoc LocB);
753 LLVM_ABI void updateLocationAfterHoist();
773 mergeDIAssignID(ArrayRef<
const Instruction *> SourceInstructions);
779 getAllMetadataImpl(SmallVectorImpl<std::pair<
unsigned, MDNode *>> &)
const;
783 void updateDIAssignIDMapping(DIAssignID *ID);
798 return Opcode ==
And || Opcode ==
Or || Opcode ==
Xor ||
799 Opcode ==
Add || Opcode ==
Mul;
835 return Opcode ==
And || Opcode ==
Or;
849 return Opcode ==
Xor;
903 case Instruction::Fence:
904 case Instruction::CatchPad:
905 case Instruction::CatchRet:
906 case Instruction::Call:
907 case Instruction::Invoke:
940 case Instruction::CatchSwitch:
941 case Instruction::CatchPad:
942 case Instruction::CleanupPad:
943 case Instruction::LandingPad:
1036 Use *Begin =
const_cast<Use *
>(
Ops.begin().getUse());
1037 Use *End =
const_cast<Use *
>(
Ops.end().getUse());
1047 return V->getValueID() >= Value::InstructionVal;
1054#define FIRST_TERM_INST(N) TermOpsBegin = N,
1055#define HANDLE_TERM_INST(N, OPC, CLASS) OPC = N,
1056#define LAST_TERM_INST(N) TermOpsEnd = N+1
1057#include "llvm/IR/Instruction.def"
1061#define FIRST_UNARY_INST(N) UnaryOpsBegin = N,
1062#define HANDLE_UNARY_INST(N, OPC, CLASS) OPC = N,
1063#define LAST_UNARY_INST(N) UnaryOpsEnd = N+1
1064#include "llvm/IR/Instruction.def"
1068#define FIRST_BINARY_INST(N) BinaryOpsBegin = N,
1069#define HANDLE_BINARY_INST(N, OPC, CLASS) OPC = N,
1070#define LAST_BINARY_INST(N) BinaryOpsEnd = N+1
1071#include "llvm/IR/Instruction.def"
1075#define FIRST_MEMORY_INST(N) MemoryOpsBegin = N,
1076#define HANDLE_MEMORY_INST(N, OPC, CLASS) OPC = N,
1077#define LAST_MEMORY_INST(N) MemoryOpsEnd = N+1
1078#include "llvm/IR/Instruction.def"
1082#define FIRST_CAST_INST(N) CastOpsBegin = N,
1083#define HANDLE_CAST_INST(N, OPC, CLASS) OPC = N,
1084#define LAST_CAST_INST(N) CastOpsEnd = N+1
1085#include "llvm/IR/Instruction.def"
1089#define FIRST_FUNCLETPAD_INST(N) FuncletPadOpsBegin = N,
1090#define HANDLE_FUNCLETPAD_INST(N, OPC, CLASS) OPC = N,
1091#define LAST_FUNCLETPAD_INST(N) FuncletPadOpsEnd = N+1
1092#include "llvm/IR/Instruction.def"
1096#define FIRST_OTHER_INST(N) OtherOpsBegin = N,
1097#define HANDLE_OTHER_INST(N, OPC, CLASS) OPC = N,
1098#define LAST_OTHER_INST(N) OtherOpsEnd = N+1
1099#include "llvm/IR/Instruction.def"
1103 friend class SymbolTableListTraits<
Instruction, ilist_iterator_bits<
true>,
1110 void setValueSubclassData(
unsigned short D) {
1114 unsigned short getSubclassDataFromValue()
const {
1122 template <
typename BitfieldElement>
1127 template <
typename BitfieldElement>
1129 auto Storage = getSubclassDataFromValue();
1131 setValueSubclassData(Storage);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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)
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.
iterator_range< user_iterator > materialized_users()
bool hasMetadata(StringRef Kind) const
Return true if this instruction has the given type of metadata attached.
static bool isFPDivRem(unsigned Opcode)
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.
iterator_range< const_user_iterator > users() const
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_user_iterator user_end() const
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
DbgMarker * getDbgMarker() const
user_iterator_impl< Instruction > user_iterator
Specialize the methods defined in Value, as we know that an instruction can only be used by other ins...
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()
static bool isIdempotent(unsigned Opcode)
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
bool isFuncletPad() const
user_iterator materialized_user_begin()
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.
iterator_range< user_iterator > users()
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
user_iterator user_begin()
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.
@ CompareCallTargets
Check for equivalence by comparing call targets.
@ 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)
user_iterator_impl< const Instruction > const_user_iterator
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.
const_user_iterator user_begin() const
LLVM_ABI void dropPoisonGeneratingAttributes()
Drops attributes that may generate poison.
iterator_range< const_user_iterator > materialized_users() const
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.
const_user_iterator materialized_user_begin() const
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
void assertModuleIsMaterialized() const
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.
bool hasUseList() const
Check if this Value has a use-list.
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.