26 :
User(ty,
Value::InstructionVal + it, Ops, NumOps), Parent(nullptr) {
31 assert(BB &&
"Instruction to insert before is not in a basic block!");
38 :
User(ty,
Value::InstructionVal + it, Ops, NumOps), Parent(nullptr) {
41 assert(InsertAtEnd &&
"Basic block to append to may not be NULL!");
48 assert(!Parent &&
"Instruction still linked in the program!");
49 if (hasMetadataHashEntry())
50 clearMetadataHashEntries();
101 assert(I == BB.
end() || I->getParent() == &BB);
114 cast<PossiblyExactOperator>(
this)->
setIsExact(b);
126 return cast<PossiblyExactOperator>(
this)->
isExact();
130 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
135 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
140 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
145 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
150 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
155 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
160 assert(isa<FPMathOperator>(
this) &&
"copying fast-math flag on invalid op");
165 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
170 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
171 return cast<FPMathOperator>(
this)->
hasNoNaNs();
175 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
176 return cast<FPMathOperator>(
this)->
hasNoInfs();
180 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
185 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
190 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
200 if (
auto *
OB = dyn_cast<OverflowingBinaryOperator>(V)) {
201 if (isa<OverflowingBinaryOperator>(
this)) {
208 if (
auto *PE = dyn_cast<PossiblyExactOperator>(V))
209 if (isa<PossiblyExactOperator>(
this))
213 if (
auto *FP = dyn_cast<FPMathOperator>(V))
214 if (isa<FPMathOperator>(
this))
217 if (
auto *SrcGEP = dyn_cast<GetElementPtrInst>(V))
218 if (
auto *DestGEP = dyn_cast<GetElementPtrInst>(
this))
219 DestGEP->setIsInBounds(SrcGEP->isInBounds() | DestGEP->isInBounds());
223 if (
auto *
OB = dyn_cast<OverflowingBinaryOperator>(V)) {
224 if (isa<OverflowingBinaryOperator>(
this)) {
230 if (
auto *PE = dyn_cast<PossiblyExactOperator>(V))
231 if (isa<PossiblyExactOperator>(
this))
234 if (
auto *FP = dyn_cast<FPMathOperator>(V)) {
235 if (isa<FPMathOperator>(
this)) {
237 FM &= FP->getFastMathFlags();
242 if (
auto *SrcGEP = dyn_cast<GetElementPtrInst>(V))
243 if (
auto *DestGEP = dyn_cast<GetElementPtrInst>(
this))
244 DestGEP->setIsInBounds(SrcGEP->isInBounds() & DestGEP->isInBounds());
250 case Ret:
return "ret";
251 case Br:
return "br";
252 case Switch:
return "switch";
253 case IndirectBr:
return "indirectbr";
254 case Invoke:
return "invoke";
255 case Resume:
return "resume";
256 case Unreachable:
return "unreachable";
257 case CleanupRet:
return "cleanupret";
258 case CatchRet:
return "catchret";
259 case CatchPad:
return "catchpad";
260 case CatchSwitch:
return "catchswitch";
263 case Add:
return "add";
264 case FAdd:
return "fadd";
265 case Sub:
return "sub";
266 case FSub:
return "fsub";
267 case Mul:
return "mul";
268 case FMul:
return "fmul";
269 case UDiv:
return "udiv";
270 case SDiv:
return "sdiv";
271 case FDiv:
return "fdiv";
272 case URem:
return "urem";
273 case SRem:
return "srem";
274 case FRem:
return "frem";
277 case And:
return "and";
278 case Or :
return "or";
279 case Xor:
return "xor";
282 case Alloca:
return "alloca";
283 case Load:
return "load";
284 case Store:
return "store";
285 case AtomicCmpXchg:
return "cmpxchg";
286 case AtomicRMW:
return "atomicrmw";
287 case Fence:
return "fence";
288 case GetElementPtr:
return "getelementptr";
291 case Trunc:
return "trunc";
292 case ZExt:
return "zext";
293 case SExt:
return "sext";
294 case FPTrunc:
return "fptrunc";
295 case FPExt:
return "fpext";
296 case FPToUI:
return "fptoui";
297 case FPToSI:
return "fptosi";
298 case UIToFP:
return "uitofp";
299 case SIToFP:
return "sitofp";
300 case IntToPtr:
return "inttoptr";
301 case PtrToInt:
return "ptrtoint";
302 case BitCast:
return "bitcast";
303 case AddrSpaceCast:
return "addrspacecast";
306 case ICmp:
return "icmp";
307 case FCmp:
return "fcmp";
308 case PHI:
return "phi";
309 case Select:
return "select";
310 case Call:
return "call";
311 case Shl:
return "shl";
312 case LShr:
return "lshr";
313 case AShr:
return "ashr";
314 case VAArg:
return "va_arg";
315 case ExtractElement:
return "extractelement";
316 case InsertElement:
return "insertelement";
317 case ShuffleVector:
return "shufflevector";
318 case ExtractValue:
return "extractvalue";
319 case InsertValue:
return "insertvalue";
320 case LandingPad:
return "landingpad";
321 case CleanupPad:
return "cleanuppad";
323 default:
return "<Invalid operator> ";
331 bool IgnoreAlignment =
false) {
333 "Can not compare special state of different instructions");
335 if (
const AllocaInst *AI = dyn_cast<AllocaInst>(I1))
336 return AI->getAllocatedType() == cast<AllocaInst>(I2)->getAllocatedType() &&
337 (AI->getAlignment() == cast<AllocaInst>(I2)->
getAlignment() ||
339 if (
const LoadInst *LI = dyn_cast<LoadInst>(I1))
340 return LI->isVolatile() == cast<LoadInst>(I2)->
isVolatile() &&
341 (LI->getAlignment() == cast<LoadInst>(I2)->
getAlignment() ||
343 LI->getOrdering() == cast<LoadInst>(I2)->getOrdering() &&
344 LI->getSynchScope() == cast<LoadInst>(I2)->getSynchScope();
346 return SI->isVolatile() == cast<StoreInst>(I2)->
isVolatile() &&
349 SI->getOrdering() == cast<StoreInst>(I2)->getOrdering() &&
350 SI->getSynchScope() == cast<StoreInst>(I2)->getSynchScope();
351 if (
const CmpInst *CI = dyn_cast<CmpInst>(I1))
352 return CI->getPredicate() == cast<CmpInst>(I2)->getPredicate();
353 if (
const CallInst *CI = dyn_cast<CallInst>(I1))
354 return CI->isTailCall() == cast<CallInst>(I2)->isTailCall() &&
355 CI->getCallingConv() == cast<CallInst>(I2)->getCallingConv() &&
356 CI->getAttributes() == cast<CallInst>(I2)->
getAttributes() &&
357 CI->hasIdenticalOperandBundleSchema(*cast<CallInst>(I2));
358 if (
const InvokeInst *CI = dyn_cast<InvokeInst>(I1))
359 return CI->getCallingConv() == cast<InvokeInst>(I2)->getCallingConv() &&
360 CI->getAttributes() == cast<InvokeInst>(I2)->
getAttributes() &&
361 CI->hasIdenticalOperandBundleSchema(*cast<InvokeInst>(I2));
363 return IVI->getIndices() == cast<InsertValueInst>(I2)->getIndices();
365 return EVI->getIndices() == cast<ExtractValueInst>(I2)->getIndices();
366 if (
const FenceInst *FI = dyn_cast<FenceInst>(I1))
367 return FI->getOrdering() == cast<FenceInst>(I2)->getOrdering() &&
368 FI->getSynchScope() == cast<FenceInst>(I2)->getSynchScope();
370 return CXI->isVolatile() == cast<AtomicCmpXchgInst>(I2)->
isVolatile() &&
371 CXI->isWeak() == cast<AtomicCmpXchgInst>(I2)->
isWeak() &&
372 CXI->getSuccessOrdering() ==
373 cast<AtomicCmpXchgInst>(I2)->getSuccessOrdering() &&
374 CXI->getFailureOrdering() ==
375 cast<AtomicCmpXchgInst>(I2)->getFailureOrdering() &&
376 CXI->getSynchScope() == cast<AtomicCmpXchgInst>(I2)->getSynchScope();
378 return RMWI->getOperation() == cast<AtomicRMWInst>(I2)->getOperation() &&
379 RMWI->isVolatile() == cast<AtomicRMWInst>(I2)->
isVolatile() &&
380 RMWI->getOrdering() == cast<AtomicRMWInst>(I2)->getOrdering() &&
381 RMWI->getSynchScope() == cast<AtomicRMWInst>(I2)->getSynchScope();
406 if (
const PHINode *thisPHI = dyn_cast<PHINode>(
this)) {
407 const PHINode *otherPHI = cast<PHINode>(
I);
408 return std::equal(thisPHI->block_begin(), thisPHI->block_end(),
418 unsigned flags)
const {
453 if (PN->getIncomingBlock(U) != BB)
461 default:
return false;
462 case Instruction::VAArg:
464 case Instruction::Fence:
465 case Instruction::AtomicCmpXchg:
466 case Instruction::AtomicRMW:
467 case Instruction::CatchPad:
468 case Instruction::CatchRet:
471 return !cast<CallInst>(
this)->doesNotAccessMemory();
472 case Instruction::Invoke:
473 return !cast<InvokeInst>(
this)->doesNotAccessMemory();
475 return !cast<StoreInst>(
this)->isUnordered();
481 default:
return false;
482 case Instruction::Fence:
484 case Instruction::VAArg:
485 case Instruction::AtomicCmpXchg:
486 case Instruction::AtomicRMW:
487 case Instruction::CatchPad:
488 case Instruction::CatchRet:
491 return !cast<CallInst>(
this)->onlyReadsMemory();
492 case Instruction::Invoke:
493 return !cast<InvokeInst>(
this)->onlyReadsMemory();
495 return !cast<LoadInst>(
this)->isUnordered();
503 case Instruction::AtomicCmpXchg:
504 case Instruction::AtomicRMW:
505 case Instruction::Fence:
515 if (
const CallInst *CI = dyn_cast<CallInst>(
this))
516 return !CI->doesNotThrow();
517 if (
const auto *CRI = dyn_cast<CleanupReturnInst>(
this))
518 return CRI->unwindsToCaller();
519 if (
const auto *CatchSwitch = dyn_cast<CatchSwitchInst>(
this))
520 return CatchSwitch->unwindsToCaller();
521 return isa<ResumeInst>(
this);
531 return Opcode ==
And || Opcode ==
Or || Opcode ==
Xor ||
532 Opcode ==
Add || Opcode == Mul;
578 return Opcode ==
And || Opcode ==
Or;
591 return Opcode ==
Xor;
605 if (MDName->
getString() !=
"branch_weights")
621 for (
unsigned M : WL)
628 for (
const auto &MD : TheMDs) {
629 if (WL.empty() || WLS.
count(MD.first))
642 #define HANDLE_INST(num, opc, clas) \
643 case Instruction::opc: \
644 New = cast<clas>(this)->cloneImpl(); \
646 #include "llvm/IR/Instruction.def"
bool isNilpotent() const
Return true if the instruction is nilpotent:
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
void copyFastMathFlags(FastMathFlags FMF)
Convenience function for transferring all fast-math flag values to this instruction, which must be an operator which supports these flags.
This class is the base class for the comparison instructions.
void setFastMathFlags(FastMathFlags FMF)
Convenience function for setting multiple fast-math flags on this instruction, which must be an opera...
iterator_range< use_iterator > uses()
iterator erase(iterator where)
A Module instance is used to store all the information related to an LLVM module. ...
An instruction for ordering other memory operations.
an instruction that atomically checks whether a specified value is in a memory location, and, if it is, stores a new value there.
Implements a dense probed hash-table based set.
unsigned getNumOperands() const
unsigned getNumOperands() const
Return number of MDNode operands.
This class represents a function call, abstracting a target machine's calling convention.
void setHasNoNaNs(bool B)
Set or clear the no-nans flag on this instruction, which must be an operator which supports this flag...
bool isUsedOutsideOfBlock(const BasicBlock *BB) const
Return true if there are any uses of this instruction in blocks other than the specified block...
FastMathFlags getFastMathFlags() const
Convenience function for getting all the fast-math flags, which must be an operator which supports th...
const Function * getParent() const
Return the enclosing method, or null if none.
An instruction for reading from memory.
an instruction that atomically reads a memory location, combines it with another value, and then stores the result back.
void copyIRFlags(const Value *V)
Convenience method to copy supported wrapping, exact, and fast-math flags from V to this instruction...
bool hasNoNaNs() const
Determine whether the no-NaNs flag is set.
bool isIdenticalTo(const Instruction *I) const
Return true if the specified instruction is exactly identical to the current one. ...
const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr it the function does no...
A Use represents the edge between a Value definition and its users.
static bool haveSameSpecialState(const Instruction *I1, const Instruction *I2, bool IgnoreAlignment=false)
Return true if both instructions have the same special state.
bool hasAllowReciprocal() const
Determine whether the allow-reciprocal flag is set.
Check for equivalence ignoring load/store alignment.
Instruction * clone() const
Create a copy of 'this' instruction that is identical in all ways except the following: ...
block_iterator block_begin()
static unsigned getAlignment(GlobalVariable *GV)
void setIsExact(bool b=true)
Set or clear the exact flag on this instruction, which must be an operator which supports this flag...
Check for equivalence treating a type and a vector of that type as equivalent.
bool mayReadFromMemory() const
Return true if this instruction may read memory.
bool isAssociative() const
Return true if the instruction is associative:
void andIRFlags(const Value *V)
Logical 'and' of any supported wrapping, exact, and fast-math flags of V and this instruction...
void setHasUnsafeAlgebra(bool B)
Set or clear the unsafe-algebra flag on this instruction, which must be an operator which supports th...
bool hasUnsafeAlgebra() const
Determine whether the unsafe-algebra flag is set.
static GCRegistry::Add< OcamlGC > B("ocaml","ocaml 3.10-compatible GC")
const Function * getFunction() const
Return the function this instruction belongs to.
An instruction for storing to memory.
const char * getOpcodeName() const
Type * getScalarType() const LLVM_READONLY
If this is a vector type, return the element type, otherwise return 'this'.
bool isAtomic() const
Return true if this instruction has an AtomicOrdering of unordered or higher.
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
bool isIdenticalToWhenDefined(const Instruction *I) const
This is like isIdenticalTo, except that it ignores the SubclassOptionalData flags, which may specify conditions under which the instruction's result is undefined.
void insertBefore(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified instruction...
LLVM Basic Block Representation.
bool isExact() const
Determine whether the exact flag is set.
The instances of the Type class are immutable: once they are created, they are never changed...
void getAllMetadataOtherThanDebugLoc(SmallVectorImpl< std::pair< unsigned, MDNode * >> &MDs) const
This does the same thing as getAllMetadata, except that it filters out the debug location.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
std::pair< iterator, bool > insert(const ValueT &V)
APInt Or(const APInt &LHS, const APInt &RHS)
Bitwise OR function for APInt.
bool hasNoSignedWrap() const
Determine whether the no signed wrap flag is set.
APInt Xor(const APInt &LHS, const APInt &RHS)
Bitwise XOR function for APInt.
bool hasMetadata() const
Return true if this instruction has any metadata attached to it.
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
void splice(iterator where, iplist_impl &L2)
const InstListType & getInstList() const
Return the underlying instruction list container.
Value * getOperand(unsigned i) const
bool isCommutative() const
Return true if the instruction is commutative:
self_iterator getIterator()
void setHasNoInfs(bool B)
Set or clear the no-infs flag on this instruction, which must be an operator which supports this flag...
void swapProfMetadata()
If the instruction has "branch_weights" MD_prof metadata and the MDNode has three operands (including...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
unsigned char SubclassOptionalData
Hold subclass data that can be dropped.
bool mayWriteToMemory() const
Return true if this instruction may modify memory.
StringRef getString() const
const MDOperand & getOperand(unsigned I) const
void setHasNoSignedWrap(bool b=true)
Set or clear the nsw flag on this instruction, which must be an operator which supports this flag...
Iterator for intrusive lists based on ilist_node.
bool hasNoUnsignedWrap() const
Determine whether the no unsigned wrap flag is set.
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Module.h This file contains the declarations for the Module class.
Type * getType() const
All values are typed, get the type of this value.
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
void push_back(pointer val)
static bool isWeak(const MCSymbolELF &Sym)
APInt And(const APInt &LHS, const APInt &RHS)
Bitwise AND function for APInt.
void removeFromParent()
This method unlinks 'this' from the containing basic block, but does not delete it.
bool mayThrow() const
Return true if this instruction may throw an exception.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
pointer remove(iterator &IT)
List that automatically updates parent links and symbol tables.
iterator insert(iterator where, pointer New)
size_type count(const ValueT &V) const
Return 1 if the specified key is in the set, 0 otherwise.
bool isIdempotent() const
Return true if the instruction is idempotent:
void insertAfter(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately after the specified instruction...
bool hasNoInfs() const
Determine whether the no-infs flag is set.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
bool hasNoSignedZeros() const
Determine whether the no-signed-zeros flag is set.
LLVMContext & getContext() const
AttributeSet getAttributes(LLVMContext &C, ID id)
Return the attributes for an intrinsic.
Instruction(const Instruction &)=delete
void setHasNoUnsignedWrap(bool b=true)
Set or clear the nsw flag on this instruction, which must be an operator which supports this flag...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
void copyMetadata(const Instruction &SrcInst, ArrayRef< unsigned > WL=ArrayRef< unsigned >())
Copy metadata from SrcInst to this instruction.
void moveBefore(Instruction *MovePos)
Unlink this instruction from its current basic block and insert it into the basic block that MovePos ...
Convenience struct for specifying and reasoning about fast-math flags.
bool isSameOperationAs(const Instruction *I, unsigned flags=0) const
This function determines if the specified instruction executes the same operation as the current one...
static bool isVolatile(Instruction *Inst)
void setHasNoSignedZeros(bool B)
Set or clear the no-signed-zeros flag on this instruction, which must be an operator which supports t...
iterator insertAfter(iterator where, pointer New)
void setHasAllowReciprocal(bool B)
Set or clear the allow-reciprocal flag on this instruction, which must be an operator which supports ...
const BasicBlock * getParent() const
an instruction to allocate memory on the stack
This instruction inserts a struct field of array element value into an aggregate value.