LLVM 17.0.0git
Instruction.cpp
Go to the documentation of this file.
1//===-- Instruction.cpp - Implement the Instruction class -----------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the Instruction class for the IR library.
10//
11//===----------------------------------------------------------------------===//
12
13#include "llvm/IR/Instruction.h"
14#include "llvm/ADT/DenseSet.h"
15#include "llvm/IR/Constants.h"
18#include "llvm/IR/Intrinsics.h"
19#include "llvm/IR/Operator.h"
21#include "llvm/IR/Type.h"
22using namespace llvm;
23
24Instruction::Instruction(Type *ty, unsigned it, Use *Ops, unsigned NumOps,
25 Instruction *InsertBefore)
26 : User(ty, Value::InstructionVal + it, Ops, NumOps), Parent(nullptr) {
27
28 // If requested, insert this instruction into a basic block...
29 if (InsertBefore) {
30 BasicBlock *BB = InsertBefore->getParent();
31 assert(BB && "Instruction to insert before is not in a basic block!");
32 insertInto(BB, InsertBefore->getIterator());
33 }
34}
35
36Instruction::Instruction(Type *ty, unsigned it, Use *Ops, unsigned NumOps,
37 BasicBlock *InsertAtEnd)
38 : User(ty, Value::InstructionVal + it, Ops, NumOps), Parent(nullptr) {
39
40 // append this instruction into the basic block
41 assert(InsertAtEnd && "Basic block to append to may not be NULL!");
42 insertInto(InsertAtEnd, InsertAtEnd->end());
43}
44
46 assert(!Parent && "Instruction still linked in the program!");
47
48 // Replace any extant metadata uses of this instruction with undef to
49 // preserve debug info accuracy. Some alternatives include:
50 // - Treat Instruction like any other Value, and point its extant metadata
51 // uses to an empty ValueAsMetadata node. This makes extant dbg.value uses
52 // trivially dead (i.e. fair game for deletion in many passes), leading to
53 // stale dbg.values being in effect for too long.
54 // - Call salvageDebugInfoOrMarkUndef. Not needed to make instruction removal
55 // correct. OTOH results in wasted work in some common cases (e.g. when all
56 // instructions in a BasicBlock are deleted).
57 if (isUsedByMetadata())
59
60 // Explicitly remove DIAssignID metadata to clear up ID -> Instruction(s)
61 // mapping in LLVMContext.
62 setMetadata(LLVMContext::MD_DIAssignID, nullptr);
63}
64
65
66void Instruction::setParent(BasicBlock *P) {
67 Parent = P;
68}
69
71 return getParent()->getModule();
72}
73
75 return getParent()->getParent();
76}
77
79 getParent()->getInstList().remove(getIterator());
80}
81
83 return getParent()->getInstList().erase(getIterator());
84}
85
86/// Insert an unlinked instruction into a basic block immediately before the
87/// specified instruction.
89 insertInto(InsertPos->getParent(), InsertPos->getIterator());
90}
91
92/// Insert an unlinked instruction into a basic block immediately after the
93/// specified instruction.
95 insertInto(InsertPos->getParent(), std::next(InsertPos->getIterator()));
96}
97
100 assert(getParent() == nullptr && "Expected detached instruction");
101 assert((It == ParentBB->end() || It->getParent() == ParentBB) &&
102 "It not in ParentBB");
103 return ParentBB->getInstList().insert(It, this);
104}
105
106/// Unlink this instruction from its current basic block and insert it into the
107/// basic block that MovePos lives in, right before MovePos.
109 moveBefore(*MovePos->getParent(), MovePos->getIterator());
110}
111
113 moveBefore(*MovePos->getParent(), ++MovePos->getIterator());
114}
115
118 assert(I == BB.end() || I->getParent() == &BB);
119 BB.splice(I, getParent(), getIterator());
120}
121
123 assert(Parent && Other->Parent &&
124 "instructions without BB parents have no order");
125 assert(Parent == Other->Parent && "cross-BB instruction order comparison");
126 if (!Parent->isInstrOrderValid())
127 Parent->renumberInstructions();
128 return Order < Other->Order;
129}
130
132 assert(!getType()->isVoidTy() && "Instruction must define result");
133 BasicBlock *InsertBB;
134 BasicBlock::iterator InsertPt;
135 if (auto *PN = dyn_cast<PHINode>(this)) {
136 InsertBB = PN->getParent();
137 InsertPt = InsertBB->getFirstInsertionPt();
138 } else if (auto *II = dyn_cast<InvokeInst>(this)) {
139 InsertBB = II->getNormalDest();
140 InsertPt = InsertBB->getFirstInsertionPt();
141 } else if (isa<CallBrInst>(this)) {
142 // Def is available in multiple successors, there's no single dominating
143 // insertion point.
144 return nullptr;
145 } else {
146 assert(!isTerminator() && "Only invoke/callbr terminators return value");
147 InsertBB = getParent();
148 InsertPt = std::next(getIterator());
149 }
150
151 // catchswitch blocks don't have any legal insertion point (because they
152 // are both an exception pad and a terminator).
153 if (InsertPt == InsertBB->end())
154 return nullptr;
155 return &*InsertPt;
156}
157
159 return any_of(operands(), [](Value *V) { return V->hasOneUser(); });
160}
161
163 cast<OverflowingBinaryOperator>(this)->setHasNoUnsignedWrap(b);
164}
165
167 cast<OverflowingBinaryOperator>(this)->setHasNoSignedWrap(b);
168}
169
171 cast<PossiblyExactOperator>(this)->setIsExact(b);
172}
173
175 return cast<OverflowingBinaryOperator>(this)->hasNoUnsignedWrap();
176}
177
179 return cast<OverflowingBinaryOperator>(this)->hasNoSignedWrap();
180}
181
183 return cast<Operator>(this)->hasPoisonGeneratingFlags();
184}
185
187 switch (getOpcode()) {
188 case Instruction::Add:
189 case Instruction::Sub:
190 case Instruction::Mul:
191 case Instruction::Shl:
192 cast<OverflowingBinaryOperator>(this)->setHasNoUnsignedWrap(false);
193 cast<OverflowingBinaryOperator>(this)->setHasNoSignedWrap(false);
194 break;
195
196 case Instruction::UDiv:
197 case Instruction::SDiv:
198 case Instruction::AShr:
199 case Instruction::LShr:
200 cast<PossiblyExactOperator>(this)->setIsExact(false);
201 break;
202
203 case Instruction::GetElementPtr:
204 cast<GetElementPtrInst>(this)->setIsInBounds(false);
205 break;
206 }
207 if (isa<FPMathOperator>(this)) {
208 setHasNoNaNs(false);
209 setHasNoInfs(false);
210 }
211
212 assert(!hasPoisonGeneratingFlags() && "must be kept in sync");
213}
214
216 return hasMetadata(LLVMContext::MD_range) ||
217 hasMetadata(LLVMContext::MD_nonnull) ||
218 hasMetadata(LLVMContext::MD_align);
219}
220
222 eraseMetadata(LLVMContext::MD_range);
223 eraseMetadata(LLVMContext::MD_nonnull);
224 eraseMetadata(LLVMContext::MD_align);
225}
226
228 ArrayRef<unsigned> KnownIDs) {
230 auto *CB = dyn_cast<CallBase>(this);
231 if (!CB)
232 return;
233 // For call instructions, we also need to drop parameter and return attributes
234 // that are can cause UB if the call is moved to a location where the
235 // attribute is not valid.
236 AttributeList AL = CB->getAttributes();
237 if (AL.isEmpty())
238 return;
239 AttributeMask UBImplyingAttributes =
241 for (unsigned ArgNo = 0; ArgNo < CB->arg_size(); ArgNo++)
242 CB->removeParamAttrs(ArgNo, UBImplyingAttributes);
243 CB->removeRetAttrs(UBImplyingAttributes);
244}
245
247 // !annotation metadata does not impact semantics.
248 // !range, !nonnull and !align produce poison, so they are safe to speculate.
249 // !noundef and various AA metadata must be dropped, as it generally produces
250 // immediate undefined behavior.
251 unsigned KnownIDs[] = {LLVMContext::MD_annotation, LLVMContext::MD_range,
252 LLVMContext::MD_nonnull, LLVMContext::MD_align};
254}
255
257 return cast<PossiblyExactOperator>(this)->isExact();
258}
259
261 assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
262 cast<FPMathOperator>(this)->setFast(B);
263}
264
266 assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
267 cast<FPMathOperator>(this)->setHasAllowReassoc(B);
268}
269
271 assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
272 cast<FPMathOperator>(this)->setHasNoNaNs(B);
273}
274
276 assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
277 cast<FPMathOperator>(this)->setHasNoInfs(B);
278}
279
281 assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
282 cast<FPMathOperator>(this)->setHasNoSignedZeros(B);
283}
284
286 assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
287 cast<FPMathOperator>(this)->setHasAllowReciprocal(B);
288}
289
291 assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
292 cast<FPMathOperator>(this)->setHasAllowContract(B);
293}
294
296 assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
297 cast<FPMathOperator>(this)->setHasApproxFunc(B);
298}
299
301 assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
302 cast<FPMathOperator>(this)->setFastMathFlags(FMF);
303}
304
306 assert(isa<FPMathOperator>(this) && "copying fast-math flag on invalid op");
307 cast<FPMathOperator>(this)->copyFastMathFlags(FMF);
308}
309
311 assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
312 return cast<FPMathOperator>(this)->isFast();
313}
314
316 assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
317 return cast<FPMathOperator>(this)->hasAllowReassoc();
318}
319
321 assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
322 return cast<FPMathOperator>(this)->hasNoNaNs();
323}
324
326 assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
327 return cast<FPMathOperator>(this)->hasNoInfs();
328}
329
331 assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
332 return cast<FPMathOperator>(this)->hasNoSignedZeros();
333}
334
336 assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
337 return cast<FPMathOperator>(this)->hasAllowReciprocal();
338}
339
341 assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
342 return cast<FPMathOperator>(this)->hasAllowContract();
343}
344
346 assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
347 return cast<FPMathOperator>(this)->hasApproxFunc();
348}
349
351 assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
352 return cast<FPMathOperator>(this)->getFastMathFlags();
353}
354
356 copyFastMathFlags(I->getFastMathFlags());
357}
358
359void Instruction::copyIRFlags(const Value *V, bool IncludeWrapFlags) {
360 // Copy the wrapping flags.
361 if (IncludeWrapFlags && isa<OverflowingBinaryOperator>(this)) {
362 if (auto *OB = dyn_cast<OverflowingBinaryOperator>(V)) {
363 setHasNoSignedWrap(OB->hasNoSignedWrap());
364 setHasNoUnsignedWrap(OB->hasNoUnsignedWrap());
365 }
366 }
367
368 // Copy the exact flag.
369 if (auto *PE = dyn_cast<PossiblyExactOperator>(V))
370 if (isa<PossiblyExactOperator>(this))
371 setIsExact(PE->isExact());
372
373 // Copy the fast-math flags.
374 if (auto *FP = dyn_cast<FPMathOperator>(V))
375 if (isa<FPMathOperator>(this))
376 copyFastMathFlags(FP->getFastMathFlags());
377
378 if (auto *SrcGEP = dyn_cast<GetElementPtrInst>(V))
379 if (auto *DestGEP = dyn_cast<GetElementPtrInst>(this))
380 DestGEP->setIsInBounds(SrcGEP->isInBounds() || DestGEP->isInBounds());
381}
382
384 if (auto *OB = dyn_cast<OverflowingBinaryOperator>(V)) {
385 if (isa<OverflowingBinaryOperator>(this)) {
386 setHasNoSignedWrap(hasNoSignedWrap() && OB->hasNoSignedWrap());
387 setHasNoUnsignedWrap(hasNoUnsignedWrap() && OB->hasNoUnsignedWrap());
388 }
389 }
390
391 if (auto *PE = dyn_cast<PossiblyExactOperator>(V))
392 if (isa<PossiblyExactOperator>(this))
393 setIsExact(isExact() && PE->isExact());
394
395 if (auto *FP = dyn_cast<FPMathOperator>(V)) {
396 if (isa<FPMathOperator>(this)) {
398 FM &= FP->getFastMathFlags();
400 }
401 }
402
403 if (auto *SrcGEP = dyn_cast<GetElementPtrInst>(V))
404 if (auto *DestGEP = dyn_cast<GetElementPtrInst>(this))
405 DestGEP->setIsInBounds(SrcGEP->isInBounds() && DestGEP->isInBounds());
406}
407
408const char *Instruction::getOpcodeName(unsigned OpCode) {
409 switch (OpCode) {
410 // Terminators
411 case Ret: return "ret";
412 case Br: return "br";
413 case Switch: return "switch";
414 case IndirectBr: return "indirectbr";
415 case Invoke: return "invoke";
416 case Resume: return "resume";
417 case Unreachable: return "unreachable";
418 case CleanupRet: return "cleanupret";
419 case CatchRet: return "catchret";
420 case CatchPad: return "catchpad";
421 case CatchSwitch: return "catchswitch";
422 case CallBr: return "callbr";
423
424 // Standard unary operators...
425 case FNeg: return "fneg";
426
427 // Standard binary operators...
428 case Add: return "add";
429 case FAdd: return "fadd";
430 case Sub: return "sub";
431 case FSub: return "fsub";
432 case Mul: return "mul";
433 case FMul: return "fmul";
434 case UDiv: return "udiv";
435 case SDiv: return "sdiv";
436 case FDiv: return "fdiv";
437 case URem: return "urem";
438 case SRem: return "srem";
439 case FRem: return "frem";
440
441 // Logical operators...
442 case And: return "and";
443 case Or : return "or";
444 case Xor: return "xor";
445
446 // Memory instructions...
447 case Alloca: return "alloca";
448 case Load: return "load";
449 case Store: return "store";
450 case AtomicCmpXchg: return "cmpxchg";
451 case AtomicRMW: return "atomicrmw";
452 case Fence: return "fence";
453 case GetElementPtr: return "getelementptr";
454
455 // Convert instructions...
456 case Trunc: return "trunc";
457 case ZExt: return "zext";
458 case SExt: return "sext";
459 case FPTrunc: return "fptrunc";
460 case FPExt: return "fpext";
461 case FPToUI: return "fptoui";
462 case FPToSI: return "fptosi";
463 case UIToFP: return "uitofp";
464 case SIToFP: return "sitofp";
465 case IntToPtr: return "inttoptr";
466 case PtrToInt: return "ptrtoint";
467 case BitCast: return "bitcast";
468 case AddrSpaceCast: return "addrspacecast";
469
470 // Other instructions...
471 case ICmp: return "icmp";
472 case FCmp: return "fcmp";
473 case PHI: return "phi";
474 case Select: return "select";
475 case Call: return "call";
476 case Shl: return "shl";
477 case LShr: return "lshr";
478 case AShr: return "ashr";
479 case VAArg: return "va_arg";
480 case ExtractElement: return "extractelement";
481 case InsertElement: return "insertelement";
482 case ShuffleVector: return "shufflevector";
483 case ExtractValue: return "extractvalue";
484 case InsertValue: return "insertvalue";
485 case LandingPad: return "landingpad";
486 case CleanupPad: return "cleanuppad";
487 case Freeze: return "freeze";
488
489 default: return "<Invalid operator> ";
490 }
491}
492
493/// This must be kept in sync with FunctionComparator::cmpOperations in
494/// lib/Transforms/IPO/MergeFunctions.cpp.
496 bool IgnoreAlignment) const {
497 auto I1 = this;
498 assert(I1->getOpcode() == I2->getOpcode() &&
499 "Can not compare special state of different instructions");
500
501 if (const AllocaInst *AI = dyn_cast<AllocaInst>(I1))
502 return AI->getAllocatedType() == cast<AllocaInst>(I2)->getAllocatedType() &&
503 (AI->getAlign() == cast<AllocaInst>(I2)->getAlign() ||
504 IgnoreAlignment);
505 if (const LoadInst *LI = dyn_cast<LoadInst>(I1))
506 return LI->isVolatile() == cast<LoadInst>(I2)->isVolatile() &&
507 (LI->getAlign() == cast<LoadInst>(I2)->getAlign() ||
508 IgnoreAlignment) &&
509 LI->getOrdering() == cast<LoadInst>(I2)->getOrdering() &&
510 LI->getSyncScopeID() == cast<LoadInst>(I2)->getSyncScopeID();
511 if (const StoreInst *SI = dyn_cast<StoreInst>(I1))
512 return SI->isVolatile() == cast<StoreInst>(I2)->isVolatile() &&
513 (SI->getAlign() == cast<StoreInst>(I2)->getAlign() ||
514 IgnoreAlignment) &&
515 SI->getOrdering() == cast<StoreInst>(I2)->getOrdering() &&
516 SI->getSyncScopeID() == cast<StoreInst>(I2)->getSyncScopeID();
517 if (const CmpInst *CI = dyn_cast<CmpInst>(I1))
518 return CI->getPredicate() == cast<CmpInst>(I2)->getPredicate();
519 if (const CallInst *CI = dyn_cast<CallInst>(I1))
520 return CI->isTailCall() == cast<CallInst>(I2)->isTailCall() &&
521 CI->getCallingConv() == cast<CallInst>(I2)->getCallingConv() &&
522 CI->getAttributes() == cast<CallInst>(I2)->getAttributes() &&
523 CI->hasIdenticalOperandBundleSchema(*cast<CallInst>(I2));
524 if (const InvokeInst *CI = dyn_cast<InvokeInst>(I1))
525 return CI->getCallingConv() == cast<InvokeInst>(I2)->getCallingConv() &&
526 CI->getAttributes() == cast<InvokeInst>(I2)->getAttributes() &&
527 CI->hasIdenticalOperandBundleSchema(*cast<InvokeInst>(I2));
528 if (const CallBrInst *CI = dyn_cast<CallBrInst>(I1))
529 return CI->getCallingConv() == cast<CallBrInst>(I2)->getCallingConv() &&
530 CI->getAttributes() == cast<CallBrInst>(I2)->getAttributes() &&
531 CI->hasIdenticalOperandBundleSchema(*cast<CallBrInst>(I2));
532 if (const InsertValueInst *IVI = dyn_cast<InsertValueInst>(I1))
533 return IVI->getIndices() == cast<InsertValueInst>(I2)->getIndices();
534 if (const ExtractValueInst *EVI = dyn_cast<ExtractValueInst>(I1))
535 return EVI->getIndices() == cast<ExtractValueInst>(I2)->getIndices();
536 if (const FenceInst *FI = dyn_cast<FenceInst>(I1))
537 return FI->getOrdering() == cast<FenceInst>(I2)->getOrdering() &&
538 FI->getSyncScopeID() == cast<FenceInst>(I2)->getSyncScopeID();
539 if (const AtomicCmpXchgInst *CXI = dyn_cast<AtomicCmpXchgInst>(I1))
540 return CXI->isVolatile() == cast<AtomicCmpXchgInst>(I2)->isVolatile() &&
541 CXI->isWeak() == cast<AtomicCmpXchgInst>(I2)->isWeak() &&
542 CXI->getSuccessOrdering() ==
543 cast<AtomicCmpXchgInst>(I2)->getSuccessOrdering() &&
544 CXI->getFailureOrdering() ==
545 cast<AtomicCmpXchgInst>(I2)->getFailureOrdering() &&
546 CXI->getSyncScopeID() ==
547 cast<AtomicCmpXchgInst>(I2)->getSyncScopeID();
548 if (const AtomicRMWInst *RMWI = dyn_cast<AtomicRMWInst>(I1))
549 return RMWI->getOperation() == cast<AtomicRMWInst>(I2)->getOperation() &&
550 RMWI->isVolatile() == cast<AtomicRMWInst>(I2)->isVolatile() &&
551 RMWI->getOrdering() == cast<AtomicRMWInst>(I2)->getOrdering() &&
552 RMWI->getSyncScopeID() == cast<AtomicRMWInst>(I2)->getSyncScopeID();
553 if (const ShuffleVectorInst *SVI = dyn_cast<ShuffleVectorInst>(I1))
554 return SVI->getShuffleMask() ==
555 cast<ShuffleVectorInst>(I2)->getShuffleMask();
556 if (const GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(I1))
557 return GEP->getSourceElementType() ==
558 cast<GetElementPtrInst>(I2)->getSourceElementType();
559
560 return true;
561}
562
564 return isIdenticalToWhenDefined(I) &&
565 SubclassOptionalData == I->SubclassOptionalData;
566}
567
569 if (getOpcode() != I->getOpcode() ||
570 getNumOperands() != I->getNumOperands() ||
571 getType() != I->getType())
572 return false;
573
574 // If both instructions have no operands, they are identical.
575 if (getNumOperands() == 0 && I->getNumOperands() == 0)
576 return this->hasSameSpecialState(I);
577
578 // We have two instructions of identical opcode and #operands. Check to see
579 // if all operands are the same.
580 if (!std::equal(op_begin(), op_end(), I->op_begin()))
581 return false;
582
583 // WARNING: this logic must be kept in sync with EliminateDuplicatePHINodes()!
584 if (const PHINode *thisPHI = dyn_cast<PHINode>(this)) {
585 const PHINode *otherPHI = cast<PHINode>(I);
586 return std::equal(thisPHI->block_begin(), thisPHI->block_end(),
587 otherPHI->block_begin());
588 }
589
590 return this->hasSameSpecialState(I);
591}
592
593// Keep this in sync with FunctionComparator::cmpOperations in
594// lib/Transforms/IPO/MergeFunctions.cpp.
596 unsigned flags) const {
597 bool IgnoreAlignment = flags & CompareIgnoringAlignment;
598 bool UseScalarTypes = flags & CompareUsingScalarTypes;
599
600 if (getOpcode() != I->getOpcode() ||
601 getNumOperands() != I->getNumOperands() ||
602 (UseScalarTypes ?
603 getType()->getScalarType() != I->getType()->getScalarType() :
604 getType() != I->getType()))
605 return false;
606
607 // We have two instructions of identical opcode and #operands. Check to see
608 // if all operands are the same type
609 for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
610 if (UseScalarTypes ?
611 getOperand(i)->getType()->getScalarType() !=
612 I->getOperand(i)->getType()->getScalarType() :
613 getOperand(i)->getType() != I->getOperand(i)->getType())
614 return false;
615
616 return this->hasSameSpecialState(I, IgnoreAlignment);
617}
618
620 for (const Use &U : uses()) {
621 // PHI nodes uses values in the corresponding predecessor block. For other
622 // instructions, just check to see whether the parent of the use matches up.
623 const Instruction *I = cast<Instruction>(U.getUser());
624 const PHINode *PN = dyn_cast<PHINode>(I);
625 if (!PN) {
626 if (I->getParent() != BB)
627 return true;
628 continue;
629 }
630
631 if (PN->getIncomingBlock(U) != BB)
632 return true;
633 }
634 return false;
635}
636
638 switch (getOpcode()) {
639 default: return false;
640 case Instruction::VAArg:
641 case Instruction::Load:
642 case Instruction::Fence: // FIXME: refine definition of mayReadFromMemory
643 case Instruction::AtomicCmpXchg:
644 case Instruction::AtomicRMW:
645 case Instruction::CatchPad:
646 case Instruction::CatchRet:
647 return true;
648 case Instruction::Call:
649 case Instruction::Invoke:
650 case Instruction::CallBr:
651 return !cast<CallBase>(this)->onlyWritesMemory();
652 case Instruction::Store:
653 return !cast<StoreInst>(this)->isUnordered();
654 }
655}
656
658 switch (getOpcode()) {
659 default: return false;
660 case Instruction::Fence: // FIXME: refine definition of mayWriteToMemory
661 case Instruction::Store:
662 case Instruction::VAArg:
663 case Instruction::AtomicCmpXchg:
664 case Instruction::AtomicRMW:
665 case Instruction::CatchPad:
666 case Instruction::CatchRet:
667 return true;
668 case Instruction::Call:
669 case Instruction::Invoke:
670 case Instruction::CallBr:
671 return !cast<CallBase>(this)->onlyReadsMemory();
672 case Instruction::Load:
673 return !cast<LoadInst>(this)->isUnordered();
674 }
675}
676
678 switch (getOpcode()) {
679 default:
680 return false;
681 case Instruction::AtomicCmpXchg:
682 case Instruction::AtomicRMW:
683 case Instruction::Fence:
684 return true;
685 case Instruction::Load:
686 return cast<LoadInst>(this)->getOrdering() != AtomicOrdering::NotAtomic;
687 case Instruction::Store:
688 return cast<StoreInst>(this)->getOrdering() != AtomicOrdering::NotAtomic;
689 }
690}
691
693 assert(isAtomic());
694 switch (getOpcode()) {
695 default:
696 return false;
697 case Instruction::AtomicCmpXchg:
698 case Instruction::AtomicRMW:
699 case Instruction::Load:
700 return true;
701 }
702}
703
705 assert(isAtomic());
706 switch (getOpcode()) {
707 default:
708 return false;
709 case Instruction::AtomicCmpXchg:
710 case Instruction::AtomicRMW:
711 case Instruction::Store:
712 return true;
713 }
714}
715
717 switch (getOpcode()) {
718 default:
719 return false;
720 case Instruction::AtomicRMW:
721 return cast<AtomicRMWInst>(this)->isVolatile();
722 case Instruction::Store:
723 return cast<StoreInst>(this)->isVolatile();
724 case Instruction::Load:
725 return cast<LoadInst>(this)->isVolatile();
726 case Instruction::AtomicCmpXchg:
727 return cast<AtomicCmpXchgInst>(this)->isVolatile();
728 case Instruction::Call:
729 case Instruction::Invoke:
730 // There are a very limited number of intrinsics with volatile flags.
731 if (auto *II = dyn_cast<IntrinsicInst>(this)) {
732 if (auto *MI = dyn_cast<MemIntrinsic>(II))
733 return MI->isVolatile();
734 switch (II->getIntrinsicID()) {
735 default: break;
736 case Intrinsic::matrix_column_major_load:
737 return cast<ConstantInt>(II->getArgOperand(2))->isOne();
738 case Intrinsic::matrix_column_major_store:
739 return cast<ConstantInt>(II->getArgOperand(3))->isOne();
740 }
741 }
742 return false;
743 }
744}
745
747 bool IncludePhaseOneUnwind) {
748 // Because phase one unwinding skips cleanup landingpads, we effectively
749 // unwind past this frame, and callers need to have valid unwind info.
750 if (LP->isCleanup())
751 return IncludePhaseOneUnwind;
752
753 for (unsigned I = 0; I < LP->getNumClauses(); ++I) {
754 Constant *Clause = LP->getClause(I);
755 // catch ptr null catches all exceptions.
756 if (LP->isCatch(I) && isa<ConstantPointerNull>(Clause))
757 return false;
758 // filter [0 x ptr] catches all exceptions.
759 if (LP->isFilter(I) && Clause->getType()->getArrayNumElements() == 0)
760 return false;
761 }
762
763 // May catch only some subset of exceptions, in which case other exceptions
764 // will continue unwinding.
765 return true;
766}
767
768bool Instruction::mayThrow(bool IncludePhaseOneUnwind) const {
769 switch (getOpcode()) {
770 case Instruction::Call:
771 return !cast<CallInst>(this)->doesNotThrow();
772 case Instruction::CleanupRet:
773 return cast<CleanupReturnInst>(this)->unwindsToCaller();
774 case Instruction::CatchSwitch:
775 return cast<CatchSwitchInst>(this)->unwindsToCaller();
776 case Instruction::Resume:
777 return true;
778 case Instruction::Invoke: {
779 // Landingpads themselves don't unwind -- however, an invoke of a skipped
780 // landingpad may continue unwinding.
781 BasicBlock *UnwindDest = cast<InvokeInst>(this)->getUnwindDest();
782 Instruction *Pad = UnwindDest->getFirstNonPHI();
783 if (auto *LP = dyn_cast<LandingPadInst>(Pad))
784 return canUnwindPastLandingPad(LP, IncludePhaseOneUnwind);
785 return false;
786 }
787 case Instruction::CleanupPad:
788 // Treat the same as cleanup landingpad.
789 return IncludePhaseOneUnwind;
790 default:
791 return false;
792 }
793}
794
796 return mayWriteToMemory() || mayThrow() || !willReturn();
797}
798
800 return (!isa<CallInst>(this) || !this->mayHaveSideEffects()) &&
801 !this->isTerminator() && !this->isEHPad();
802}
803
805 // Volatile store isn't guaranteed to return; see LangRef.
806 if (auto *SI = dyn_cast<StoreInst>(this))
807 return !SI->isVolatile();
808
809 if (const auto *CB = dyn_cast<CallBase>(this))
810 return CB->hasFnAttr(Attribute::WillReturn);
811 return true;
812}
813
815 auto *II = dyn_cast<IntrinsicInst>(this);
816 if (!II)
817 return false;
818 Intrinsic::ID ID = II->getIntrinsicID();
819 return ID == Intrinsic::lifetime_start || ID == Intrinsic::lifetime_end;
820}
821
823 auto *II = dyn_cast<IntrinsicInst>(this);
824 if (!II)
825 return false;
826 Intrinsic::ID ID = II->getIntrinsicID();
827 return ID == Intrinsic::launder_invariant_group ||
828 ID == Intrinsic::strip_invariant_group;
829}
830
832 return isa<DbgInfoIntrinsic>(this) || isa<PseudoProbeInst>(this);
833}
834
835const Instruction *
837 for (const Instruction *I = getNextNode(); I; I = I->getNextNode())
838 if (!isa<DbgInfoIntrinsic>(I) && !(SkipPseudoOp && isa<PseudoProbeInst>(I)))
839 return I;
840 return nullptr;
841}
842
843const Instruction *
845 for (const Instruction *I = getPrevNode(); I; I = I->getPrevNode())
846 if (!isa<DbgInfoIntrinsic>(I) && !(SkipPseudoOp && isa<PseudoProbeInst>(I)))
847 return I;
848 return nullptr;
849}
850
852 unsigned Opcode = getOpcode();
853 if (isAssociative(Opcode))
854 return true;
855
856 switch (Opcode) {
857 case FMul:
858 case FAdd:
859 return cast<FPMathOperator>(this)->hasAllowReassoc() &&
860 cast<FPMathOperator>(this)->hasNoSignedZeros();
861 default:
862 return false;
863 }
864}
865
867 if (auto *II = dyn_cast<IntrinsicInst>(this))
868 return II->isCommutative();
869 // TODO: Should allow icmp/fcmp?
870 return isCommutative(getOpcode());
871}
872
874 switch (getOpcode()) {
875#define HANDLE_TERM_INST(N, OPC, CLASS) \
876 case Instruction::OPC: \
877 return static_cast<const CLASS *>(this)->getNumSuccessors();
878#include "llvm/IR/Instruction.def"
879 default:
880 break;
881 }
882 llvm_unreachable("not a terminator");
883}
884
886 switch (getOpcode()) {
887#define HANDLE_TERM_INST(N, OPC, CLASS) \
888 case Instruction::OPC: \
889 return static_cast<const CLASS *>(this)->getSuccessor(idx);
890#include "llvm/IR/Instruction.def"
891 default:
892 break;
893 }
894 llvm_unreachable("not a terminator");
895}
896
898 switch (getOpcode()) {
899#define HANDLE_TERM_INST(N, OPC, CLASS) \
900 case Instruction::OPC: \
901 return static_cast<CLASS *>(this)->setSuccessor(idx, B);
902#include "llvm/IR/Instruction.def"
903 default:
904 break;
905 }
906 llvm_unreachable("not a terminator");
907}
908
910 for (unsigned Idx = 0, NumSuccessors = Instruction::getNumSuccessors();
911 Idx != NumSuccessors; ++Idx)
912 if (getSuccessor(Idx) == OldBB)
913 setSuccessor(Idx, NewBB);
914}
915
916Instruction *Instruction::cloneImpl() const {
917 llvm_unreachable("Subclass of Instruction failed to implement cloneImpl");
918}
919
921 MDNode *ProfileData = getBranchWeightMDNode(*this);
922 if (!ProfileData || ProfileData->getNumOperands() != 3)
923 return;
924
925 // The first operand is the name. Fetch them backwards and build a new one.
926 Metadata *Ops[] = {ProfileData->getOperand(0), ProfileData->getOperand(2),
927 ProfileData->getOperand(1)};
928 setMetadata(LLVMContext::MD_prof,
929 MDNode::get(ProfileData->getContext(), Ops));
930}
931
934 if (!SrcInst.hasMetadata())
935 return;
936
938 for (unsigned M : WL)
939 WLS.insert(M);
940
941 // Otherwise, enumerate and copy over metadata from the old instruction to the
942 // new one.
944 SrcInst.getAllMetadataOtherThanDebugLoc(TheMDs);
945 for (const auto &MD : TheMDs) {
946 if (WL.empty() || WLS.count(MD.first))
947 setMetadata(MD.first, MD.second);
948 }
949 if (WL.empty() || WLS.count(LLVMContext::MD_dbg))
950 setDebugLoc(SrcInst.getDebugLoc());
951}
952
954 Instruction *New = nullptr;
955 switch (getOpcode()) {
956 default:
957 llvm_unreachable("Unhandled Opcode.");
958#define HANDLE_INST(num, opc, clas) \
959 case Instruction::opc: \
960 New = cast<clas>(this)->cloneImpl(); \
961 break;
962#include "llvm/IR/Instruction.def"
963#undef HANDLE_INST
964 }
965
966 New->SubclassOptionalData = SubclassOptionalData;
967 New->copyMetadata(*this);
968 return New;
969}
amdgpu AMDGPU Register Bank Select
Rewrite undef for PHI
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
This file defines the DenseSet and SmallDenseSet classes.
Hexagon Common GEP
IRTranslator LLVM IR MI
static bool canUnwindPastLandingPad(const LandingPadInst *LP, bool IncludePhaseOneUnwind)
#define I(x, y, z)
Definition: MD5.cpp:58
#define P(N)
This file contains the declarations for profiling metadata utility functions.
@ SI
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
an instruction to allocate memory on the stack
Definition: Instructions.h:58
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:158
An instruction that atomically checks whether a specified value is in a memory location,...
Definition: Instructions.h:513
an instruction that atomically reads a memory location, combines it with another value,...
Definition: Instructions.h:718
LLVM Basic Block Representation.
Definition: BasicBlock.h:56
iterator end()
Definition: BasicBlock.h:328
const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
Definition: BasicBlock.cpp:253
void renumberInstructions()
Renumber instructions and mark the ordering as valid.
Definition: BasicBlock.cpp:548
const Instruction * getFirstNonPHI() const
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
Definition: BasicBlock.cpp:216
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:112
InstListType::iterator iterator
Instruction iterators...
Definition: BasicBlock.h:87
bool isInstrOrderValid() const
Returns true if the Order field of child Instructions is valid.
Definition: BasicBlock.h:549
void splice(BasicBlock::iterator ToIt, BasicBlock *FromBB)
Transfer all instructions from FromBB to this basic block at ToIt.
Definition: BasicBlock.h:480
const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr if the function does no...
Definition: BasicBlock.cpp:145
CallBr instruction, tracking function calls that may not return control but instead transfer it to a ...
This class represents a function call, abstracting a target machine's calling convention.
This class is the base class for the comparison instructions.
Definition: InstrTypes.h:701
This is an important base class in LLVM.
Definition: Constant.h:41
Implements a dense probed hash-table based set.
Definition: DenseSet.h:271
This instruction extracts a struct member or array element value from an aggregate value.
Convenience struct for specifying and reasoning about fast-math flags.
Definition: FMF.h:20
An instruction for ordering other memory operations.
Definition: Instructions.h:436
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
Definition: Instructions.h:940
This instruction inserts a struct field of array element value into an aggregate value.
bool mayThrow(bool IncludePhaseOneUnwind=false) const LLVM_READONLY
Return true if this instruction may throw an exception.
Instruction * clone() const
Create a copy of 'this' instruction that is identical in all ways except the following:
void setHasNoUnsignedWrap(bool b=true)
Set or clear the nuw flag on this instruction, which must be an operator which supports this flag.
bool hasNoNaNs() const LLVM_READONLY
Determine whether the no-NaNs flag is set.
void removeFromParent()
This method unlinks 'this' from the containing basic block, but does not delete it.
Definition: Instruction.cpp:78
bool hasNoUnsignedWrap() const LLVM_READONLY
Determine whether the no unsigned wrap flag is set.
bool hasNoInfs() const LLVM_READONLY
Determine whether the no-infs flag is set.
bool isLifetimeStartOrEnd() const LLVM_READONLY
Return true if the instruction is a llvm.lifetime.start or llvm.lifetime.end marker.
void copyFastMathFlags(FastMathFlags FMF)
Convenience function for transferring all fast-math flag values to this instruction,...
bool isSameOperationAs(const Instruction *I, unsigned flags=0) const LLVM_READONLY
This function determines if the specified instruction executes the same operation as the current one.
void setHasNoSignedZeros(bool B)
Set or clear the no-signed-zeros flag on this instruction, which must be an operator which supports t...
bool hasNoSignedZeros() const LLVM_READONLY
Determine whether the no-signed-zeros flag is set.
bool isDebugOrPseudoInst() const LLVM_READONLY
Return true if the instruction is a DbgInfoIntrinsic or PseudoProbeInst.
unsigned getNumSuccessors() const LLVM_READONLY
Return the number of successors that this instruction has.
bool hasNoSignedWrap() const LLVM_READONLY
Determine whether the no signed wrap flag is set.
bool mayWriteToMemory() const LLVM_READONLY
Return true if this instruction may modify memory.
void copyIRFlags(const Value *V, bool IncludeWrapFlags=true)
Convenience method to copy supported exact, fast-math, and (optionally) wrapping flags from V to this...
void setHasAllowContract(bool B)
Set or clear the allow-contract flag on this instruction, which must be an operator which supports th...
bool hasAtomicStore() const LLVM_READONLY
Return true if this atomic instruction stores to memory.
void setHasNoSignedWrap(bool b=true)
Set or clear the nsw flag on this instruction, which must be an operator which supports this flag.
bool isOnlyUserOfAnyOperand()
It checks if this instruction is the only user of at least one of its operands.
void insertBefore(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified instruction.
Definition: Instruction.cpp:88
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
Definition: Instruction.h:365
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
Definition: Instruction.cpp:70
void andIRFlags(const Value *V)
Logical 'and' of any supported wrapping, exact, and fast-math flags of V and this instruction.
void setHasNoNaNs(bool B)
Set or clear the no-nans flag on this instruction, which must be an operator which supports this flag...
bool isAssociative() const LLVM_READONLY
Return true if the instruction is associative:
const Instruction * getPrevNonDebugInstruction(bool SkipPseudoOp=false) const
Return a pointer to the previous non-debug instruction in the same basic block as 'this',...
void setHasApproxFunc(bool B)
Set or clear the approximate-math-functions flag on this instruction, which must be an operator which...
void moveAfter(Instruction *MovePos)
Unlink this instruction from its current basic block and insert it into the basic block that MovePos ...
bool isCommutative() const LLVM_READONLY
Return true if the instruction is commutative:
bool hasMetadata() const
Return true if this instruction has any metadata attached to it.
Definition: Instruction.h:257
bool isAtomic() const LLVM_READONLY
Return true if this instruction has an AtomicOrdering of unordered or higher.
void setHasAllowReassoc(bool B)
Set or clear the reassociation flag on this instruction, which must be an operator which supports thi...
void setFastMathFlags(FastMathFlags FMF)
Convenience function for setting multiple fast-math flags on this instruction, which must be an opera...
bool isEHPad() const
Return true if the instruction is a variety of EH-block.
Definition: Instruction.h:700
const BasicBlock * getParent() const
Definition: Instruction.h:90
bool isFast() const LLVM_READONLY
Determine whether all fast-math-flags are set.
void replaceSuccessorWith(BasicBlock *OldBB, BasicBlock *NewBB)
Replace specified successor OldBB to point at the provided block.
bool isExact() const LLVM_READONLY
Determine whether the exact flag is set.
bool isIdenticalToWhenDefined(const Instruction *I) const LLVM_READONLY
This is like isIdenticalTo, except that it ignores the SubclassOptionalData flags,...
const Function * getFunction() const
Return the function this instruction belongs to.
Definition: Instruction.cpp:74
void swapProfMetadata()
If the instruction has "branch_weights" MD_prof metadata and the MDNode has three operands (including...
BasicBlock * getSuccessor(unsigned Idx) const LLVM_READONLY
Return the specified successor. This instruction must be a terminator.
bool mayHaveSideEffects() const LLVM_READONLY
Return true if the instruction may have side effects.
bool isTerminator() const
Definition: Instruction.h:171
bool hasSameSpecialState(const Instruction *I2, bool IgnoreAlignment=false) const LLVM_READONLY
This function determines if the speficied instruction has the same "special" characteristics as the c...
bool hasAllowReciprocal() const LLVM_READONLY
Determine whether the allow-reciprocal flag is set.
bool comesBefore(const Instruction *Other) const
Given an instruction Other in the same basic block as this instruction, return true if this instructi...
void dropUBImplyingAttrsAndMetadata()
Drop any attributes or metadata that can cause immediate undefined behavior.
bool hasPoisonGeneratingFlags() const LLVM_READONLY
Return true if this operator has flags which may cause this instruction to evaluate to poison despite...
bool mayReadFromMemory() const LLVM_READONLY
Return true if this instruction may read memory.
const Instruction * getNextNonDebugInstruction(bool SkipPseudoOp=false) const
Return a pointer to the next non-debug instruction in the same basic block as 'this',...
bool isUsedOutsideOfBlock(const BasicBlock *BB) const LLVM_READONLY
Return true if there are any uses of this instruction in blocks other than the specified block.
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
Definition: Metadata.cpp:1521
bool isVolatile() const LLVM_READONLY
Return true if this instruction has a volatile memory access.
void setHasNoInfs(bool B)
Set or clear the no-infs flag on this instruction, which must be an operator which supports this flag...
FastMathFlags getFastMathFlags() const LLVM_READONLY
Convenience function for getting all the fast-math flags, which must be an operator which supports th...
const char * getOpcodeName() const
Definition: Instruction.h:170
bool willReturn() const LLVM_READONLY
Return true if the instruction will return (unwinding is considered as a form of returning control fl...
bool hasApproxFunc() const LLVM_READONLY
Determine whether the approximate-math-functions flag is set.
@ CompareIgnoringAlignment
Check for equivalence ignoring load/store alignment.
Definition: Instruction.h:766
@ CompareUsingScalarTypes
Check for equivalence treating a type and a vector of that type as equivalent.
Definition: Instruction.h:769
void getAllMetadataOtherThanDebugLoc(SmallVectorImpl< std::pair< unsigned, MDNode * > > &MDs) const
This does the same thing as getAllMetadata, except that it filters out the debug location.
Definition: Instruction.h:298
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
Definition: Instruction.h:168
bool hasAtomicLoad() const LLVM_READONLY
Return true if this atomic instruction loads from memory.
void dropUnknownNonDebugMetadata()
Definition: Instruction.h:326
void setIsExact(bool b=true)
Set or clear the exact flag on this instruction, which must be an operator which supports this flag.
void dropPoisonGeneratingMetadata()
Drops metadata that may generate poison.
Instruction * getInsertionPointAfterDef()
Get the first insertion point at which the result of this instruction is defined.
void setHasAllowReciprocal(bool B)
Set or clear the allow-reciprocal flag on this instruction, which must be an operator which supports ...
void dropPoisonGeneratingFlags()
Drops flags that may cause this instruction to evaluate to poison despite having non-poison inputs.
void dropUBImplyingAttrsAndUnknownMetadata(ArrayRef< unsigned > KnownIDs={})
This function drops non-debug unknown metadata (through dropUnknownNonDebugMetadata).
bool isIdenticalTo(const Instruction *I) const LLVM_READONLY
Return true if the specified instruction is exactly identical to the current one.
SymbolTableList< Instruction >::iterator insertInto(BasicBlock *ParentBB, SymbolTableList< Instruction >::iterator It)
Inserts an unlinked instruction into ParentBB at position It and returns the iterator of the inserted...
Definition: Instruction.cpp:98
bool isLaunderOrStripInvariantGroup() const LLVM_READONLY
Return true if the instruction is a llvm.launder.invariant.group or llvm.strip.invariant....
bool hasAllowContract() const LLVM_READONLY
Determine whether the allow-contract flag is set.
bool hasPoisonGeneratingMetadata() const LLVM_READONLY
Return true if this instruction has poison-generating metadata.
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
Definition: Instruction.cpp:82
Instruction(const Instruction &)=delete
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
Definition: Instruction.h:362
void setSuccessor(unsigned Idx, BasicBlock *BB)
Update the specified successor to point at the provided block.
void copyMetadata(const Instruction &SrcInst, ArrayRef< unsigned > WL=ArrayRef< unsigned >())
Copy metadata from SrcInst to this instruction.
void setFast(bool B)
Set or clear all fast-math-flags on this instruction, which must be an operator which supports this f...
bool hasAllowReassoc() const LLVM_READONLY
Determine whether the allow-reassociation flag is set.
void insertAfter(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately after the specified instruction.
Definition: Instruction.cpp:94
void moveBefore(Instruction *MovePos)
Unlink this instruction from its current basic block and insert it into the basic block that MovePos ...
bool isSafeToRemove() const LLVM_READONLY
Return true if the instruction can be removed if the result is unused.
Invoke instruction.
The landingpad instruction holds all of the information necessary to generate correct exception handl...
bool isCleanup() const
Return 'true' if this landingpad instruction is a cleanup.
unsigned getNumClauses() const
Get the number of clauses for this landing pad.
bool isCatch(unsigned Idx) const
Return 'true' if the clause and index Idx is a catch clause.
bool isFilter(unsigned Idx) const
Return 'true' if the clause and index Idx is a filter clause.
Constant * getClause(unsigned Idx) const
Get the value of the clause at index Idx.
An instruction for reading from memory.
Definition: Instructions.h:177
Metadata node.
Definition: Metadata.h:950
const MDOperand & getOperand(unsigned I) const
Definition: Metadata.h:1303
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1416
unsigned getNumOperands() const
Return number of MDNode operands.
Definition: Metadata.h:1309
LLVMContext & getContext() const
Definition: Metadata.h:1114
Root of the metadata hierarchy.
Definition: Metadata.h:61
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
const_block_iterator block_begin() const
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
This instruction constructs a fixed permutation of two input vectors.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1200
An instruction for storing to memory.
Definition: Instructions.h:301
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
Definition: Constants.cpp:1724
A Use represents the edge between a Value definition and its users.
Definition: Use.h:43
op_range operands()
Definition: User.h:242
op_iterator op_begin()
Definition: User.h:234
Value * getOperand(unsigned i) const
Definition: User.h:169
unsigned getNumOperands() const
Definition: User.h:191
op_iterator op_end()
Definition: User.h:236
static void handleRAUW(Value *From, Value *To)
Definition: Metadata.cpp:437
LLVM Value Representation.
Definition: Value.h:74
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:255
unsigned char SubclassOptionalData
Hold subclass data that can be dropped.
Definition: Value.h:90
bool isUsedByMetadata() const
Return true if there is metadata referencing this value.
Definition: Value.h:557
bool eraseMetadata(unsigned KindID)
Erase all metadata attachments with the given kind.
Definition: Metadata.cpp:1436
iterator_range< use_iterator > uses()
Definition: Value.h:376
Iterator for intrusive lists based on ilist_node.
self_iterator getIterator()
Definition: ilist_node.h:82
Instruction * getNextNode()
Get the next node, or nullptr for the list tail.
Definition: ilist_node.h:289
iterator erase(iterator where)
Definition: ilist.h:204
pointer remove(iterator &IT)
Definition: ilist.h:188
iterator insert(iterator where, pointer New)
Definition: ilist.h:165
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
AttributeMask getUBImplyingAttributes()
Get param/return attributes which imply immediate undefined behavior if an invalid value is passed.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
MDNode * getBranchWeightMDNode(const Instruction &I)
Get the branch weights metadata node.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1826
@ Or
Bitwise or logical OR of integers.
@ Mul
Product of integers.
@ Xor
Bitwise or logical XOR of integers.
@ FMul
Product of floats.
@ And
Bitwise or logical AND of integers.
@ Add
Sum of integers.
@ FAdd
Sum of floats.