24 Instruction::Instruction(
Type *ty,
unsigned it,
Use *Ops,
unsigned NumOps,
26 :
User(ty,
Value::InstructionVal + it, Ops, NumOps), Parent(0) {
33 "Instruction to insert before is not in a basic block!");
38 Instruction::Instruction(
Type *ty,
unsigned it,
Use *Ops,
unsigned NumOps,
40 :
User(ty,
Value::InstructionVal + it, Ops, NumOps), Parent(0) {
45 assert(InsertAtEnd &&
"Basic block to append to may not be NULL!");
52 assert(Parent == 0 &&
"Instruction still linked in the program!");
53 if (hasMetadataHashEntry())
54 clearMetadataHashEntries();
100 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
107 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
114 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
122 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
130 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
138 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
144 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
150 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
151 return cast<FPMathOperator>(
this)->
hasNoNaNs();
156 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
157 return cast<FPMathOperator>(
this)->
hasNoInfs();
162 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
168 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
176 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
189 case Ret:
return "ret";
190 case Br:
return "br";
191 case Switch:
return "switch";
192 case IndirectBr:
return "indirectbr";
193 case Invoke:
return "invoke";
194 case Resume:
return "resume";
195 case Unreachable:
return "unreachable";
198 case Add:
return "add";
199 case FAdd:
return "fadd";
200 case Sub:
return "sub";
201 case FSub:
return "fsub";
202 case Mul:
return "mul";
203 case FMul:
return "fmul";
204 case UDiv:
return "udiv";
205 case SDiv:
return "sdiv";
206 case FDiv:
return "fdiv";
207 case URem:
return "urem";
208 case SRem:
return "srem";
209 case FRem:
return "frem";
212 case And:
return "and";
213 case Or :
return "or";
214 case Xor:
return "xor";
217 case Alloca:
return "alloca";
218 case Load:
return "load";
219 case Store:
return "store";
220 case AtomicCmpXchg:
return "cmpxchg";
221 case AtomicRMW:
return "atomicrmw";
222 case Fence:
return "fence";
223 case GetElementPtr:
return "getelementptr";
226 case Trunc:
return "trunc";
227 case ZExt:
return "zext";
228 case SExt:
return "sext";
229 case FPTrunc:
return "fptrunc";
230 case FPExt:
return "fpext";
231 case FPToUI:
return "fptoui";
232 case FPToSI:
return "fptosi";
233 case UIToFP:
return "uitofp";
234 case SIToFP:
return "sitofp";
235 case IntToPtr:
return "inttoptr";
236 case PtrToInt:
return "ptrtoint";
237 case BitCast:
return "bitcast";
238 case AddrSpaceCast:
return "addrspacecast";
241 case ICmp:
return "icmp";
242 case FCmp:
return "fcmp";
243 case PHI:
return "phi";
244 case Select:
return "select";
245 case Call:
return "call";
246 case Shl:
return "shl";
247 case LShr:
return "lshr";
248 case AShr:
return "ashr";
249 case VAArg:
return "va_arg";
251 case InsertElement:
return "insertelement";
252 case ShuffleVector:
return "shufflevector";
253 case ExtractValue:
return "extractvalue";
254 case InsertValue:
return "insertvalue";
255 case LandingPad:
return "landingpad";
257 default:
return "<Invalid operator> ";
285 if (
const LoadInst *
LI = dyn_cast<LoadInst>(
this))
286 return LI->isVolatile() == cast<LoadInst>(
I)->isVolatile() &&
287 LI->getAlignment() == cast<LoadInst>(
I)->getAlignment() &&
288 LI->getOrdering() == cast<LoadInst>(
I)->getOrdering() &&
289 LI->getSynchScope() == cast<LoadInst>(
I)->getSynchScope();
290 if (
const StoreInst *SI = dyn_cast<StoreInst>(
this))
291 return SI->isVolatile() == cast<StoreInst>(
I)->isVolatile() &&
292 SI->getAlignment() == cast<StoreInst>(
I)->getAlignment() &&
293 SI->getOrdering() == cast<StoreInst>(
I)->getOrdering() &&
294 SI->getSynchScope() == cast<StoreInst>(
I)->getSynchScope();
295 if (
const CmpInst *CI = dyn_cast<CmpInst>(
this))
296 return CI->getPredicate() == cast<CmpInst>(
I)->getPredicate();
297 if (
const CallInst *CI = dyn_cast<CallInst>(
this))
298 return CI->isTailCall() == cast<CallInst>(
I)->isTailCall() &&
299 CI->getCallingConv() == cast<CallInst>(
I)->getCallingConv() &&
301 if (
const InvokeInst *CI = dyn_cast<InvokeInst>(
this))
302 return CI->getCallingConv() == cast<InvokeInst>(
I)->getCallingConv() &&
305 return IVI->getIndices() == cast<InsertValueInst>(
I)->getIndices();
307 return EVI->getIndices() == cast<ExtractValueInst>(
I)->getIndices();
308 if (
const FenceInst *FI = dyn_cast<FenceInst>(
this))
309 return FI->getOrdering() == cast<FenceInst>(FI)->getOrdering() &&
310 FI->getSynchScope() == cast<FenceInst>(FI)->getSynchScope();
312 return CXI->isVolatile() == cast<AtomicCmpXchgInst>(
I)->isVolatile() &&
313 CXI->getOrdering() == cast<AtomicCmpXchgInst>(
I)->getOrdering() &&
314 CXI->getSynchScope() == cast<AtomicCmpXchgInst>(
I)->getSynchScope();
315 if (
const AtomicRMWInst *RMWI = dyn_cast<AtomicRMWInst>(
this))
316 return RMWI->getOperation() == cast<AtomicRMWInst>(
I)->getOperation() &&
317 RMWI->isVolatile() == cast<AtomicRMWInst>(
I)->isVolatile() &&
318 RMWI->getOrdering() == cast<AtomicRMWInst>(
I)->getOrdering() &&
319 RMWI->getSynchScope() == cast<AtomicRMWInst>(
I)->getSynchScope();
320 if (
const PHINode *thisPHI = dyn_cast<PHINode>(
this)) {
321 const PHINode *otherPHI = cast<PHINode>(
I);
322 for (
unsigned i = 0, e = thisPHI->getNumOperands(); i != e; ++i) {
335 unsigned flags)
const {
356 if (
const LoadInst *
LI = dyn_cast<LoadInst>(
this))
357 return LI->isVolatile() == cast<LoadInst>(
I)->isVolatile() &&
358 (
LI->getAlignment() == cast<LoadInst>(
I)->getAlignment() ||
360 LI->getOrdering() == cast<LoadInst>(
I)->getOrdering() &&
361 LI->getSynchScope() == cast<LoadInst>(
I)->getSynchScope();
362 if (
const StoreInst *SI = dyn_cast<StoreInst>(
this))
363 return SI->isVolatile() == cast<StoreInst>(
I)->isVolatile() &&
364 (SI->getAlignment() == cast<StoreInst>(
I)->getAlignment() ||
366 SI->getOrdering() == cast<StoreInst>(
I)->getOrdering() &&
367 SI->getSynchScope() == cast<StoreInst>(
I)->getSynchScope();
368 if (
const CmpInst *CI = dyn_cast<CmpInst>(
this))
369 return CI->getPredicate() == cast<CmpInst>(
I)->getPredicate();
370 if (
const CallInst *CI = dyn_cast<CallInst>(
this))
371 return CI->isTailCall() == cast<CallInst>(
I)->isTailCall() &&
372 CI->getCallingConv() == cast<CallInst>(
I)->getCallingConv() &&
374 if (
const InvokeInst *CI = dyn_cast<InvokeInst>(
this))
375 return CI->getCallingConv() == cast<InvokeInst>(
I)->getCallingConv() &&
376 CI->getAttributes() ==
379 return IVI->getIndices() == cast<InsertValueInst>(
I)->getIndices();
381 return EVI->getIndices() == cast<ExtractValueInst>(
I)->getIndices();
382 if (
const FenceInst *FI = dyn_cast<FenceInst>(
this))
383 return FI->getOrdering() == cast<FenceInst>(
I)->getOrdering() &&
384 FI->getSynchScope() == cast<FenceInst>(
I)->getSynchScope();
386 return CXI->isVolatile() == cast<AtomicCmpXchgInst>(
I)->isVolatile() &&
387 CXI->getOrdering() == cast<AtomicCmpXchgInst>(
I)->getOrdering() &&
388 CXI->getSynchScope() == cast<AtomicCmpXchgInst>(
I)->getSynchScope();
389 if (
const AtomicRMWInst *RMWI = dyn_cast<AtomicRMWInst>(
this))
390 return RMWI->getOperation() == cast<AtomicRMWInst>(
I)->getOperation() &&
391 RMWI->isVolatile() == cast<AtomicRMWInst>(
I)->isVolatile() &&
392 RMWI->getOrdering() == cast<AtomicRMWInst>(
I)->getOrdering() &&
393 RMWI->getSynchScope() == cast<AtomicRMWInst>(
I)->getSynchScope();
408 if (cast<Instruction>(U)->getParent() != BB)
423 default:
return false;
424 case Instruction::VAArg:
426 case Instruction::Fence:
427 case Instruction::AtomicCmpXchg:
428 case Instruction::AtomicRMW:
431 return !cast<CallInst>(
this)->doesNotAccessMemory();
432 case Instruction::Invoke:
433 return !cast<InvokeInst>(
this)->doesNotAccessMemory();
435 return !cast<StoreInst>(
this)->isUnordered();
443 default:
return false;
444 case Instruction::Fence:
446 case Instruction::VAArg:
447 case Instruction::AtomicCmpXchg:
448 case Instruction::AtomicRMW:
451 return !cast<CallInst>(
this)->onlyReadsMemory();
452 case Instruction::Invoke:
453 return !cast<InvokeInst>(
this)->onlyReadsMemory();
455 return !cast<LoadInst>(
this)->isUnordered();
460 if (
const CallInst *CI = dyn_cast<CallInst>(
this))
461 return !CI->doesNotThrow();
462 return isa<ResumeInst>(
this);
466 if (
const CallInst *CI = dyn_cast<CallInst>(
this))
467 return !CI->doesNotReturn();
478 return Opcode ==
And || Opcode ==
Or || Opcode ==
Xor ||
479 Opcode == Add || Opcode == Mul;
525 return Opcode ==
And || Opcode ==
Or;
538 return Opcode ==
Xor;
551 for (
unsigned i = 0, e = TheMDs.
size(); i != e; ++i)
552 New->
setMetadata(TheMDs[i].first, TheMDs[i].second);
Abstract base class of comparison instructions.
void setFastMathFlags(FastMathFlags FMF)
enable_if_c<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
unsigned getNumOperands() const
void setHasNoNaNs(bool B)
bool isUsedOutsideOfBlock(const BasicBlock *BB) const
FastMathFlags getFastMathFlags() const
void setDebugLoc(const DebugLoc &Loc)
setDebugLoc - Set the debug location information for this instruction.
LoopInfoBase< BlockT, LoopT > * LI
void getAllMetadataOtherThanDebugLoc(SmallVectorImpl< std::pair< unsigned, MDNode * > > &MDs) const
static void removeGarbageObject(void *Object)
bool hasNoNaNs() const
Determine whether the no-NaNs flag is set.
void push_back(NodeTy *val)
bool isIdenticalTo(const Instruction *I) const
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
bool mayReadFromMemory() const
bool isAssociative() const
void setHasUnsafeAlgebra(bool B)
bool hasUnsafeAlgebra() const
Determine whether the unsafe-algebra flag is set.
const char * getOpcodeName() const
bool isIdenticalToWhenDefined(const Instruction *I) const
void insertBefore(Instruction *InsertPos)
LLVM Basic Block Representation.
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.
iterator insertAfter(iterator where, NodeTy *New)
const DebugLoc & getDebugLoc() const
getDebugLoc - Return the debug location for this node as a DebugLoc.
BasicBlock * getIncomingBlock(unsigned i) const
const InstListType & getInstList() const
Return the underlying instruction list container.
iterator insert(iterator where, NodeTy *New)
Value * getOperand(unsigned i) const
bool isCommutative() const
void setHasNoInfs(bool B)
iterator erase(iterator where)
void setMetadata(unsigned KindID, MDNode *Node)
unsigned char SubclassOptionalData
bool mayWriteToMemory() const
void copyFastMathFlags(const Instruction *I)
Copy I's fast-math flags.
void splice(iterator where, iplist &L2)
static void addGarbageObject(void *Object)
APInt And(const APInt &LHS, const APInt &RHS)
Bitwise AND function for APInt.
bool isIdempotent() const
void insertAfter(Instruction *InsertPos)
bool hasNoInfs() const
Determine whether the no-infs flag is set.
const Type * getScalarType() const
bool hasNoSignedZeros() const
Determine whether the no-signed-zeros flag is set.
AttributeSet getAttributes(LLVMContext &C, ID id)
virtual Instruction * clone_impl() const =0
LLVM Value Representation.
unsigned getOpcode() const
getOpcode() returns a member of one of the enums like Instruction::Add.
void moveBefore(Instruction *MovePos)
Convenience struct for specifying and reasoning about fast-math flags.
bool isSameOperationAs(const Instruction *I, unsigned flags=0) const
Determine if one instruction is the same operation as another.
void setHasNoSignedZeros(bool B)
NodeTy * remove(iterator &IT)
void setHasAllowReciprocal(bool B)
const BasicBlock * getParent() const