14#ifndef LLVM_IR_INSTRUCTION_H
15#define LLVM_IR_INSTRUCTION_H
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();
210 void insertBefore(InstListType::iterator InsertPos);
218 InstListType::iterator insertInto(
BasicBlock *ParentBB,
219 InstListType::iterator It);
221 void insertBefore(
BasicBlock &BB, InstListType::iterator InsertPos);
237 void moveBeforeImpl(
BasicBlock &BB, InstListType::iterator
I,
bool Preserve);
243 void moveBefore(
BasicBlock &BB, InstListType::iterator
I);
246 void moveBeforePreserving(
BasicBlock &BB, InstListType::iterator
I);
267 std::optional<InstListType::iterator> getInsertionPointAfterDef();
274 unsigned getOpcode()
const {
return getValueID() - InstructionVal; }
288 bool isOnlyUserOfAnyOperand();
293 return Opcode >= TermOpsBegin && Opcode < TermOpsEnd;
297 return Opcode >= UnaryOpsBegin && Opcode < UnaryOpsEnd;
300 return Opcode >= BinaryOpsBegin && Opcode < BinaryOpsEnd;
304 return Opcode == UDiv || Opcode == SDiv || Opcode == URem || Opcode == SRem;
309 return Opcode >= Shl && Opcode <= AShr;
324 return Opcode ==
And || Opcode ==
Or || Opcode ==
Xor;
333 static inline bool isCast(
unsigned Opcode) {
334 return Opcode >= CastOpsBegin && Opcode < CastOpsEnd;
339 return Opcode >= FuncletPadOpsBegin && Opcode < FuncletPadOpsEnd;
346 case Instruction::CatchSwitch:
347 case Instruction::CatchRet:
348 case Instruction::CleanupRet:
349 case Instruction::Invoke:
350 case Instruction::Resume:
351 case Instruction::CallBr:
363 bool hasMetadata()
const {
return DbgLoc || Value::hasMetadata(); }
371 return getMetadata(KindID) !=
nullptr;
376 return getMetadata(Kind) !=
nullptr;
383 if (KindID == LLVMContext::MD_dbg)
385 return Value::getMetadata(KindID);
391 if (!hasMetadata())
return nullptr;
392 return getMetadataImpl(Kind);
401 getAllMetadataImpl(MDs);
408 Value::getAllMetadata(MDs);
413 void setMetadata(
unsigned KindID,
MDNode *
Node);
428 void swapProfMetadata();
438 return dropUnknownNonDebugMetadata(std::nullopt);
441 return dropUnknownNonDebugMetadata(
ArrayRef(ID1));
444 unsigned IDs[] = {ID1, ID2};
445 return dropUnknownNonDebugMetadata(IDs);
452 void addAnnotationMetadata(
StringRef Annotation);
465 void setNoSanitizeMetadata();
480 const DebugLoc &getStableDebugLoc()
const;
484 void setHasNoUnsignedWrap(
bool b =
true);
488 void setHasNoSignedWrap(
bool b =
true);
492 void setIsExact(
bool b =
true);
496 void setNonNeg(
bool b =
true);
513 void dropPoisonGeneratingFlags();
519 void dropPoisonGeneratingMetadata();
525 void dropPoisonGeneratingReturnAttributes();
529 bool hasPoisonGeneratingAnnotations()
const {
530 return hasPoisonGeneratingFlags() ||
531 hasPoisonGeneratingReturnAttributes() ||
532 hasPoisonGeneratingMetadata();
537 dropPoisonGeneratingFlags();
538 dropPoisonGeneratingReturnAttributes();
539 dropPoisonGeneratingMetadata();
551 void dropUBImplyingAttrsAndMetadata();
559 void setFast(
bool B);
564 void setHasAllowReassoc(
bool B);
569 void setHasNoNaNs(
bool B);
574 void setHasNoInfs(
bool B);
579 void setHasNoSignedZeros(
bool B);
584 void setHasAllowReciprocal(
bool B);
589 void setHasAllowContract(
bool B);
594 void setHasApproxFunc(
bool B);
599 void setFastMathFlags(FastMathFlags FMF);
604 void copyFastMathFlags(FastMathFlags FMF);
636 void copyFastMathFlags(
const Instruction *
I);
640 void copyIRFlags(
const Value *V,
bool IncludeWrapFlags =
true);
644 void andIRFlags(
const Value *V);
659 void applyMergedLocation(DILocation *LocA, DILocation *LocB);
665 void updateLocationAfterHoist();
684 void mergeDIAssignID(ArrayRef<
const Instruction *> SourceInstructions);
688 MDNode *getMetadataImpl(StringRef Kind)
const;
690 getAllMetadataImpl(SmallVectorImpl<
std::pair<
unsigned, MDNode *>> &)
const;
694 void updateDIAssignIDMapping(DIAssignID *ID);
709 return Opcode ==
And || Opcode ==
Or || Opcode ==
Xor ||
710 Opcode == Add || Opcode ==
Mul;
740 return Opcode ==
And || Opcode ==
Or;
754 return Opcode ==
Xor;
764 bool mayReadOrWriteMemory()
const {
765 return mayReadFromMemory() || mayWriteToMemory();
793 bool isFenceLike()
const {
799 case Instruction::Fence:
800 case Instruction::CatchPad:
801 case Instruction::CatchRet:
802 case Instruction::Call:
803 case Instruction::Invoke:
834 bool isEHPad()
const {
836 case Instruction::CatchSwitch:
837 case Instruction::CatchPad:
838 case Instruction::CleanupPad:
839 case Instruction::LandingPad:
861 getNextNonDebugInstruction(
bool SkipPseudoOp =
false)
const;
864 static_cast<const Instruction *
>(
this)->getNextNonDebugInstruction(
872 getPrevNonDebugInstruction(
bool SkipPseudoOp =
false)
const;
875 static_cast<const Instruction *
>(
this)->getPrevNonDebugInstruction(
900 CompareIgnoringAlignment = 1<<0,
903 CompareUsingScalarTypes = 1<<1
949 return V->getValueID() >= Value::InstructionVal;
956#define FIRST_TERM_INST(N) TermOpsBegin = N,
957#define HANDLE_TERM_INST(N, OPC, CLASS) OPC = N,
958#define LAST_TERM_INST(N) TermOpsEnd = N+1
959#include "llvm/IR/Instruction.def"
963#define FIRST_UNARY_INST(N) UnaryOpsBegin = N,
964#define HANDLE_UNARY_INST(N, OPC, CLASS) OPC = N,
965#define LAST_UNARY_INST(N) UnaryOpsEnd = N+1
966#include "llvm/IR/Instruction.def"
970#define FIRST_BINARY_INST(N) BinaryOpsBegin = N,
971#define HANDLE_BINARY_INST(N, OPC, CLASS) OPC = N,
972#define LAST_BINARY_INST(N) BinaryOpsEnd = N+1
973#include "llvm/IR/Instruction.def"
977#define FIRST_MEMORY_INST(N) MemoryOpsBegin = N,
978#define HANDLE_MEMORY_INST(N, OPC, CLASS) OPC = N,
979#define LAST_MEMORY_INST(N) MemoryOpsEnd = N+1
980#include "llvm/IR/Instruction.def"
984#define FIRST_CAST_INST(N) CastOpsBegin = N,
985#define HANDLE_CAST_INST(N, OPC, CLASS) OPC = N,
986#define LAST_CAST_INST(N) CastOpsEnd = N+1
987#include "llvm/IR/Instruction.def"
991#define FIRST_FUNCLETPAD_INST(N) FuncletPadOpsBegin = N,
992#define HANDLE_FUNCLETPAD_INST(N, OPC, CLASS) OPC = N,
993#define LAST_FUNCLETPAD_INST(N) FuncletPadOpsEnd = N+1
994#include "llvm/IR/Instruction.def"
998#define FIRST_OTHER_INST(N) OtherOpsBegin = N,
999#define HANDLE_OTHER_INST(N, OPC, CLASS) OPC = N,
1000#define LAST_OTHER_INST(N) OtherOpsEnd = N+1
1001#include "llvm/IR/Instruction.def"
1005 friend class SymbolTableListTraits<Instruction, ilist_iterator_bits<
true>,
1011 void setValueSubclassData(
unsigned short D) {
1012 Value::setValueSubclassData(
D);
1015 unsigned short getSubclassDataFromValue()
const {
1016 return Value::getSubclassDataFromValue();
1023 template <
typename BitfieldElement>
1026 std::is_same<BitfieldElement, HasMetadataField>::value ||
1027 !Bitfield::isOverlapping<BitfieldElement, HasMetadataField>(),
1028 "Must not overlap with the metadata bit");
1029 return Bitfield::get<BitfieldElement>(getSubclassDataFromValue());
1032 template <
typename BitfieldElement>
1035 std::is_same<BitfieldElement, HasMetadataField>::value ||
1036 !Bitfield::isOverlapping<BitfieldElement, HasMetadataField>(),
1037 "Must not overlap with the metadata bit");
1038 auto Storage = getSubclassDataFromValue();
1039 Bitfield::set<BitfieldElement>(Storage,
Value);
1040 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 unsigned getFastMathFlags(const MachineInstr &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)
Annotations lets you mark points and ranges inside source code, for tests:
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.
InsertPosition(InstListType::iterator InsertAt)
BasicBlock * getBasicBlock()
InsertPosition(std::nullptr_t)
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 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
void dropUnknownNonDebugMetadata(unsigned ID1, unsigned ID2)
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)
void dropUnknownNonDebugMetadata()
bool isBitwiseLogicOp() const
Return true if this is and/or/xor.
static bool isTerminator(unsigned Opcode)
void dropUnknownNonDebugMetadata(unsigned ID1)
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...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
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.
bool extractProfTotalWeight(const MDNode *ProfileData, uint64_t &TotalWeights)
Retrieve the total of all weights from MD_prof data.
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.
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
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.