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