27 :
User(ty,
Value::InstructionVal + it, Ops, NumOps), Parent(nullptr) {
32 assert(BB &&
"Instruction to insert before is not in a basic block!");
39 :
User(ty,
Value::InstructionVal + it, Ops, NumOps), Parent(nullptr) {
42 assert(InsertAtEnd &&
"Basic block to append to may not be NULL!");
47 assert(!Parent &&
"Instruction still linked in the program!");
48 if (hasMetadataHashEntry())
49 clearMetadataHashEntries();
94 assert(I == BB.
end() || I->getParent() == &BB);
107 cast<PossiblyExactOperator>(
this)->
setIsExact(b);
121 case Instruction::Sub:
122 case Instruction::Mul:
123 case Instruction::Shl:
128 case Instruction::UDiv:
129 case Instruction::SDiv:
130 case Instruction::AShr:
131 case Instruction::LShr:
132 cast<PossiblyExactOperator>(
this)->
setIsExact(
false);
135 case Instruction::GetElementPtr:
136 cast<GetElementPtrInst>(
this)->setIsInBounds(
false);
142 return cast<PossiblyExactOperator>(
this)->
isExact();
146 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
151 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
156 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
161 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
166 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
171 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
176 assert(isa<FPMathOperator>(
this) &&
"copying fast-math flag on invalid op");
181 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
186 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
187 return cast<FPMathOperator>(
this)->
hasNoNaNs();
191 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
192 return cast<FPMathOperator>(
this)->
hasNoInfs();
196 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
201 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
206 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
211 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
221 if (IncludeWrapFlags && isa<OverflowingBinaryOperator>(
this)) {
222 if (
auto *
OB = dyn_cast<OverflowingBinaryOperator>(V)) {
229 if (
auto *PE = dyn_cast<PossiblyExactOperator>(V))
230 if (isa<PossiblyExactOperator>(
this))
234 if (
auto *FP = dyn_cast<FPMathOperator>(V))
235 if (isa<FPMathOperator>(
this))
238 if (
auto *SrcGEP = dyn_cast<GetElementPtrInst>(V))
239 if (
auto *DestGEP = dyn_cast<GetElementPtrInst>(
this))
240 DestGEP->setIsInBounds(SrcGEP->isInBounds() | DestGEP->isInBounds());
244 if (
auto *
OB = dyn_cast<OverflowingBinaryOperator>(V)) {
245 if (isa<OverflowingBinaryOperator>(
this)) {
251 if (
auto *PE = dyn_cast<PossiblyExactOperator>(V))
252 if (isa<PossiblyExactOperator>(
this))
255 if (
auto *FP = dyn_cast<FPMathOperator>(V)) {
256 if (isa<FPMathOperator>(
this)) {
258 FM &= FP->getFastMathFlags();
263 if (
auto *SrcGEP = dyn_cast<GetElementPtrInst>(V))
264 if (
auto *DestGEP = dyn_cast<GetElementPtrInst>(
this))
265 DestGEP->setIsInBounds(SrcGEP->isInBounds() & DestGEP->isInBounds());
271 case Ret:
return "ret";
272 case Br:
return "br";
273 case Switch:
return "switch";
274 case IndirectBr:
return "indirectbr";
275 case Invoke:
return "invoke";
276 case Resume:
return "resume";
277 case Unreachable:
return "unreachable";
278 case CleanupRet:
return "cleanupret";
279 case CatchRet:
return "catchret";
280 case CatchPad:
return "catchpad";
281 case CatchSwitch:
return "catchswitch";
284 case Add:
return "add";
285 case FAdd:
return "fadd";
286 case Sub:
return "sub";
287 case FSub:
return "fsub";
288 case Mul:
return "mul";
289 case FMul:
return "fmul";
290 case UDiv:
return "udiv";
291 case SDiv:
return "sdiv";
292 case FDiv:
return "fdiv";
293 case URem:
return "urem";
294 case SRem:
return "srem";
295 case FRem:
return "frem";
298 case And:
return "and";
299 case Or :
return "or";
300 case Xor:
return "xor";
303 case Alloca:
return "alloca";
304 case Load:
return "load";
305 case Store:
return "store";
306 case AtomicCmpXchg:
return "cmpxchg";
307 case AtomicRMW:
return "atomicrmw";
308 case Fence:
return "fence";
309 case GetElementPtr:
return "getelementptr";
312 case Trunc:
return "trunc";
313 case ZExt:
return "zext";
314 case SExt:
return "sext";
315 case FPTrunc:
return "fptrunc";
316 case FPExt:
return "fpext";
317 case FPToUI:
return "fptoui";
318 case FPToSI:
return "fptosi";
319 case UIToFP:
return "uitofp";
320 case SIToFP:
return "sitofp";
321 case IntToPtr:
return "inttoptr";
322 case PtrToInt:
return "ptrtoint";
323 case BitCast:
return "bitcast";
324 case AddrSpaceCast:
return "addrspacecast";
327 case ICmp:
return "icmp";
328 case FCmp:
return "fcmp";
329 case PHI:
return "phi";
330 case Select:
return "select";
331 case Call:
return "call";
332 case Shl:
return "shl";
333 case LShr:
return "lshr";
334 case AShr:
return "ashr";
335 case VAArg:
return "va_arg";
336 case ExtractElement:
return "extractelement";
337 case InsertElement:
return "insertelement";
338 case ShuffleVector:
return "shufflevector";
339 case ExtractValue:
return "extractvalue";
340 case InsertValue:
return "insertvalue";
341 case LandingPad:
return "landingpad";
342 case CleanupPad:
return "cleanuppad";
344 default:
return "<Invalid operator> ";
352 bool IgnoreAlignment =
false) {
354 "Can not compare special state of different instructions");
356 if (
const AllocaInst *AI = dyn_cast<AllocaInst>(I1))
357 return AI->getAllocatedType() == cast<AllocaInst>(I2)->getAllocatedType() &&
358 (AI->getAlignment() == cast<AllocaInst>(I2)->
getAlignment() ||
360 if (
const LoadInst *LI = dyn_cast<LoadInst>(I1))
361 return LI->isVolatile() == cast<LoadInst>(I2)->
isVolatile() &&
362 (LI->getAlignment() == cast<LoadInst>(I2)->
getAlignment() ||
364 LI->getOrdering() == cast<LoadInst>(I2)->getOrdering() &&
365 LI->getSyncScopeID() == cast<LoadInst>(I2)->getSyncScopeID();
367 return SI->isVolatile() == cast<StoreInst>(I2)->
isVolatile() &&
370 SI->getOrdering() == cast<StoreInst>(I2)->getOrdering() &&
371 SI->getSyncScopeID() == cast<StoreInst>(I2)->getSyncScopeID();
372 if (
const CmpInst *CI = dyn_cast<CmpInst>(I1))
373 return CI->getPredicate() == cast<CmpInst>(I2)->getPredicate();
374 if (
const CallInst *CI = dyn_cast<CallInst>(I1))
375 return CI->isTailCall() == cast<CallInst>(I2)->isTailCall() &&
376 CI->getCallingConv() == cast<CallInst>(I2)->getCallingConv() &&
377 CI->getAttributes() == cast<CallInst>(I2)->
getAttributes() &&
378 CI->hasIdenticalOperandBundleSchema(*cast<CallInst>(I2));
379 if (
const InvokeInst *CI = dyn_cast<InvokeInst>(I1))
380 return CI->getCallingConv() == cast<InvokeInst>(I2)->getCallingConv() &&
382 CI->hasIdenticalOperandBundleSchema(*cast<InvokeInst>(I2));
384 return IVI->getIndices() == cast<InsertValueInst>(I2)->getIndices();
386 return EVI->getIndices() == cast<ExtractValueInst>(I2)->getIndices();
387 if (
const FenceInst *FI = dyn_cast<FenceInst>(I1))
388 return FI->getOrdering() == cast<FenceInst>(I2)->getOrdering() &&
389 FI->getSyncScopeID() == cast<FenceInst>(I2)->getSyncScopeID();
391 return CXI->isVolatile() == cast<AtomicCmpXchgInst>(I2)->
isVolatile() &&
392 CXI->isWeak() == cast<AtomicCmpXchgInst>(I2)->
isWeak() &&
393 CXI->getSuccessOrdering() ==
394 cast<AtomicCmpXchgInst>(I2)->getSuccessOrdering() &&
395 CXI->getFailureOrdering() ==
396 cast<AtomicCmpXchgInst>(I2)->getFailureOrdering() &&
397 CXI->getSyncScopeID() ==
398 cast<AtomicCmpXchgInst>(I2)->getSyncScopeID();
400 return RMWI->getOperation() == cast<AtomicRMWInst>(I2)->getOperation() &&
401 RMWI->isVolatile() == cast<AtomicRMWInst>(I2)->
isVolatile() &&
402 RMWI->getOrdering() == cast<AtomicRMWInst>(I2)->getOrdering() &&
403 RMWI->getSyncScopeID() == cast<AtomicRMWInst>(I2)->getSyncScopeID();
428 if (
const PHINode *thisPHI = dyn_cast<PHINode>(
this)) {
429 const PHINode *otherPHI = cast<PHINode>(
I);
430 return std::equal(thisPHI->block_begin(), thisPHI->block_end(),
440 unsigned flags)
const {
475 if (PN->getIncomingBlock(U) != BB)
483 default:
return false;
484 case Instruction::VAArg:
486 case Instruction::Fence:
487 case Instruction::AtomicCmpXchg:
488 case Instruction::AtomicRMW:
489 case Instruction::CatchPad:
490 case Instruction::CatchRet:
493 return !cast<CallInst>(
this)->doesNotAccessMemory();
494 case Instruction::Invoke:
495 return !cast<InvokeInst>(
this)->doesNotAccessMemory();
497 return !cast<StoreInst>(
this)->isUnordered();
503 default:
return false;
504 case Instruction::Fence:
506 case Instruction::VAArg:
507 case Instruction::AtomicCmpXchg:
508 case Instruction::AtomicRMW:
509 case Instruction::CatchPad:
510 case Instruction::CatchRet:
513 return !cast<CallInst>(
this)->onlyReadsMemory();
514 case Instruction::Invoke:
515 return !cast<InvokeInst>(
this)->onlyReadsMemory();
517 return !cast<LoadInst>(
this)->isUnordered();
525 case Instruction::AtomicCmpXchg:
526 case Instruction::AtomicRMW:
527 case Instruction::Fence:
541 case Instruction::AtomicCmpXchg:
542 case Instruction::AtomicRMW:
553 case Instruction::AtomicCmpXchg:
554 case Instruction::AtomicRMW:
561 if (
const CallInst *CI = dyn_cast<CallInst>(
this))
562 return !CI->doesNotThrow();
563 if (
const auto *CRI = dyn_cast<CleanupReturnInst>(
this))
564 return CRI->unwindsToCaller();
565 if (
const auto *CatchSwitch = dyn_cast<CatchSwitchInst>(
this))
566 return CatchSwitch->unwindsToCaller();
567 return isa<ResumeInst>(
this);
595 if (MDName->
getString() !=
"branch_weights")
611 for (
unsigned M : WL)
618 for (
const auto &MD : TheMDs) {
619 if (WL.empty() || WLS.
count(MD.first))
632 #define HANDLE_INST(num, opc, clas) \
633 case Instruction::opc: \
634 New = cast<clas>(this)->cloneImpl(); \
636 #include "llvm/IR/Instruction.def"
647 if (ProfileData ==
nullptr)
651 if (!ProfDataName || (!ProfDataName->getString().equals(
"branch_weights") &&
652 !ProfDataName->getString().equals(
"VP")))
657 Vals.
push_back(ProfileData->getOperand(0));
658 APInt APS(128, S), APT(128, T);
659 if (ProfDataName->getString().equals(
"branch_weights"))
660 for (
unsigned i = 1; i < ProfileData->getNumOperands(); i++) {
663 mdconst::dyn_extract<ConstantInt>(ProfileData->getOperand(i))
669 Val.udiv(APT).getLimitedValue())));
671 else if (ProfDataName->getString().equals(
"VP"))
672 for (
unsigned i = 1; i < ProfileData->getNumOperands(); i += 2) {
674 Vals.
push_back(ProfileData->getOperand(i));
677 mdconst::dyn_extract<ConstantInt>(ProfileData->getOperand(i + 1))
683 Val.udiv(APT).getLimitedValue())));
689 assert((isa<CallInst>(
this) || isa<InvokeInst>(
this)) &&
690 "Can only set weights for call and invoke instrucitons");
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
void push_back(const T &Elt)
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)
ConstantAsMetadata * createConstant(Constant *C)
Return the given constant as metadata.
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.
unsigned getNumOperands() const
unsigned getNumOperands() const
Return number of MDNode operands.
void setProfWeight(uint64_t W)
Sets the branch_weights metadata to W for CallInst.
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...
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
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.
static IntegerType * getInt64Ty(LLVMContext &C)
an instruction that atomically reads a memory location, combines it with another value, and then stores the result back.
void copyIRFlags(const Value *V, bool IncludeWrapFlags=true)
Convenience method to copy supported exact, fast-math, and (optionally) wrapping flags from V to this...
static uint32_t getAlignment(const MCSectionCOFF &Sec)
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.
void dropPoisonGeneratingFlags()
Drops flags that may cause this instruction to evaluate to poison despite having non-poison inputs...
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()
AttributeList getAttributes(LLVMContext &C, ID id)
Return the attributes for an intrinsic.
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 hasAllowContract() const
Determine whether the allow-contract flag is set.
bool hasAtomicLoad() const
Return true if this atomic instruction loads from memory.
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.
AttributeSet getAttributes(unsigned Index) const
The attributes for the specified index are returned.
const Function * getFunction() const
Return the function this instruction belongs to.
An instruction for storing to memory.
const char * getOpcodeName() const
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)
bool hasNoSignedWrap() const
Determine whether the no signed wrap flag is set.
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.
bool isAssociative() const LLVM_READONLY
Return true if the instruction is associative:
void splice(iterator where, iplist_impl &L2)
const InstListType & getInstList() const
Return the underlying instruction list container.
Value * getOperand(unsigned i) const
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...
LLVMContext & getContext() const
All values hold a context through their type.
MDNode * createBranchWeights(uint32_t TrueWeight, uint32_t FalseWeight)
Return metadata containing two branch weights.
void swapProfMetadata()
If the instruction has "branch_weights" MD_prof metadata and the MDNode has three operands (including...
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.
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
Class for arbitrary precision integers.
void push_back(pointer val)
static bool isWeak(const MCSymbolELF &Sym)
bool hasAtomicStore() const
Return true if this atomic instruction stores to memory.
void removeFromParent()
This method unlinks 'this' from the containing basic block, but does not delete it.
llvm_unreachable("Unknown RegBank!")
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)
void updateProfWeight(uint64_t S, uint64_t T)
Updates branch_weights metadata by scaling it by S / T.
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
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
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.