23 Instruction::Instruction(
Type *ty,
unsigned it,
Use *Ops,
unsigned NumOps,
25 :
User(ty,
Value::InstructionVal + it, Ops, NumOps), Parent(nullptr) {
30 assert(BB &&
"Instruction to insert before is not in a basic block!");
35 Instruction::Instruction(
Type *ty,
unsigned it,
Use *Ops,
unsigned NumOps,
37 :
User(ty,
Value::InstructionVal + it, Ops, NumOps), Parent(nullptr) {
40 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();
98 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
105 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
112 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
120 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
128 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
136 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
141 assert(isa<FPMathOperator>(
this) &&
"copying fast-math flag on invalid op");
147 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
153 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
154 return cast<FPMathOperator>(
this)->
hasNoNaNs();
159 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
160 return cast<FPMathOperator>(
this)->
hasNoInfs();
165 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
171 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
179 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
192 case Ret:
return "ret";
193 case Br:
return "br";
194 case Switch:
return "switch";
195 case IndirectBr:
return "indirectbr";
196 case Invoke:
return "invoke";
197 case Resume:
return "resume";
198 case Unreachable:
return "unreachable";
201 case Add:
return "add";
202 case FAdd:
return "fadd";
203 case Sub:
return "sub";
204 case FSub:
return "fsub";
205 case Mul:
return "mul";
206 case FMul:
return "fmul";
207 case UDiv:
return "udiv";
208 case SDiv:
return "sdiv";
209 case FDiv:
return "fdiv";
210 case URem:
return "urem";
211 case SRem:
return "srem";
212 case FRem:
return "frem";
215 case And:
return "and";
216 case Or :
return "or";
217 case Xor:
return "xor";
220 case Alloca:
return "alloca";
221 case Load:
return "load";
222 case Store:
return "store";
223 case AtomicCmpXchg:
return "cmpxchg";
224 case AtomicRMW:
return "atomicrmw";
225 case Fence:
return "fence";
226 case GetElementPtr:
return "getelementptr";
229 case Trunc:
return "trunc";
230 case ZExt:
return "zext";
231 case SExt:
return "sext";
232 case FPTrunc:
return "fptrunc";
233 case FPExt:
return "fpext";
234 case FPToUI:
return "fptoui";
235 case FPToSI:
return "fptosi";
236 case UIToFP:
return "uitofp";
237 case SIToFP:
return "sitofp";
238 case IntToPtr:
return "inttoptr";
239 case PtrToInt:
return "ptrtoint";
240 case BitCast:
return "bitcast";
241 case AddrSpaceCast:
return "addrspacecast";
244 case ICmp:
return "icmp";
245 case FCmp:
return "fcmp";
246 case PHI:
return "phi";
247 case Select:
return "select";
248 case Call:
return "call";
249 case Shl:
return "shl";
250 case LShr:
return "lshr";
251 case AShr:
return "ashr";
252 case VAArg:
return "va_arg";
254 case InsertElement:
return "insertelement";
255 case ShuffleVector:
return "shufflevector";
256 case ExtractValue:
return "extractvalue";
257 case InsertValue:
return "insertvalue";
258 case LandingPad:
return "landingpad";
260 default:
return "<Invalid operator> ";
267 bool IgnoreAlignment =
false) {
269 "Can not compare special state of different instructions");
271 if (
const LoadInst *LI = dyn_cast<LoadInst>(I1))
272 return LI->isVolatile() == cast<LoadInst>(I2)->
isVolatile() &&
273 (LI->getAlignment() == cast<LoadInst>(I2)->getAlignment() ||
275 LI->getOrdering() == cast<LoadInst>(I2)->getOrdering() &&
276 LI->getSynchScope() == cast<LoadInst>(I2)->getSynchScope();
278 return SI->isVolatile() == cast<StoreInst>(I2)->
isVolatile() &&
279 (
SI->getAlignment() == cast<StoreInst>(I2)->getAlignment() ||
281 SI->getOrdering() == cast<StoreInst>(I2)->getOrdering() &&
282 SI->getSynchScope() == cast<StoreInst>(I2)->getSynchScope();
283 if (
const CmpInst *CI = dyn_cast<CmpInst>(I1))
284 return CI->getPredicate() == cast<CmpInst>(I2)->getPredicate();
285 if (
const CallInst *CI = dyn_cast<CallInst>(I1))
286 return CI->isTailCall() == cast<CallInst>(I2)->isTailCall() &&
287 CI->getCallingConv() == cast<CallInst>(I2)->getCallingConv() &&
289 if (
const InvokeInst *CI = dyn_cast<InvokeInst>(I1))
290 return CI->getCallingConv() == cast<InvokeInst>(I2)->getCallingConv() &&
291 CI->getAttributes() ==
294 return IVI->getIndices() == cast<InsertValueInst>(I2)->getIndices();
296 return EVI->getIndices() == cast<ExtractValueInst>(I2)->getIndices();
297 if (
const FenceInst *FI = dyn_cast<FenceInst>(I1))
298 return FI->getOrdering() == cast<FenceInst>(I2)->getOrdering() &&
299 FI->getSynchScope() == cast<FenceInst>(I2)->getSynchScope();
301 return CXI->isVolatile() == cast<AtomicCmpXchgInst>(I2)->
isVolatile() &&
302 CXI->isWeak() == cast<AtomicCmpXchgInst>(I2)->
isWeak() &&
303 CXI->getSuccessOrdering() ==
304 cast<AtomicCmpXchgInst>(I2)->getSuccessOrdering() &&
305 CXI->getFailureOrdering() ==
306 cast<AtomicCmpXchgInst>(I2)->getFailureOrdering() &&
307 CXI->getSynchScope() == cast<AtomicCmpXchgInst>(I2)->getSynchScope();
309 return RMWI->getOperation() == cast<AtomicRMWInst>(I2)->getOperation() &&
310 RMWI->isVolatile() == cast<AtomicRMWInst>(I2)->
isVolatile() &&
311 RMWI->getOrdering() == cast<AtomicRMWInst>(I2)->getOrdering() &&
312 RMWI->getSynchScope() == cast<AtomicRMWInst>(I2)->getSynchScope();
343 if (
const PHINode *thisPHI = dyn_cast<PHINode>(
this)) {
344 const PHINode *otherPHI = cast<PHINode>(
I);
345 return std::equal(thisPHI->block_begin(), thisPHI->block_end(),
356 unsigned flags)
const {
394 if (PN->getIncomingBlock(U) != BB)
404 default:
return false;
405 case Instruction::VAArg:
407 case Instruction::Fence:
408 case Instruction::AtomicCmpXchg:
409 case Instruction::AtomicRMW:
412 return !cast<CallInst>(
this)->doesNotAccessMemory();
413 case Instruction::Invoke:
414 return !cast<InvokeInst>(
this)->doesNotAccessMemory();
416 return !cast<StoreInst>(
this)->isUnordered();
424 default:
return false;
425 case Instruction::Fence:
427 case Instruction::VAArg:
428 case Instruction::AtomicCmpXchg:
429 case Instruction::AtomicRMW:
432 return !cast<CallInst>(
this)->onlyReadsMemory();
433 case Instruction::Invoke:
434 return !cast<InvokeInst>(
this)->onlyReadsMemory();
436 return !cast<LoadInst>(
this)->isUnordered();
444 case Instruction::AtomicCmpXchg:
445 case Instruction::AtomicRMW:
446 case Instruction::Fence:
449 return cast<LoadInst>(
this)->getOrdering() !=
NotAtomic;
451 return cast<StoreInst>(
this)->getOrdering() !=
NotAtomic;
456 if (
const CallInst *CI = dyn_cast<CallInst>(
this))
457 return !CI->doesNotThrow();
458 return isa<ResumeInst>(
this);
462 if (
const CallInst *CI = dyn_cast<CallInst>(
this))
463 return !CI->doesNotReturn();
474 return Opcode ==
And || Opcode ==
Or || Opcode ==
Xor ||
475 Opcode == Add || Opcode == Mul;
521 return Opcode ==
And || Opcode ==
Or;
534 return Opcode ==
Xor;
546 #define HANDLE_INST(num, opc, clas) \
547 case Instruction::opc: \
548 New = cast<clas>(this)->cloneImpl(); \
550 #include "llvm/IR/Instruction.def"
562 for (
const auto &MD : TheMDs)
bool isNilpotent() const
isNilpotent - Return true if the instruction is nilpotent:
iplist< Instruction >::iterator eraseFromParent()
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()
A Module instance is used to store all the information related to an LLVM module. ...
FenceInst - an instruction for ordering other memory operations.
AtomicCmpXchgInst - an instruction that atomically checks whether a specified value is in a memory lo...
unsigned getNumOperands() const
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
isUsedOutsideOfBlock - Return true if there are any uses of this instruction in blocks other than the...
FastMathFlags getFastMathFlags() const
Convenience function for getting all the fast-math flags, which must be an operator which supports th...
LoadInst - an instruction for reading from memory.
AtomicRMWInst - an instruction that atomically reads a memory location, combines it with another valu...
bool hasNoNaNs() const
Determine whether the no-NaNs flag is set.
bool mayReturn() const
mayReturn - Return true if this is a function that may return.
void push_back(NodeTy *val)
bool isIdenticalTo(const Instruction *I) const
isIdenticalTo - 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...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
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 This must be kept in sync with lib/Trans...
bool hasAllowReciprocal() const
Determine whether the allow-reciprocal flag is set.
Check for equivalence ignoring load/store alignment.
static ConstantInt * ExtractElement(Constant *V, Constant *Idx)
Instruction * clone() const
clone() - Create a copy of 'this' instruction that is identical in all ways except the following: ...
block_iterator block_begin()
Check for equivalence treating a type and a vector of that type as equivalent.
bool mayReadFromMemory() const
mayReadFromMemory - Return true if this instruction may read memory.
bool isAssociative() const
isAssociative - Return true if the instruction is associative:
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.
StoreInst - an instruction for storing to memory.
const char * getOpcodeName() const
bool isAtomic() const
isAtomic - Return true if this instruction has an AtomicOrdering of unordered or higher.
void setDebugLoc(DebugLoc Loc)
setDebugLoc - Set the debug location information for this instruction.
bool isIdenticalToWhenDefined(const Instruction *I) const
isIdenticalToWhenDefined - This is like isIdenticalTo, except that it ignores the SubclassOptionalDat...
void insertBefore(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified instruction...
LLVM Basic Block Representation.
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
getAllMetadataOtherThanDebugLoc - This does the same thing as getAllMetadata, except that it filters ...
This file contains the declarations for the subclasses of Constant, which represent the different fla...
APInt Or(const APInt &LHS, const APInt &RHS)
Bitwise OR function for APInt.
APInt Xor(const APInt &LHS, const APInt &RHS)
Bitwise XOR function for APInt.
bool hasMetadata() const
hasMetadata() - Return true if this instruction has any metadata attached to it.
iterator insertAfter(iterator where, NodeTy *New)
const DebugLoc & getDebugLoc() const
getDebugLoc - Return the debug location for this node as a DebugLoc.
const InstListType & getInstList() const
Return the underlying instruction list container.
iterator insert(iterator where, NodeTy *New)
Value * getOperand(unsigned i) const
bool isCommutative() const
isCommutative - Return true if the instruction is commutative:
void setHasNoInfs(bool B)
Set or clear the no-infs flag on this instruction, which must be an operator which supports this flag...
iplist - The subset of list functionality that can safely be used on nodes of polymorphic types...
iterator erase(iterator where)
void setMetadata(unsigned KindID, MDNode *Node)
setMetadata - Set the metadata of the specified kind to the specified node.
unsigned char SubclassOptionalData
Hold subclass data that can be dropped.
bool mayWriteToMemory() const
mayWriteToMemory - Return true if this instruction may modify memory.
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.
void splice(iterator where, iplist &L2)
static bool isWeak(const MCSymbolELF &Sym)
LLVM_ATTRIBUTE_UNUSED_RESULT std::enable_if< !is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
const Type * getScalarType() const LLVM_READONLY
getScalarType - If this is a vector type, return the element type, otherwise return 'this'...
APInt And(const APInt &LHS, const APInt &RHS)
Bitwise AND function for APInt.
void removeFromParent()
removeFromParent - This method unlinks 'this' from the containing basic block, but does not delete it...
bool mayThrow() const
mayThrow - Return true if this instruction may throw an exception.
bool isIdempotent() const
isIdempotent - 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.
bool hasNoSignedZeros() const
Determine whether the no-signed-zeros flag is set.
AttributeSet getAttributes(LLVMContext &C, ID id)
Return the attributes for an intrinsic.
LLVM Value Representation.
unsigned getOpcode() const
getOpcode() returns a member of one of the enums like Instruction::Add.
void moveBefore(Instruction *MovePos)
moveBefore - Unlink this instruction from its current basic block and insert it into the basic block ...
InvokeInst - Invoke instruction.
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...
NodeTy * remove(iterator &IT)
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
InsertValueInst - This instruction inserts a struct field of array element value into an aggregate va...