14 #ifndef LLVM_IR_INSTRUCTION_H 15 #define LLVM_IR_INSTRUCTION_H 51 HasMetadataBit = 1 << 15
74 const Module *getModule()
const;
76 return const_cast<Module *
>(
77 static_cast<const Instruction *
>(
this)->getModule());
92 void removeFromParent();
125 unsigned getOpcode()
const {
return getValueID() - InstructionVal; }
136 return isExceptionalTerminator(
getOpcode());
139 return isIndirectTerminator(
getOpcode());
142 static const char* getOpcodeName(
unsigned OpCode);
145 return OpCode >= TermOpsBegin && OpCode < TermOpsEnd;
149 return Opcode >= UnaryOpsBegin && Opcode < UnaryOpsEnd;
152 return Opcode >= BinaryOpsBegin && Opcode < BinaryOpsEnd;
156 return Opcode == UDiv || Opcode == SDiv || Opcode == URem || Opcode == SRem;
161 return Opcode >= Shl && Opcode <= AShr;
176 return Opcode == And || Opcode == Or || Opcode == Xor;
185 static inline bool isCast(
unsigned OpCode) {
186 return OpCode >= CastOpsBegin && OpCode < CastOpsEnd;
191 return OpCode >= FuncletPadOpsBegin && OpCode < FuncletPadOpsEnd;
197 case Instruction::CatchSwitch:
198 case Instruction::CatchRet:
199 case Instruction::CleanupRet:
200 case Instruction::Invoke:
201 case Instruction::Resume:
211 case Instruction::IndirectBr:
212 case Instruction::CallBr:
224 bool hasMetadata()
const {
return DbgLoc || hasMetadataHashEntry(); }
229 return hasMetadataHashEntry();
234 return getMetadata(KindID) !=
nullptr;
239 return getMetadata(Kind) !=
nullptr;
245 if (!hasMetadata())
return nullptr;
246 return getMetadataImpl(KindID);
252 if (!hasMetadata())
return nullptr;
253 return getMetadataImpl(Kind);
262 getAllMetadataImpl(MDs);
270 getAllMetadataOtherThanDebugLocImpl(MDs);
292 void swapProfMetadata();
300 return dropUnknownNonDebugMetadata(
None);
306 unsigned IDs[] = {ID1, ID2};
307 return dropUnknownNonDebugMetadata(IDs);
317 bool extractProfMetadata(uint64_t &TrueVal, uint64_t &FalseVal)
const;
322 bool extractProfTotalWeight(uint64_t &TotalVal)
const;
325 void setProfWeight(uint64_t
W);
335 void setHasNoUnsignedWrap(
bool b =
true);
339 void setHasNoSignedWrap(
bool b =
true);
343 void setIsExact(
bool b =
true);
353 void dropPoisonGeneratingFlags();
356 bool isExact()
const;
361 void setFast(
bool B);
366 void setHasAllowReassoc(
bool B);
371 void setHasNoNaNs(
bool B);
376 void setHasNoInfs(
bool B);
381 void setHasNoSignedZeros(
bool B);
386 void setHasAllowReciprocal(
bool B);
391 void setHasApproxFunc(
bool B);
407 bool hasAllowReassoc()
const;
410 bool hasNoNaNs()
const;
413 bool hasNoInfs()
const;
416 bool hasNoSignedZeros()
const;
419 bool hasAllowReciprocal()
const;
422 bool hasAllowContract()
const;
425 bool hasApproxFunc()
const;
437 void copyIRFlags(
const Value *V,
bool IncludeWrapFlags =
true);
441 void andIRFlags(
const Value *V);
460 bool hasMetadataHashEntry()
const {
461 return (getSubclassDataFromValue() & HasMetadataBit) != 0;
465 MDNode *getMetadataImpl(
unsigned KindID)
const;
468 getAllMetadataImpl(
SmallVectorImpl<std::pair<unsigned, MDNode *>> &)
const;
469 void getAllMetadataOtherThanDebugLocImpl(
472 void clearMetadataHashEntries();
487 return Opcode == And || Opcode == Or || Opcode == Xor ||
488 Opcode ==
Add || Opcode == Mul;
503 case And:
case Or:
case Xor:
518 return Opcode == And || Opcode == Or;
532 return Opcode == Xor;
536 bool mayWriteToMemory()
const;
539 bool mayReadFromMemory()
const;
543 return mayReadFromMemory() || mayWriteToMemory();
551 bool hasAtomicLoad()
const;
554 bool hasAtomicStore()
const;
567 case Instruction::Fence:
568 case Instruction::CatchPad:
569 case Instruction::CatchRet:
571 case Instruction::Invoke:
590 bool isSafeToRemove()
const;
595 case Instruction::CatchSwitch:
596 case Instruction::CatchPad:
597 case Instruction::CleanupPad:
598 case Instruction::LandingPad:
607 bool isLifetimeStartOrEnd()
const;
611 const Instruction *getNextNonDebugInstruction()
const;
614 static_cast<const Instruction *
>(
this)->getNextNonDebugInstruction());
619 const Instruction *getPrevNonDebugInstruction()
const;
622 static_cast<const Instruction *
>(
this)->getPrevNonDebugInstruction());
640 bool isIdenticalToWhenDefined(
const Instruction *I)
const;
646 CompareIgnoringAlignment = 1<<0,
649 CompareUsingScalarTypes = 1<<1
660 bool isSameOperationAs(
const Instruction *I,
unsigned flags = 0)
const;
665 bool isUsedOutsideOfBlock(
const BasicBlock *BB)
const;
669 unsigned getNumSuccessors()
const;
676 void setSuccessor(
unsigned Idx,
BasicBlock *BB);
684 return V->
getValueID() >= Value::InstructionVal;
691 #define FIRST_TERM_INST(N) TermOpsBegin = N, 692 #define HANDLE_TERM_INST(N, OPC, CLASS) OPC = N, 693 #define LAST_TERM_INST(N) TermOpsEnd = N+1 694 #include "llvm/IR/Instruction.def" 698 #define FIRST_UNARY_INST(N) UnaryOpsBegin = N, 699 #define HANDLE_UNARY_INST(N, OPC, CLASS) OPC = N, 700 #define LAST_UNARY_INST(N) UnaryOpsEnd = N+1 701 #include "llvm/IR/Instruction.def" 705 #define FIRST_BINARY_INST(N) BinaryOpsBegin = N, 706 #define HANDLE_BINARY_INST(N, OPC, CLASS) OPC = N, 707 #define LAST_BINARY_INST(N) BinaryOpsEnd = N+1 708 #include "llvm/IR/Instruction.def" 712 #define FIRST_MEMORY_INST(N) MemoryOpsBegin = N, 713 #define HANDLE_MEMORY_INST(N, OPC, CLASS) OPC = N, 714 #define LAST_MEMORY_INST(N) MemoryOpsEnd = N+1 715 #include "llvm/IR/Instruction.def" 719 #define FIRST_CAST_INST(N) CastOpsBegin = N, 720 #define HANDLE_CAST_INST(N, OPC, CLASS) OPC = N, 721 #define LAST_CAST_INST(N) CastOpsEnd = N+1 722 #include "llvm/IR/Instruction.def" 726 #define FIRST_FUNCLETPAD_INST(N) FuncletPadOpsBegin = N, 727 #define HANDLE_FUNCLETPAD_INST(N, OPC, CLASS) OPC = N, 728 #define LAST_FUNCLETPAD_INST(N) FuncletPadOpsEnd = N+1 729 #include "llvm/IR/Instruction.def" 733 #define FIRST_OTHER_INST(N) OtherOpsBegin = N, 734 #define HANDLE_OTHER_INST(N, OPC, CLASS) OPC = N, 735 #define LAST_OTHER_INST(N) OtherOpsEnd = N+1 736 #include "llvm/IR/Instruction.def" 744 void setValueSubclassData(
unsigned short D) {
748 unsigned short getSubclassDataFromValue()
const {
752 void setHasMetadataHashEntry(
bool V) {
753 setValueSubclassData((getSubclassDataFromValue() & ~HasMetadataBit) |
754 (V ? HasMetadataBit : 0));
765 assert((D & HasMetadataBit) == 0 &&
"Out of range value put into field");
766 setValueSubclassData((getSubclassDataFromValue() & HasMetadataBit) | D);
770 return getSubclassDataFromValue() & ~HasMetadataBit;
789 #endif // LLVM_IR_INSTRUCTION_H
void getAllMetadataOtherThanDebugLoc(SmallVectorImpl< std::pair< unsigned, MDNode *>> &MDs) const
This does the same thing as getAllMetadata, except that it filters out the debug location.
unsigned short getSubclassDataFromValue() const
unsigned getValueID() const
Return an ID for the concrete type of this object.
bool isFuncletPad() const
bool isFenceLike() const
Return true if this instruction behaves like a memory fence: it can load or store to memory location ...
This class represents lattice values for constants.
unsigned getSubclassDataFromInstruction() const
bool hasMetadataOtherThanDebugLoc() const
Return true if this instruction has metadata attached to it other than a debug location.
A Module instance is used to store all the information related to an LLVM module. ...
bool isIdempotent() const
Return true if the instruction is idempotent:
bool mayThrow(const MachineInstr &MI)
MDNode * getMetadata(StringRef Kind) const
Get the metadata of given kind attached to this Instruction.
bool isTerminator() const
void deleteValue()
Delete a pointer to a generic Value.
bool isArithmeticShift() const
Return true if this is an arithmetic shift right.
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 isCommutative(unsigned Opcode)
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
bool isNilpotent() const
Return true if the instruction is nilpotent:
bool hasMetadata(unsigned KindID) const
Return true if this instruction has the given type of metadata attached.
A Use represents the edge between a Value definition and its users.
static Optional< unsigned > getOpcode(ArrayRef< VPValue *> Values)
Returns the opcode of Values or ~0 if they do not all agree.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
static bool isIndirectTerminator(unsigned OpCode)
Returns true if the OpCode is a terminator with indirect targets.
bool hasMetadata() const
Return true if this instruction has any metadata attached to it.
void dropUnknownNonDebugMetadata(unsigned ID1)
OperationEquivalenceFlags
When checking for operation equivalence (using isSameOperationAs) it is sometimes useful to ignore ce...
bool isBitwiseLogicOp() const
Return true if this is and/or/xor.
void dropUnknownNonDebugMetadata()
static bool isBinaryOp(unsigned Opcode)
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
void setInstructionSubclassData(unsigned short D)
Instruction * getNextNonDebugInstruction()
static bool hasMetadataOtherThanDebugLoc(const GlobalVariable *GV)
bool hasMetadata(StringRef Kind) const
Return true if this instruction has the given type of metadata attached.
static Function * getFunction(Constant *C)
static bool hasNoSignedWrap(BinaryOperator &I)
static bool isTerminator(unsigned OpCode)
Use delete by default for iplist and ilist.
An ilist node that can access its parent list.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
const char * getOpcodeName() const
bool mayHaveSideEffects() const
Return true if the instruction may have side effects.
static bool isUnaryOp(unsigned Opcode)
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
static bool hasNoUnsignedWrap(BinaryOperator &I)
bool isExceptionalTerminator() const
static bool isAtomic(Instruction *I)
C setMetadata(LLVMContext::MD_range, MDNode::get(Context, LowAndHigh))
Instruction * user_back()
Specialize the methods defined in Value, as we know that an instruction can only be used by other ins...
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
static bool isCast(unsigned OpCode)
Determine if the OpCode is one of the CastInst instructions.
void dropUnknownNonDebugMetadata(unsigned ID1, unsigned ID2)
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static void deleteNode(NodeTy *V)
bool isCommutative() const
Return true if the instruction is commutative:
void setValueSubclassData(unsigned short D)
void getAllMetadata(SmallVectorImpl< std::pair< unsigned, MDNode *>> &MDs) const
Get all metadata attached to this Instruction.
static bool isExceptionalTerminator(unsigned OpCode)
Returns true if the OpCode is a terminator related to exception handling.
const Instruction * user_back() const
List that automatically updates parent links and symbol tables.
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
static bool isNilpotent(unsigned Opcode)
bool isLogicalShift() const
Return true if this is a logical shift left or a logical shift right.
static bool isFuncletPad(unsigned OpCode)
Determine if the OpCode is one of the FuncletPadInst instructions.
bool isIndirectTerminator() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
static bool isIntDivRem(unsigned Opcode)
Instruction * getPrevNonDebugInstruction()
bool isEHPad() const
Return true if the instruction is a variety of EH-block.
Convenience struct for specifying and reasoning about fast-math flags.
StringRef - Represent a constant reference to a string, i.e.
static bool isIdempotent(unsigned Opcode)
static bool isAssociative(const COFFSection &Section)
static bool isAssociative(unsigned Opcode)
const BasicBlock * getParent() const
bool mayReadOrWriteMemory() const
Return true if this instruction may read or write memory.