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();
442 void addAnnotationMetadata(
StringRef Annotation);
455 void setNoSanitizeMetadata();
470 const DebugLoc &getStableDebugLoc()
const;
474 void setHasNoUnsignedWrap(
bool b =
true);
478 void setHasNoSignedWrap(
bool b =
true);
482 void setIsExact(
bool b =
true);
486 void setNonNeg(
bool b =
true);
503 void dropPoisonGeneratingFlags();
509 void dropPoisonGeneratingMetadata();
515 void dropPoisonGeneratingReturnAttributes();
519 bool hasPoisonGeneratingAnnotations()
const {
520 return hasPoisonGeneratingFlags() ||
521 hasPoisonGeneratingReturnAttributes() ||
522 hasPoisonGeneratingMetadata();
527 dropPoisonGeneratingFlags();
528 dropPoisonGeneratingReturnAttributes();
529 dropPoisonGeneratingMetadata();
541 void dropUBImplyingAttrsAndMetadata();
549 void setFast(
bool B);
554 void setHasAllowReassoc(
bool B);
559 void setHasNoNaNs(
bool B);
564 void setHasNoInfs(
bool B);
569 void setHasNoSignedZeros(
bool B);
574 void setHasAllowReciprocal(
bool B);
579 void setHasAllowContract(
bool B);
584 void setHasApproxFunc(
bool B);
589 void setFastMathFlags(FastMathFlags FMF);
594 void copyFastMathFlags(FastMathFlags FMF);
626 void copyFastMathFlags(
const Instruction *
I);
630 void copyIRFlags(
const Value *V,
bool IncludeWrapFlags =
true);
634 void andIRFlags(
const Value *V);
649 void applyMergedLocation(DILocation *LocA, DILocation *LocB);
655 void updateLocationAfterHoist();
674 void mergeDIAssignID(ArrayRef<
const Instruction *> SourceInstructions);
678 MDNode *getMetadataImpl(StringRef Kind)
const;
680 getAllMetadataImpl(SmallVectorImpl<
std::pair<
unsigned, MDNode *>> &)
const;
684 void updateDIAssignIDMapping(DIAssignID *ID);
699 return Opcode ==
And || Opcode ==
Or || Opcode ==
Xor ||
700 Opcode == Add || Opcode ==
Mul;
730 return Opcode ==
And || Opcode ==
Or;
744 return Opcode ==
Xor;
754 bool mayReadOrWriteMemory()
const {
755 return mayReadFromMemory() || mayWriteToMemory();
783 bool isFenceLike()
const {
789 case Instruction::Fence:
790 case Instruction::CatchPad:
791 case Instruction::CatchRet:
792 case Instruction::Call:
793 case Instruction::Invoke:
824 bool isEHPad()
const {
826 case Instruction::CatchSwitch:
827 case Instruction::CatchPad:
828 case Instruction::CleanupPad:
829 case Instruction::LandingPad:
851 getNextNonDebugInstruction(
bool SkipPseudoOp =
false)
const;
854 static_cast<const Instruction *
>(
this)->getNextNonDebugInstruction(
862 getPrevNonDebugInstruction(
bool SkipPseudoOp =
false)
const;
865 static_cast<const Instruction *
>(
this)->getPrevNonDebugInstruction(
890 CompareIgnoringAlignment = 1<<0,
893 CompareUsingScalarTypes = 1<<1
939 return V->getValueID() >= Value::InstructionVal;
946#define FIRST_TERM_INST(N) TermOpsBegin = N,
947#define HANDLE_TERM_INST(N, OPC, CLASS) OPC = N,
948#define LAST_TERM_INST(N) TermOpsEnd = N+1
949#include "llvm/IR/Instruction.def"
953#define FIRST_UNARY_INST(N) UnaryOpsBegin = N,
954#define HANDLE_UNARY_INST(N, OPC, CLASS) OPC = N,
955#define LAST_UNARY_INST(N) UnaryOpsEnd = N+1
956#include "llvm/IR/Instruction.def"
960#define FIRST_BINARY_INST(N) BinaryOpsBegin = N,
961#define HANDLE_BINARY_INST(N, OPC, CLASS) OPC = N,
962#define LAST_BINARY_INST(N) BinaryOpsEnd = N+1
963#include "llvm/IR/Instruction.def"
967#define FIRST_MEMORY_INST(N) MemoryOpsBegin = N,
968#define HANDLE_MEMORY_INST(N, OPC, CLASS) OPC = N,
969#define LAST_MEMORY_INST(N) MemoryOpsEnd = N+1
970#include "llvm/IR/Instruction.def"
974#define FIRST_CAST_INST(N) CastOpsBegin = N,
975#define HANDLE_CAST_INST(N, OPC, CLASS) OPC = N,
976#define LAST_CAST_INST(N) CastOpsEnd = N+1
977#include "llvm/IR/Instruction.def"
981#define FIRST_FUNCLETPAD_INST(N) FuncletPadOpsBegin = N,
982#define HANDLE_FUNCLETPAD_INST(N, OPC, CLASS) OPC = N,
983#define LAST_FUNCLETPAD_INST(N) FuncletPadOpsEnd = N+1
984#include "llvm/IR/Instruction.def"
988#define FIRST_OTHER_INST(N) OtherOpsBegin = N,
989#define HANDLE_OTHER_INST(N, OPC, CLASS) OPC = N,
990#define LAST_OTHER_INST(N) OtherOpsEnd = N+1
991#include "llvm/IR/Instruction.def"
995 friend class SymbolTableListTraits<Instruction, ilist_iterator_bits<
true>,
1001 void setValueSubclassData(
unsigned short D) {
1002 Value::setValueSubclassData(
D);
1005 unsigned short getSubclassDataFromValue()
const {
1006 return Value::getSubclassDataFromValue();
1013 template <
typename BitfieldElement>
1016 std::is_same<BitfieldElement, HasMetadataField>::value ||
1017 !Bitfield::isOverlapping<BitfieldElement, HasMetadataField>(),
1018 "Must not overlap with the metadata bit");
1019 return Bitfield::get<BitfieldElement>(getSubclassDataFromValue());
1022 template <
typename BitfieldElement>
1025 std::is_same<BitfieldElement, HasMetadataField>::value ||
1026 !Bitfield::isOverlapping<BitfieldElement, HasMetadataField>(),
1027 "Must not overlap with the metadata bit");
1028 auto Storage = getSubclassDataFromValue();
1029 Bitfield::set<BitfieldElement>(Storage,
Value);
1030 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
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)
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.