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();
219 void insertBefore(InstListType::iterator InsertPos);
227 void insertAfter(InstListType::iterator InsertPos);
231 InstListType::iterator insertInto(
BasicBlock *ParentBB,
232 InstListType::iterator It);
234 void insertBefore(
BasicBlock &BB, InstListType::iterator InsertPos);
248 void moveBefore(InstListType::iterator InsertPos);
253 void moveBeforePreserving(InstListType::iterator MovePos);
258 void moveBeforePreserving(
BasicBlock &BB, InstListType::iterator
I);
272 void moveBeforeImpl(
BasicBlock &BB, InstListType::iterator
I,
bool Preserve);
278 void moveBefore(
BasicBlock &BB, InstListType::iterator
I);
310 unsigned getOpcode()
const {
return getValueID() - InstructionVal; }
325 bool isOnlyUserOfAnyOperand();
330 return Opcode >= TermOpsBegin && Opcode < TermOpsEnd;
334 return Opcode >= UnaryOpsBegin && Opcode < UnaryOpsEnd;
337 return Opcode >= BinaryOpsBegin && Opcode < BinaryOpsEnd;
341 return Opcode == UDiv || Opcode == SDiv || Opcode == URem || Opcode == SRem;
345 return Opcode == FDiv || Opcode == FRem;
350 return Opcode >= Shl && Opcode <= AShr;
365 return Opcode ==
And || Opcode ==
Or || Opcode ==
Xor;
374 static inline bool isCast(
unsigned Opcode) {
375 return Opcode >= CastOpsBegin && Opcode < CastOpsEnd;
380 return Opcode >= FuncletPadOpsBegin && Opcode < FuncletPadOpsEnd;
387 case Instruction::CatchSwitch:
388 case Instruction::CatchRet:
389 case Instruction::CleanupRet:
390 case Instruction::Invoke:
391 case Instruction::Resume:
392 case Instruction::CallBr:
404 bool hasMetadata()
const {
return DbgLoc || Value::hasMetadata(); }
408 bool hasNonDebugLocLoopMetadata()
const;
416 return getMetadata(KindID) !=
nullptr;
421 return getMetadata(Kind) !=
nullptr;
428 if (KindID == LLVMContext::MD_dbg)
430 return Value::getMetadata(KindID);
436 if (!hasMetadata())
return nullptr;
437 return getMetadataImpl(Kind);
446 getAllMetadataImpl(MDs);
453 Value::getAllMetadata(MDs);
458 void setMetadata(
unsigned KindID,
MDNode *
Node);
473 void swapProfMetadata();
487 void addAnnotationMetadata(StringRef Annotation);
492 void addAnnotationMetadata(SmallVector<StringRef> Annotations);
494 AAMDNodes getAAMetadata()
const;
497 void setAAMetadata(
const AAMDNodes &
N);
500 void setNoSanitizeMetadata();
505 bool extractProfTotalWeight(
uint64_t &TotalVal)
const;
515 const DebugLoc &getStableDebugLoc()
const;
519 void setHasNoUnsignedWrap(
bool b =
true);
523 void setHasNoSignedWrap(
bool b =
true);
527 void setIsExact(
bool b =
true);
531 void setNonNeg(
bool b =
true);
548 void dropPoisonGeneratingFlags();
554 void dropPoisonGeneratingMetadata();
560 void dropPoisonGeneratingReturnAttributes();
564 bool hasPoisonGeneratingAnnotations()
const {
565 return hasPoisonGeneratingFlags() ||
566 hasPoisonGeneratingReturnAttributes() ||
567 hasPoisonGeneratingMetadata();
572 dropPoisonGeneratingFlags();
573 dropPoisonGeneratingReturnAttributes();
574 dropPoisonGeneratingMetadata();
586 void dropUBImplyingAttrsAndMetadata();
594 void setFast(
bool B);
599 void setHasAllowReassoc(
bool B);
604 void setHasNoNaNs(
bool B);
609 void setHasNoInfs(
bool B);
614 void setHasNoSignedZeros(
bool B);
619 void setHasAllowReciprocal(
bool B);
624 void setHasAllowContract(
bool B);
629 void setHasApproxFunc(
bool B);
634 void setFastMathFlags(FastMathFlags FMF);
639 void copyFastMathFlags(FastMathFlags FMF);
671 void copyFastMathFlags(
const Instruction *
I);
675 void copyIRFlags(
const Value *V,
bool IncludeWrapFlags =
true);
679 void andIRFlags(
const Value *V);
694 void applyMergedLocation(DILocation *LocA, DILocation *LocB);
700 void updateLocationAfterHoist();
719 void mergeDIAssignID(ArrayRef<
const Instruction *> SourceInstructions);
723 MDNode *getMetadataImpl(StringRef Kind)
const;
725 getAllMetadataImpl(SmallVectorImpl<
std::pair<
unsigned, MDNode *>> &)
const;
729 void updateDIAssignIDMapping(DIAssignID *ID);
744 return Opcode ==
And || Opcode ==
Or || Opcode ==
Xor ||
745 Opcode == Add || Opcode ==
Mul;
775 return Opcode ==
And || Opcode ==
Or;
789 return Opcode ==
Xor;
799 bool mayReadOrWriteMemory()
const {
800 return mayReadFromMemory() || mayWriteToMemory();
828 bool isFenceLike()
const {
834 case Instruction::Fence:
835 case Instruction::CatchPad:
836 case Instruction::CatchRet:
837 case Instruction::Call:
838 case Instruction::Invoke:
869 bool isEHPad()
const {
871 case Instruction::CatchSwitch:
872 case Instruction::CatchPad:
873 case Instruction::CleanupPad:
874 case Instruction::LandingPad:
896 getNextNonDebugInstruction(
bool SkipPseudoOp =
false)
const;
899 static_cast<const Instruction *
>(
this)->getNextNonDebugInstruction(
907 getPrevNonDebugInstruction(
bool SkipPseudoOp =
false)
const;
910 static_cast<const Instruction *
>(
this)->getPrevNonDebugInstruction(
937 CompareIgnoringAlignment = 1 << 0,
940 CompareUsingScalarTypes = 1 << 1,
942 CompareUsingIntersectedAttrs = 1 << 2,
988 return V->getValueID() >= Value::InstructionVal;
995#define FIRST_TERM_INST(N) TermOpsBegin = N,
996#define HANDLE_TERM_INST(N, OPC, CLASS) OPC = N,
997#define LAST_TERM_INST(N) TermOpsEnd = N+1
998#include "llvm/IR/Instruction.def"
1002#define FIRST_UNARY_INST(N) UnaryOpsBegin = N,
1003#define HANDLE_UNARY_INST(N, OPC, CLASS) OPC = N,
1004#define LAST_UNARY_INST(N) UnaryOpsEnd = N+1
1005#include "llvm/IR/Instruction.def"
1009#define FIRST_BINARY_INST(N) BinaryOpsBegin = N,
1010#define HANDLE_BINARY_INST(N, OPC, CLASS) OPC = N,
1011#define LAST_BINARY_INST(N) BinaryOpsEnd = N+1
1012#include "llvm/IR/Instruction.def"
1016#define FIRST_MEMORY_INST(N) MemoryOpsBegin = N,
1017#define HANDLE_MEMORY_INST(N, OPC, CLASS) OPC = N,
1018#define LAST_MEMORY_INST(N) MemoryOpsEnd = N+1
1019#include "llvm/IR/Instruction.def"
1023#define FIRST_CAST_INST(N) CastOpsBegin = N,
1024#define HANDLE_CAST_INST(N, OPC, CLASS) OPC = N,
1025#define LAST_CAST_INST(N) CastOpsEnd = N+1
1026#include "llvm/IR/Instruction.def"
1030#define FIRST_FUNCLETPAD_INST(N) FuncletPadOpsBegin = N,
1031#define HANDLE_FUNCLETPAD_INST(N, OPC, CLASS) OPC = N,
1032#define LAST_FUNCLETPAD_INST(N) FuncletPadOpsEnd = N+1
1033#include "llvm/IR/Instruction.def"
1037#define FIRST_OTHER_INST(N) OtherOpsBegin = N,
1038#define HANDLE_OTHER_INST(N, OPC, CLASS) OPC = N,
1039#define LAST_OTHER_INST(N) OtherOpsEnd = N+1
1040#include "llvm/IR/Instruction.def"
1044 friend class SymbolTableListTraits<Instruction, ilist_iterator_bits<
true>,
1050 void setValueSubclassData(
unsigned short D) {
1051 Value::setValueSubclassData(
D);
1054 unsigned short getSubclassDataFromValue()
const {
1055 return Value::getSubclassDataFromValue();
1062 template <
typename BitfieldElement>
1065 std::is_same<BitfieldElement, HasMetadataField>::value ||
1066 !Bitfield::isOverlapping<BitfieldElement, HasMetadataField>(),
1067 "Must not overlap with the metadata bit");
1068 return Bitfield::get<BitfieldElement>(getSubclassDataFromValue());
1071 template <
typename BitfieldElement>
1074 std::is_same<BitfieldElement, HasMetadataField>::value ||
1075 !Bitfield::isOverlapping<BitfieldElement, HasMetadataField>(),
1076 "Must not overlap with the metadata bit");
1077 auto Storage = getSubclassDataFromValue();
1078 Bitfield::set<BitfieldElement>(Storage,
Value);
1079 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 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)
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.
@ 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.