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();
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; }
289 bool isOnlyUserOfAnyOperand();
294 return Opcode >= TermOpsBegin && Opcode < TermOpsEnd;
298 return Opcode >= UnaryOpsBegin && Opcode < UnaryOpsEnd;
301 return Opcode >= BinaryOpsBegin && Opcode < BinaryOpsEnd;
305 return Opcode == UDiv || Opcode == SDiv || Opcode == URem || Opcode == SRem;
309 return Opcode == FDiv || Opcode == FRem;
314 return Opcode >= Shl && Opcode <= AShr;
329 return Opcode ==
And || Opcode ==
Or || Opcode ==
Xor;
338 static inline bool isCast(
unsigned Opcode) {
339 return Opcode >= CastOpsBegin && Opcode < CastOpsEnd;
344 return Opcode >= FuncletPadOpsBegin && Opcode < FuncletPadOpsEnd;
351 case Instruction::CatchSwitch:
352 case Instruction::CatchRet:
353 case Instruction::CleanupRet:
354 case Instruction::Invoke:
355 case Instruction::Resume:
356 case Instruction::CallBr:
368 bool hasMetadata()
const {
return DbgLoc || Value::hasMetadata(); }
372 bool hasNonDebugLocLoopMetadata()
const;
380 return getMetadata(KindID) !=
nullptr;
385 return getMetadata(Kind) !=
nullptr;
392 if (KindID == LLVMContext::MD_dbg)
394 return Value::getMetadata(KindID);
400 if (!hasMetadata())
return nullptr;
401 return getMetadataImpl(Kind);
410 getAllMetadataImpl(MDs);
417 Value::getAllMetadata(MDs);
422 void setMetadata(
unsigned KindID,
MDNode *
Node);
437 void swapProfMetadata();
451 void addAnnotationMetadata(StringRef Annotation);
456 void addAnnotationMetadata(SmallVector<StringRef> Annotations);
458 AAMDNodes getAAMetadata()
const;
461 void setAAMetadata(
const AAMDNodes &
N);
464 void setNoSanitizeMetadata();
469 bool extractProfTotalWeight(
uint64_t &TotalVal)
const;
479 const DebugLoc &getStableDebugLoc()
const;
483 void setHasNoUnsignedWrap(
bool b =
true);
487 void setHasNoSignedWrap(
bool b =
true);
491 void setIsExact(
bool b =
true);
495 void setNonNeg(
bool b =
true);
512 void dropPoisonGeneratingFlags();
518 void dropPoisonGeneratingMetadata();
524 void dropPoisonGeneratingReturnAttributes();
528 bool hasPoisonGeneratingAnnotations()
const {
529 return hasPoisonGeneratingFlags() ||
530 hasPoisonGeneratingReturnAttributes() ||
531 hasPoisonGeneratingMetadata();
536 dropPoisonGeneratingFlags();
537 dropPoisonGeneratingReturnAttributes();
538 dropPoisonGeneratingMetadata();
550 void dropUBImplyingAttrsAndMetadata();
558 void setFast(
bool B);
563 void setHasAllowReassoc(
bool B);
568 void setHasNoNaNs(
bool B);
573 void setHasNoInfs(
bool B);
578 void setHasNoSignedZeros(
bool B);
583 void setHasAllowReciprocal(
bool B);
588 void setHasAllowContract(
bool B);
593 void setHasApproxFunc(
bool B);
598 void setFastMathFlags(FastMathFlags FMF);
603 void copyFastMathFlags(FastMathFlags FMF);
635 void copyFastMathFlags(
const Instruction *
I);
639 void copyIRFlags(
const Value *V,
bool IncludeWrapFlags =
true);
643 void andIRFlags(
const Value *V);
658 void applyMergedLocation(DILocation *LocA, DILocation *LocB);
664 void updateLocationAfterHoist();
683 void mergeDIAssignID(ArrayRef<
const Instruction *> SourceInstructions);
687 MDNode *getMetadataImpl(StringRef Kind)
const;
689 getAllMetadataImpl(SmallVectorImpl<
std::pair<
unsigned, MDNode *>> &)
const;
693 void updateDIAssignIDMapping(DIAssignID *ID);
708 return Opcode ==
And || Opcode ==
Or || Opcode ==
Xor ||
709 Opcode == Add || Opcode ==
Mul;
739 return Opcode ==
And || Opcode ==
Or;
753 return Opcode ==
Xor;
763 bool mayReadOrWriteMemory()
const {
764 return mayReadFromMemory() || mayWriteToMemory();
792 bool isFenceLike()
const {
798 case Instruction::Fence:
799 case Instruction::CatchPad:
800 case Instruction::CatchRet:
801 case Instruction::Call:
802 case Instruction::Invoke:
833 bool isEHPad()
const {
835 case Instruction::CatchSwitch:
836 case Instruction::CatchPad:
837 case Instruction::CleanupPad:
838 case Instruction::LandingPad:
860 getNextNonDebugInstruction(
bool SkipPseudoOp =
false)
const;
863 static_cast<const Instruction *
>(
this)->getNextNonDebugInstruction(
871 getPrevNonDebugInstruction(
bool SkipPseudoOp =
false)
const;
874 static_cast<const Instruction *
>(
this)->getPrevNonDebugInstruction(
901 CompareIgnoringAlignment = 1 << 0,
904 CompareUsingScalarTypes = 1 << 1,
906 CompareUsingIntersectedAttrs = 1 << 2,
952 return V->getValueID() >= Value::InstructionVal;
959#define FIRST_TERM_INST(N) TermOpsBegin = N,
960#define HANDLE_TERM_INST(N, OPC, CLASS) OPC = N,
961#define LAST_TERM_INST(N) TermOpsEnd = N+1
962#include "llvm/IR/Instruction.def"
966#define FIRST_UNARY_INST(N) UnaryOpsBegin = N,
967#define HANDLE_UNARY_INST(N, OPC, CLASS) OPC = N,
968#define LAST_UNARY_INST(N) UnaryOpsEnd = N+1
969#include "llvm/IR/Instruction.def"
973#define FIRST_BINARY_INST(N) BinaryOpsBegin = N,
974#define HANDLE_BINARY_INST(N, OPC, CLASS) OPC = N,
975#define LAST_BINARY_INST(N) BinaryOpsEnd = N+1
976#include "llvm/IR/Instruction.def"
980#define FIRST_MEMORY_INST(N) MemoryOpsBegin = N,
981#define HANDLE_MEMORY_INST(N, OPC, CLASS) OPC = N,
982#define LAST_MEMORY_INST(N) MemoryOpsEnd = N+1
983#include "llvm/IR/Instruction.def"
987#define FIRST_CAST_INST(N) CastOpsBegin = N,
988#define HANDLE_CAST_INST(N, OPC, CLASS) OPC = N,
989#define LAST_CAST_INST(N) CastOpsEnd = N+1
990#include "llvm/IR/Instruction.def"
994#define FIRST_FUNCLETPAD_INST(N) FuncletPadOpsBegin = N,
995#define HANDLE_FUNCLETPAD_INST(N, OPC, CLASS) OPC = N,
996#define LAST_FUNCLETPAD_INST(N) FuncletPadOpsEnd = N+1
997#include "llvm/IR/Instruction.def"
1001#define FIRST_OTHER_INST(N) OtherOpsBegin = N,
1002#define HANDLE_OTHER_INST(N, OPC, CLASS) OPC = N,
1003#define LAST_OTHER_INST(N) OtherOpsEnd = N+1
1004#include "llvm/IR/Instruction.def"
1008 friend class SymbolTableListTraits<Instruction, ilist_iterator_bits<
true>,
1014 void setValueSubclassData(
unsigned short D) {
1015 Value::setValueSubclassData(
D);
1018 unsigned short getSubclassDataFromValue()
const {
1019 return Value::getSubclassDataFromValue();
1026 template <
typename BitfieldElement>
1029 std::is_same<BitfieldElement, HasMetadataField>::value ||
1030 !Bitfield::isOverlapping<BitfieldElement, HasMetadataField>(),
1031 "Must not overlap with the metadata bit");
1032 return Bitfield::get<BitfieldElement>(getSubclassDataFromValue());
1035 template <
typename BitfieldElement>
1038 std::is_same<BitfieldElement, HasMetadataField>::value ||
1039 !Bitfield::isOverlapping<BitfieldElement, HasMetadataField>(),
1040 "Must not overlap with the metadata bit");
1041 auto Storage = getSubclassDataFromValue();
1042 Bitfield::set<BitfieldElement>(Storage,
Value);
1043 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)
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)
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.