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