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>
245 return const_cast<Module *
>(
246 static_cast<const Instruction *
>(
this)->getModule());
256 static_cast<const Instruction *
>(
this)->getFunction());
271 LLVM_ABI InstListType::iterator eraseFromParent();
275 LLVM_ABI void insertBefore(InstListType::iterator InsertPos);
283 LLVM_ABI void insertAfter(InstListType::iterator InsertPos);
288 InstListType::iterator It);
294 LLVM_ABI void moveBefore(InstListType::iterator InsertPos);
299 LLVM_ABI void moveBeforePreserving(InstListType::iterator MovePos);
309 void moveBeforeImpl(
BasicBlock &BB, InstListType::iterator
I,
bool Preserve);
323 LLVM_ABI void moveAfter(InstListType::iterator MovePos);
340 LLVM_ABI std::optional<InstListType::iterator> getInsertionPointAfterDef();
362 LLVM_ABI bool isOnlyUserOfAnyOperand();
367 return Opcode >= TermOpsBegin && Opcode < TermOpsEnd;
371 return Opcode >= UnaryOpsBegin && Opcode < UnaryOpsEnd;
374 return Opcode >= BinaryOpsBegin && Opcode < BinaryOpsEnd;
378 return Opcode == UDiv || Opcode == SDiv || Opcode == URem || Opcode == SRem;
382 return Opcode == FDiv || Opcode == FRem;
387 return Opcode >= Shl && Opcode <= AShr;
402 return Opcode ==
And || Opcode ==
Or || Opcode ==
Xor;
411 static inline bool isCast(
unsigned Opcode) {
412 return Opcode >= CastOpsBegin && Opcode < CastOpsEnd;
417 return Opcode >= FuncletPadOpsBegin && Opcode < FuncletPadOpsEnd;
424 case Instruction::CatchSwitch:
425 case Instruction::CatchRet:
426 case Instruction::CleanupRet:
427 case Instruction::Invoke:
428 case Instruction::Resume:
429 case Instruction::CallBr:
445 LLVM_ABI bool hasNonDebugLocLoopMetadata()
const;
465 if (KindID == LLVMContext::MD_dbg)
466 return DbgLoc.getAsMDNode();
475 return getMetadataImpl(Kind);
484 getAllMetadataImpl(MDs);
530 LLVM_ABI void addAnnotationMetadata(StringRef Annotation);
535 LLVM_ABI void addAnnotationMetadata(SmallVector<StringRef> Annotations);
537 LLVM_ABI AAMDNodes getAAMetadata()
const;
540 LLVM_ABI void setAAMetadata(
const AAMDNodes &
N);
543 LLVM_ABI void setNoSanitizeMetadata();
562 LLVM_ABI void setHasNoUnsignedWrap(
bool b =
true);
566 LLVM_ABI void setHasNoSignedWrap(
bool b =
true);
570 LLVM_ABI void setIsExact(
bool b =
true);
574 LLVM_ABI void setNonNeg(
bool b =
true);
591 LLVM_ABI void dropPoisonGeneratingFlags();
597 LLVM_ABI void dropPoisonGeneratingMetadata();
603 LLVM_ABI void dropPoisonGeneratingAttributes();
630 LLVM_ABI void dropUBImplyingAttrsAndMetadata(ArrayRef<unsigned> Keep = {});
647 LLVM_ABI void setHasAllowReassoc(
bool B);
662 LLVM_ABI void setHasNoSignedZeros(
bool B);
667 LLVM_ABI void setHasAllowReciprocal(
bool B);
672 LLVM_ABI void setHasAllowContract(
bool B);
682 LLVM_ABI void setFastMathFlags(FastMathFlags FMF);
687 LLVM_ABI void copyFastMathFlags(FastMathFlags FMF);
746 LLVM_ABI void applyMergedLocation(DebugLoc LocA, DebugLoc LocB);
752 LLVM_ABI void updateLocationAfterHoist();
772 mergeDIAssignID(ArrayRef<
const Instruction *> SourceInstructions);
778 getAllMetadataImpl(SmallVectorImpl<std::pair<
unsigned, MDNode *>> &)
const;
782 void updateDIAssignIDMapping(DIAssignID *ID);
797 return Opcode ==
And || Opcode ==
Or || Opcode ==
Xor ||
798 Opcode ==
Add || Opcode ==
Mul;
834 return Opcode ==
And || Opcode ==
Or;
848 return Opcode ==
Xor;
902 case Instruction::Fence:
903 case Instruction::CatchPad:
904 case Instruction::CatchRet:
905 case Instruction::Call:
906 case Instruction::Invoke:
939 case Instruction::CatchSwitch:
940 case Instruction::CatchPad:
941 case Instruction::CleanupPad:
942 case Instruction::LandingPad:
1035 Use *Begin =
const_cast<Use *
>(
Ops.begin().getUse());
1036 Use *End =
const_cast<Use *
>(
Ops.end().getUse());
1046 return V->getValueID() >= Value::InstructionVal;
1053#define FIRST_TERM_INST(N) TermOpsBegin = N,
1054#define HANDLE_TERM_INST(N, OPC, CLASS) OPC = N,
1055#define LAST_TERM_INST(N) TermOpsEnd = N+1
1056#include "llvm/IR/Instruction.def"
1060#define FIRST_UNARY_INST(N) UnaryOpsBegin = N,
1061#define HANDLE_UNARY_INST(N, OPC, CLASS) OPC = N,
1062#define LAST_UNARY_INST(N) UnaryOpsEnd = N+1
1063#include "llvm/IR/Instruction.def"
1067#define FIRST_BINARY_INST(N) BinaryOpsBegin = N,
1068#define HANDLE_BINARY_INST(N, OPC, CLASS) OPC = N,
1069#define LAST_BINARY_INST(N) BinaryOpsEnd = N+1
1070#include "llvm/IR/Instruction.def"
1074#define FIRST_MEMORY_INST(N) MemoryOpsBegin = N,
1075#define HANDLE_MEMORY_INST(N, OPC, CLASS) OPC = N,
1076#define LAST_MEMORY_INST(N) MemoryOpsEnd = N+1
1077#include "llvm/IR/Instruction.def"
1081#define FIRST_CAST_INST(N) CastOpsBegin = N,
1082#define HANDLE_CAST_INST(N, OPC, CLASS) OPC = N,
1083#define LAST_CAST_INST(N) CastOpsEnd = N+1
1084#include "llvm/IR/Instruction.def"
1088#define FIRST_FUNCLETPAD_INST(N) FuncletPadOpsBegin = N,
1089#define HANDLE_FUNCLETPAD_INST(N, OPC, CLASS) OPC = N,
1090#define LAST_FUNCLETPAD_INST(N) FuncletPadOpsEnd = N+1
1091#include "llvm/IR/Instruction.def"
1095#define FIRST_OTHER_INST(N) OtherOpsBegin = N,
1096#define HANDLE_OTHER_INST(N, OPC, CLASS) OPC = N,
1097#define LAST_OTHER_INST(N) OtherOpsEnd = N+1
1098#include "llvm/IR/Instruction.def"
1102 friend class SymbolTableListTraits<
Instruction, ilist_iterator_bits<
true>,
1108 void setValueSubclassData(
unsigned short D) {
1112 unsigned short getSubclassDataFromValue()
const {
1120 template <
typename BitfieldElement>
1125 template <
typename BitfieldElement>
1127 auto Storage = getSubclassDataFromValue();
1129 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)
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.
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)
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.
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
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.