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 // If requested, append this instruction into the basic block.
52 if (InsertAtEnd)
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
76void Instruction::setParent(BasicBlock *P) {
77 Parent = P;
78}
79
81 return getParent()->getModule();
82}
83
85 return getParent()->getParent();
86}
87
89 // Perform any debug-info maintenence required.
91
92 getParent()->getInstList().remove(getIterator());
93}
94
96 if (!Parent->IsNewDbgInfoFormat || !DbgMarker)
97 return;
98
100}
101
104 return getParent()->getInstList().erase(getIterator());
105}
106
108 insertBefore(InsertPos->getIterator());
109}
110
111/// Insert an unlinked instruction into a basic block immediately before the
112/// specified instruction.
114 insertBefore(*InsertPos->getParent(), InsertPos);
115}
116
117/// Insert an unlinked instruction into a basic block immediately after the
118/// specified instruction.
120 BasicBlock *DestParent = InsertPos->getParent();
121
122 DestParent->getInstList().insertAfter(InsertPos->getIterator(), this);
123}
124
127 assert(getParent() == nullptr && "Expected detached instruction");
128 assert((It == ParentBB->end() || It->getParent() == ParentBB) &&
129 "It not in ParentBB");
130 insertBefore(*ParentBB, It);
131 return getIterator();
132}
133
135
137 InstListType::iterator InsertPos) {
139
140 BB.getInstList().insert(InsertPos, this);
141
142 if (!BB.IsNewDbgInfoFormat)
143 return;
144
145 // We've inserted "this": if InsertAtHead is set then it comes before any
146 // DPValues attached to InsertPos. But if it's not set, then any DbgRecords
147 // should now come before "this".
148 bool InsertAtHead = InsertPos.getHeadBit();
149 if (!InsertAtHead) {
150 DPMarker *SrcMarker = BB.getMarker(InsertPos);
151 if (SrcMarker && !SrcMarker->empty()) {
152 // If this assertion fires, the calling code is about to insert a PHI
153 // after debug-records, which would form a sequence like:
154 // %0 = PHI
155 // #dbg_value
156 // %1 = PHI
157 // Which is de-normalised and undesired -- hence the assertion. To avoid
158 // this, you must insert at that position using an iterator, and it must
159 // be aquired by calling getFirstNonPHIIt / begin or similar methods on
160 // the block. This will signal to this behind-the-scenes debug-info
161 // maintenence code that you intend the PHI to be ahead of everything,
162 // including any debug-info.
163 assert(!isa<PHINode>(this) && "Inserting PHI after debug-records!");
164 adoptDbgRecords(&BB, InsertPos, false);
165 }
166 }
167
168 // If we're inserting a terminator, check if we need to flush out
169 // TrailingDbgRecords. Inserting instructions at the end of an incomplete
170 // block is handled by the code block above.
171 if (isTerminator())
173}
174
175/// Unlink this instruction from its current basic block and insert it into the
176/// basic block that MovePos lives in, right before MovePos.
178 moveBeforeImpl(*MovePos->getParent(), MovePos->getIterator(), false);
179}
180
182 moveBeforeImpl(*MovePos->getParent(), MovePos->getIterator(), true);
183}
184
186 auto NextIt = std::next(MovePos->getIterator());
187 // We want this instruction to be moved to before NextIt in the instruction
188 // list, but before NextIt's debug value range.
189 NextIt.setHeadBit(true);
190 moveBeforeImpl(*MovePos->getParent(), NextIt, false);
191}
192
194 auto NextIt = std::next(MovePos->getIterator());
195 // We want this instruction and its debug range to be moved to before NextIt
196 // in the instruction list, but before NextIt's debug value range.
197 NextIt.setHeadBit(true);
198 moveBeforeImpl(*MovePos->getParent(), NextIt, true);
199}
200
202 moveBeforeImpl(BB, I, false);
203}
204
207 moveBeforeImpl(BB, I, true);
208}
209
210void Instruction::moveBeforeImpl(BasicBlock &BB, InstListType::iterator I,
211 bool Preserve) {
212 assert(I == BB.end() || I->getParent() == &BB);
213 bool InsertAtHead = I.getHeadBit();
214
215 // If we've been given the "Preserve" flag, then just move the DbgRecords with
216 // the instruction, no more special handling needed.
217 if (BB.IsNewDbgInfoFormat && DbgMarker && !Preserve) {
218 if (I != this->getIterator() || InsertAtHead) {
219 // "this" is definitely moving in the list, or it's moving ahead of its
220 // attached DPValues. Detach any existing DbgRecords.
222 }
223 }
224
225 // Move this single instruction. Use the list splice method directly, not
226 // the block splicer, which will do more debug-info things.
227 BB.getInstList().splice(I, getParent()->getInstList(), getIterator());
228
229 if (BB.IsNewDbgInfoFormat && !Preserve) {
230 DPMarker *NextMarker = getParent()->getNextMarker(this);
231
232 // If we're inserting at point I, and not in front of the DbgRecords
233 // attached there, then we should absorb the DbgRecords attached to I.
234 if (!InsertAtHead && NextMarker && !NextMarker->empty()) {
235 adoptDbgRecords(&BB, I, false);
236 }
237 }
238
239 if (isTerminator())
241}
242
244 const Instruction *From, std::optional<DbgRecord::self_iterator> FromHere,
245 bool InsertAtHead) {
246 if (!From->DbgMarker)
248
249 assert(getParent()->IsNewDbgInfoFormat);
250 assert(getParent()->IsNewDbgInfoFormat ==
251 From->getParent()->IsNewDbgInfoFormat);
252
253 if (!DbgMarker)
254 getParent()->createMarker(this);
255
256 return DbgMarker->cloneDebugInfoFrom(From->DbgMarker, FromHere, InsertAtHead);
257}
258
259std::optional<DbgRecord::self_iterator>
261 // Is there a marker on the next instruction?
262 DPMarker *NextMarker = getParent()->getNextMarker(this);
263 if (!NextMarker)
264 return std::nullopt;
265
266 // Are there any DbgRecords in the next marker?
267 if (NextMarker->StoredDbgRecords.empty())
268 return std::nullopt;
269
270 return NextMarker->StoredDbgRecords.begin();
271}
272
273bool Instruction::hasDbgRecords() const { return !getDbgRecordRange().empty(); }
274
276 bool InsertAtHead) {
277 DPMarker *SrcMarker = BB->getMarker(It);
278 auto ReleaseTrailingDbgRecords = [BB, It, SrcMarker]() {
279 if (BB->end() == It) {
280 SrcMarker->eraseFromParent();
282 }
283 };
284
285 if (!SrcMarker || SrcMarker->StoredDbgRecords.empty()) {
286 ReleaseTrailingDbgRecords();
287 return;
288 }
289
290 // If we have DPMarkers attached to this instruction, we have to honour the
291 // ordering of DbgRecords between this and the other marker. Fall back to just
292 // absorbing from the source.
293 if (DbgMarker || It == BB->end()) {
294 // Ensure we _do_ have a marker.
295 getParent()->createMarker(this);
296 DbgMarker->absorbDebugValues(*SrcMarker, InsertAtHead);
297
298 // Having transferred everything out of SrcMarker, we _could_ clean it up
299 // and free the marker now. However, that's a lot of heap-accounting for a
300 // small amount of memory with a good chance of re-use. Leave it for the
301 // moment. It will be released when the Instruction is freed in the worst
302 // case.
303 // However: if we transferred from a trailing marker off the end of the
304 // block, it's important to not leave the empty marker trailing. It will
305 // give a misleading impression that some debug records have been left
306 // trailing.
307 ReleaseTrailingDbgRecords();
308 } else {
309 // Optimisation: we're transferring all the DbgRecords from the source
310 // marker onto this empty location: just adopt the other instructions
311 // marker.
312 DbgMarker = SrcMarker;
313 DbgMarker->MarkedInstr = this;
314 It->DbgMarker = nullptr;
315 }
316}
317
319 if (DbgMarker)
321}
322
325}
326
328 assert(Parent && Other->Parent &&
329 "instructions without BB parents have no order");
330 assert(Parent == Other->Parent && "cross-BB instruction order comparison");
331 if (!Parent->isInstrOrderValid())
332 Parent->renumberInstructions();
333 return Order < Other->Order;
334}
335
336std::optional<BasicBlock::iterator> Instruction::getInsertionPointAfterDef() {
337 assert(!getType()->isVoidTy() && "Instruction must define result");
338 BasicBlock *InsertBB;
339 BasicBlock::iterator InsertPt;
340 if (auto *PN = dyn_cast<PHINode>(this)) {
341 InsertBB = PN->getParent();
342 InsertPt = InsertBB->getFirstInsertionPt();
343 } else if (auto *II = dyn_cast<InvokeInst>(this)) {
344 InsertBB = II->getNormalDest();
345 InsertPt = InsertBB->getFirstInsertionPt();
346 } else if (isa<CallBrInst>(this)) {
347 // Def is available in multiple successors, there's no single dominating
348 // insertion point.
349 return std::nullopt;
350 } else {
351 assert(!isTerminator() && "Only invoke/callbr terminators return value");
352 InsertBB = getParent();
353 InsertPt = std::next(getIterator());
354 // Any instruction inserted immediately after "this" will come before any
355 // debug-info records take effect -- thus, set the head bit indicating that
356 // to debug-info-transfer code.
357 InsertPt.setHeadBit(true);
358 }
359
360 // catchswitch blocks don't have any legal insertion point (because they
361 // are both an exception pad and a terminator).
362 if (InsertPt == InsertBB->end())
363 return std::nullopt;
364 return InsertPt;
365}
366
368 return any_of(operands(), [](Value *V) { return V->hasOneUser(); });
369}
370
372 cast<OverflowingBinaryOperator>(this)->setHasNoUnsignedWrap(b);
373}
374
376 cast<OverflowingBinaryOperator>(this)->setHasNoSignedWrap(b);
377}
378
380 cast<PossiblyExactOperator>(this)->setIsExact(b);
381}
382
384 assert(isa<PossiblyNonNegInst>(this) && "Must be zext");
387}
388
390 return cast<OverflowingBinaryOperator>(this)->hasNoUnsignedWrap();
391}
392
394 return cast<OverflowingBinaryOperator>(this)->hasNoSignedWrap();
395}
396
398 assert(isa<PossiblyNonNegInst>(this) && "Must be zext");
400}
401
403 return cast<Operator>(this)->hasPoisonGeneratingFlags();
404}
405
407 switch (getOpcode()) {
408 case Instruction::Add:
409 case Instruction::Sub:
410 case Instruction::Mul:
411 case Instruction::Shl:
412 cast<OverflowingBinaryOperator>(this)->setHasNoUnsignedWrap(false);
413 cast<OverflowingBinaryOperator>(this)->setHasNoSignedWrap(false);
414 break;
415
416 case Instruction::UDiv:
417 case Instruction::SDiv:
418 case Instruction::AShr:
419 case Instruction::LShr:
420 cast<PossiblyExactOperator>(this)->setIsExact(false);
421 break;
422
423 case Instruction::Or:
424 cast<PossiblyDisjointInst>(this)->setIsDisjoint(false);
425 break;
426
427 case Instruction::GetElementPtr:
428 cast<GetElementPtrInst>(this)->setIsInBounds(false);
429 break;
430
431 case Instruction::ZExt:
432 setNonNeg(false);
433 break;
434 }
435
436 if (isa<FPMathOperator>(this)) {
437 setHasNoNaNs(false);
438 setHasNoInfs(false);
439 }
440
441 assert(!hasPoisonGeneratingFlags() && "must be kept in sync");
442}
443
445 return hasMetadata(LLVMContext::MD_range) ||
446 hasMetadata(LLVMContext::MD_nonnull) ||
447 hasMetadata(LLVMContext::MD_align);
448}
449
451 eraseMetadata(LLVMContext::MD_range);
452 eraseMetadata(LLVMContext::MD_nonnull);
453 eraseMetadata(LLVMContext::MD_align);
454}
455
457 ArrayRef<unsigned> KnownIDs) {
459 auto *CB = dyn_cast<CallBase>(this);
460 if (!CB)
461 return;
462 // For call instructions, we also need to drop parameter and return attributes
463 // that are can cause UB if the call is moved to a location where the
464 // attribute is not valid.
465 AttributeList AL = CB->getAttributes();
466 if (AL.isEmpty())
467 return;
468 AttributeMask UBImplyingAttributes =
470 for (unsigned ArgNo = 0; ArgNo < CB->arg_size(); ArgNo++)
471 CB->removeParamAttrs(ArgNo, UBImplyingAttributes);
472 CB->removeRetAttrs(UBImplyingAttributes);
473}
474
476 // !annotation metadata does not impact semantics.
477 // !range, !nonnull and !align produce poison, so they are safe to speculate.
478 // !noundef and various AA metadata must be dropped, as it generally produces
479 // immediate undefined behavior.
480 unsigned KnownIDs[] = {LLVMContext::MD_annotation, LLVMContext::MD_range,
481 LLVMContext::MD_nonnull, LLVMContext::MD_align};
483}
484
486 return cast<PossiblyExactOperator>(this)->isExact();
487}
488
490 assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
491 cast<FPMathOperator>(this)->setFast(B);
492}
493
495 assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
496 cast<FPMathOperator>(this)->setHasAllowReassoc(B);
497}
498
500 assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
501 cast<FPMathOperator>(this)->setHasNoNaNs(B);
502}
503
505 assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
506 cast<FPMathOperator>(this)->setHasNoInfs(B);
507}
508
510 assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
511 cast<FPMathOperator>(this)->setHasNoSignedZeros(B);
512}
513
515 assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
516 cast<FPMathOperator>(this)->setHasAllowReciprocal(B);
517}
518
520 assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
521 cast<FPMathOperator>(this)->setHasAllowContract(B);
522}
523
525 assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
526 cast<FPMathOperator>(this)->setHasApproxFunc(B);
527}
528
530 assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
531 cast<FPMathOperator>(this)->setFastMathFlags(FMF);
532}
533
535 assert(isa<FPMathOperator>(this) && "copying fast-math flag on invalid op");
536 cast<FPMathOperator>(this)->copyFastMathFlags(FMF);
537}
538
540 assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
541 return cast<FPMathOperator>(this)->isFast();
542}
543
545 assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
546 return cast<FPMathOperator>(this)->hasAllowReassoc();
547}
548
550 assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
551 return cast<FPMathOperator>(this)->hasNoNaNs();
552}
553
555 assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
556 return cast<FPMathOperator>(this)->hasNoInfs();
557}
558
560 assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
561 return cast<FPMathOperator>(this)->hasNoSignedZeros();
562}
563
565 assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
566 return cast<FPMathOperator>(this)->hasAllowReciprocal();
567}
568
570 assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
571 return cast<FPMathOperator>(this)->hasAllowContract();
572}
573
575 assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
576 return cast<FPMathOperator>(this)->hasApproxFunc();
577}
578
580 assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
581 return cast<FPMathOperator>(this)->getFastMathFlags();
582}
583
585 copyFastMathFlags(I->getFastMathFlags());
586}
587
588void Instruction::copyIRFlags(const Value *V, bool IncludeWrapFlags) {
589 // Copy the wrapping flags.
590 if (IncludeWrapFlags && isa<OverflowingBinaryOperator>(this)) {
591 if (auto *OB = dyn_cast<OverflowingBinaryOperator>(V)) {
592 setHasNoSignedWrap(OB->hasNoSignedWrap());
593 setHasNoUnsignedWrap(OB->hasNoUnsignedWrap());
594 }
595 }
596
597 // Copy the exact flag.
598 if (auto *PE = dyn_cast<PossiblyExactOperator>(V))
599 if (isa<PossiblyExactOperator>(this))
600 setIsExact(PE->isExact());
601
602 if (auto *SrcPD = dyn_cast<PossiblyDisjointInst>(V))
603 if (auto *DestPD = dyn_cast<PossiblyDisjointInst>(this))
604 DestPD->setIsDisjoint(SrcPD->isDisjoint());
605
606 // Copy the fast-math flags.
607 if (auto *FP = dyn_cast<FPMathOperator>(V))
608 if (isa<FPMathOperator>(this))
609 copyFastMathFlags(FP->getFastMathFlags());
610
611 if (auto *SrcGEP = dyn_cast<GetElementPtrInst>(V))
612 if (auto *DestGEP = dyn_cast<GetElementPtrInst>(this))
613 DestGEP->setIsInBounds(SrcGEP->isInBounds() || DestGEP->isInBounds());
614
615 if (auto *NNI = dyn_cast<PossiblyNonNegInst>(V))
616 if (isa<PossiblyNonNegInst>(this))
617 setNonNeg(NNI->hasNonNeg());
618}
619
621 if (auto *OB = dyn_cast<OverflowingBinaryOperator>(V)) {
622 if (isa<OverflowingBinaryOperator>(this)) {
623 setHasNoSignedWrap(hasNoSignedWrap() && OB->hasNoSignedWrap());
624 setHasNoUnsignedWrap(hasNoUnsignedWrap() && OB->hasNoUnsignedWrap());
625 }
626 }
627
628 if (auto *PE = dyn_cast<PossiblyExactOperator>(V))
629 if (isa<PossiblyExactOperator>(this))
630 setIsExact(isExact() && PE->isExact());
631
632 if (auto *SrcPD = dyn_cast<PossiblyDisjointInst>(V))
633 if (auto *DestPD = dyn_cast<PossiblyDisjointInst>(this))
634 DestPD->setIsDisjoint(DestPD->isDisjoint() && SrcPD->isDisjoint());
635
636 if (auto *FP = dyn_cast<FPMathOperator>(V)) {
637 if (isa<FPMathOperator>(this)) {
639 FM &= FP->getFastMathFlags();
641 }
642 }
643
644 if (auto *SrcGEP = dyn_cast<GetElementPtrInst>(V))
645 if (auto *DestGEP = dyn_cast<GetElementPtrInst>(this))
646 DestGEP->setIsInBounds(SrcGEP->isInBounds() && DestGEP->isInBounds());
647
648 if (auto *NNI = dyn_cast<PossiblyNonNegInst>(V))
649 if (isa<PossiblyNonNegInst>(this))
650 setNonNeg(hasNonNeg() && NNI->hasNonNeg());
651}
652
653const char *Instruction::getOpcodeName(unsigned OpCode) {
654 switch (OpCode) {
655 // Terminators
656 case Ret: return "ret";
657 case Br: return "br";
658 case Switch: return "switch";
659 case IndirectBr: return "indirectbr";
660 case Invoke: return "invoke";
661 case Resume: return "resume";
662 case Unreachable: return "unreachable";
663 case CleanupRet: return "cleanupret";
664 case CatchRet: return "catchret";
665 case CatchPad: return "catchpad";
666 case CatchSwitch: return "catchswitch";
667 case CallBr: return "callbr";
668
669 // Standard unary operators...
670 case FNeg: return "fneg";
671
672 // Standard binary operators...
673 case Add: return "add";
674 case FAdd: return "fadd";
675 case Sub: return "sub";
676 case FSub: return "fsub";
677 case Mul: return "mul";
678 case FMul: return "fmul";
679 case UDiv: return "udiv";
680 case SDiv: return "sdiv";
681 case FDiv: return "fdiv";
682 case URem: return "urem";
683 case SRem: return "srem";
684 case FRem: return "frem";
685
686 // Logical operators...
687 case And: return "and";
688 case Or : return "or";
689 case Xor: return "xor";
690
691 // Memory instructions...
692 case Alloca: return "alloca";
693 case Load: return "load";
694 case Store: return "store";
695 case AtomicCmpXchg: return "cmpxchg";
696 case AtomicRMW: return "atomicrmw";
697 case Fence: return "fence";
698 case GetElementPtr: return "getelementptr";
699
700 // Convert instructions...
701 case Trunc: return "trunc";
702 case ZExt: return "zext";
703 case SExt: return "sext";
704 case FPTrunc: return "fptrunc";
705 case FPExt: return "fpext";
706 case FPToUI: return "fptoui";
707 case FPToSI: return "fptosi";
708 case UIToFP: return "uitofp";
709 case SIToFP: return "sitofp";
710 case IntToPtr: return "inttoptr";
711 case PtrToInt: return "ptrtoint";
712 case BitCast: return "bitcast";
713 case AddrSpaceCast: return "addrspacecast";
714
715 // Other instructions...
716 case ICmp: return "icmp";
717 case FCmp: return "fcmp";
718 case PHI: return "phi";
719 case Select: return "select";
720 case Call: return "call";
721 case Shl: return "shl";
722 case LShr: return "lshr";
723 case AShr: return "ashr";
724 case VAArg: return "va_arg";
725 case ExtractElement: return "extractelement";
726 case InsertElement: return "insertelement";
727 case ShuffleVector: return "shufflevector";
728 case ExtractValue: return "extractvalue";
729 case InsertValue: return "insertvalue";
730 case LandingPad: return "landingpad";
731 case CleanupPad: return "cleanuppad";
732 case Freeze: return "freeze";
733
734 default: return "<Invalid operator> ";
735 }
736}
737
738/// This must be kept in sync with FunctionComparator::cmpOperations in
739/// lib/Transforms/IPO/MergeFunctions.cpp.
741 bool IgnoreAlignment) const {
742 auto I1 = this;
743 assert(I1->getOpcode() == I2->getOpcode() &&
744 "Can not compare special state of different instructions");
745
746 if (const AllocaInst *AI = dyn_cast<AllocaInst>(I1))
747 return AI->getAllocatedType() == cast<AllocaInst>(I2)->getAllocatedType() &&
748 (AI->getAlign() == cast<AllocaInst>(I2)->getAlign() ||
749 IgnoreAlignment);
750 if (const LoadInst *LI = dyn_cast<LoadInst>(I1))
751 return LI->isVolatile() == cast<LoadInst>(I2)->isVolatile() &&
752 (LI->getAlign() == cast<LoadInst>(I2)->getAlign() ||
753 IgnoreAlignment) &&
754 LI->getOrdering() == cast<LoadInst>(I2)->getOrdering() &&
755 LI->getSyncScopeID() == cast<LoadInst>(I2)->getSyncScopeID();
756 if (const StoreInst *SI = dyn_cast<StoreInst>(I1))
757 return SI->isVolatile() == cast<StoreInst>(I2)->isVolatile() &&
758 (SI->getAlign() == cast<StoreInst>(I2)->getAlign() ||
759 IgnoreAlignment) &&
760 SI->getOrdering() == cast<StoreInst>(I2)->getOrdering() &&
761 SI->getSyncScopeID() == cast<StoreInst>(I2)->getSyncScopeID();
762 if (const CmpInst *CI = dyn_cast<CmpInst>(I1))
763 return CI->getPredicate() == cast<CmpInst>(I2)->getPredicate();
764 if (const CallInst *CI = dyn_cast<CallInst>(I1))
765 return CI->isTailCall() == cast<CallInst>(I2)->isTailCall() &&
766 CI->getCallingConv() == cast<CallInst>(I2)->getCallingConv() &&
767 CI->getAttributes() == cast<CallInst>(I2)->getAttributes() &&
768 CI->hasIdenticalOperandBundleSchema(*cast<CallInst>(I2));
769 if (const InvokeInst *CI = dyn_cast<InvokeInst>(I1))
770 return CI->getCallingConv() == cast<InvokeInst>(I2)->getCallingConv() &&
771 CI->getAttributes() == cast<InvokeInst>(I2)->getAttributes() &&
772 CI->hasIdenticalOperandBundleSchema(*cast<InvokeInst>(I2));
773 if (const CallBrInst *CI = dyn_cast<CallBrInst>(I1))
774 return CI->getCallingConv() == cast<CallBrInst>(I2)->getCallingConv() &&
775 CI->getAttributes() == cast<CallBrInst>(I2)->getAttributes() &&
776 CI->hasIdenticalOperandBundleSchema(*cast<CallBrInst>(I2));
777 if (const InsertValueInst *IVI = dyn_cast<InsertValueInst>(I1))
778 return IVI->getIndices() == cast<InsertValueInst>(I2)->getIndices();
779 if (const ExtractValueInst *EVI = dyn_cast<ExtractValueInst>(I1))
780 return EVI->getIndices() == cast<ExtractValueInst>(I2)->getIndices();
781 if (const FenceInst *FI = dyn_cast<FenceInst>(I1))
782 return FI->getOrdering() == cast<FenceInst>(I2)->getOrdering() &&
783 FI->getSyncScopeID() == cast<FenceInst>(I2)->getSyncScopeID();
784 if (const AtomicCmpXchgInst *CXI = dyn_cast<AtomicCmpXchgInst>(I1))
785 return CXI->isVolatile() == cast<AtomicCmpXchgInst>(I2)->isVolatile() &&
786 CXI->isWeak() == cast<AtomicCmpXchgInst>(I2)->isWeak() &&
787 CXI->getSuccessOrdering() ==
788 cast<AtomicCmpXchgInst>(I2)->getSuccessOrdering() &&
789 CXI->getFailureOrdering() ==
790 cast<AtomicCmpXchgInst>(I2)->getFailureOrdering() &&
791 CXI->getSyncScopeID() ==
792 cast<AtomicCmpXchgInst>(I2)->getSyncScopeID();
793 if (const AtomicRMWInst *RMWI = dyn_cast<AtomicRMWInst>(I1))
794 return RMWI->getOperation() == cast<AtomicRMWInst>(I2)->getOperation() &&
795 RMWI->isVolatile() == cast<AtomicRMWInst>(I2)->isVolatile() &&
796 RMWI->getOrdering() == cast<AtomicRMWInst>(I2)->getOrdering() &&
797 RMWI->getSyncScopeID() == cast<AtomicRMWInst>(I2)->getSyncScopeID();
798 if (const ShuffleVectorInst *SVI = dyn_cast<ShuffleVectorInst>(I1))
799 return SVI->getShuffleMask() ==
800 cast<ShuffleVectorInst>(I2)->getShuffleMask();
801 if (const GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(I1))
802 return GEP->getSourceElementType() ==
803 cast<GetElementPtrInst>(I2)->getSourceElementType();
804
805 return true;
806}
807
809 return isIdenticalToWhenDefined(I) &&
810 SubclassOptionalData == I->SubclassOptionalData;
811}
812
814 if (getOpcode() != I->getOpcode() ||
815 getNumOperands() != I->getNumOperands() ||
816 getType() != I->getType())
817 return false;
818
819 // If both instructions have no operands, they are identical.
820 if (getNumOperands() == 0 && I->getNumOperands() == 0)
821 return this->hasSameSpecialState(I);
822
823 // We have two instructions of identical opcode and #operands. Check to see
824 // if all operands are the same.
825 if (!std::equal(op_begin(), op_end(), I->op_begin()))
826 return false;
827
828 // WARNING: this logic must be kept in sync with EliminateDuplicatePHINodes()!
829 if (const PHINode *thisPHI = dyn_cast<PHINode>(this)) {
830 const PHINode *otherPHI = cast<PHINode>(I);
831 return std::equal(thisPHI->block_begin(), thisPHI->block_end(),
832 otherPHI->block_begin());
833 }
834
835 return this->hasSameSpecialState(I);
836}
837
838// Keep this in sync with FunctionComparator::cmpOperations in
839// lib/Transforms/IPO/MergeFunctions.cpp.
841 unsigned flags) const {
842 bool IgnoreAlignment = flags & CompareIgnoringAlignment;
843 bool UseScalarTypes = flags & CompareUsingScalarTypes;
844
845 if (getOpcode() != I->getOpcode() ||
846 getNumOperands() != I->getNumOperands() ||
847 (UseScalarTypes ?
848 getType()->getScalarType() != I->getType()->getScalarType() :
849 getType() != I->getType()))
850 return false;
851
852 // We have two instructions of identical opcode and #operands. Check to see
853 // if all operands are the same type
854 for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
855 if (UseScalarTypes ?
856 getOperand(i)->getType()->getScalarType() !=
857 I->getOperand(i)->getType()->getScalarType() :
858 getOperand(i)->getType() != I->getOperand(i)->getType())
859 return false;
860
861 return this->hasSameSpecialState(I, IgnoreAlignment);
862}
863
865 for (const Use &U : uses()) {
866 // PHI nodes uses values in the corresponding predecessor block. For other
867 // instructions, just check to see whether the parent of the use matches up.
868 const Instruction *I = cast<Instruction>(U.getUser());
869 const PHINode *PN = dyn_cast<PHINode>(I);
870 if (!PN) {
871 if (I->getParent() != BB)
872 return true;
873 continue;
874 }
875
876 if (PN->getIncomingBlock(U) != BB)
877 return true;
878 }
879 return false;
880}
881
883 switch (getOpcode()) {
884 default: return false;
885 case Instruction::VAArg:
886 case Instruction::Load:
887 case Instruction::Fence: // FIXME: refine definition of mayReadFromMemory
888 case Instruction::AtomicCmpXchg:
889 case Instruction::AtomicRMW:
890 case Instruction::CatchPad:
891 case Instruction::CatchRet:
892 return true;
893 case Instruction::Call:
894 case Instruction::Invoke:
895 case Instruction::CallBr:
896 return !cast<CallBase>(this)->onlyWritesMemory();
897 case Instruction::Store:
898 return !cast<StoreInst>(this)->isUnordered();
899 }
900}
901
903 switch (getOpcode()) {
904 default: return false;
905 case Instruction::Fence: // FIXME: refine definition of mayWriteToMemory
906 case Instruction::Store:
907 case Instruction::VAArg:
908 case Instruction::AtomicCmpXchg:
909 case Instruction::AtomicRMW:
910 case Instruction::CatchPad:
911 case Instruction::CatchRet:
912 return true;
913 case Instruction::Call:
914 case Instruction::Invoke:
915 case Instruction::CallBr:
916 return !cast<CallBase>(this)->onlyReadsMemory();
917 case Instruction::Load:
918 return !cast<LoadInst>(this)->isUnordered();
919 }
920}
921
923 switch (getOpcode()) {
924 default:
925 return false;
926 case Instruction::AtomicCmpXchg:
927 case Instruction::AtomicRMW:
928 case Instruction::Fence:
929 return true;
930 case Instruction::Load:
931 return cast<LoadInst>(this)->getOrdering() != AtomicOrdering::NotAtomic;
932 case Instruction::Store:
933 return cast<StoreInst>(this)->getOrdering() != AtomicOrdering::NotAtomic;
934 }
935}
936
938 assert(isAtomic());
939 switch (getOpcode()) {
940 default:
941 return false;
942 case Instruction::AtomicCmpXchg:
943 case Instruction::AtomicRMW:
944 case Instruction::Load:
945 return true;
946 }
947}
948
950 assert(isAtomic());
951 switch (getOpcode()) {
952 default:
953 return false;
954 case Instruction::AtomicCmpXchg:
955 case Instruction::AtomicRMW:
956 case Instruction::Store:
957 return true;
958 }
959}
960
962 switch (getOpcode()) {
963 default:
964 return false;
965 case Instruction::AtomicRMW:
966 return cast<AtomicRMWInst>(this)->isVolatile();
967 case Instruction::Store:
968 return cast<StoreInst>(this)->isVolatile();
969 case Instruction::Load:
970 return cast<LoadInst>(this)->isVolatile();
971 case Instruction::AtomicCmpXchg:
972 return cast<AtomicCmpXchgInst>(this)->isVolatile();
973 case Instruction::Call:
974 case Instruction::Invoke:
975 // There are a very limited number of intrinsics with volatile flags.
976 if (auto *II = dyn_cast<IntrinsicInst>(this)) {
977 if (auto *MI = dyn_cast<MemIntrinsic>(II))
978 return MI->isVolatile();
979 switch (II->getIntrinsicID()) {
980 default: break;
981 case Intrinsic::matrix_column_major_load:
982 return cast<ConstantInt>(II->getArgOperand(2))->isOne();
983 case Intrinsic::matrix_column_major_store:
984 return cast<ConstantInt>(II->getArgOperand(3))->isOne();
985 }
986 }
987 return false;
988 }
989}
990
992 switch (getOpcode()) {
993 case Instruction::Store:
994 return cast<StoreInst>(this)->getValueOperand()->getType();
995 case Instruction::Load:
996 case Instruction::AtomicRMW:
997 return getType();
998 case Instruction::AtomicCmpXchg:
999 return cast<AtomicCmpXchgInst>(this)->getNewValOperand()->getType();
1000 case Instruction::Call:
1001 case Instruction::Invoke:
1002 if (const IntrinsicInst *II = dyn_cast<IntrinsicInst>(this)) {
1003 switch (II->getIntrinsicID()) {
1004 case Intrinsic::masked_load:
1005 case Intrinsic::masked_gather:
1006 case Intrinsic::masked_expandload:
1007 case Intrinsic::vp_load:
1008 case Intrinsic::vp_gather:
1009 case Intrinsic::experimental_vp_strided_load:
1010 return II->getType();
1011 case Intrinsic::masked_store:
1012 case Intrinsic::masked_scatter:
1013 case Intrinsic::masked_compressstore:
1014 case Intrinsic::vp_store:
1015 case Intrinsic::vp_scatter:
1016 case Intrinsic::experimental_vp_strided_store:
1017 return II->getOperand(0)->getType();
1018 default:
1019 break;
1020 }
1021 }
1022 }
1023
1024 return nullptr;
1025}
1026
1028 bool IncludePhaseOneUnwind) {
1029 // Because phase one unwinding skips cleanup landingpads, we effectively
1030 // unwind past this frame, and callers need to have valid unwind info.
1031 if (LP->isCleanup())
1032 return IncludePhaseOneUnwind;
1033
1034 for (unsigned I = 0; I < LP->getNumClauses(); ++I) {
1035 Constant *Clause = LP->getClause(I);
1036 // catch ptr null catches all exceptions.
1037 if (LP->isCatch(I) && isa<ConstantPointerNull>(Clause))
1038 return false;
1039 // filter [0 x ptr] catches all exceptions.
1040 if (LP->isFilter(I) && Clause->getType()->getArrayNumElements() == 0)
1041 return false;
1042 }
1043
1044 // May catch only some subset of exceptions, in which case other exceptions
1045 // will continue unwinding.
1046 return true;
1047}
1048
1049bool Instruction::mayThrow(bool IncludePhaseOneUnwind) const {
1050 switch (getOpcode()) {
1051 case Instruction::Call:
1052 return !cast<CallInst>(this)->doesNotThrow();
1053 case Instruction::CleanupRet:
1054 return cast<CleanupReturnInst>(this)->unwindsToCaller();
1055 case Instruction::CatchSwitch:
1056 return cast<CatchSwitchInst>(this)->unwindsToCaller();
1057 case Instruction::Resume:
1058 return true;
1059 case Instruction::Invoke: {
1060 // Landingpads themselves don't unwind -- however, an invoke of a skipped
1061 // landingpad may continue unwinding.
1062 BasicBlock *UnwindDest = cast<InvokeInst>(this)->getUnwindDest();
1063 Instruction *Pad = UnwindDest->getFirstNonPHI();
1064 if (auto *LP = dyn_cast<LandingPadInst>(Pad))
1065 return canUnwindPastLandingPad(LP, IncludePhaseOneUnwind);
1066 return false;
1067 }
1068 case Instruction::CleanupPad:
1069 // Treat the same as cleanup landingpad.
1070 return IncludePhaseOneUnwind;
1071 default:
1072 return false;
1073 }
1074}
1075
1077 return mayWriteToMemory() || mayThrow() || !willReturn();
1078}
1079
1081 return (!isa<CallInst>(this) || !this->mayHaveSideEffects()) &&
1082 !this->isTerminator() && !this->isEHPad();
1083}
1084
1086 // Volatile store isn't guaranteed to return; see LangRef.
1087 if (auto *SI = dyn_cast<StoreInst>(this))
1088 return !SI->isVolatile();
1089
1090 if (const auto *CB = dyn_cast<CallBase>(this))
1091 return CB->hasFnAttr(Attribute::WillReturn);
1092 return true;
1093}
1094
1096 auto *II = dyn_cast<IntrinsicInst>(this);
1097 if (!II)
1098 return false;
1099 Intrinsic::ID ID = II->getIntrinsicID();
1100 return ID == Intrinsic::lifetime_start || ID == Intrinsic::lifetime_end;
1101}
1102
1104 auto *II = dyn_cast<IntrinsicInst>(this);
1105 if (!II)
1106 return false;
1107 Intrinsic::ID ID = II->getIntrinsicID();
1108 return ID == Intrinsic::launder_invariant_group ||
1109 ID == Intrinsic::strip_invariant_group;
1110}
1111
1113 return isa<DbgInfoIntrinsic>(this) || isa<PseudoProbeInst>(this);
1114}
1115
1116const Instruction *
1118 for (const Instruction *I = getNextNode(); I; I = I->getNextNode())
1119 if (!isa<DbgInfoIntrinsic>(I) && !(SkipPseudoOp && isa<PseudoProbeInst>(I)))
1120 return I;
1121 return nullptr;
1122}
1123
1124const Instruction *
1126 for (const Instruction *I = getPrevNode(); I; I = I->getPrevNode())
1127 if (!isa<DbgInfoIntrinsic>(I) && !(SkipPseudoOp && isa<PseudoProbeInst>(I)))
1128 return I;
1129 return nullptr;
1130}
1131
1133 if (isa<DbgInfoIntrinsic>(this))
1134 if (const Instruction *Next = getNextNonDebugInstruction())
1135 return Next->getDebugLoc();
1136 return getDebugLoc();
1137}
1138
1140 if (auto *II = dyn_cast<IntrinsicInst>(this))
1141 return II->isAssociative();
1142 unsigned Opcode = getOpcode();
1143 if (isAssociative(Opcode))
1144 return true;
1145
1146 switch (Opcode) {
1147 case FMul:
1148 case FAdd:
1149 return cast<FPMathOperator>(this)->hasAllowReassoc() &&
1150 cast<FPMathOperator>(this)->hasNoSignedZeros();
1151 default:
1152 return false;
1153 }
1154}
1155
1157 if (auto *II = dyn_cast<IntrinsicInst>(this))
1158 return II->isCommutative();
1159 // TODO: Should allow icmp/fcmp?
1160 return isCommutative(getOpcode());
1161}
1162
1164 switch (getOpcode()) {
1165#define HANDLE_TERM_INST(N, OPC, CLASS) \
1166 case Instruction::OPC: \
1167 return static_cast<const CLASS *>(this)->getNumSuccessors();
1168#include "llvm/IR/Instruction.def"
1169 default:
1170 break;
1171 }
1172 llvm_unreachable("not a terminator");
1173}
1174
1176 switch (getOpcode()) {
1177#define HANDLE_TERM_INST(N, OPC, CLASS) \
1178 case Instruction::OPC: \
1179 return static_cast<const CLASS *>(this)->getSuccessor(idx);
1180#include "llvm/IR/Instruction.def"
1181 default:
1182 break;
1183 }
1184 llvm_unreachable("not a terminator");
1185}
1186
1188 switch (getOpcode()) {
1189#define HANDLE_TERM_INST(N, OPC, CLASS) \
1190 case Instruction::OPC: \
1191 return static_cast<CLASS *>(this)->setSuccessor(idx, B);
1192#include "llvm/IR/Instruction.def"
1193 default:
1194 break;
1195 }
1196 llvm_unreachable("not a terminator");
1197}
1198
1200 for (unsigned Idx = 0, NumSuccessors = Instruction::getNumSuccessors();
1201 Idx != NumSuccessors; ++Idx)
1202 if (getSuccessor(Idx) == OldBB)
1203 setSuccessor(Idx, NewBB);
1204}
1205
1206Instruction *Instruction::cloneImpl() const {
1207 llvm_unreachable("Subclass of Instruction failed to implement cloneImpl");
1208}
1209
1211 MDNode *ProfileData = getBranchWeightMDNode(*this);
1212 if (!ProfileData || ProfileData->getNumOperands() != 3)
1213 return;
1214
1215 // The first operand is the name. Fetch them backwards and build a new one.
1216 Metadata *Ops[] = {ProfileData->getOperand(0), ProfileData->getOperand(2),
1217 ProfileData->getOperand(1)};
1218 setMetadata(LLVMContext::MD_prof,
1219 MDNode::get(ProfileData->getContext(), Ops));
1220}
1221
1223 ArrayRef<unsigned> WL) {
1224 if (!SrcInst.hasMetadata())
1225 return;
1226
1227 SmallDenseSet<unsigned, 4> WLS(WL.begin(), WL.end());
1228
1229 // Otherwise, enumerate and copy over metadata from the old instruction to the
1230 // new one.
1232 SrcInst.getAllMetadataOtherThanDebugLoc(TheMDs);
1233 for (const auto &MD : TheMDs) {
1234 if (WL.empty() || WLS.count(MD.first))
1235 setMetadata(MD.first, MD.second);
1236 }
1237 if (WL.empty() || WLS.count(LLVMContext::MD_dbg))
1238 setDebugLoc(SrcInst.getDebugLoc());
1239}
1240
1242 Instruction *New = nullptr;
1243 switch (getOpcode()) {
1244 default:
1245 llvm_unreachable("Unhandled Opcode.");
1246#define HANDLE_INST(num, opc, clas) \
1247 case Instruction::opc: \
1248 New = cast<clas>(this)->cloneImpl(); \
1249 break;
1250#include "llvm/IR/Instruction.def"
1251#undef HANDLE_INST
1252 }
1253
1254 New->SubclassOptionalData = SubclassOptionalData;
1255 New->copyMetadata(*this);
1256 return New;
1257}
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:442
DPMarker * getMarker(InstListType::iterator It)
Return the DPMarker for the position given by It, so that DbgRecords can be inserted there.
void deleteTrailingDbgRecords()
Delete any trailing DbgRecords at the end of this block, see setTrailingDbgRecords.
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:396
void renumberInstructions()
Renumber instructions and mark the ordering as valid.
Definition: BasicBlock.cpp:686
const Instruction * getFirstNonPHI() const
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
Definition: BasicBlock.cpp:347
DPMarker * createMarker(Instruction *I)
Attach a DPMarker to the given instruction.
Definition: BasicBlock.cpp:44
void flushTerminatorDbgRecords()
Eject any debug-info trailing at the end of a block.
Definition: BasicBlock.cpp:699
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:205
InstListType::iterator iterator
Instruction iterators...
Definition: BasicBlock.h:164
bool IsNewDbgInfoFormat
Flag recording whether or not this block stores debug-info in the form of intrinsic instructions (fal...
Definition: BasicBlock.h:65
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:681
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:276
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:955
This is an important base class in LLVM.
Definition: Constant.h:41
Per-instruction record of debug-info.
void dropDbgRecords()
Erase all DbgRecords in this DPMarker.
Instruction * MarkedInstr
Link back to the Instruction that owns this marker.
void dropOneDbgRecord(DbgRecord *DR)
Erase a single DbgRecord from this marker.
static iterator_range< simple_ilist< DbgRecord >::iterator > getEmptyDbgRecordRange()
void absorbDebugValues(DPMarker &Src, bool InsertAtHead)
Transfer any DbgRecords from Src into this DPMarker.
simple_ilist< DbgRecord > StoredDbgRecords
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:88
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...
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.
iterator_range< simple_ilist< DbgRecord >::iterator > getDbgRecordRange() const
Return a range over the DbgRecords attached to this instruction.
Definition: Instruction.h:83
void insertBefore(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified instruction.
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
Definition: Instruction.h:453
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
Definition: Instruction.cpp:80
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:340
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:801
const BasicBlock * getParent() const
Definition: Instruction.h:151
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:84
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 dropOneDbgRecord(DbgRecord *I)
Erase a single DbgRecord I that is attached to this instruction.
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:254
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...
void adoptDbgRecords(BasicBlock *BB, InstListType::iterator It, bool InsertAtHead)
Transfer any DbgRecords on the position It onto this instruction, by simply adopting the sequence of ...
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:253
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:867
@ CompareUsingScalarTypes
Check for equivalence treating a type and a vector of that type as equivalent.
Definition: Instruction.h:870
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:383
void moveAfterPreserving(Instruction *MovePos)
See moveBeforePreserving .
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
Definition: Instruction.h:251
bool hasAtomicLoad() const LLVM_READONLY
Return true if this atomic instruction loads from memory.
void dropUnknownNonDebugMetadata()
Definition: Instruction.h:414
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.
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:95
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" DbgRecord after this instruction,...
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.
Instruction(const Instruction &)=delete
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
Definition: Instruction.h:450
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 dropDbgRecords()
Erase any DbgRecords attached to this instruction.
void insertAfter(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately after the specified 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...
bool hasDbgRecords() const
Returns true if any DbgRecords are attached to this instruction.
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:936
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.