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