LLVM 23.0.0git
BasicBlock.cpp
Go to the documentation of this file.
1//===-- BasicBlock.cpp - Implement BasicBlock related methods -------------===//
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 BasicBlock class for the IR library.
10//
11//===----------------------------------------------------------------------===//
12
13#include "llvm/IR/BasicBlock.h"
15#include "llvm/ADT/STLExtras.h"
16#include "llvm/ADT/Statistic.h"
17#include "llvm/IR/CFG.h"
18#include "llvm/IR/Constants.h"
22#include "llvm/IR/LLVMContext.h"
23#include "llvm/IR/Type.h"
25
26#include "LLVMContextImpl.h"
27
28using namespace llvm;
29
30#define DEBUG_TYPE "ir"
31STATISTIC(NumInstrRenumberings, "Number of renumberings across all blocks");
32
34 if (I->DebugMarker)
35 return I->DebugMarker;
36 DbgMarker *Marker = new DbgMarker();
37 Marker->MarkedInstr = I;
38 I->DebugMarker = Marker;
39 return Marker;
40}
41
42DbgMarker *BasicBlock::createMarker(InstListType::iterator It) {
43 if (It != end())
44 return createMarker(&*It);
45 DbgMarker *DM = getTrailingDbgRecords();
46 if (DM)
47 return DM;
48 DM = new DbgMarker();
49 setTrailingDbgRecords(DM);
50 return DM;
51}
52
54 // Iterate over all instructions in the instruction list, collecting debug
55 // info intrinsics and converting them to DbgRecords. Once we find a "real"
56 // instruction, attach all those DbgRecords to a DbgMarker in that
57 // instruction.
59 for (Instruction &I : make_early_inc_range(InstList)) {
61 // Convert this dbg.value to a DbgVariableRecord.
62 DbgVariableRecord *Value = new DbgVariableRecord(DVI);
63 DbgVarRecs.push_back(Value);
64 DVI->eraseFromParent();
65 continue;
66 }
67
69 DbgVarRecs.push_back(
70 new DbgLabelRecord(DLI->getLabel(), DLI->getDebugLoc()));
71 DLI->eraseFromParent();
72 continue;
73 }
74
75 if (DbgVarRecs.empty())
76 continue;
77
78 // Create a marker to store DbgRecords in.
79 createMarker(&I);
80 DbgMarker *Marker = I.DebugMarker;
81
82 for (DbgRecord *DVR : DbgVarRecs)
83 Marker->insertDbgRecord(DVR, false);
84
85 DbgVarRecs.clear();
86 }
87}
88
90 invalidateOrders();
91
92 // Iterate over the block, finding instructions annotated with DbgMarkers.
93 // Convert any attached DbgRecords to debug intrinsics and insert ahead of the
94 // instruction.
95 for (auto &Inst : *this) {
96 if (!Inst.DebugMarker)
97 continue;
98
99 DbgMarker &Marker = *Inst.DebugMarker;
100 for (DbgRecord &DR : Marker.getDbgRecordRange())
101 InstList.insert(Inst.getIterator(),
102 DR.createDebugIntrinsic(getModule(), nullptr));
103
104 Marker.eraseFromParent();
105 }
106
107 // Assume no trailing DbgRecords: we could technically create them at the end
108 // of the block, after a terminator, but this would be non-cannonical and
109 // indicates that something else is broken somewhere.
110 assert(!getTrailingDbgRecords());
111}
112
113#ifndef NDEBUG
114void BasicBlock::dumpDbgValues() const {
115 for (auto &Inst : *this) {
116 if (!Inst.DebugMarker)
117 continue;
118
119 dbgs() << "@ " << Inst.DebugMarker << " ";
120 Inst.DebugMarker->dump();
121 };
122}
123#endif
124
126 if (Function *F = getParent())
127 return F->getValueSymbolTable();
128 return nullptr;
129}
130
132 return getType()->getContext();
133}
134
136 BB->invalidateOrders();
137}
138
139// Explicit instantiation of SymbolTableListTraits since some of the methods
140// are not in the public header file...
141template class llvm::SymbolTableListTraits<
143
144BasicBlock::BasicBlock(LLVMContext &C, const Twine &Name, Function *NewParent,
145 BasicBlock *InsertBefore)
146 : Value(Type::getLabelTy(C), Value::BasicBlockVal), Parent(nullptr) {
147
148 if (NewParent)
149 insertInto(NewParent, InsertBefore);
150 else
151 assert(!InsertBefore &&
152 "Cannot insert block before another block with no function!");
153
154 end().getNodePtr()->setParent(this);
155 setName(Name);
156}
157
158void BasicBlock::insertInto(Function *NewParent, BasicBlock *InsertBefore) {
159 assert(NewParent && "Expected a parent");
160 assert(!Parent && "Already has a parent");
161
162 if (InsertBefore)
163 NewParent->insert(InsertBefore->getIterator(), this);
164 else
165 NewParent->insert(NewParent->end(), this);
166}
167
169 validateInstrOrdering();
170
171 // If the address of the block is taken and it is being deleted (e.g. because
172 // it is dead), this means that there is either a dangling constant expr
173 // hanging off the block, or an undefined use of the block (source code
174 // expecting the address of a label to keep the block alive even though there
175 // is no indirect branch). Handle these cases by zapping the BlockAddress
176 // nodes. There are no other possible uses at this point.
177 if (hasAddressTaken()) {
178 assert(!use_empty() && "There should be at least one blockaddress!");
179 BlockAddress *BA = cast<BlockAddress>(user_back());
180
181 Constant *Replacement = ConstantInt::get(Type::getInt32Ty(getContext()), 1);
183 ConstantExpr::getIntToPtr(Replacement, BA->getType()));
184 BA->destroyConstant();
185 }
186
187 assert(getParent() == nullptr && "BasicBlock still linked into the program!");
188 dropAllReferences();
189 for (auto &Inst : *this) {
190 if (!Inst.DebugMarker)
191 continue;
192 Inst.DebugMarker->eraseFromParent();
193 }
194 InstList.clear();
195}
196
197void BasicBlock::setParent(Function *parent) {
198 // Set Parent=parent, updating instruction symtab entries as appropriate.
199 if (Parent != parent)
200 Number = parent ? parent->NextBlockNum++ : -1u;
201 InstList.setSymTabObject(&Parent, parent);
202}
203
205 std::function<bool(const Instruction &)>>>
206BasicBlock::instructionsWithoutDebug(bool SkipPseudoOp) const {
207 std::function<bool(const Instruction &)> Fn = [=](const Instruction &I) {
208 return !isa<DbgInfoIntrinsic>(I) &&
209 !(SkipPseudoOp && isa<PseudoProbeInst>(I));
210 };
211 return make_filter_range(*this, Fn);
212}
213
216BasicBlock::instructionsWithoutDebug(bool SkipPseudoOp) {
217 std::function<bool(Instruction &)> Fn = [=](Instruction &I) {
218 return !isa<DbgInfoIntrinsic>(I) &&
219 !(SkipPseudoOp && isa<PseudoProbeInst>(I));
220 };
221 return make_filter_range(*this, Fn);
222}
223
225 std::function<bool(const Instruction &)>>::difference_type
227 return std::distance(instructionsWithoutDebug().begin(),
229}
230
232 getParent()->getBasicBlockList().remove(getIterator());
233}
234
236 return getParent()->getBasicBlockList().erase(getIterator());
237}
238
240 getParent()->splice(MovePos, getParent(), getIterator());
241}
242
243void BasicBlock::moveAfter(BasicBlock *MovePos) {
244 MovePos->getParent()->splice(++MovePos->getIterator(), getParent(),
245 getIterator());
246}
247
248const Module *BasicBlock::getModule() const {
249 return getParent()->getParent();
250}
251
253 return getModule()->getDataLayout();
254}
255
257 if (InstList.empty())
258 return nullptr;
259 const ReturnInst *RI = dyn_cast<ReturnInst>(&InstList.back());
260 if (!RI || RI == &InstList.front())
261 return nullptr;
262
263 const Instruction *Prev = RI->getPrevNode();
264 if (!Prev)
265 return nullptr;
266
267 if (Value *RV = RI->getReturnValue()) {
268 if (RV != Prev)
269 return nullptr;
270
271 // Look through the optional bitcast.
272 if (auto *BI = dyn_cast<BitCastInst>(Prev)) {
273 RV = BI->getOperand(0);
274 Prev = BI->getPrevNode();
275 if (!Prev || RV != Prev)
276 return nullptr;
277 }
278 }
279
280 if (auto *CI = dyn_cast<CallInst>(Prev)) {
281 if (CI->isMustTailCall())
282 return CI;
283 }
284 return nullptr;
285}
286
288 if (InstList.empty())
289 return nullptr;
290 auto *RI = dyn_cast<ReturnInst>(&InstList.back());
291 if (!RI || RI == &InstList.front())
292 return nullptr;
293
294 if (auto *CI = dyn_cast_or_null<CallInst>(RI->getPrevNode()))
295 if (Function *F = CI->getCalledFunction())
296 if (F->getIntrinsicID() == Intrinsic::experimental_deoptimize)
297 return CI;
298
299 return nullptr;
300}
301
303 const BasicBlock* BB = this;
305 Visited.insert(BB);
306 while (auto *Succ = BB->getUniqueSuccessor()) {
307 if (!Visited.insert(Succ).second)
308 return nullptr;
309 BB = Succ;
310 }
311 return BB->getTerminatingDeoptimizeCall();
312}
313
315 if (InstList.empty())
316 return nullptr;
317 for (const Instruction &I : *this)
319 return &I;
320 return nullptr;
321}
322
323const Instruction* BasicBlock::getFirstNonPHI() const {
324 for (const Instruction &I : *this)
325 if (!isa<PHINode>(I))
326 return &I;
327 return nullptr;
328}
329
330Instruction *BasicBlock::getFirstNonPHI() {
331 for (Instruction &I : *this)
332 if (!isa<PHINode>(I))
333 return &I;
334 return nullptr;
335}
336
338 for (const Instruction &I : *this) {
339 if (isa<PHINode>(I))
340 continue;
341
342 BasicBlock::const_iterator It = I.getIterator();
343 // Set the head-inclusive bit to indicate that this iterator includes
344 // any debug-info at the start of the block. This is a no-op unless the
345 // appropriate CMake flag is set.
346 It.setHeadBit(true);
347 return It;
348 }
349
350 return end();
351}
352
354BasicBlock::getFirstNonPHIOrDbg(bool SkipPseudoOp) const {
355 for (const Instruction &I : *this) {
357 continue;
358
359 if (SkipPseudoOp && isa<PseudoProbeInst>(I))
360 continue;
361
362 BasicBlock::const_iterator It = I.getIterator();
363 // This position comes after any debug records, the head bit should remain
364 // unset.
365 assert(!It.getHeadBit());
366 return It;
367 }
368 return end();
369}
370
372BasicBlock::getFirstNonPHIOrDbgOrLifetime(bool SkipPseudoOp) const {
373 for (const Instruction &I : *this) {
375 continue;
376
377 if (I.isLifetimeStartOrEnd())
378 continue;
379
380 if (SkipPseudoOp && isa<PseudoProbeInst>(I))
381 continue;
382
383 BasicBlock::const_iterator It = I.getIterator();
384 // This position comes after any debug records, the head bit should remain
385 // unset.
386 assert(!It.getHeadBit());
387
388 return It;
389 }
390 return end();
391}
392
394 const_iterator InsertPt = getFirstNonPHIIt();
395 if (InsertPt == end())
396 return end();
397
398 if (InsertPt->isEHPad()) ++InsertPt;
399 // Set the head-inclusive bit to indicate that this iterator includes
400 // any debug-info at the start of the block. This is a no-op unless the
401 // appropriate CMake flag is set.
402 InsertPt.setHeadBit(true);
403 return InsertPt;
404}
405
407 const_iterator InsertPt = getFirstNonPHIIt();
408 if (InsertPt == end())
409 return end();
410
411 if (InsertPt->isEHPad())
412 ++InsertPt;
413
414 if (isEntryBlock()) {
415 const_iterator End = end();
416 while (InsertPt != End &&
417 (isa<AllocaInst>(*InsertPt) || isa<DbgInfoIntrinsic>(*InsertPt) ||
418 isa<PseudoProbeInst>(*InsertPt))) {
419 if (const AllocaInst *AI = dyn_cast<AllocaInst>(&*InsertPt)) {
420 if (!AI->isStaticAlloca())
421 break;
422 }
423 ++InsertPt;
424 }
425 }
426
427 // Signal that this comes after any debug records.
428 InsertPt.setHeadBit(false);
429 return InsertPt;
430}
431
433 for (Instruction &I : *this)
434 I.dropAllReferences();
435}
436
438 const_pred_iterator PI = pred_begin(this), E = pred_end(this);
439 if (PI == E) return nullptr; // No preds.
440 const BasicBlock *ThePred = *PI;
441 ++PI;
442 return (PI == E) ? ThePred : nullptr /*multiple preds*/;
443}
444
446 const_pred_iterator PI = pred_begin(this), E = pred_end(this);
447 if (PI == E) return nullptr; // No preds.
448 const BasicBlock *PredBB = *PI;
449 ++PI;
450 for (;PI != E; ++PI) {
451 if (*PI != PredBB)
452 return nullptr;
453 // The same predecessor appears multiple times in the predecessor list.
454 // This is OK.
455 }
456 return PredBB;
457}
458
459bool BasicBlock::hasNPredecessors(unsigned N) const {
460 return hasNItems(pred_begin(this), pred_end(this), N);
461}
462
463bool BasicBlock::hasNPredecessorsOrMore(unsigned N) const {
464 return hasNItemsOrMore(pred_begin(this), pred_end(this), N);
465}
466
468 const_succ_iterator SI = succ_begin(this), E = succ_end(this);
469 if (SI == E) return nullptr; // no successors
470 const BasicBlock *TheSucc = *SI;
471 ++SI;
472 return (SI == E) ? TheSucc : nullptr /* multiple successors */;
473}
474
476 const_succ_iterator SI = succ_begin(this), E = succ_end(this);
477 if (SI == E) return nullptr; // No successors
478 const BasicBlock *SuccBB = *SI;
479 ++SI;
480 for (;SI != E; ++SI) {
481 if (*SI != SuccBB)
482 return nullptr;
483 // The same successor appears multiple times in the successor list.
484 // This is OK.
485 }
486 return SuccBB;
487}
488
490 PHINode *P = empty() ? nullptr : dyn_cast<PHINode>(&*begin());
491 return make_range<phi_iterator>(P, nullptr);
492}
493
495 bool KeepOneInputPHIs) {
496 // Use hasNUsesOrMore to bound the cost of this assertion for complex CFGs.
497 assert((hasNUsesOrMore(16) || llvm::is_contained(predecessors(this), Pred)) &&
498 "Pred is not a predecessor!");
499
500 // Return early if there are no PHI nodes to update.
501 if (empty() || !isa<PHINode>(begin()))
502 return;
503
504 unsigned NumPreds = cast<PHINode>(front()).getNumIncomingValues();
505 for (PHINode &Phi : make_early_inc_range(phis())) {
506 Phi.removeIncomingValue(Pred, !KeepOneInputPHIs);
507 if (KeepOneInputPHIs)
508 continue;
509
510 // If we have a single predecessor, removeIncomingValue may have erased the
511 // PHI node itself.
512 if (NumPreds == 1)
513 continue;
514
515 // Try to replace the PHI node with a constant value.
516 if (Value *PhiConstant = Phi.hasConstantValue()) {
517 Phi.replaceAllUsesWith(PhiConstant);
518 Phi.eraseFromParent();
519 }
520 }
521}
522
524 const_iterator FirstNonPHI = getFirstNonPHIIt();
525 if (isa<LandingPadInst>(FirstNonPHI))
526 return true;
527 // This is perhaps a little conservative because constructs like
528 // CleanupBlockInst are pretty easy to split. However, SplitBlockPredecessors
529 // cannot handle such things just yet.
530 if (FirstNonPHI->isEHPad())
531 return false;
532 return true;
533}
534
536 auto *Term = getTerminator();
537 // No terminator means the block is under construction.
538 if (!Term)
539 return true;
540
541 // If the block has no successors, there can be no instructions to hoist.
542 assert(Term->getNumSuccessors() > 0);
543
544 // Instructions should not be hoisted across special terminators, which may
545 // have side effects or return values.
546 return !Term->isSpecialTerminator();
547}
548
549bool BasicBlock::isEntryBlock() const {
550 const Function *F = getParent();
551 assert(F && "Block must have a parent function to use this API");
552 return this == &F->getEntryBlock();
553}
554
555BasicBlock *BasicBlock::splitBasicBlock(iterator I, const Twine &BBName) {
556 assert(getTerminator() && "Can't use splitBasicBlock on degenerate BB!");
557 assert(I != InstList.end() &&
558 "Trying to get me to create degenerate basic block!");
559
561 this->getNextNode());
562
563 // Save DebugLoc of split point before invalidating iterator.
564 DebugLoc Loc = I->getStableDebugLoc();
565 if (Loc)
566 Loc = Loc->getWithoutAtom();
567
568 // Move all of the specified instructions from the original basic block into
569 // the new basic block.
570 New->splice(New->end(), this, I, end());
571
572 // Add a branch instruction to the newly formed basic block.
573 BranchInst *BI = BranchInst::Create(New, this);
574 BI->setDebugLoc(Loc);
575
576 // Now we must loop through all of the successors of the New block (which
577 // _were_ the successors of the 'this' block), and update any PHI nodes in
578 // successors. If there were PHI nodes in the successors, then they need to
579 // know that incoming branches will be from New, not from Old (this).
580 //
581 New->replaceSuccessorsPhiUsesWith(this, New);
582 return New;
583}
584
585BasicBlock *BasicBlock::splitBasicBlockBefore(iterator I, const Twine &BBName) {
587 "Can't use splitBasicBlockBefore on degenerate BB!");
588 assert(I != InstList.end() &&
589 "Trying to get me to create degenerate basic block!");
590
591 assert((!isa<PHINode>(*I) || getSinglePredecessor()) &&
592 "cannot split on multi incoming phis");
593
595 // Save DebugLoc of split point before invalidating iterator.
596 DebugLoc Loc = I->getDebugLoc();
597 if (Loc)
598 Loc = Loc->getWithoutAtom();
599
600 // Move all of the specified instructions from the original basic block into
601 // the new basic block.
602 New->splice(New->end(), this, begin(), I);
603
604 // Loop through all of the predecessors of the 'this' block (which will be the
605 // predecessors of the New block), replace the specified successor 'this'
606 // block to point at the New block and update any PHI nodes in 'this' block.
607 // If there were PHI nodes in 'this' block, the PHI nodes are updated
608 // to reflect that the incoming branches will be from the New block and not
609 // from predecessors of the 'this' block.
610 // Save predecessors to separate vector before modifying them.
611 SmallVector<BasicBlock *, 4> Predecessors(predecessors(this));
612 for (BasicBlock *Pred : Predecessors) {
613 Instruction *TI = Pred->getTerminator();
614 TI->replaceSuccessorWith(this, New);
615 this->replacePhiUsesWith(Pred, New);
616 }
617 // Add a branch instruction from "New" to "this" Block.
618 BranchInst *BI = BranchInst::Create(this, New);
619 BI->setDebugLoc(Loc);
620
621 return New;
622}
623
626 for (Instruction &I : make_early_inc_range(make_range(FromIt, ToIt)))
627 I.eraseFromParent();
628 return ToIt;
629}
630
632 // N.B. This might not be a complete BasicBlock, so don't assume
633 // that it ends with a non-phi instruction.
634 for (Instruction &I : *this) {
636 if (!PN)
637 break;
638 PN->replaceIncomingBlockWith(Old, New);
639 }
640}
641
643 BasicBlock *New) {
645 if (!TI)
646 // Cope with being called on a BasicBlock that doesn't have a terminator
647 // yet. Clang's CodeGenFunction::EmitReturnBlock() likes to do this.
648 return;
649 for (BasicBlock *Succ : successors(TI))
650 Succ->replacePhiUsesWith(Old, New);
651}
652
654 this->replaceSuccessorsPhiUsesWith(this, New);
655}
656
657bool BasicBlock::isLandingPad() const {
658 return isa<LandingPadInst>(getFirstNonPHIIt());
659}
660
662 return dyn_cast<LandingPadInst>(getFirstNonPHIIt());
663}
664
665std::optional<uint64_t> BasicBlock::getIrrLoopHeaderWeight() const {
666 const Instruction *TI = getTerminator();
667 if (MDNode *MDIrrLoopHeader =
668 TI->getMetadata(LLVMContext::MD_irr_loop)) {
669 MDString *MDName = cast<MDString>(MDIrrLoopHeader->getOperand(0));
670 if (MDName->getString() == "loop_header_weight") {
671 auto *CI = mdconst::extract<ConstantInt>(MDIrrLoopHeader->getOperand(1));
672 return std::optional<uint64_t>(CI->getValue().getZExtValue());
673 }
674 }
675 return std::nullopt;
676}
677
679 while (isa<DbgInfoIntrinsic>(It))
680 ++It;
681 return It;
682}
683
685 unsigned Order = 0;
686 for (Instruction &I : *this)
687 I.Order = Order++;
688
689 // Set the bit to indicate that the instruction order valid and cached.
690 SubclassOptionalData |= InstrOrderValid;
691
692 NumInstrRenumberings++;
693}
694
696 // If we erase the terminator in a block, any DbgRecords will sink and "fall
697 // off the end", existing after any terminator that gets inserted. With
698 // dbg.value intrinsics we would just insert the terminator at end() and
699 // the dbg.values would come before the terminator. With DbgRecords, we must
700 // do this manually.
701 // To get out of this unfortunate form, whenever we insert a terminator,
702 // check whether there's anything trailing at the end and move those
703 // DbgRecords in front of the terminator.
704
705 // If there's no terminator, there's nothing to do.
707 if (!Term)
708 return;
709
710 // Are there any dangling DbgRecords?
711 DbgMarker *TrailingDbgRecords = getTrailingDbgRecords();
712 if (!TrailingDbgRecords)
713 return;
714
715 // Transfer DbgRecords from the trailing position onto the terminator.
716 createMarker(Term);
717 Term->DebugMarker->absorbDebugValues(*TrailingDbgRecords, false);
718 TrailingDbgRecords->eraseFromParent();
719 deleteTrailingDbgRecords();
720}
721
722void BasicBlock::spliceDebugInfoEmptyBlock(BasicBlock::iterator Dest,
723 BasicBlock *Src,
726 // Imagine the folowing:
727 //
728 // bb1:
729 // dbg.value(...
730 // ret i32 0
731 //
732 // If an optimisation pass attempts to splice the contents of the block from
733 // BB1->begin() to BB1->getTerminator(), then the dbg.value will be
734 // transferred to the destination.
735 // However, in the "new" DbgRecord format for debug-info, that range is empty:
736 // begin() returns an iterator to the terminator, as there will only be a
737 // single instruction in the block. We must piece together from the bits set
738 // in the iterators whether there was the intention to transfer any debug
739 // info.
740
741 assert(First == Last);
742 bool InsertAtHead = Dest.getHeadBit();
743 bool ReadFromHead = First.getHeadBit();
744
745 // If the source block is completely empty, including no terminator, then
746 // transfer any trailing DbgRecords that are still hanging around. This can
747 // occur when a block is optimised away and the terminator has been moved
748 // somewhere else.
749 if (Src->empty()) {
750 DbgMarker *SrcTrailingDbgRecords = Src->getTrailingDbgRecords();
751 if (!SrcTrailingDbgRecords)
752 return;
753
754 Dest->adoptDbgRecords(Src, Src->end(), InsertAtHead);
755 // adoptDbgRecords should have released the trailing DbgRecords.
756 assert(!Src->getTrailingDbgRecords());
757 return;
758 }
759
760 // There are instructions in this block; if the First iterator was
761 // with begin() / getFirstInsertionPt() then the caller intended debug-info
762 // at the start of the block to be transferred. Return otherwise.
763 if (Src->empty() || First != Src->begin() || !ReadFromHead)
764 return;
765
766 // Is there actually anything to transfer?
767 if (!First->hasDbgRecords())
768 return;
769
770 createMarker(Dest)->absorbDebugValues(*First->DebugMarker, InsertAtHead);
771}
772
773void BasicBlock::spliceDebugInfo(BasicBlock::iterator Dest, BasicBlock *Src,
776 /* Do a quick normalisation before calling the real splice implementation. We
777 might be operating on a degenerate basic block that has no instructions
778 in it, a legitimate transient state. In that case, Dest will be end() and
779 any DbgRecords temporarily stored in the TrailingDbgRecords map in
780 LLVMContext. We might illustrate it thus:
781
782 Dest
783 |
784 this-block: ~~~~~~~~
785 Src-block: ++++B---B---B---B:::C
786 | |
787 First Last
788
789 However: does the caller expect the "~" DbgRecords to end up before or
790 after the spliced segment? This is communciated in the "Head" bit of Dest,
791 which signals whether the caller called begin() or end() on this block.
792
793 If the head bit is set, then all is well, we leave DbgRecords trailing just
794 like how dbg.value instructions would trail after instructions spliced to
795 the beginning of this block.
796
797 If the head bit isn't set, then try to jam the "~" DbgRecords onto the
798 front of the First instruction, then splice like normal, which joins the
799 "~" DbgRecords with the "+" DbgRecords. However if the "+" DbgRecords are
800 supposed to be left behind in Src, then:
801 * detach the "+" DbgRecords,
802 * move the "~" DbgRecords onto First,
803 * splice like normal,
804 * replace the "+" DbgRecords onto the Last position.
805 Complicated, but gets the job done. */
806
807 // If we're inserting at end(), and not in front of dangling DbgRecords, then
808 // move the DbgRecords onto "First". They'll then be moved naturally in the
809 // splice process.
810 DbgMarker *MoreDanglingDbgRecords = nullptr;
811 DbgMarker *OurTrailingDbgRecords = getTrailingDbgRecords();
812 if (Dest == end() && !Dest.getHeadBit() && OurTrailingDbgRecords) {
813 // Are the "+" DbgRecords not supposed to move? If so, detach them
814 // temporarily.
815 if (!First.getHeadBit() && First->hasDbgRecords()) {
816 MoreDanglingDbgRecords = Src->getMarker(First);
817 MoreDanglingDbgRecords->removeFromParent();
818 }
819
820 if (First->hasDbgRecords()) {
821 // Place them at the front, it would look like this:
822 // Dest
823 // |
824 // this-block:
825 // Src-block: ~~~~~~~~++++B---B---B---B:::C
826 // | |
827 // First Last
828 First->adoptDbgRecords(this, end(), true);
829 } else {
830 // No current marker, create one and absorb in. (FIXME: we can avoid an
831 // allocation in the future).
832 DbgMarker *CurMarker = Src->createMarker(&*First);
833 CurMarker->absorbDebugValues(*OurTrailingDbgRecords, false);
834 OurTrailingDbgRecords->eraseFromParent();
835 }
836 deleteTrailingDbgRecords();
837 First.setHeadBit(true);
838 }
839
840 // Call the main debug-info-splicing implementation.
841 spliceDebugInfoImpl(Dest, Src, First, Last);
842
843 // Do we have some "+" DbgRecords hanging around that weren't supposed to
844 // move, and we detached to make things easier?
845 if (!MoreDanglingDbgRecords)
846 return;
847
848 // FIXME: we could avoid an allocation here sometimes. (adoptDbgRecords
849 // requires an iterator).
850 DbgMarker *LastMarker = Src->createMarker(Last);
851 LastMarker->absorbDebugValues(*MoreDanglingDbgRecords, true);
852 MoreDanglingDbgRecords->eraseFromParent();
853}
854
855void BasicBlock::spliceDebugInfoImpl(BasicBlock::iterator Dest, BasicBlock *Src,
858 // Find out where to _place_ these dbg.values; if InsertAtHead is specified,
859 // this will be at the start of Dest's debug value range, otherwise this is
860 // just Dest's marker.
861 bool InsertAtHead = Dest.getHeadBit();
862 bool ReadFromHead = First.getHeadBit();
863 // Use this flag to signal the abnormal case, where we don't want to copy the
864 // DbgRecords ahead of the "Last" position.
865 bool ReadFromTail = !Last.getTailBit();
866 bool LastIsEnd = (Last == Src->end());
867
868 /*
869 Here's an illustration of what we're about to do. We have two blocks, this
870 and Src, and two segments of list. Each instruction is marked by a capital
871 while potential DbgRecord debug-info is marked out by "-" characters and a
872 few other special characters (+:=) where I want to highlight what's going
873 on.
874
875 Dest
876 |
877 this-block: A----A----A ====A----A----A----A---A---A
878 Src-block ++++B---B---B---B:::C
879 | |
880 First Last
881
882 The splice method is going to take all the instructions from First up to
883 (but not including) Last and insert them in _front_ of Dest, forming one
884 long list. All the DbgRecords attached to instructions _between_ First and
885 Last need no maintenence. However, we have to do special things with the
886 DbgRecords marked with the +:= characters. We only have three positions:
887 should the "+" DbgRecords be transferred, and if so to where? Do we move the
888 ":" DbgRecords? Would they go in front of the "=" DbgRecords, or should the
889 "=" DbgRecords go before "+" DbgRecords?
890
891 We're told which way it should be by the bits carried in the iterators. The
892 "Head" bit indicates whether the specified position is supposed to be at the
893 front of the attached DbgRecords (true) or not (false). The Tail bit is true
894 on the other end of a range: is the range intended to include DbgRecords up
895 to the end (false) or not (true).
896
897 FIXME: the tail bit doesn't need to be distinct from the head bit, we could
898 combine them.
899
900 Here are some examples of different configurations:
901
902 Dest.Head = true, First.Head = true, Last.Tail = false
903
904 this-block: A----A----A++++B---B---B---B:::====A----A----A----A---A---A
905 | |
906 First Dest
907
908 Wheras if we didn't want to read from the Src list,
909
910 Dest.Head = true, First.Head = false, Last.Tail = false
911
912 this-block: A----A----AB---B---B---B:::====A----A----A----A---A---A
913 | |
914 First Dest
915
916 Or if we didn't want to insert at the head of Dest:
917
918 Dest.Head = false, First.Head = false, Last.Tail = false
919
920 this-block: A----A----A====B---B---B---B:::A----A----A----A---A---A
921 | |
922 First Dest
923
924 Tests for these various configurations can be found in the unit test file
925 BasicBlockDbgInfoTest.cpp.
926
927 */
928
929 // Detach the marker at Dest -- this lets us move the "====" DbgRecords
930 // around.
931 DbgMarker *DestMarker = nullptr;
932 if ((DestMarker = getMarker(Dest))) {
933 if (Dest == end()) {
934 assert(DestMarker == getTrailingDbgRecords());
935 deleteTrailingDbgRecords();
936 } else {
937 DestMarker->removeFromParent();
938 }
939 }
940
941 // If we're moving the tail range of DbgRecords (":::"), absorb them into the
942 // front of the DbgRecords at Dest.
943 if (ReadFromTail && Src->getMarker(Last)) {
944 DbgMarker *FromLast = Src->getMarker(Last);
945 if (LastIsEnd) {
946 if (Dest == end()) {
947 // Abosrb the trailing markers from Src.
948 assert(FromLast == Src->getTrailingDbgRecords());
949 createMarker(Dest)->absorbDebugValues(*FromLast, true);
950 FromLast->eraseFromParent();
951 Src->deleteTrailingDbgRecords();
952 } else {
953 // adoptDbgRecords will release any trailers.
954 Dest->adoptDbgRecords(Src, Last, true);
955 }
956 assert(!Src->getTrailingDbgRecords());
957 } else {
958 // FIXME: can we use adoptDbgRecords here to reduce allocations?
959 DbgMarker *OntoDest = createMarker(Dest);
960 OntoDest->absorbDebugValues(*FromLast, true);
961 }
962 }
963
964 // If we're _not_ reading from the head of First, i.e. the "++++" DbgRecords,
965 // move their markers onto Last. They remain in the Src block. No action
966 // needed.
967 if (!ReadFromHead && First->hasDbgRecords()) {
968 if (Last != Src->end()) {
969 Last->adoptDbgRecords(Src, First, true);
970 } else {
971 DbgMarker *OntoLast = Src->createMarker(Last);
972 DbgMarker *FromFirst = Src->createMarker(First);
973 // Always insert at front of Last.
974 OntoLast->absorbDebugValues(*FromFirst, true);
975 }
976 }
977
978 // Finally, do something with the "====" DbgRecords we detached.
979 if (DestMarker) {
980 if (InsertAtHead) {
981 // Insert them at the end of the DbgRecords at Dest. The "::::" DbgRecords
982 // might be in front of them.
983 DbgMarker *NewDestMarker = createMarker(Dest);
984 NewDestMarker->absorbDebugValues(*DestMarker, false);
985 } else {
986 // Insert them right at the start of the range we moved, ahead of First
987 // and the "++++" DbgRecords.
988 // This also covers the rare circumstance where we insert at end(), and we
989 // did not generate the iterator with begin() / getFirstInsertionPt(),
990 // meaning any trailing debug-info at the end of the block would
991 // "normally" have been pushed in front of "First". We move it there now.
992 DbgMarker *FirstMarker = createMarker(First);
993 FirstMarker->absorbDebugValues(*DestMarker, true);
994 }
995 DestMarker->eraseFromParent();
996 }
997}
998
999void BasicBlock::splice(iterator Dest, BasicBlock *Src, iterator First,
1000 iterator Last) {
1001#ifdef EXPENSIVE_CHECKS
1002 // Check that First is before Last.
1003 auto FromBBEnd = Src->end();
1004 for (auto It = First; It != Last; ++It)
1005 assert(It != FromBBEnd && "FromBeginIt not before FromEndIt!");
1006#endif // EXPENSIVE_CHECKS
1007
1008 // Lots of horrible special casing for empty transfers: the dbg.values between
1009 // two positions could be spliced in dbg.value mode.
1010 if (First == Last) {
1011 spliceDebugInfoEmptyBlock(Dest, Src, First, Last);
1012 return;
1013 }
1014
1015 spliceDebugInfo(Dest, Src, First, Last);
1016
1017 // And move the instructions.
1018 getInstList().splice(Dest, Src->getInstList(), First, Last);
1019
1020 flushTerminatorDbgRecords();
1021}
1022
1024 assert(I->getParent() == this);
1025
1026 iterator NextIt = std::next(I->getIterator());
1027 DbgMarker *NextMarker = createMarker(NextIt);
1028 NextMarker->insertDbgRecord(DR, true);
1029}
1030
1032 InstListType::iterator Where) {
1033 assert(Where == end() || Where->getParent() == this);
1034 bool InsertAtHead = Where.getHeadBit();
1035 DbgMarker *M = createMarker(Where);
1036 M->insertDbgRecord(DR, InsertAtHead);
1037}
1038
1040 return getMarker(std::next(I->getIterator()));
1041}
1042
1043DbgMarker *BasicBlock::getMarker(InstListType::iterator It) {
1044 if (It == end()) {
1045 DbgMarker *DM = getTrailingDbgRecords();
1046 return DM;
1047 }
1048 return It->DebugMarker;
1049}
1050
1052 Instruction *I, std::optional<DbgRecord::self_iterator> Pos) {
1053 // "I" was originally removed from a position where it was
1054 // immediately in front of Pos. Any DbgRecords on that position then "fell
1055 // down" onto Pos. "I" has been re-inserted at the front of that wedge of
1056 // DbgRecords, shuffle them around to represent the original positioning. To
1057 // illustrate:
1058 //
1059 // Instructions: I1---I---I0
1060 // DbgRecords: DDD DDD
1061 //
1062 // Instruction "I" removed,
1063 //
1064 // Instructions: I1------I0
1065 // DbgRecords: DDDDDD
1066 // ^Pos
1067 //
1068 // Instruction "I" re-inserted (now):
1069 //
1070 // Instructions: I1---I------I0
1071 // DbgRecords: DDDDDD
1072 // ^Pos
1073 //
1074 // After this method completes:
1075 //
1076 // Instructions: I1---I---I0
1077 // DbgRecords: DDD DDD
1078
1079 // This happens if there were no DbgRecords on I0. Are there now DbgRecords
1080 // there?
1081 if (!Pos) {
1082 DbgMarker *NextMarker = getNextMarker(I);
1083 if (!NextMarker)
1084 return;
1085 if (NextMarker->StoredDbgRecords.empty())
1086 return;
1087 // There are DbgMarkers there now -- they fell down from "I".
1088 DbgMarker *ThisMarker = createMarker(I);
1089 ThisMarker->absorbDebugValues(*NextMarker, false);
1090 return;
1091 }
1092
1093 // Is there even a range of DbgRecords to move?
1094 DbgMarker *DM = (*Pos)->getMarker();
1095 auto Range = make_range(DM->StoredDbgRecords.begin(), (*Pos));
1096 if (Range.begin() == Range.end())
1097 return;
1098
1099 // Otherwise: splice.
1100 DbgMarker *ThisMarker = createMarker(I);
1101 assert(ThisMarker->StoredDbgRecords.empty());
1102 ThisMarker->absorbDebugValues(Range, *DM, true);
1103}
1104
1105#ifndef NDEBUG
1106/// In asserts builds, this checks the numbering. In non-asserts builds, it
1107/// is defined as a no-op inline function in BasicBlock.h.
1109 if (!isInstrOrderValid())
1110 return;
1111 const Instruction *Prev = nullptr;
1112 for (const Instruction &I : *this) {
1113 assert((!Prev || Prev->comesBefore(&I)) &&
1114 "cached instruction ordering is incorrect");
1115 Prev = &I;
1116 }
1117}
1118#endif
1119
1121 getContext().pImpl->setTrailingDbgRecords(this, foo);
1122}
1123
1125 return getContext().pImpl->getTrailingDbgRecords(this);
1126}
1127
1129 getContext().pImpl->deleteTrailingDbgRecords(this);
1130}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
VarLocInsertPt getNextNode(const DbgRecord *DVR)
static const Function * getParent(const Value *V)
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static RegisterPass< DebugifyModulePass > DM("debugify", "Attach debug info to everything")
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
Machine Check Debug Module
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
#define P(N)
StandardInstrumentations SI(Mod->getContext(), Debug, VerifyEach)
This file contains some templates that are useful if you are working with the STL at all.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Definition Statistic.h:171
static SymbolRef::Type getType(const Symbol *Sym)
Definition TapiFile.cpp:39
an instruction to allocate memory on the stack
LLVM Basic Block Representation.
Definition BasicBlock.h:62
LLVM_ABI BasicBlock::iterator erase(BasicBlock::iterator FromIt, BasicBlock::iterator ToIt)
Erases a range of instructions from FromIt to (not including) ToIt.
LLVM_ABI void replaceSuccessorsPhiUsesWith(BasicBlock *Old, BasicBlock *New)
Update all phi nodes in this basic block's successors to refer to basic block New instead of basic bl...
LLVM_ABI void deleteTrailingDbgRecords()
Delete any trailing DbgRecords at the end of this block, see setTrailingDbgRecords.
iterator_range< const_phi_iterator > phis() const
Returns a range that iterates over the phis in the basic block.
Definition BasicBlock.h:539
LLVM_ABI const LandingPadInst * getLandingPadInst() const
Return the landingpad instruction associated with the landing pad.
LLVM_ABI void setTrailingDbgRecords(DbgMarker *M)
Record that the collection of DbgRecords in M "trails" after the last instruction of this block.
LLVM_ABI const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
LLVM_ABI BasicBlock * splitBasicBlock(iterator I, const Twine &BBName="")
Split the basic block into two basic blocks at the specified instruction.
const Function * getParent() const
Return the enclosing method, or null if none.
Definition BasicBlock.h:213
LLVM_ABI void renumberInstructions()
Renumber instructions and mark the ordering as valid.
LLVM_ABI iterator_range< filter_iterator< BasicBlock::const_iterator, std::function< bool(const Instruction &)> > > instructionsWithoutDebug(bool SkipPseudoOp=true) const
Return a const iterator range over the instructions in the block, skipping any debug instructions.
LLVM_ABI DbgMarker * createMarker(Instruction *I)
Attach a DbgMarker to the given instruction.
LLVM_ABI BasicBlock * splitBasicBlockBefore(iterator I, const Twine &BBName="")
Split the basic block into two basic blocks at the specified instruction and insert the new basic blo...
LLVM_ABI InstListType::const_iterator getFirstNonPHIIt() const
Returns an iterator to the first instruction in this block that is not a PHINode instruction.
LLVM_ABI void insertDbgRecordBefore(DbgRecord *DR, InstListType::iterator Here)
Insert a DbgRecord into a block at the position given by Here.
void invalidateOrders()
Mark instruction ordering invalid. Done on every instruction insert.
Definition BasicBlock.h:743
friend void Instruction::removeFromParent()
LLVM_ABI void convertToNewDbgValues()
Convert variable location debugging information stored in dbg.value intrinsics into DbgMarkers / DbgR...
InstListType::const_iterator const_iterator
Definition BasicBlock.h:171
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
Definition BasicBlock.h:206
friend BasicBlock::iterator Instruction::eraseFromParent()
LLVM_ABI bool isEntryBlock() const
Return true if this is the entry block of the containing function.
LLVM_ABI ValueSymbolTable * getValueSymbolTable()
Returns a pointer to the symbol table if one exists.
LLVM_ABI void moveAfter(BasicBlock *MovePos)
Unlink this basic block from its current function and insert it right after MovePos in the function M...
LLVM_ABI InstListType::const_iterator getFirstNonPHIOrDbg(bool SkipPseudoOp=true) const
Returns a pointer to the first instruction in this block that is not a PHINode or a debug intrinsic,...
LLVM_ABI bool hasNPredecessors(unsigned N) const
Return true if this block has exactly N predecessors.
LLVM_ABI void convertFromNewDbgValues()
Convert variable location debugging information stored in DbgMarkers and DbgRecords into the dbg....
LLVM_ABI const BasicBlock * getUniqueSuccessor() const
Return the successor of this block if it has a unique successor.
LLVM_ABI const BasicBlock * getSinglePredecessor() const
Return the predecessor of this block if it has a single predecessor block.
LLVM_ABI std::optional< uint64_t > getIrrLoopHeaderWeight() const
LLVM_ABI void dumpDbgValues() const
LLVM_ABI const CallInst * getTerminatingDeoptimizeCall() const
Returns the call instruction calling @llvm.experimental.deoptimize prior to the terminating return in...
LLVM_ABI void replacePhiUsesWith(BasicBlock *Old, BasicBlock *New)
Update all phi nodes in this basic block to refer to basic block New instead of basic block Old.
LLVM_ABI const BasicBlock * getUniquePredecessor() const
Return the predecessor of this block if it has a unique predecessor block.
LLVM_ABI const BasicBlock * getSingleSuccessor() const
Return the successor of this block if it has a single successor.
LLVM_ABI void flushTerminatorDbgRecords()
Eject any debug-info trailing at the end of a block.
LLVM_ABI const DataLayout & getDataLayout() const
Get the data layout of the module this basic block belongs to.
LLVM_ABI void insertDbgRecordAfter(DbgRecord *DR, Instruction *I)
Insert a DbgRecord into a block at the position given by I.
LLVM_ABI_FOR_TEST void validateInstrOrdering() const
Asserts that instruction order numbers are marked invalid, or that they are in ascending order.
LLVM_ABI DbgMarker * getMarker(InstListType::iterator It)
Return the DbgMarker for the position given by It, so that DbgRecords can be inserted there.
LLVM_ABI filter_iterator< BasicBlock::const_iterator, std::function< bool(constInstruction &)> >::difference_type sizeWithoutDebug() const
Return the size of the basic block ignoring debug instructions.
LLVM_ABI ~BasicBlock()
InstListType::iterator iterator
Instruction iterators...
Definition BasicBlock.h:170
LLVM_ABI LLVMContext & getContext() const
Get the context in which this basic block lives.
LLVM_ABI const_iterator getFirstNonPHIOrDbgOrAlloca() const
Returns an iterator to the first instruction in this block that is not a PHINode, a debug intrinsic,...
LLVM_ABI void dropAllReferences()
Cause all subinstructions to "let go" of all the references that said subinstructions are maintaining...
LLVM_ABI void reinsertInstInDbgRecords(Instruction *I, std::optional< DbgRecord::self_iterator > Pos)
In rare circumstances instructions can be speculatively removed from blocks, and then be re-inserted ...
void moveBefore(BasicBlock *MovePos)
Unlink this basic block from its current function and insert it into the function that MovePos lives ...
Definition BasicBlock.h:397
LLVM_ABI InstListType::const_iterator getFirstNonPHIOrDbgOrLifetime(bool SkipPseudoOp=true) const
Returns a pointer to the first instruction in this block that is not a PHINode, a debug intrinsic,...
LLVM_ABI bool isLandingPad() const
Return true if this basic block is a landing pad.
LLVM_ABI DbgMarker * getTrailingDbgRecords()
Fetch the collection of DbgRecords that "trail" after the last instruction of this block,...
LLVM_ABI bool canSplitPredecessors() const
LLVM_ABI const CallInst * getTerminatingMustTailCall() const
Returns the call instruction marked 'musttail' prior to the terminating return instruction of this ba...
friend BasicBlock::iterator Instruction::insertInto(BasicBlock *BB, BasicBlock::iterator It)
LLVM_ABI bool isLegalToHoistInto() const
Return true if it is legal to hoist instructions into this block.
LLVM_ABI bool hasNPredecessorsOrMore(unsigned N) const
Return true if this block has N predecessors or more.
LLVM_ABI const CallInst * getPostdominatingDeoptimizeCall() const
Returns the call instruction calling @llvm.experimental.deoptimize that is present either in current ...
LLVM_ABI DbgMarker * getNextMarker(Instruction *I)
Return the DbgMarker for the position that comes after I.
LLVM_ABI const Instruction * getFirstMayFaultInst() const
Returns the first potential AsynchEH faulty instruction currently it checks for loads/stores (which m...
void splice(BasicBlock::iterator ToIt, BasicBlock *FromBB)
Transfer all instructions from FromBB to this basic block at ToIt.
Definition BasicBlock.h:668
LLVM_ABI const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr if the function does no...
LLVM_ABI void removePredecessor(BasicBlock *Pred, bool KeepOneInputPHIs=false)
Update PHI nodes in this BasicBlock before removal of predecessor Pred.
The address of a basic block.
Definition Constants.h:904
Conditional or Unconditional Branch instruction.
static BranchInst * Create(BasicBlock *IfTrue, InsertPosition InsertBefore=nullptr)
This class represents a function call, abstracting a target machine's calling convention.
static LLVM_ABI Constant * getIntToPtr(Constant *C, Type *Ty, bool OnlyIfReduced=false)
This is an important base class in LLVM.
Definition Constant.h:43
LLVM_ABI void destroyConstant()
Called if some element of this constant is no longer valid.
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
This represents the llvm.dbg.label instruction.
Records a position in IR for a source label (DILabel).
Per-instruction record of debug-info.
LLVM_ABI void removeFromParent()
Instruction * MarkedInstr
Link back to the Instruction that owns this marker.
LLVM_ABI void eraseFromParent()
LLVM_ABI iterator_range< simple_ilist< DbgRecord >::iterator > getDbgRecordRange()
Produce a range over all the DbgRecords in this Marker.
LLVM_ABI void insertDbgRecord(DbgRecord *New, bool InsertAtHead)
Insert a DbgRecord into this DbgMarker, at the end of the list.
simple_ilist< DbgRecord > StoredDbgRecords
List of DbgRecords, the non-instruction equivalent of llvm.dbg.
LLVM_ABI void absorbDebugValues(DbgMarker &Src, bool InsertAtHead)
Transfer any DbgRecords from Src into this DbgMarker.
Base class for non-instruction debug metadata records that have positions within IR.
This is the common base class for debug info intrinsics for variables.
Record of a variable value-assignment, aka a non instruction representation of the dbg....
A debug info location.
Definition DebugLoc.h:123
void splice(Function::iterator ToIt, Function *FromF)
Transfer all blocks from FromF to this function at ToIt.
Definition Function.h:761
Function::iterator insert(Function::iterator Position, BasicBlock *BB)
Insert BB in the basic block list at Position.
Definition Function.h:755
iterator end()
Definition Function.h:855
LLVM_ABI void replaceSuccessorWith(BasicBlock *OldBB, BasicBlock *NewBB)
Replace specified successor OldBB to point at the provided block.
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
LLVM_ABI bool comesBefore(const Instruction *Other) const
Given an instruction Other in the same basic block as this instruction, return true if this instructi...
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
The landingpad instruction holds all of the information necessary to generate correct exception handl...
Metadata node.
Definition Metadata.h:1080
A single uniqued string.
Definition Metadata.h:722
LLVM_ABI StringRef getString() const
Definition Metadata.cpp:632
void replaceIncomingBlockWith(const BasicBlock *Old, BasicBlock *New)
Replace every incoming basic block Old to basic block New.
Return a value (possibly void), from a function.
Value * getReturnValue() const
Convenience accessor. Returns null if there is no return value.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
Definition Type.cpp:296
This class provides a symbol table of name/value pairs.
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:256
LLVM_ABI void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Definition Value.cpp:553
self_iterator getIterator()
Definition ilist_node.h:123
A range adaptor for a pair of iterators.
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > extract(Y &&MD)
Extract a Value from Metadata.
Definition Metadata.h:668
NodeAddr< PhiNode * > Phi
Definition RDFGraph.h:390
bool empty() const
Definition BasicBlock.h:101
Context & getContext() const
Definition BasicBlock.h:99
iterator end() const
Definition BasicBlock.h:89
LLVM_ABI iterator begin() const
LLVM_ABI Instruction * getTerminator() const
LLVM_ABI Instruction & front() const
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
auto pred_end(const MachineBasicBlock *BB)
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
auto successors(const MachineBasicBlock *BB)
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
Definition STLExtras.h:634
PredIterator< const BasicBlock, Value::const_user_iterator > const_pred_iterator
Definition CFG.h:106
bool hasNItemsOrMore(IterTy &&Begin, IterTy &&End, unsigned N, Pred &&ShouldBeCounted=[](const decltype(*std::declval< IterTy >()) &) { return true;}, std::enable_if_t< !std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< std::remove_reference_t< decltype(Begin)> >::iterator_category >::value, void > *=nullptr)
Return true if the sequence [Begin, End) has N or more items.
Definition STLExtras.h:2638
auto dyn_cast_or_null(const Y &Val)
Definition Casting.h:753
LLVM_ABI BasicBlock::iterator skipDebugIntrinsics(BasicBlock::iterator It)
Advance It while it points to a debug instruction and return the result.
bool hasNItems(IterTy &&Begin, IterTy &&End, unsigned N, Pred &&ShouldBeCounted=[](const decltype(*std::declval< IterTy >()) &) { return true;}, std::enable_if_t< !std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< std::remove_reference_t< decltype(Begin)> >::iterator_category >::value, void > *=nullptr)
Return true if the sequence [Begin, End) has exactly N items.
Definition STLExtras.h:2613
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:207
iterator_range< filter_iterator< detail::IterOfRange< RangeT >, PredicateT > > make_filter_range(RangeT &&Range, PredicateT Pred)
Convenience function that takes a range of elements and a predicate, and return a new filter_iterator...
Definition STLExtras.h:552
auto instructionsWithoutDebug(IterT It, IterT End, bool SkipPseudoOp=true)
Construct a range iterator which begins at It and moves forwards until End is reached,...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
RNSuccIterator< NodeRef, BlockT, RegionT > succ_begin(NodeRef Node)
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
Definition ModRef.h:74
RNSuccIterator< NodeRef, BlockT, RegionT > succ_end(NodeRef Node)
void invalidateParentIListOrdering(ParentClass *Parent)
Notify basic blocks when an instruction is inserted.
auto pred_begin(const MachineBasicBlock *BB)
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
auto predecessors(const MachineBasicBlock *BB)
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition STLExtras.h:1947
filter_iterator_impl< WrappedIteratorT, PredicateT, detail::fwd_or_bidi_tag< WrappedIteratorT > > filter_iterator
Defines filter_iterator to a suitable specialization of filter_iterator_impl, based on the underlying...
Definition STLExtras.h:539
SuccIterator< const Instruction, const BasicBlock > const_succ_iterator
Definition CFG.h:245
#define N
Option to add extra bits to the ilist_iterator.
Option to add a pointer to this list's owner in every node.