14#ifndef LLVM_IR_INSTRUCTION_H
15#define LLVM_IR_INSTRUCTION_H
57 "BasicBlock::iterator")
62 bool isValid()
const {
return InsertAt.isValid(); }
68 ilist_iterator_bits<true>,
69 ilist_parent<BasicBlock>> {
79 mutable unsigned Order = 0;
102 bool InsertAtHead =
false);
112 LLVM_ABI std::optional<simple_ilist<DbgRecord>::iterator>
113 getDbgReinsertionPosition();
116 LLVM_ABI bool hasDbgRecords()
const;
132 LLVM_ABI void handleMarkerRemoval();
144 template <
unsigned Offset>
147 Value::MaxAlignmentExponent>;
149 template <
unsigned Offset>
152 template <
unsigned Offset>
155 AtomicOrdering::LAST>;
181 return const_cast<Module *
>(
182 static_cast<const Instruction *
>(
this)->getModule());
207 LLVM_ABI InstListType::iterator eraseFromParent();
269 "")
void moveBeforePreserving(
Instruction *MovePos);
312 unsigned getOpcode()
const {
return getValueID() - InstructionVal; }
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:
406 bool hasMetadata()
const {
return DbgLoc || Value::hasMetadata(); }
410 LLVM_ABI bool hasNonDebugLocLoopMetadata()
const;
418 return getMetadata(KindID) !=
nullptr;
423 return getMetadata(Kind) !=
nullptr;
430 if (KindID == LLVMContext::MD_dbg)
432 return Value::getMetadata(KindID);
438 if (!hasMetadata())
return nullptr;
439 return getMetadataImpl(Kind);
448 getAllMetadataImpl(MDs);
455 Value::getAllMetadata(MDs);
489 LLVM_ABI void addAnnotationMetadata(StringRef Annotation);
494 LLVM_ABI void addAnnotationMetadata(SmallVector<StringRef> Annotations);
496 LLVM_ABI AAMDNodes getAAMetadata()
const;
499 LLVM_ABI void setAAMetadata(
const AAMDNodes &
N);
502 LLVM_ABI void setNoSanitizeMetadata();
521 LLVM_ABI void setHasNoUnsignedWrap(
bool b =
true);
525 LLVM_ABI void setHasNoSignedWrap(
bool b =
true);
529 LLVM_ABI void setIsExact(
bool b =
true);
533 LLVM_ABI void setNonNeg(
bool b =
true);
550 LLVM_ABI void dropPoisonGeneratingFlags();
556 LLVM_ABI void dropPoisonGeneratingMetadata();
562 LLVM_ABI void dropPoisonGeneratingReturnAttributes();
566 bool hasPoisonGeneratingAnnotations()
const {
567 return hasPoisonGeneratingFlags() ||
568 hasPoisonGeneratingReturnAttributes() ||
569 hasPoisonGeneratingMetadata();
574 dropPoisonGeneratingFlags();
575 dropPoisonGeneratingReturnAttributes();
576 dropPoisonGeneratingMetadata();
590 LLVM_ABI void dropUBImplyingAttrsAndMetadata(ArrayRef<unsigned> Keep = {});
607 LLVM_ABI void setHasAllowReassoc(
bool B);
622 LLVM_ABI void setHasNoSignedZeros(
bool B);
627 LLVM_ABI void setHasAllowReciprocal(
bool B);
632 LLVM_ABI void setHasAllowContract(
bool B);
642 LLVM_ABI void setFastMathFlags(FastMathFlags FMF);
647 LLVM_ABI void copyFastMathFlags(FastMathFlags FMF);
702 LLVM_ABI void applyMergedLocation(DebugLoc LocA, DebugLoc LocB);
708 LLVM_ABI void updateLocationAfterHoist();
728 mergeDIAssignID(ArrayRef<
const Instruction *> SourceInstructions);
734 getAllMetadataImpl(SmallVectorImpl<
std::pair<
unsigned, MDNode *>> &)
const;
738 void updateDIAssignIDMapping(DIAssignID *ID);
753 return Opcode ==
And || Opcode ==
Or || Opcode ==
Xor ||
754 Opcode == Add || Opcode ==
Mul;
784 return Opcode ==
And || Opcode ==
Or;
798 return Opcode ==
Xor;
808 bool mayReadOrWriteMemory()
const {
809 return mayReadFromMemory() || mayWriteToMemory();
838 bool isFenceLike()
const {
844 case Instruction::Fence:
845 case Instruction::CatchPad:
846 case Instruction::CatchRet:
847 case Instruction::Call:
848 case Instruction::Invoke:
879 bool isEHPad()
const {
881 case Instruction::CatchSwitch:
882 case Instruction::CatchPad:
883 case Instruction::CleanupPad:
884 case Instruction::LandingPad:
925 CompareIgnoringAlignment = 1 << 0,
928 CompareUsingScalarTypes = 1 << 1,
930 CompareUsingIntersectedAttrs = 1 << 2,
978 return V->getValueID() >= Value::InstructionVal;
985#define FIRST_TERM_INST(N) TermOpsBegin = N,
986#define HANDLE_TERM_INST(N, OPC, CLASS) OPC = N,
987#define LAST_TERM_INST(N) TermOpsEnd = N+1
988#include "llvm/IR/Instruction.def"
992#define FIRST_UNARY_INST(N) UnaryOpsBegin = N,
993#define HANDLE_UNARY_INST(N, OPC, CLASS) OPC = N,
994#define LAST_UNARY_INST(N) UnaryOpsEnd = N+1
995#include "llvm/IR/Instruction.def"
999#define FIRST_BINARY_INST(N) BinaryOpsBegin = N,
1000#define HANDLE_BINARY_INST(N, OPC, CLASS) OPC = N,
1001#define LAST_BINARY_INST(N) BinaryOpsEnd = N+1
1002#include "llvm/IR/Instruction.def"
1006#define FIRST_MEMORY_INST(N) MemoryOpsBegin = N,
1007#define HANDLE_MEMORY_INST(N, OPC, CLASS) OPC = N,
1008#define LAST_MEMORY_INST(N) MemoryOpsEnd = N+1
1009#include "llvm/IR/Instruction.def"
1013#define FIRST_CAST_INST(N) CastOpsBegin = N,
1014#define HANDLE_CAST_INST(N, OPC, CLASS) OPC = N,
1015#define LAST_CAST_INST(N) CastOpsEnd = N+1
1016#include "llvm/IR/Instruction.def"
1020#define FIRST_FUNCLETPAD_INST(N) FuncletPadOpsBegin = N,
1021#define HANDLE_FUNCLETPAD_INST(N, OPC, CLASS) OPC = N,
1022#define LAST_FUNCLETPAD_INST(N) FuncletPadOpsEnd = N+1
1023#include "llvm/IR/Instruction.def"
1027#define FIRST_OTHER_INST(N) OtherOpsBegin = N,
1028#define HANDLE_OTHER_INST(N, OPC, CLASS) OPC = N,
1029#define LAST_OTHER_INST(N) OtherOpsEnd = N+1
1030#include "llvm/IR/Instruction.def"
1034 friend class SymbolTableListTraits<Instruction, ilist_iterator_bits<
true>,
1040 void setValueSubclassData(
unsigned short D) {
1041 Value::setValueSubclassData(
D);
1044 unsigned short getSubclassDataFromValue()
const {
1045 return Value::getSubclassDataFromValue();
1052 template <
typename BitfieldElement>
1055 std::is_same<BitfieldElement, HasMetadataField>::value ||
1056 !Bitfield::isOverlapping<BitfieldElement, HasMetadataField>(),
1057 "Must not overlap with the metadata bit");
1058 return Bitfield::get<BitfieldElement>(getSubclassDataFromValue());
1061 template <
typename BitfieldElement>
1064 std::is_same<BitfieldElement, HasMetadataField>::value ||
1065 !Bitfield::isOverlapping<BitfieldElement, HasMetadataField>(),
1066 "Must not overlap with the metadata bit");
1067 auto Storage = getSubclassDataFromValue();
1068 Bitfield::set<BitfieldElement>(Storage,
Value);
1069 setValueSubclassData(Storage);
Atomic ordering constants.
This file implements methods to test, set and extract typed bits from packed unsigned integers.
BlockVerifier::State From
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
#define LLVM_DEPRECATED(MSG, FIX)
static bool hasNoInfs(const TargetOptions &Options, SDValue N)
static StringRef getOpcodeName(uint8_t Opcode, uint8_t OpcodeBase)
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
std::optional< std::vector< StOtherPiece > > Other
static bool hasNoSignedWrap(BinaryOperator &I)
static bool hasNoUnsignedWrap(BinaryOperator &I)
static MemAccessTy getAccessType(const TargetTransformInfo &TTI, Instruction *Inst, Value *OperandVal)
Return the type of the memory being accessed.
Machine Check Debug Module
static bool mayHaveSideEffects(MachineInstr &MI)
static bool isCommutative(Instruction *I, Value *ValWithUses)
static std::optional< unsigned > getOpcode(ArrayRef< VPValue * > Values)
Returns the opcode of Values or ~0 if they do not all agree.
static Function * getFunction(FunctionType *Ty, const Twine &Name, Module *M)
static bool isAssociative(const COFFSection &Section)
ArrayRef - 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.
DebugLoc getCopied() const
MDNode * getAsMDNode() const
Return this as a bar MDNode.
BasicBlock * getBasicBlock()
InsertPosition(std::nullptr_t)
LLVM_ABI LLVM_DEPRECATED("Use BasicBlock::iterators for insertion instead", "BasicBlock::iterator") InsertPosition(Instruction *InsertBefore)
operator InstListType::iterator() const
BitfieldElement::Type getSubclassData() const
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.
LLVM_ABI LLVM_DEPRECATED("Use iterators as instruction positions", "") void insertBefore(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified instruction.
static bool isFPDivRem(unsigned Opcode)
static bool isBitwiseLogicOp(unsigned Opcode)
Determine if the Opcode is and/or/xor.
static bool isShift(unsigned Opcode)
Determine if the Opcode is one of the shift instructions.
static bool isSpecialTerminator(unsigned Opcode)
Returns true if the Opcode is a "special" terminator that does more than branch to a successor (e....
typename Bitfield::Element< AtomicOrdering, Offset, 3, AtomicOrdering::LAST > AtomicOrderingBitfieldElementT
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.
Instruction & operator=(const Instruction &)=delete
bool hasMetadataOtherThanDebugLoc() const
Return true if this instruction has metadata attached to it other than a debug location.
typename Bitfield::Element< bool, Offset, 1 > BoolBitfieldElementT
bool hasMetadata() const
Return true if this instruction has any metadata attached to it.
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
typename Bitfield::Element< unsigned, Offset, 6, Value::MaxAlignmentExponent > AlignmentBitfieldElementT
bool isNilpotent() const
Return true if the instruction is nilpotent:
void dropPoisonGeneratingAnnotations()
Drops flags, return 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...
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)
static bool isNilpotent(unsigned Opcode)
bool isBitwiseLogicOp() const
Return true if this is and/or/xor.
static bool isTerminator(unsigned Opcode)
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:
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...
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.
An efficient, type-erasing, non-owning reference to a callable.
An ilist node that can access its parent list.
base_list_type::iterator iterator
A range adaptor for a pair of iterators.
typename ilist_select_iterator_type< OptionsT::has_iterator_bits, OptionsT, false, false >::type iterator
This file defines the ilist_node class template, which is a convenient base class for creating classe...
@ BasicBlock
Various leaf nodes.
This is an optimization pass for GlobalISel generic memory operations.
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.
@ Xor
Bitwise or logical XOR of integers.
Implement std::hash so that hash_code can be used in STL containers.
Summary of memprof metadata on allocations.
Describes an element of a Bitfield.
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.