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; }
136 static const char* getOpcodeName(
unsigned OpCode);
139 return OpCode >= TermOpsBegin && OpCode < TermOpsEnd;
143 return Opcode >= BinaryOpsBegin && Opcode < BinaryOpsEnd;
147 return Opcode == UDiv || Opcode == SDiv || Opcode == URem || Opcode == SRem;
152 return Opcode >= Shl && Opcode <= AShr;
157 return getOpcode() == Shl || getOpcode() == LShr;
162 return getOpcode() == AShr;
167 return Opcode == And || Opcode == Or || Opcode == Xor;
172 return isBitwiseLogicOp(getOpcode());
176 static inline bool isCast(
unsigned OpCode) {
177 return OpCode >= CastOpsBegin && OpCode < CastOpsEnd;
182 return OpCode >= FuncletPadOpsBegin && OpCode < FuncletPadOpsEnd;
190 bool hasMetadata()
const {
return DbgLoc || hasMetadataHashEntry(); }
195 return hasMetadataHashEntry();
201 if (!hasMetadata())
return nullptr;
202 return getMetadataImpl(KindID);
208 if (!hasMetadata())
return nullptr;
209 return getMetadataImpl(Kind);
218 getAllMetadataImpl(MDs);
226 getAllMetadataOtherThanDebugLocImpl(MDs);
248 void swapProfMetadata();
256 return dropUnknownNonDebugMetadata(
None);
262 unsigned IDs[] = {ID1, ID2};
263 return dropUnknownNonDebugMetadata(IDs);
273 bool extractProfMetadata(uint64_t &TrueVal, uint64_t &FalseVal)
const;
278 bool extractProfTotalWeight(uint64_t &TotalVal)
const;
281 void updateProfWeight(uint64_t S, uint64_t
T);
284 void setProfWeight(uint64_t
W);
294 void setHasNoUnsignedWrap(
bool b =
true);
298 void setHasNoSignedWrap(
bool b =
true);
302 void setIsExact(
bool b =
true);
305 bool hasNoUnsignedWrap()
const;
308 bool hasNoSignedWrap()
const;
312 void dropPoisonGeneratingFlags();
315 bool isExact()
const;
320 void setFast(
bool B);
325 void setHasAllowReassoc(
bool B);
330 void setHasNoNaNs(
bool B);
335 void setHasNoInfs(
bool B);
340 void setHasNoSignedZeros(
bool B);
345 void setHasAllowReciprocal(
bool B);
350 void setHasApproxFunc(
bool B);
366 bool hasAllowReassoc()
const;
369 bool hasNoNaNs()
const;
372 bool hasNoInfs()
const;
375 bool hasNoSignedZeros()
const;
378 bool hasAllowReciprocal()
const;
381 bool hasAllowContract()
const;
384 bool hasApproxFunc()
const;
396 void copyIRFlags(
const Value *V,
bool IncludeWrapFlags =
true);
400 void andIRFlags(
const Value *V);
419 bool hasMetadataHashEntry()
const {
420 return (getSubclassDataFromValue() & HasMetadataBit) != 0;
424 MDNode *getMetadataImpl(
unsigned KindID)
const;
427 getAllMetadataImpl(
SmallVectorImpl<std::pair<unsigned, MDNode *>> &)
const;
428 void getAllMetadataOtherThanDebugLocImpl(
431 void clearMetadataHashEntries();
446 return Opcode == And || Opcode == Or || Opcode == Xor ||
447 Opcode ==
Add || Opcode == Mul;
462 case And:
case Or:
case Xor:
477 return Opcode == And || Opcode == Or;
491 return Opcode == Xor;
495 bool mayWriteToMemory()
const;
498 bool mayReadFromMemory()
const;
502 return mayReadFromMemory() || mayWriteToMemory();
510 bool hasAtomicLoad()
const;
513 bool hasAtomicStore()
const;
521 switch (getOpcode()) {
526 case Instruction::Fence:
527 case Instruction::CatchPad:
528 case Instruction::CatchRet:
530 case Instruction::Invoke:
549 bool isSafeToRemove()
const;
553 switch (getOpcode()) {
554 case Instruction::CatchSwitch:
555 case Instruction::CatchPad:
556 case Instruction::CleanupPad:
557 case Instruction::LandingPad:
566 const Instruction *getNextNonDebugInstruction()
const;
569 static_cast<const Instruction *
>(
this)->getNextNonDebugInstruction());
587 bool isIdenticalToWhenDefined(
const Instruction *I)
const;
593 CompareIgnoringAlignment = 1<<0,
596 CompareUsingScalarTypes = 1<<1
607 bool isSameOperationAs(
const Instruction *I,
unsigned flags = 0)
const;
612 bool isUsedOutsideOfBlock(
const BasicBlock *BB)
const;
617 return V->
getValueID() >= Value::InstructionVal;
624 #define FIRST_TERM_INST(N) TermOpsBegin = N, 625 #define HANDLE_TERM_INST(N, OPC, CLASS) OPC = N, 626 #define LAST_TERM_INST(N) TermOpsEnd = N+1 627 #include "llvm/IR/Instruction.def" 631 #define FIRST_BINARY_INST(N) BinaryOpsBegin = N, 632 #define HANDLE_BINARY_INST(N, OPC, CLASS) OPC = N, 633 #define LAST_BINARY_INST(N) BinaryOpsEnd = N+1 634 #include "llvm/IR/Instruction.def" 638 #define FIRST_MEMORY_INST(N) MemoryOpsBegin = N, 639 #define HANDLE_MEMORY_INST(N, OPC, CLASS) OPC = N, 640 #define LAST_MEMORY_INST(N) MemoryOpsEnd = N+1 641 #include "llvm/IR/Instruction.def" 645 #define FIRST_CAST_INST(N) CastOpsBegin = N, 646 #define HANDLE_CAST_INST(N, OPC, CLASS) OPC = N, 647 #define LAST_CAST_INST(N) CastOpsEnd = N+1 648 #include "llvm/IR/Instruction.def" 652 #define FIRST_FUNCLETPAD_INST(N) FuncletPadOpsBegin = N, 653 #define HANDLE_FUNCLETPAD_INST(N, OPC, CLASS) OPC = N, 654 #define LAST_FUNCLETPAD_INST(N) FuncletPadOpsEnd = N+1 655 #include "llvm/IR/Instruction.def" 659 #define FIRST_OTHER_INST(N) OtherOpsBegin = N, 660 #define HANDLE_OTHER_INST(N, OPC, CLASS) OPC = N, 661 #define LAST_OTHER_INST(N) OtherOpsEnd = N+1 662 #include "llvm/IR/Instruction.def" 670 void setValueSubclassData(
unsigned short D) {
674 unsigned short getSubclassDataFromValue()
const {
678 void setHasMetadataHashEntry(
bool V) {
679 setValueSubclassData((getSubclassDataFromValue() & ~HasMetadataBit) |
680 (V ? HasMetadataBit : 0));
691 assert((D & HasMetadataBit) == 0 &&
"Out of range value put into field");
692 setValueSubclassData((getSubclassDataFromValue() & HasMetadataBit) | D);
696 return getSubclassDataFromValue() & ~HasMetadataBit;
715 #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 ...
Compute iterated dominance frontiers using a linear time algorithm.
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.
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 classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
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.
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)
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.