LLVM 19.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"
16#include "llvm/IR/Constants.h"
19#include "llvm/IR/Intrinsics.h"
20#include "llvm/IR/Operator.h"
22#include "llvm/IR/Type.h"
23using namespace llvm;
24
25Instruction::Instruction(Type *ty, unsigned it, Use *Ops, unsigned NumOps,
26 InstListType::iterator InsertBefore)
27 : User(ty, Value::InstructionVal + it, Ops, NumOps), Parent(nullptr) {
28
29 // When called with an iterator, there must be a block to insert into.
30 BasicBlock *BB = InsertBefore->getParent();
31 assert(BB && "Instruction to insert before is not in a basic block!");
32 insertInto(BB, InsertBefore);
33}
34
35Instruction::Instruction(Type *ty, unsigned it, Use *Ops, unsigned NumOps,
36 Instruction *InsertBefore)
37 : User(ty, Value::InstructionVal + it, Ops, NumOps), Parent(nullptr) {
38
39 // If requested, insert this instruction into a basic block...
40 if (InsertBefore) {
41 BasicBlock *BB = InsertBefore->getParent();
42 assert(BB && "Instruction to insert before is not in a basic block!");
43 insertInto(BB, InsertBefore->getIterator());
44 }
45}
46
47Instruction::Instruction(Type *ty, unsigned it, Use *Ops, unsigned NumOps,
48 BasicBlock *InsertAtEnd)
49 : User(ty, Value::InstructionVal + it, Ops, NumOps), Parent(nullptr) {
50
51 // append this instruction into the basic block
52 assert(InsertAtEnd && "Basic block to append to may not be NULL!");
53 insertInto(InsertAtEnd, InsertAtEnd->end());
54}
55
57 assert(!Parent && "Instruction still linked in the program!");
58
59 // Replace any extant metadata uses of this instruction with undef to
60 // preserve debug info accuracy. Some alternatives include:
61 // - Treat Instruction like any other Value, and point its extant metadata
62 // uses to an empty ValueAsMetadata node. This makes extant dbg.value uses
63 // trivially dead (i.e. fair game for deletion in many passes), leading to
64 // stale dbg.values being in effect for too long.
65 // - Call salvageDebugInfoOrMarkUndef. Not needed to make instruction removal
66 // correct. OTOH results in wasted work in some common cases (e.g. when all
67 // instructions in a BasicBlock are deleted).
68 if (isUsedByMetadata())
70
71 // Explicitly remove DIAssignID metadata to clear up ID -> Instruction(s)
72 // mapping in LLVMContext.
73 setMetadata(LLVMContext::MD_DIAssignID, nullptr);
74}
75
76
77void Instruction::setParent(BasicBlock *P) {
78 Parent = P;
79}
80
82 return getParent()->getModule();
83}
84
86 return getParent()->getParent();
87}
88
90 // Perform any debug-info maintenence required.
92
93 getParent()->getInstList().remove(getIterator());
94}
95
97 if (!Parent->IsNewDbgInfoFormat || !DbgMarker)
98 return;
99
101}
102
105 return getParent()->getInstList().erase(getIterator());
106}
107
109 insertBefore(InsertPos->getIterator());
110}
111
112/// Insert an unlinked instruction into a basic block immediately before the
113/// specified instruction.
115 insertBefore(*InsertPos->getParent(), InsertPos);
116}
117
118/// Insert an unlinked instruction into a basic block immediately after the
119/// specified instruction.
121 BasicBlock *DestParent = InsertPos->getParent();
122
123 DestParent->getInstList().insertAfter(InsertPos->getIterator(), this);
124}
125
128 assert(getParent() == nullptr && "Expected detached instruction");
129 assert((It == ParentBB->end() || It->getParent() == ParentBB) &&
130 "It not in ParentBB");
131 insertBefore(*ParentBB, It);
132 return getIterator();
133}
134
136
138 InstListType::iterator InsertPos) {
140
141 BB.getInstList().insert(InsertPos, this);
142
143 if (!BB.IsNewDbgInfoFormat)
144 return;
145
146 // We've inserted "this": if InsertAtHead is set then it comes before any
147 // DPValues attached to InsertPos. But if it's not set, then any DPValues
148 // should now come before "this".
149 bool InsertAtHead = InsertPos.getHeadBit();
150 if (!InsertAtHead) {
151 DPMarker *SrcMarker = BB.getMarker(InsertPos);
152 if (SrcMarker && !SrcMarker->empty()) {
153 adoptDbgValues(&BB, InsertPos, false);
154 }
155 }
156
157 // If we're inserting a terminator, check if we need to flush out
158 // TrailingDPValues.
159 if (isTerminator())
161}
162
163/// Unlink this instruction from its current basic block and insert it into the
164/// basic block that MovePos lives in, right before MovePos.
166 moveBeforeImpl(*MovePos->getParent(), MovePos->getIterator(), false);
167}
168
170 moveBeforeImpl(*MovePos->getParent(), MovePos->getIterator(), true);
171}
172
174 auto NextIt = std::next(MovePos->getIterator());
175 // We want this instruction to be moved to before NextIt in the instruction
176 // list, but before NextIt's debug value range.
177 NextIt.setHeadBit(true);
178 moveBeforeImpl(*MovePos->getParent(), NextIt, false);
179}
180
182 auto NextIt = std::next(MovePos->getIterator());
183 // We want this instruction and its debug range to be moved to before NextIt
184 // in the instruction list, but before NextIt's debug value range.
185 NextIt.setHeadBit(true);
186 moveBeforeImpl(*MovePos->getParent(), NextIt, true);
187}
188
190 moveBeforeImpl(BB, I, false);
191}
192
195 moveBeforeImpl(BB, I, true);
196}
197
198void Instruction::moveBeforeImpl(BasicBlock &BB, InstListType::iterator I,
199 bool Preserve) {
200 assert(I == BB.end() || I->getParent() == &BB);
201 bool InsertAtHead = I.getHeadBit();
202
203 // If we've been given the "Preserve" flag, then just move the DPValues with
204 // the instruction, no more special handling needed.
205 if (BB.IsNewDbgInfoFormat && DbgMarker && !Preserve) {
206 if (I != this->getIterator() || InsertAtHead) {
207 // "this" is definitely moving in the list, or it's moving ahead of its
208 // attached DPValues. Detach any existing DPValues.
210 }
211 }
212
213 // Move this single instruction. Use the list splice method directly, not
214 // the block splicer, which will do more debug-info things.
215 BB.getInstList().splice(I, getParent()->getInstList(), getIterator());
216
217 if (BB.IsNewDbgInfoFormat && !Preserve) {
218 DPMarker *NextMarker = getParent()->getNextMarker(this);
219
220 // If we're inserting at point I, and not in front of the DPValues attached
221 // there, then we should absorb the DPValues attached to I.
222 if (!InsertAtHead && NextMarker && !NextMarker->empty()) {
223 adoptDbgValues(&BB, I, false);
224 }
225 }
226
227 if (isTerminator())
229}
230
232 const Instruction *From, std::optional<DbgRecord::self_iterator> FromHere,
233 bool InsertAtHead) {
234 if (!From->DbgMarker)
236
237 assert(getParent()->IsNewDbgInfoFormat);
238 assert(getParent()->IsNewDbgInfoFormat ==
239 From->getParent()->IsNewDbgInfoFormat);
240
241 if (!DbgMarker)
242 getParent()->createMarker(this);
243
244 return DbgMarker->cloneDebugInfoFrom(From->DbgMarker, FromHere, InsertAtHead);
245}
246
247std::optional<DbgRecord::self_iterator>
249 // Is there a marker on the next instruction?
250 DPMarker *NextMarker = getParent()->getNextMarker(this);
251 if (!NextMarker)
252 return std::nullopt;
253
254 // Are there any DPValues in the next marker?
255 if (NextMarker->StoredDPValues.empty())
256 return std::nullopt;
257
258 return NextMarker->StoredDPValues.begin();
259}
260
261bool Instruction::hasDbgValues() const { return !getDbgValueRange().empty(); }
262
264 bool InsertAtHead) {
265 DPMarker *SrcMarker = BB->getMarker(It);
266 auto ReleaseTrailingDPValues = [BB, It, SrcMarker]() {
267 if (BB->end() == It) {
268 SrcMarker->eraseFromParent();
270 }
271 };
272
273 if (!SrcMarker || SrcMarker->StoredDPValues.empty()) {
274 ReleaseTrailingDPValues();
275 return;
276 }
277
278 // If we have DPMarkers attached to this instruction, we have to honour the
279 // ordering of DPValues between this and the other marker. Fall back to just
280 // absorbing from the source.
281 if (DbgMarker || It == BB->end()) {
282 // Ensure we _do_ have a marker.
283 getParent()->createMarker(this);
284 DbgMarker->absorbDebugValues(*SrcMarker, InsertAtHead);
285
286 // Having transferred everything out of SrcMarker, we _could_ clean it up
287 // and free the marker now. However, that's a lot of heap-accounting for a
288 // small amount of memory with a good chance of re-use. Leave it for the
289 // moment. It will be released when the Instruction is freed in the worst
290 // case.
291 // However: if we transferred from a trailing marker off the end of the
292 // block, it's important to not leave the empty marker trailing. It will
293 // give a misleading impression that some debug records have been left
294 // trailing.
295 ReleaseTrailingDPValues();
296 } else {
297 // Optimisation: we're transferring all the DPValues from the source marker
298 // onto this empty location: just adopt the other instructions marker.
299 DbgMarker = SrcMarker;
300 DbgMarker->MarkedInstr = this;
301 It->DbgMarker = nullptr;
302 }
303}
304
306 if (DbgMarker)
308}
309
312}
313
315 assert(Parent && Other->Parent &&
316 "instructions without BB parents have no order");
317 assert(Parent == Other->Parent && "cross-BB instruction order comparison");
318 if (!Parent->isInstrOrderValid())
319 Parent->renumberInstructions();
320 return Order < Other->Order;
321}
322
323std::optional<BasicBlock::iterator> Instruction::getInsertionPointAfterDef() {
324 assert(!getType()->isVoidTy() && "Instruction must define result");
325 BasicBlock *InsertBB;
326 BasicBlock::iterator InsertPt;
327 if (auto *PN = dyn_cast<PHINode>(this)) {
328 InsertBB = PN->getParent();
329 InsertPt = InsertBB->getFirstInsertionPt();
330 } else if (auto *II = dyn_cast<InvokeInst>(this)) {
331 InsertBB = II->getNormalDest();
332 InsertPt = InsertBB->getFirstInsertionPt();
333 } else if (isa<CallBrInst>(this)) {
334 // Def is available in multiple successors, there's no single dominating
335 // insertion point.
336 return std::nullopt;
337 } else {
338 assert(!isTerminator() && "Only invoke/callbr terminators return value");
339 InsertBB = getParent();
340 InsertPt = std::next(getIterator());
341 // Any instruction inserted immediately after "this" will come before any
342 // debug-info records take effect -- thus, set the head bit indicating that
343 // to debug-info-transfer code.
344 InsertPt.setHeadBit(true);
345 }
346
347 // catchswitch blocks don't have any legal insertion point (because they
348 // are both an exception pad and a terminator).
349 if (InsertPt == InsertBB->end())
350 return std::nullopt;
351 return InsertPt;
352}
353
355 return any_of(operands(), [](Value *V) { return V->hasOneUser(); });
356}
357
359 cast<OverflowingBinaryOperator>(this)->setHasNoUnsignedWrap(b);
360}
361
363 cast<OverflowingBinaryOperator>(this)->setHasNoSignedWrap(b);
364}
365
367 cast<PossiblyExactOperator>(this)->setIsExact(b);
368}
369
371 assert(isa<PossiblyNonNegInst>(this) && "Must be zext");
374}
375
377 return cast<OverflowingBinaryOperator>(this)->hasNoUnsignedWrap();
378}
379
381 return cast<OverflowingBinaryOperator>(this)->hasNoSignedWrap();
382}
383
385 assert(isa<PossiblyNonNegInst>(this) && "Must be zext");
387}
388
390 return cast<Operator>(this)->hasPoisonGeneratingFlags();
391}
392
394 switch (getOpcode()) {
395 case Instruction::Add:
396 case Instruction::Sub:
397 case Instruction::Mul:
398 case Instruction::Shl:
399 cast<OverflowingBinaryOperator>(this)->setHasNoUnsignedWrap(false);
400 cast<OverflowingBinaryOperator>(this)->setHasNoSignedWrap(false);
401 break;
402
403 case Instruction::UDiv:
404 case Instruction::SDiv:
405 case Instruction::AShr:
406 case Instruction::LShr:
407 cast<PossiblyExactOperator>(this)->setIsExact(false);
408 break;
409
410 case Instruction::Or:
411 cast<PossiblyDisjointInst>(this)->setIsDisjoint(false);
412 break;
413
414 case Instruction::GetElementPtr:
415 cast<GetElementPtrInst>(this)->setIsInBounds(false);
416 break;
417
418 case Instruction::ZExt:
419 setNonNeg(false);
420 break;
421 }
422
423 if (isa<FPMathOperator>(this)) {
424 setHasNoNaNs(false);
425 setHasNoInfs(false);
426 }
427
428 assert(!hasPoisonGeneratingFlags() && "must be kept in sync");
429}
430
432 return hasMetadata(LLVMContext::MD_range) ||
433 hasMetadata(LLVMContext::MD_nonnull) ||
434 hasMetadata(LLVMContext::MD_align);
435}
436
438 eraseMetadata(LLVMContext::MD_range);
439 eraseMetadata(LLVMContext::MD_nonnull);
440 eraseMetadata(LLVMContext::MD_align);
441}
442
444 ArrayRef<unsigned> KnownIDs) {
446 auto *CB = dyn_cast<CallBase>(this);
447 if (!CB)
448 return;
449 // For call instructions, we also need to drop parameter and return attributes
450 // that are can cause UB if the call is moved to a location where the
451 // attribute is not valid.
452 AttributeList AL = CB->getAttributes();
453 if (AL.isEmpty())
454 return;
455 AttributeMask UBImplyingAttributes =
457 for (unsigned ArgNo = 0; ArgNo < CB->arg_size(); ArgNo++)
458 CB->removeParamAttrs(ArgNo, UBImplyingAttributes);
459 CB->removeRetAttrs(UBImplyingAttributes);
460}
461
463 // !annotation metadata does not impact semantics.
464 // !range, !nonnull and !align produce poison, so they are safe to speculate.
465 // !noundef and various AA metadata must be dropped, as it generally produces
466 // immediate undefined behavior.
467 unsigned KnownIDs[] = {LLVMContext::MD_annotation, LLVMContext::MD_range,
468 LLVMContext::MD_nonnull, LLVMContext::MD_align};
470}
471
473 return cast<PossiblyExactOperator>(this)->isExact();
474}
475
477 assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
478 cast<FPMathOperator>(this)->setFast(B);
479}
480
482 assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
483 cast<FPMathOperator>(this)->setHasAllowReassoc(B);
484}
485
487 assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
488 cast<FPMathOperator>(this)->setHasNoNaNs(B);
489}
490
492 assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
493 cast<FPMathOperator>(this)->setHasNoInfs(B);
494}
495
497 assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
498 cast<FPMathOperator>(this)->setHasNoSignedZeros(B);
499}
500
502 assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
503 cast<FPMathOperator>(this)->setHasAllowReciprocal(B);
504}
505
507 assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
508 cast<FPMathOperator>(this)->setHasAllowContract(B);
509}
510
512 assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
513 cast<FPMathOperator>(this)->setHasApproxFunc(B);
514}
515
517 assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
518 cast<FPMathOperator>(this)->setFastMathFlags(FMF);
519}
520
522 assert(isa<FPMathOperator>(this) && "copying fast-math flag on invalid op");
523 cast<FPMathOperator>(this)->copyFastMathFlags(FMF);
524}
525
527 assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
528 return cast<FPMathOperator>(this)->isFast();
529}
530
532 assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
533 return cast<FPMathOperator>(this)->hasAllowReassoc();
534}
535
537 assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
538 return cast<FPMathOperator>(this)->hasNoNaNs();
539}
540
542 assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
543 return cast<FPMathOperator>(this)->hasNoInfs();
544}
545
547 assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
548 return cast<FPMathOperator>(this)->hasNoSignedZeros();
549}
550
552 assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
553 return cast<FPMathOperator>(this)->hasAllowReciprocal();
554}
555
557 assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
558 return cast<FPMathOperator>(this)->hasAllowContract();
559}
560
562 assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
563 return cast<FPMathOperator>(this)->hasApproxFunc();
564}
565
567 assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
568 return cast<FPMathOperator>(this)->getFastMathFlags();
569}
570
572 copyFastMathFlags(I->getFastMathFlags());
573}
574
575void Instruction::copyIRFlags(const Value *V, bool IncludeWrapFlags) {
576 // Copy the wrapping flags.
577 if (IncludeWrapFlags && isa<OverflowingBinaryOperator>(this)) {
578 if (auto *OB = dyn_cast<OverflowingBinaryOperator>(V)) {
579 setHasNoSignedWrap(OB->hasNoSignedWrap());
580 setHasNoUnsignedWrap(OB->hasNoUnsignedWrap());
581 }
582 }
583
584 // Copy the exact flag.
585 if (auto *PE = dyn_cast<PossiblyExactOperator>(V))
586 if (isa<PossiblyExactOperator>(this))
587 setIsExact(PE->isExact());
588
589 if (auto *SrcPD = dyn_cast<PossiblyDisjointInst>(V))
590 if (auto *DestPD = dyn_cast<PossiblyDisjointInst>(this))
591 DestPD->setIsDisjoint(SrcPD->isDisjoint());
592
593 // Copy the fast-math flags.
594 if (auto *FP = dyn_cast<FPMathOperator>(V))
595 if (isa<FPMathOperator>(this))
596 copyFastMathFlags(FP->getFastMathFlags());
597
598 if (auto *SrcGEP = dyn_cast<GetElementPtrInst>(V))
599 if (auto *DestGEP = dyn_cast<GetElementPtrInst>(this))
600 DestGEP->setIsInBounds(SrcGEP->isInBounds() || DestGEP->isInBounds());
601
602 if (auto *NNI = dyn_cast<PossiblyNonNegInst>(V))
603 if (isa<PossiblyNonNegInst>(this))
604 setNonNeg(NNI->hasNonNeg());
605}
606
608 if (auto *OB = dyn_cast<OverflowingBinaryOperator>(V)) {
609 if (isa<OverflowingBinaryOperator>(this)) {
610 setHasNoSignedWrap(hasNoSignedWrap() && OB->hasNoSignedWrap());
611 setHasNoUnsignedWrap(hasNoUnsignedWrap() && OB->hasNoUnsignedWrap());
612 }
613 }
614
615 if (auto *PE = dyn_cast<PossiblyExactOperator>(V))
616 if (isa<PossiblyExactOperator>(this))
617 setIsExact(isExact() && PE->isExact());
618
619 if (auto *SrcPD = dyn_cast<PossiblyDisjointInst>(V))
620 if (auto *DestPD = dyn_cast<PossiblyDisjointInst>(this))
621 DestPD->setIsDisjoint(DestPD->isDisjoint() && SrcPD->isDisjoint());
622
623 if (auto *FP = dyn_cast<FPMathOperator>(V)) {
624 if (isa<FPMathOperator>(this)) {
626 FM &= FP->getFastMathFlags();
628 }
629 }
630
631 if (auto *SrcGEP = dyn_cast<GetElementPtrInst>(V))
632 if (auto *DestGEP = dyn_cast<GetElementPtrInst>(this))
633 DestGEP->setIsInBounds(SrcGEP->isInBounds() && DestGEP->isInBounds());
634
635 if (auto *NNI = dyn_cast<PossiblyNonNegInst>(V))
636 if (isa<PossiblyNonNegInst>(this))
637 setNonNeg(hasNonNeg() && NNI->hasNonNeg());
638}
639
640const char *Instruction::getOpcodeName(unsigned OpCode) {
641 switch (OpCode) {
642 // Terminators
643 case Ret: return "ret";
644 case Br: return "br";
645 case Switch: return "switch";
646 case IndirectBr: return "indirectbr";
647 case Invoke: return "invoke";
648 case Resume: return "resume";
649 case Unreachable: return "unreachable";
650 case CleanupRet: return "cleanupret";
651 case CatchRet: return "catchret";
652 case CatchPad: return "catchpad";
653 case CatchSwitch: return "catchswitch";
654 case CallBr: return "callbr";
655
656 // Standard unary operators...
657 case FNeg: return "fneg";
658
659 // Standard binary operators...
660 case Add: return "add";
661 case FAdd: return "fadd";
662 case Sub: return "sub";
663 case FSub: return "fsub";
664 case Mul: return "mul";
665 case FMul: return "fmul";
666 case UDiv: return "udiv";
667 case SDiv: return "sdiv";
668 case FDiv: return "fdiv";
669 case URem: return "urem";
670 case SRem: return "srem";
671 case FRem: return "frem";
672
673 // Logical operators...
674 case And: return "and";
675 case Or : return "or";
676 case Xor: return "xor";
677
678 // Memory instructions...
679 case Alloca: return "alloca";
680 case Load: return "load";
681 case Store: return "store";
682 case AtomicCmpXchg: return "cmpxchg";
683 case AtomicRMW: return "atomicrmw";
684 case Fence: return "fence";
685 case GetElementPtr: return "getelementptr";
686
687 // Convert instructions...
688 case Trunc: return "trunc";
689 case ZExt: return "zext";
690 case SExt: return "sext";
691 case FPTrunc: return "fptrunc";
692 case FPExt: return "fpext";
693 case FPToUI: return "fptoui";
694 case FPToSI: return "fptosi";
695 case UIToFP: return "uitofp";
696 case SIToFP: return "sitofp";
697 case IntToPtr: return "inttoptr";
698 case PtrToInt: return "ptrtoint";
699 case BitCast: return "bitcast";
700 case AddrSpaceCast: return "addrspacecast";
701
702 // Other instructions...
703 case ICmp: return "icmp";
704 case FCmp: return "fcmp";
705 case PHI: return "phi";
706 case Select: return "select";
707 case Call: return "call";
708 case Shl: return "shl";
709 case LShr: return "lshr";
710 case AShr: return "ashr";
711 case VAArg: return "va_arg";
712 case ExtractElement: return "extractelement";
713 case InsertElement: return "insertelement";
714 case ShuffleVector: return "shufflevector";
715 case ExtractValue: return "extractvalue";
716 case InsertValue: return "insertvalue";
717 case LandingPad: return "landingpad";
718 case CleanupPad: return "cleanuppad";
719 case Freeze: return "freeze";
720
721 default: return "<Invalid operator> ";
722 }
723}
724
725/// This must be kept in sync with FunctionComparator::cmpOperations in
726/// lib/Transforms/IPO/MergeFunctions.cpp.
728 bool IgnoreAlignment) const {
729 auto I1 = this;
730 assert(I1->getOpcode() == I2->getOpcode() &&
731 "Can not compare special state of different instructions");
732
733 if (const AllocaInst *AI = dyn_cast<AllocaInst>(I1))
734 return AI->getAllocatedType() == cast<AllocaInst>(I2)->getAllocatedType() &&
735 (AI->getAlign() == cast<AllocaInst>(I2)->getAlign() ||
736 IgnoreAlignment);
737 if (const LoadInst *LI = dyn_cast<LoadInst>(I1))
738 return LI->isVolatile() == cast<LoadInst>(I2)->isVolatile() &&
739 (LI->getAlign() == cast<LoadInst>(I2)->getAlign() ||
740 IgnoreAlignment) &&
741 LI->getOrdering() == cast<LoadInst>(I2)->getOrdering() &&
742 LI->getSyncScopeID() == cast<LoadInst>(I2)->getSyncScopeID();
743 if (const StoreInst *SI = dyn_cast<StoreInst>(I1))
744 return SI->isVolatile() == cast<StoreInst>(I2)->isVolatile() &&
745 (SI->getAlign() == cast<StoreInst>(I2)->getAlign() ||
746 IgnoreAlignment) &&
747 SI->getOrdering() == cast<StoreInst>(I2)->getOrdering() &&
748 SI->getSyncScopeID() == cast<StoreInst>(I2)->getSyncScopeID();
749 if (const CmpInst *CI = dyn_cast<CmpInst>(I1))
750 return CI->getPredicate() == cast<CmpInst>(I2)->getPredicate();
751 if (const CallInst *CI = dyn_cast<CallInst>(I1))
752 return CI->isTailCall() == cast<CallInst>(I2)->isTailCall() &&
753 CI->getCallingConv() == cast<CallInst>(I2)->getCallingConv() &&
754 CI->getAttributes() == cast<CallInst>(I2)->getAttributes() &&
755 CI->hasIdenticalOperandBundleSchema(*cast<CallInst>(I2));
756 if (const InvokeInst *CI = dyn_cast<InvokeInst>(I1))
757 return CI->getCallingConv() == cast<InvokeInst>(I2)->getCallingConv() &&
758 CI->getAttributes() == cast<InvokeInst>(I2)->getAttributes() &&
759 CI->hasIdenticalOperandBundleSchema(*cast<InvokeInst>(I2));
760 if (const CallBrInst *CI = dyn_cast<CallBrInst>(I1))
761 return CI->getCallingConv() == cast<CallBrInst>(I2)->getCallingConv() &&
762 CI->getAttributes() == cast<CallBrInst>(I2)->getAttributes() &&
763 CI->hasIdenticalOperandBundleSchema(*cast<CallBrInst>(I2));
764 if (const InsertValueInst *IVI = dyn_cast<InsertValueInst>(I1))
765 return IVI->getIndices() == cast<InsertValueInst>(I2)->getIndices();
766 if (const ExtractValueInst *EVI = dyn_cast<ExtractValueInst>(I1))
767 return EVI->getIndices() == cast<ExtractValueInst>(I2)->getIndices();
768 if (const FenceInst *FI = dyn_cast<FenceInst>(I1))
769 return FI->getOrdering() == cast<FenceInst>(I2)->getOrdering() &&
770 FI->getSyncScopeID() == cast<FenceInst>(I2)->getSyncScopeID();
771 if (const AtomicCmpXchgInst *CXI = dyn_cast<AtomicCmpXchgInst>(I1))
772 return CXI->isVolatile() == cast<AtomicCmpXchgInst>(I2)->isVolatile() &&
773 CXI->isWeak() == cast<AtomicCmpXchgInst>(I2)->isWeak() &&
774 CXI->getSuccessOrdering() ==
775 cast<AtomicCmpXchgInst>(I2)->getSuccessOrdering() &&
776 CXI->getFailureOrdering() ==
777 cast<AtomicCmpXchgInst>(I2)->getFailureOrdering() &&
778 CXI->getSyncScopeID() ==
779 cast<AtomicCmpXchgInst>(I2)->getSyncScopeID();
780 if (const AtomicRMWInst *RMWI = dyn_cast<AtomicRMWInst>(I1))
781 return RMWI->getOperation() == cast<AtomicRMWInst>(I2)->getOperation() &&
782 RMWI->isVolatile() == cast<AtomicRMWInst>(I2)->isVolatile() &&
783 RMWI->getOrdering() == cast<AtomicRMWInst>(I2)->getOrdering() &&
784 RMWI->getSyncScopeID() == cast<AtomicRMWInst>(I2)->getSyncScopeID();
785 if (const ShuffleVectorInst *SVI = dyn_cast<ShuffleVectorInst>(I1))
786 return SVI->getShuffleMask() ==
787 cast<ShuffleVectorInst>(I2)->getShuffleMask();
788 if (const GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(I1))
789 return GEP->getSourceElementType() ==
790 cast<GetElementPtrInst>(I2)->getSourceElementType();
791
792 return true;
793}
794
796 return isIdenticalToWhenDefined(I) &&
797 SubclassOptionalData == I->SubclassOptionalData;
798}
799
801 if (getOpcode() != I->getOpcode() ||
802 getNumOperands() != I->getNumOperands() ||
803 getType() != I->getType())
804 return false;
805
806 // If both instructions have no operands, they are identical.
807 if (getNumOperands() == 0 && I->getNumOperands() == 0)
808 return this->hasSameSpecialState(I);
809
810 // We have two instructions of identical opcode and #operands. Check to see
811 // if all operands are the same.
812 if (!std::equal(op_begin(), op_end(), I->op_begin()))
813 return false;
814
815 // WARNING: this logic must be kept in sync with EliminateDuplicatePHINodes()!
816 if (const PHINode *thisPHI = dyn_cast<PHINode>(this)) {
817 const PHINode *otherPHI = cast<PHINode>(I);
818 return std::equal(thisPHI->block_begin(), thisPHI->block_end(),
819 otherPHI->block_begin());
820 }
821
822 return this->hasSameSpecialState(I);
823}
824
825// Keep this in sync with FunctionComparator::cmpOperations in
826// lib/Transforms/IPO/MergeFunctions.cpp.
828 unsigned flags) const {
829 bool IgnoreAlignment = flags & CompareIgnoringAlignment;
830 bool UseScalarTypes = flags & CompareUsingScalarTypes;
831
832 if (getOpcode() != I->getOpcode() ||
833 getNumOperands() != I->getNumOperands() ||
834 (UseScalarTypes ?
835 getType()->getScalarType() != I->getType()->getScalarType() :
836 getType() != I->getType()))
837 return false;
838
839 // We have two instructions of identical opcode and #operands. Check to see
840 // if all operands are the same type
841 for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
842 if (UseScalarTypes ?
843 getOperand(i)->getType()->getScalarType() !=
844 I->getOperand(i)->getType()->getScalarType() :
845 getOperand(i)->getType() != I->getOperand(i)->getType())
846 return false;
847
848 return this->hasSameSpecialState(I, IgnoreAlignment);
849}
850
852 for (const Use &U : uses()) {
853 // PHI nodes uses values in the corresponding predecessor block. For other
854 // instructions, just check to see whether the parent of the use matches up.
855 const Instruction *I = cast<Instruction>(U.getUser());
856 const PHINode *PN = dyn_cast<PHINode>(I);
857 if (!PN) {
858 if (I->getParent() != BB)
859 return true;
860 continue;
861 }
862
863 if (PN->getIncomingBlock(U) != BB)
864 return true;
865 }
866 return false;
867}
868
870 switch (getOpcode()) {
871 default: return false;
872 case Instruction::VAArg:
873 case Instruction::Load:
874 case Instruction::Fence: // FIXME: refine definition of mayReadFromMemory
875 case Instruction::AtomicCmpXchg:
876 case Instruction::AtomicRMW:
877 case Instruction::CatchPad:
878 case Instruction::CatchRet:
879 return true;
880 case Instruction::Call:
881 case Instruction::Invoke:
882 case Instruction::CallBr:
883 return !cast<CallBase>(this)->onlyWritesMemory();
884 case Instruction::Store:
885 return !cast<StoreInst>(this)->isUnordered();
886 }
887}
888
890 switch (getOpcode()) {
891 default: return false;
892 case Instruction::Fence: // FIXME: refine definition of mayWriteToMemory
893 case Instruction::Store:
894 case Instruction::VAArg:
895 case Instruction::AtomicCmpXchg:
896 case Instruction::AtomicRMW:
897 case Instruction::CatchPad:
898 case Instruction::CatchRet:
899 return true;
900 case Instruction::Call:
901 case Instruction::Invoke:
902 case Instruction::CallBr:
903 return !cast<CallBase>(this)->onlyReadsMemory();
904 case Instruction::Load:
905 return !cast<LoadInst>(this)->isUnordered();
906 }
907}
908
910 switch (getOpcode()) {
911 default:
912 return false;
913 case Instruction::AtomicCmpXchg:
914 case Instruction::AtomicRMW:
915 case Instruction::Fence:
916 return true;
917 case Instruction::Load:
918 return cast<LoadInst>(this)->getOrdering() != AtomicOrdering::NotAtomic;
919 case Instruction::Store:
920 return cast<StoreInst>(this)->getOrdering() != AtomicOrdering::NotAtomic;
921 }
922}
923
925 assert(isAtomic());
926 switch (getOpcode()) {
927 default:
928 return false;
929 case Instruction::AtomicCmpXchg:
930 case Instruction::AtomicRMW:
931 case Instruction::Load:
932 return true;
933 }
934}
935
937 assert(isAtomic());
938 switch (getOpcode()) {
939 default:
940 return false;
941 case Instruction::AtomicCmpXchg:
942 case Instruction::AtomicRMW:
943 case Instruction::Store:
944 return true;
945 }
946}
947
949 switch (getOpcode()) {
950 default:
951 return false;
952 case Instruction::AtomicRMW:
953 return cast<AtomicRMWInst>(this)->isVolatile();
954 case Instruction::Store:
955 return cast<StoreInst>(this)->isVolatile();
956 case Instruction::Load:
957 return cast<LoadInst>(this)->isVolatile();
958 case Instruction::AtomicCmpXchg:
959 return cast<AtomicCmpXchgInst>(this)->isVolatile();
960 case Instruction::Call:
961 case Instruction::Invoke:
962 // There are a very limited number of intrinsics with volatile flags.
963 if (auto *II = dyn_cast<IntrinsicInst>(this)) {
964 if (auto *MI = dyn_cast<MemIntrinsic>(II))
965 return MI->isVolatile();
966 switch (II->getIntrinsicID()) {
967 default: break;
968 case Intrinsic::matrix_column_major_load:
969 return cast<ConstantInt>(II->getArgOperand(2))->isOne();
970 case Intrinsic::matrix_column_major_store:
971 return cast<ConstantInt>(II->getArgOperand(3))->isOne();
972 }
973 }
974 return false;
975 }
976}
977
979 switch (getOpcode()) {
980 case Instruction::Store:
981 return cast<StoreInst>(this)->getValueOperand()->getType();
982 case Instruction::Load:
983 case Instruction::AtomicRMW:
984 return getType();
985 case Instruction::AtomicCmpXchg:
986 return cast<AtomicCmpXchgInst>(this)->getNewValOperand()->getType();
987 case Instruction::Call:
988 case Instruction::Invoke:
989 if (const IntrinsicInst *II = dyn_cast<IntrinsicInst>(this)) {
990 switch (II->getIntrinsicID()) {
991 case Intrinsic::masked_load:
992 case Intrinsic::masked_gather:
993 case Intrinsic::masked_expandload:
994 case Intrinsic::vp_load:
995 case Intrinsic::vp_gather:
996 case Intrinsic::experimental_vp_strided_load:
997 return II->getType();
998 case Intrinsic::masked_store:
999 case Intrinsic::masked_scatter:
1000 case Intrinsic::masked_compressstore:
1001 case Intrinsic::vp_store:
1002 case Intrinsic::vp_scatter:
1003 case Intrinsic::experimental_vp_strided_store:
1004 return II->getOperand(0)->getType();
1005 default:
1006 break;
1007 }
1008 }
1009 }
1011 return nullptr;
1013
1015 bool IncludePhaseOneUnwind) {
1016 // Because phase one unwinding skips cleanup landingpads, we effectively
1017 // unwind past this frame, and callers need to have valid unwind info.
1018 if (LP->isCleanup())
1019 return IncludePhaseOneUnwind;
1020
1021 for (unsigned I = 0; I < LP->getNumClauses(); ++I) {
1022 Constant *Clause = LP->getClause(I);
1023 // catch ptr null catches all exceptions.
1024 if (LP->isCatch(I) && isa<ConstantPointerNull>(Clause))
1025 return false;
1026 // filter [0 x ptr] catches all exceptions.
1027 if (LP->isFilter(I) && Clause->getType()->getArrayNumElements() == 0)
1028 return false;
1029 }
1030
1031 // May catch only some subset of exceptions, in which case other exceptions
1032 // will continue unwinding.
1033 return true;
1034}
1035
1036bool Instruction::mayThrow(bool IncludePhaseOneUnwind) const {
1037 switch (getOpcode()) {
1038 case Instruction::Call:
1039 return !cast<CallInst>(this)->doesNotThrow();
1040 case Instruction::CleanupRet:
1041 return cast<CleanupReturnInst>(this)->unwindsToCaller();
1042 case Instruction::CatchSwitch:
1043 return cast<CatchSwitchInst>(this)->unwindsToCaller();
1044 case Instruction::Resume:
1045 return true;
1046 case Instruction::Invoke: {
1047 // Landingpads themselves don't unwind -- however, an invoke of a skipped
1048 // landingpad may continue unwinding.
1049 BasicBlock *UnwindDest = cast<InvokeInst>(this)->getUnwindDest();
1050 Instruction *Pad = UnwindDest->getFirstNonPHI();
1051 if (auto *LP = dyn_cast<LandingPadInst>(Pad))
1052 return canUnwindPastLandingPad(LP, IncludePhaseOneUnwind);
1053 return false;
1054 }
1055 case Instruction::CleanupPad:
1056 // Treat the same as cleanup landingpad.
1057 return IncludePhaseOneUnwind;
1058 default:
1059 return false;
1060 }
1061}
1062
1064 return mayWriteToMemory() || mayThrow() || !willReturn();
1065}
1066
1068 return (!isa<CallInst>(this) || !this->mayHaveSideEffects()) &&
1069 !this->isTerminator() && !this->isEHPad();
1070}
1071
1073 // Volatile store isn't guaranteed to return; see LangRef.
1074 if (auto *SI = dyn_cast<StoreInst>(this))
1075 return !SI->isVolatile();
1076
1077 if (const auto *CB = dyn_cast<CallBase>(this))
1078 return CB->hasFnAttr(Attribute::WillReturn);
1079 return true;
1080}
1081
1083 auto *II = dyn_cast<IntrinsicInst>(this);
1084 if (!II)
1085 return false;
1086 Intrinsic::ID ID = II->getIntrinsicID();
1087 return ID == Intrinsic::lifetime_start || ID == Intrinsic::lifetime_end;
1088}
1089
1091 auto *II = dyn_cast<IntrinsicInst>(this);
1092 if (!II)
1093 return false;
1094 Intrinsic::ID ID = II->getIntrinsicID();
1095 return ID == Intrinsic::launder_invariant_group ||
1096 ID == Intrinsic::strip_invariant_group;
1097}
1098
1100 return isa<DbgInfoIntrinsic>(this) || isa<PseudoProbeInst>(this);
1101}
1102
1103const Instruction *
1105 for (const Instruction *I = getNextNode(); I; I = I->getNextNode())
1106 if (!isa<DbgInfoIntrinsic>(I) && !(SkipPseudoOp && isa<PseudoProbeInst>(I)))
1107 return I;
1108 return nullptr;
1109}
1110
1111const Instruction *
1113 for (const Instruction *I = getPrevNode(); I; I = I->getPrevNode())
1114 if (!isa<DbgInfoIntrinsic>(I) && !(SkipPseudoOp && isa<PseudoProbeInst>(I)))
1115 return I;
1116 return nullptr;
1117}
1118
1120 if (isa<DbgInfoIntrinsic>(this))
1121 if (const Instruction *Next = getNextNonDebugInstruction())
1122 return Next->getDebugLoc();
1123 return getDebugLoc();
1124}
1125
1127 if (auto *II = dyn_cast<IntrinsicInst>(this))
1128 return II->isAssociative();
1129 unsigned Opcode = getOpcode();
1130 if (isAssociative(Opcode))
1131 return true;
1132
1133 switch (Opcode) {
1134 case FMul:
1135 case FAdd:
1136 return cast<FPMathOperator>(this)->hasAllowReassoc() &&
1137 cast<FPMathOperator>(this)->hasNoSignedZeros();
1138 default:
1139 return false;
1140 }
1141}
1142
1144 if (auto *II = dyn_cast<IntrinsicInst>(this))
1145 return II->isCommutative();
1146 // TODO: Should allow icmp/fcmp?
1147 return isCommutative(getOpcode());
1148}
1149
1151 switch (getOpcode()) {
1152#define HANDLE_TERM_INST(N, OPC, CLASS) \
1153 case Instruction::OPC: \
1154 return static_cast<const CLASS *>(this)->getNumSuccessors();
1155#include "llvm/IR/Instruction.def"
1156 default:
1157 break;
1158 }
1159 llvm_unreachable("not a terminator");
1160}
1161
1163 switch (getOpcode()) {
1164#define HANDLE_TERM_INST(N, OPC, CLASS) \
1165 case Instruction::OPC: \
1166 return static_cast<const CLASS *>(this)->getSuccessor(idx);
1167#include "llvm/IR/Instruction.def"
1168 default:
1169 break;
1170 }
1171 llvm_unreachable("not a terminator");
1172}
1173
1175 switch (getOpcode()) {
1176#define HANDLE_TERM_INST(N, OPC, CLASS) \
1177 case Instruction::OPC: \
1178 return static_cast<CLASS *>(this)->setSuccessor(idx, B);
1179#include "llvm/IR/Instruction.def"
1180 default:
1181 break;
1182 }
1183 llvm_unreachable("not a terminator");
1184}
1185
1187 for (unsigned Idx = 0, NumSuccessors = Instruction::getNumSuccessors();
1188 Idx != NumSuccessors; ++Idx)
1189 if (getSuccessor(Idx) == OldBB)
1190 setSuccessor(Idx, NewBB);
1191}
1192
1193Instruction *Instruction::cloneImpl() const {
1194 llvm_unreachable("Subclass of Instruction failed to implement cloneImpl");
1195}
1196
1198 MDNode *ProfileData = getBranchWeightMDNode(*this);
1199 if (!ProfileData || ProfileData->getNumOperands() != 3)
1200 return;
1201
1202 // The first operand is the name. Fetch them backwards and build a new one.
1203 Metadata *Ops[] = {ProfileData->getOperand(0), ProfileData->getOperand(2),
1204 ProfileData->getOperand(1)};
1205 setMetadata(LLVMContext::MD_prof,
1206 MDNode::get(ProfileData->getContext(), Ops));
1207}
1208
1210 ArrayRef<unsigned> WL) {
1211 if (!SrcInst.hasMetadata())
1212 return;
1213
1214 SmallDenseSet<unsigned, 4> WLS(WL.begin(), WL.end());
1215
1216 // Otherwise, enumerate and copy over metadata from the old instruction to the
1217 // new one.
1219 SrcInst.getAllMetadataOtherThanDebugLoc(TheMDs);
1220 for (const auto &MD : TheMDs) {
1221 if (WL.empty() || WLS.count(MD.first))
1222 setMetadata(MD.first, MD.second);
1223 }
1224 if (WL.empty() || WLS.count(LLVMContext::MD_dbg))
1225 setDebugLoc(SrcInst.getDebugLoc());
1226}
1227
1229 Instruction *New = nullptr;
1230 switch (getOpcode()) {
1231 default:
1232 llvm_unreachable("Unhandled Opcode.");
1233#define HANDLE_INST(num, opc, clas) \
1234 case Instruction::opc: \
1235 New = cast<clas>(this)->cloneImpl(); \
1236 break;
1237#include "llvm/IR/Instruction.def"
1238#undef HANDLE_INST
1239 }
1240
1241 New->SubclassOptionalData = SubclassOptionalData;
1242 New->copyMetadata(*this);
1243 return New;
1244}
amdgpu AMDGPU Register Bank Select
Rewrite undef for PHI
BlockVerifier::State From
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)
llvm::cl::opt< bool > UseNewDbgInfoFormat
This file contains the declarations for profiling metadata utility functions.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
an instruction to allocate memory on the stack
Definition: Instructions.h:59
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
iterator end() const
Definition: ArrayRef.h:154
iterator begin() const
Definition: ArrayRef.h:153
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:160
An instruction that atomically checks whether a specified value is in a memory location,...
Definition: Instructions.h:539
an instruction that atomically reads a memory location, combines it with another value,...
Definition: Instructions.h:748
LLVM Basic Block Representation.
Definition: BasicBlock.h:60
iterator end()
Definition: BasicBlock.h:451
DPMarker * getMarker(InstListType::iterator It)
Return the DPMarker for the position given by It, so that DPValues can be inserted there.
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:454
void renumberInstructions()
Renumber instructions and mark the ordering as valid.
Definition: BasicBlock.cpp:744
const Instruction * getFirstNonPHI() const
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
Definition: BasicBlock.cpp:407
DPMarker * createMarker(Instruction *I)
Attach a DPMarker to the given instruction.
Definition: BasicBlock.cpp:39
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:214
InstListType::iterator iterator
Instruction iterators...
Definition: BasicBlock.h:173
bool IsNewDbgInfoFormat
Flag recording whether or not this block stores debug-info in the form of intrinsic instructions (fal...
Definition: BasicBlock.h:65
void deleteTrailingDPValues()
Delete any trailing DPValues at the end of this block, see setTrailingDPValues.
DPMarker * getNextMarker(Instruction *I)
Return the DPMarker for the position that comes after I.
bool isInstrOrderValid() const
Returns true if the Order field of child Instructions is valid.
Definition: BasicBlock.h:690
void flushTerminatorDbgValues()
Eject any debug-info trailing at the end of a block.
Definition: BasicBlock.cpp:757
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:336
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:957
This is an important base class in LLVM.
Definition: Constant.h:41
Per-instruction record of debug-info.
static iterator_range< simple_ilist< DbgRecord >::iterator > getEmptyDPValueRange()
void dropOneDbgValue(DbgRecord *DR)
Erase a single DbgRecord from this marker.
void dropDbgValues()
Erase all DPValues in this DPMarker.
Instruction * MarkedInstr
Link back to the Instruction that owns this marker.
void absorbDebugValues(DPMarker &Src, bool InsertAtHead)
Transfer any DPValues from Src into this DPMarker.
simple_ilist< DbgRecord > StoredDPValues
List of DbgRecords, the non-instruction equivalent of llvm.dbg.
iterator_range< simple_ilist< DbgRecord >::iterator > cloneDebugInfoFrom(DPMarker *From, std::optional< simple_ilist< DbgRecord >::iterator > FromHere, bool InsertAtHead=false)
Clone all DPMarkers from From into this marker.
void removeMarker()
Handle the removal of a marker: the position of debug-info has gone away, but the stored debug record...
Base class for non-instruction debug metadata records that have positions within IR.
A debug info location.
Definition: DebugLoc.h:33
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:460
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
Definition: Instructions.h:973
This instruction inserts a struct field of array element value into an aggregate value.
const DebugLoc & getStableDebugLoc() const
Fetch the debug location for this node, unless this is a debug intrinsic, in which case fetch the deb...
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:89
bool hasNoUnsignedWrap() const LLVM_READONLY
Determine whether the no unsigned wrap flag is set.
bool hasDbgValues() const
Returns true if any DPValues are attached to this instruction.
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...
void moveBeforePreserving(Instruction *MovePos)
Perform a moveBefore operation, while signalling that the caller intends to preserve the original ord...
bool hasNoSignedZeros() const LLVM_READONLY
Determine whether the no-signed-zeros flag is set.
iterator_range< simple_ilist< DbgRecord >::iterator > cloneDebugInfoFrom(const Instruction *From, std::optional< simple_ilist< DbgRecord >::iterator > FromHere=std::nullopt, bool InsertAtHead=false)
Clone any debug-info attached to From onto this instruction.
DPMarker * DbgMarker
Optional marker recording the position for debugging information that takes effect immediately before...
Definition: Instruction.h:63
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.
iterator_range< simple_ilist< DbgRecord >::iterator > getDbgValueRange() const
Return a range over the DPValues attached to this instruction.
Definition: Instruction.h:82
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
Definition: Instruction.h:452
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
Definition: Instruction.cpp:81
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:339
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:800
const BasicBlock * getParent() const
Definition: Instruction.h:150
InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
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:85
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.
void setNonNeg(bool b=true)
Set or clear the nneg flag on this instruction, which must be a zext instruction.
bool isTerminator() const
Definition: Instruction.h:253
Type * getAccessType() const LLVM_READONLY
Return the type this instruction accesses in memory, if any.
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 hasNonNeg() const LLVM_READONLY
Determine whether the the nneg flag is set.
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:1633
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:252
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:866
@ CompareUsingScalarTypes
Check for equivalence treating a type and a vector of that type as equivalent.
Definition: Instruction.h:869
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:382
void moveAfterPreserving(Instruction *MovePos)
See moveBeforePreserving .
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
Definition: Instruction.h:250
bool hasAtomicLoad() const LLVM_READONLY
Return true if this atomic instruction loads from memory.
void dropUnknownNonDebugMetadata()
Definition: Instruction.h:413
void setIsExact(bool b=true)
Set or clear the exact flag on this instruction, which must be an operator which supports this flag.
void dropOneDbgValue(DbgRecord *I)
Erase a single DPValue I that is attached to this instruction.
void dropPoisonGeneratingMetadata()
Drops metadata that may generate poison.
void setHasAllowReciprocal(bool B)
Set or clear the allow-reciprocal flag on this instruction, which must be an operator which supports ...
void handleMarkerRemoval()
Handle the debug-info implications of this instruction being removed.
Definition: Instruction.cpp:96
std::optional< InstListType::iterator > getInsertionPointAfterDef()
Get the first insertion point at which the result of this instruction is defined.
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.
std::optional< simple_ilist< DbgRecord >::iterator > getDbgReinsertionPosition()
Return an iterator to the position of the "Next" DPValue after this instruction, or std::nullopt.
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.
void adoptDbgValues(BasicBlock *BB, InstListType::iterator It, bool InsertAtHead)
Transfer any DPValues on the position It onto this instruction, by simply adopting the sequence of DP...
bool hasPoisonGeneratingMetadata() const LLVM_READONLY
Return true if this instruction has poison-generating metadata.
Instruction(const Instruction &)=delete
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
Definition: Instruction.h:449
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.
void dropDbgValues()
Erase any DPValues attached to this instruction.
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.
InstListType::iterator insertInto(BasicBlock *ParentBB, InstListType::iterator It)
Inserts an unlinked instruction into ParentBB at position It and returns the iterator of the inserted...
A wrapper class for inspecting calls to intrinsic functions.
Definition: IntrinsicInst.h:47
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:184
Metadata node.
Definition: Metadata.h:1067
const MDOperand & getOperand(unsigned I) const
Definition: Metadata.h:1428
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1541
unsigned getNumOperands() const
Return number of MDNode operands.
Definition: Metadata.h:1434
LLVMContext & getContext() const
Definition: Metadata.h:1231
Root of the metadata hierarchy.
Definition: Metadata.h:62
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.
Instruction that can have a nneg flag (only zext).
Definition: InstrTypes.h:938
This instruction constructs a fixed permutation of two input vectors.
Implements a dense probed hash-table based set with some number of buckets stored inline.
Definition: DenseSet.h:290
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1209
An instruction for storing to memory.
Definition: Instructions.h:317
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:1808
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:535
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:84
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:1530
iterator_range< use_iterator > uses()
Definition: Value.h:376
self_iterator getIterator()
Definition: ilist_node.h:109
Instruction * getNextNode()
Get the next node, or nullptr for the list tail.
Definition: ilist_node.h:316
void splice(iterator where, iplist_impl &L2)
Definition: ilist.h:266
base_list_type::iterator iterator
Definition: ilist.h:121
iterator erase(iterator where)
Definition: ilist.h:204
pointer remove(iterator &IT)
Definition: ilist.h:188
iterator insertAfter(iterator where, pointer New)
Definition: ilist.h:174
iterator insert(iterator where, pointer New)
Definition: ilist.h:165
A range adaptor for a pair of iterators.
#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:1738
@ Other
Any other memory.
@ 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.