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