14#ifndef LLVM_IR_INSTRUCTION_H
15#define LLVM_IR_INSTRUCTION_H
56 "BasicBlock::iterator")
61 bool isValid()
const {
return InsertAt.isValid(); }
67 ilist_iterator_bits<true>,
68 ilist_parent<BasicBlock>> {
78 mutable unsigned Order = 0;
101 bool InsertAtHead =
false);
111 std::optional<simple_ilist<DbgRecord>::iterator> getDbgReinsertionPosition();
114 bool hasDbgRecords()
const;
119 void adoptDbgRecords(
BasicBlock *BB, InstListType::iterator It,
123 void dropDbgRecords();
130 void handleMarkerRemoval();
142 template <
unsigned Offset>
145 Value::MaxAlignmentExponent>;
147 template <
unsigned Offset>
150 template <
unsigned Offset>
153 AtomicOrdering::LAST>;
177 const Module *getModule()
const;
179 return const_cast<Module *
>(
180 static_cast<const Instruction *
>(
this)->getModule());
200 void removeFromParent();
205 InstListType::iterator eraseFromParent();
213 void insertBefore(InstListType::iterator InsertPos);
221 void insertAfter(InstListType::iterator InsertPos);
225 InstListType::iterator insertInto(
BasicBlock *ParentBB,
226 InstListType::iterator It);
228 void insertBefore(
BasicBlock &BB, InstListType::iterator InsertPos);
236 void moveBefore(InstListType::iterator InsertPos);
248 void moveBeforeImpl(
BasicBlock &BB, InstListType::iterator
I,
bool Preserve);
254 void moveBefore(
BasicBlock &BB, InstListType::iterator
I);
256 void moveBeforePreserving(
BasicBlock &BB, InstListType::iterator
I);
259 void moveBeforePreserving(InstListType::iterator
I);
284 std::optional<InstListType::iterator> getInsertionPointAfterDef();
291 unsigned getOpcode()
const {
return getValueID() - InstructionVal; }
306 bool isOnlyUserOfAnyOperand();
311 return Opcode >= TermOpsBegin && Opcode < TermOpsEnd;
315 return Opcode >= UnaryOpsBegin && Opcode < UnaryOpsEnd;
318 return Opcode >= BinaryOpsBegin && Opcode < BinaryOpsEnd;
322 return Opcode == UDiv || Opcode == SDiv || Opcode == URem || Opcode == SRem;
326 return Opcode == FDiv || Opcode == FRem;
331 return Opcode >= Shl && Opcode <= AShr;
346 return Opcode ==
And || Opcode ==
Or || Opcode ==
Xor;
355 static inline bool isCast(
unsigned Opcode) {
356 return Opcode >= CastOpsBegin && Opcode < CastOpsEnd;
361 return Opcode >= FuncletPadOpsBegin && Opcode < FuncletPadOpsEnd;
368 case Instruction::CatchSwitch:
369 case Instruction::CatchRet:
370 case Instruction::CleanupRet:
371 case Instruction::Invoke:
372 case Instruction::Resume:
373 case Instruction::CallBr:
385 bool hasMetadata()
const {
return DbgLoc || Value::hasMetadata(); }
389 bool hasNonDebugLocLoopMetadata()
const;
397 return getMetadata(KindID) !=
nullptr;
402 return getMetadata(Kind) !=
nullptr;
409 if (KindID == LLVMContext::MD_dbg)
411 return Value::getMetadata(KindID);
417 if (!hasMetadata())
return nullptr;
418 return getMetadataImpl(Kind);
427 getAllMetadataImpl(MDs);
434 Value::getAllMetadata(MDs);
439 void setMetadata(
unsigned KindID,
MDNode *
Node);
454 void swapProfMetadata();
468 void addAnnotationMetadata(StringRef Annotation);
473 void addAnnotationMetadata(SmallVector<StringRef> Annotations);
475 AAMDNodes getAAMetadata()
const;
478 void setAAMetadata(
const AAMDNodes &
N);
481 void setNoSanitizeMetadata();
486 bool extractProfTotalWeight(
uint64_t &TotalVal)
const;
496 const DebugLoc &getStableDebugLoc()
const;
500 void setHasNoUnsignedWrap(
bool b =
true);
504 void setHasNoSignedWrap(
bool b =
true);
508 void setIsExact(
bool b =
true);
512 void setNonNeg(
bool b =
true);
529 void dropPoisonGeneratingFlags();
535 void dropPoisonGeneratingMetadata();
541 void dropPoisonGeneratingReturnAttributes();
545 bool hasPoisonGeneratingAnnotations()
const {
546 return hasPoisonGeneratingFlags() ||
547 hasPoisonGeneratingReturnAttributes() ||
548 hasPoisonGeneratingMetadata();
553 dropPoisonGeneratingFlags();
554 dropPoisonGeneratingReturnAttributes();
555 dropPoisonGeneratingMetadata();
567 void dropUBImplyingAttrsAndMetadata();
575 void setFast(
bool B);
580 void setHasAllowReassoc(
bool B);
585 void setHasNoNaNs(
bool B);
590 void setHasNoInfs(
bool B);
595 void setHasNoSignedZeros(
bool B);
600 void setHasAllowReciprocal(
bool B);
605 void setHasAllowContract(
bool B);
610 void setHasApproxFunc(
bool B);
615 void setFastMathFlags(FastMathFlags FMF);
620 void copyFastMathFlags(FastMathFlags FMF);
652 void copyFastMathFlags(
const Instruction *
I);
656 void copyIRFlags(
const Value *V,
bool IncludeWrapFlags =
true);
660 void andIRFlags(
const Value *V);
675 void applyMergedLocation(DILocation *LocA, DILocation *LocB);
681 void updateLocationAfterHoist();
700 void mergeDIAssignID(ArrayRef<
const Instruction *> SourceInstructions);
704 MDNode *getMetadataImpl(StringRef Kind)
const;
706 getAllMetadataImpl(SmallVectorImpl<
std::pair<
unsigned, MDNode *>> &)
const;
710 void updateDIAssignIDMapping(DIAssignID *ID);
725 return Opcode ==
And || Opcode ==
Or || Opcode ==
Xor ||
726 Opcode == Add || Opcode ==
Mul;
756 return Opcode ==
And || Opcode ==
Or;
770 return Opcode ==
Xor;
780 bool mayReadOrWriteMemory()
const {
781 return mayReadFromMemory() || mayWriteToMemory();
809 bool isFenceLike()
const {
815 case Instruction::Fence:
816 case Instruction::CatchPad:
817 case Instruction::CatchRet:
818 case Instruction::Call:
819 case Instruction::Invoke:
850 bool isEHPad()
const {
852 case Instruction::CatchSwitch:
853 case Instruction::CatchPad:
854 case Instruction::CleanupPad:
855 case Instruction::LandingPad:
877 getNextNonDebugInstruction(
bool SkipPseudoOp =
false)
const;
880 static_cast<const Instruction *
>(
this)->getNextNonDebugInstruction(
888 getPrevNonDebugInstruction(
bool SkipPseudoOp =
false)
const;
891 static_cast<const Instruction *
>(
this)->getPrevNonDebugInstruction(
918 CompareIgnoringAlignment = 1 << 0,
921 CompareUsingScalarTypes = 1 << 1,
923 CompareUsingIntersectedAttrs = 1 << 2,
969 return V->getValueID() >= Value::InstructionVal;
976#define FIRST_TERM_INST(N) TermOpsBegin = N,
977#define HANDLE_TERM_INST(N, OPC, CLASS) OPC = N,
978#define LAST_TERM_INST(N) TermOpsEnd = N+1
979#include "llvm/IR/Instruction.def"
983#define FIRST_UNARY_INST(N) UnaryOpsBegin = N,
984#define HANDLE_UNARY_INST(N, OPC, CLASS) OPC = N,
985#define LAST_UNARY_INST(N) UnaryOpsEnd = N+1
986#include "llvm/IR/Instruction.def"
990#define FIRST_BINARY_INST(N) BinaryOpsBegin = N,
991#define HANDLE_BINARY_INST(N, OPC, CLASS) OPC = N,
992#define LAST_BINARY_INST(N) BinaryOpsEnd = N+1
993#include "llvm/IR/Instruction.def"
997#define FIRST_MEMORY_INST(N) MemoryOpsBegin = N,
998#define HANDLE_MEMORY_INST(N, OPC, CLASS) OPC = N,
999#define LAST_MEMORY_INST(N) MemoryOpsEnd = N+1
1000#include "llvm/IR/Instruction.def"
1004#define FIRST_CAST_INST(N) CastOpsBegin = N,
1005#define HANDLE_CAST_INST(N, OPC, CLASS) OPC = N,
1006#define LAST_CAST_INST(N) CastOpsEnd = N+1
1007#include "llvm/IR/Instruction.def"
1011#define FIRST_FUNCLETPAD_INST(N) FuncletPadOpsBegin = N,
1012#define HANDLE_FUNCLETPAD_INST(N, OPC, CLASS) OPC = N,
1013#define LAST_FUNCLETPAD_INST(N) FuncletPadOpsEnd = N+1
1014#include "llvm/IR/Instruction.def"
1018#define FIRST_OTHER_INST(N) OtherOpsBegin = N,
1019#define HANDLE_OTHER_INST(N, OPC, CLASS) OPC = N,
1020#define LAST_OTHER_INST(N) OtherOpsEnd = N+1
1021#include "llvm/IR/Instruction.def"
1025 friend class SymbolTableListTraits<Instruction, ilist_iterator_bits<
true>,
1031 void setValueSubclassData(
unsigned short D) {
1032 Value::setValueSubclassData(
D);
1035 unsigned short getSubclassDataFromValue()
const {
1036 return Value::getSubclassDataFromValue();
1043 template <
typename BitfieldElement>
1046 std::is_same<BitfieldElement, HasMetadataField>::value ||
1047 !Bitfield::isOverlapping<BitfieldElement, HasMetadataField>(),
1048 "Must not overlap with the metadata bit");
1049 return Bitfield::get<BitfieldElement>(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 auto Storage = getSubclassDataFromValue();
1059 Bitfield::set<BitfieldElement>(Storage,
Value);
1060 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")
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 Function * getFunction(Constant *C)
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)
static std::optional< unsigned > getOpcode(ArrayRef< VPValue * > Values)
Returns the opcode of Values or ~0 if they do not all agree.
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.
MDNode * getAsMDNode() const
Return this as a bar MDNode.
BasicBlock * getBasicBlock()
InsertPosition(std::nullptr_t)
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.
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
Instruction * getPrevNonDebugInstruction(bool SkipPseudoOp=false)
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)
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
static bool isNilpotent(unsigned Opcode)
bool isBitwiseLogicOp() const
Return true if this is and/or/xor.
static bool isTerminator(unsigned Opcode)
void moveAfter(InstListType::iterator MovePos)
Unlink this instruction from its current basic block and insert it into the basic block that MovePos ...
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.
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.
@ Or
Bitwise or logical OR of integers.
@ Xor
Bitwise or logical XOR of integers.
@ And
Bitwise or logical AND 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.