15 #ifndef LLVM_IR_INSTRUCTION_H 16 #define LLVM_IR_INSTRUCTION_H 52 HasMetadataBit = 1 << 15
75 const Module *getModule()
const;
77 return const_cast<Module *
>(
78 static_cast<const Instruction *
>(
this)->getModule());
93 void removeFromParent();
126 unsigned getOpcode()
const {
return getValueID() - InstructionVal; }
137 return isExceptionalTerminator(
getOpcode());
140 static const char* getOpcodeName(
unsigned OpCode);
143 return OpCode >= TermOpsBegin && OpCode < TermOpsEnd;
147 return Opcode >= UnaryOpsBegin && Opcode < UnaryOpsEnd;
150 return Opcode >= BinaryOpsBegin && Opcode < BinaryOpsEnd;
154 return Opcode == UDiv || Opcode == SDiv || Opcode == URem || Opcode == SRem;
159 return Opcode >= Shl && Opcode <= AShr;
174 return Opcode == And || Opcode == Or || Opcode == Xor;
183 static inline bool isCast(
unsigned OpCode) {
184 return OpCode >= CastOpsBegin && OpCode < CastOpsEnd;
189 return OpCode >= FuncletPadOpsBegin && OpCode < FuncletPadOpsEnd;
195 case Instruction::CatchSwitch:
196 case Instruction::CatchRet:
197 case Instruction::CleanupRet:
198 case Instruction::Invoke:
199 case Instruction::Resume:
211 bool hasMetadata()
const {
return DbgLoc || hasMetadataHashEntry(); }
216 return hasMetadataHashEntry();
222 if (!hasMetadata())
return nullptr;
223 return getMetadataImpl(KindID);
229 if (!hasMetadata())
return nullptr;
230 return getMetadataImpl(Kind);
239 getAllMetadataImpl(MDs);
247 getAllMetadataOtherThanDebugLocImpl(MDs);
269 void swapProfMetadata();
277 return dropUnknownNonDebugMetadata(
None);
283 unsigned IDs[] = {ID1, ID2};
284 return dropUnknownNonDebugMetadata(IDs);
294 bool extractProfMetadata(uint64_t &TrueVal, uint64_t &FalseVal)
const;
299 bool extractProfTotalWeight(uint64_t &TotalVal)
const;
302 void updateProfWeight(uint64_t S, uint64_t
T);
305 void setProfWeight(uint64_t
W);
315 void setHasNoUnsignedWrap(
bool b =
true);
319 void setHasNoSignedWrap(
bool b =
true);
323 void setIsExact(
bool b =
true);
326 bool hasNoUnsignedWrap()
const;
329 bool hasNoSignedWrap()
const;
333 void dropPoisonGeneratingFlags();
336 bool isExact()
const;
341 void setFast(
bool B);
346 void setHasAllowReassoc(
bool B);
351 void setHasNoNaNs(
bool B);
356 void setHasNoInfs(
bool B);
361 void setHasNoSignedZeros(
bool B);
366 void setHasAllowReciprocal(
bool B);
371 void setHasApproxFunc(
bool B);
387 bool hasAllowReassoc()
const;
390 bool hasNoNaNs()
const;
393 bool hasNoInfs()
const;
396 bool hasNoSignedZeros()
const;
399 bool hasAllowReciprocal()
const;
402 bool hasAllowContract()
const;
405 bool hasApproxFunc()
const;
417 void copyIRFlags(
const Value *V,
bool IncludeWrapFlags =
true);
421 void andIRFlags(
const Value *V);
440 bool hasMetadataHashEntry()
const {
441 return (getSubclassDataFromValue() & HasMetadataBit) != 0;
445 MDNode *getMetadataImpl(
unsigned KindID)
const;
448 getAllMetadataImpl(
SmallVectorImpl<std::pair<unsigned, MDNode *>> &)
const;
449 void getAllMetadataOtherThanDebugLocImpl(
452 void clearMetadataHashEntries();
467 return Opcode == And || Opcode == Or || Opcode == Xor ||
468 Opcode ==
Add || Opcode == Mul;
483 case And:
case Or:
case Xor:
498 return Opcode == And || Opcode == Or;
512 return Opcode == Xor;
516 bool mayWriteToMemory()
const;
519 bool mayReadFromMemory()
const;
523 return mayReadFromMemory() || mayWriteToMemory();
531 bool hasAtomicLoad()
const;
534 bool hasAtomicStore()
const;
547 case Instruction::Fence:
548 case Instruction::CatchPad:
549 case Instruction::CatchRet:
551 case Instruction::Invoke:
570 bool isSafeToRemove()
const;
575 case Instruction::CatchSwitch:
576 case Instruction::CatchPad:
577 case Instruction::CleanupPad:
578 case Instruction::LandingPad:
587 bool isLifetimeStartOrEnd()
const;
591 const Instruction *getNextNonDebugInstruction()
const;
594 static_cast<const Instruction *
>(
this)->getNextNonDebugInstruction());
599 const Instruction *getPrevNonDebugInstruction()
const;
602 static_cast<const Instruction *
>(
this)->getPrevNonDebugInstruction());
620 bool isIdenticalToWhenDefined(
const Instruction *I)
const;
626 CompareIgnoringAlignment = 1<<0,
629 CompareUsingScalarTypes = 1<<1
640 bool isSameOperationAs(
const Instruction *I,
unsigned flags = 0)
const;
645 bool isUsedOutsideOfBlock(
const BasicBlock *BB)
const;
649 unsigned getNumSuccessors()
const;
656 void setSuccessor(
unsigned Idx,
BasicBlock *BB);
660 return V->
getValueID() >= Value::InstructionVal;
667 #define FIRST_TERM_INST(N) TermOpsBegin = N, 668 #define HANDLE_TERM_INST(N, OPC, CLASS) OPC = N, 669 #define LAST_TERM_INST(N) TermOpsEnd = N+1 670 #include "llvm/IR/Instruction.def" 674 #define FIRST_UNARY_INST(N) UnaryOpsBegin = N, 675 #define HANDLE_UNARY_INST(N, OPC, CLASS) OPC = N, 676 #define LAST_UNARY_INST(N) UnaryOpsEnd = N+1 677 #include "llvm/IR/Instruction.def" 681 #define FIRST_BINARY_INST(N) BinaryOpsBegin = N, 682 #define HANDLE_BINARY_INST(N, OPC, CLASS) OPC = N, 683 #define LAST_BINARY_INST(N) BinaryOpsEnd = N+1 684 #include "llvm/IR/Instruction.def" 688 #define FIRST_MEMORY_INST(N) MemoryOpsBegin = N, 689 #define HANDLE_MEMORY_INST(N, OPC, CLASS) OPC = N, 690 #define LAST_MEMORY_INST(N) MemoryOpsEnd = N+1 691 #include "llvm/IR/Instruction.def" 695 #define FIRST_CAST_INST(N) CastOpsBegin = N, 696 #define HANDLE_CAST_INST(N, OPC, CLASS) OPC = N, 697 #define LAST_CAST_INST(N) CastOpsEnd = N+1 698 #include "llvm/IR/Instruction.def" 702 #define FIRST_FUNCLETPAD_INST(N) FuncletPadOpsBegin = N, 703 #define HANDLE_FUNCLETPAD_INST(N, OPC, CLASS) OPC = N, 704 #define LAST_FUNCLETPAD_INST(N) FuncletPadOpsEnd = N+1 705 #include "llvm/IR/Instruction.def" 709 #define FIRST_OTHER_INST(N) OtherOpsBegin = N, 710 #define HANDLE_OTHER_INST(N, OPC, CLASS) OPC = N, 711 #define LAST_OTHER_INST(N) OtherOpsEnd = N+1 712 #include "llvm/IR/Instruction.def" 720 void setValueSubclassData(
unsigned short D) {
724 unsigned short getSubclassDataFromValue()
const {
728 void setHasMetadataHashEntry(
bool V) {
729 setValueSubclassData((getSubclassDataFromValue() & ~HasMetadataBit) |
730 (V ? HasMetadataBit : 0));
741 assert((D & HasMetadataBit) == 0 &&
"Out of range value put into field");
742 setValueSubclassData((getSubclassDataFromValue() & HasMetadataBit) | D);
746 return getSubclassDataFromValue() & ~HasMetadataBit;
765 #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:
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...
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)
static Function * getFunction(Constant *C)
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:
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.
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.