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