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()) {
178 assert(!use_empty() && "There should be at least one blockaddress!");
179 BlockAddress *BA = cast<BlockAddress>(user_back());
180
181 Constant *Replacement = ConstantInt::get(Type::getInt32Ty(getContext()), 1);
183 ConstantExpr::getIntToPtr(Replacement, BA->getType()));
184 BA->destroyConstant();
185 }
186
187 assert(getParent() == nullptr && "BasicBlock still linked into the program!");
188 dropAllReferences();
189 for (auto &Inst : *this) {
190 if (!Inst.DebugMarker)
191 continue;
192 Inst.DebugMarker->eraseFromParent();
193 }
194 InstList.clear();
195}
196
197void BasicBlock::setParent(Function *parent) {
198 // Set Parent=parent, updating instruction symtab entries as appropriate.
199 if (Parent != parent)
200 Number = parent ? parent->NextBlockNum++ : -1u;
201 InstList.setSymTabObject(&Parent, parent);
202}
203
205 getParent()->getBasicBlockList().remove(getIterator());
206}
207
209 return getParent()->getBasicBlockList().erase(getIterator());
210}
211
213 getParent()->splice(MovePos, getParent(), getIterator());
214}
215
216void BasicBlock::moveAfter(BasicBlock *MovePos) {
217 MovePos->getParent()->splice(++MovePos->getIterator(), getParent(),
218 getIterator());
219}
220
221const Module *BasicBlock::getModule() const {
222 return getParent()->getParent();
223}
224
226 return getModule()->getDataLayout();
227}
228
230 if (InstList.empty())
231 return nullptr;
232 const ReturnInst *RI = dyn_cast<ReturnInst>(&InstList.back());
233 if (!RI || RI == &InstList.front())
234 return nullptr;
235
236 const Instruction *Prev = RI->getPrevNode();
237 if (!Prev)
238 return nullptr;
239
240 if (Value *RV = RI->getReturnValue()) {
241 if (RV != Prev)
242 return nullptr;
243
244 // Look through the optional bitcast.
245 if (auto *BI = dyn_cast<BitCastInst>(Prev)) {
246 RV = BI->getOperand(0);
247 Prev = BI->getPrevNode();
248 if (!Prev || RV != Prev)
249 return nullptr;
250 }
251 }
252
253 if (auto *CI = dyn_cast<CallInst>(Prev)) {
254 if (CI->isMustTailCall())
255 return CI;
256 }
257 return nullptr;
258}
259
261 if (InstList.empty())
262 return nullptr;
263 auto *RI = dyn_cast<ReturnInst>(&InstList.back());
264 if (!RI || RI == &InstList.front())
265 return nullptr;
266
267 if (auto *CI = dyn_cast_or_null<CallInst>(RI->getPrevNode()))
268 if (Function *F = CI->getCalledFunction())
269 if (F->getIntrinsicID() == Intrinsic::experimental_deoptimize)
270 return CI;
271
272 return nullptr;
273}
274
276 const BasicBlock* BB = this;
278 Visited.insert(BB);
279 while (auto *Succ = BB->getUniqueSuccessor()) {
280 if (!Visited.insert(Succ).second)
281 return nullptr;
282 BB = Succ;
283 }
284 return BB->getTerminatingDeoptimizeCall();
285}
286
288 if (InstList.empty())
289 return nullptr;
290 for (const Instruction &I : *this)
292 return &I;
293 return nullptr;
294}
295
296const Instruction* BasicBlock::getFirstNonPHI() const {
297 for (const Instruction &I : *this)
298 if (!isa<PHINode>(I))
299 return &I;
300 return nullptr;
301}
302
303Instruction *BasicBlock::getFirstNonPHI() {
304 for (Instruction &I : *this)
305 if (!isa<PHINode>(I))
306 return &I;
307 return nullptr;
308}
309
311 for (const Instruction &I : *this) {
312 if (isa<PHINode>(I))
313 continue;
314
315 BasicBlock::const_iterator It = I.getIterator();
316 // Set the head-inclusive bit to indicate that this iterator includes
317 // any debug-info at the start of the block. This is a no-op unless the
318 // appropriate CMake flag is set.
319 It.setHeadBit(true);
320 return It;
321 }
322
323 return end();
324}
325
327BasicBlock::getFirstNonPHIOrDbg(bool SkipPseudoOp) const {
328 for (const Instruction &I : *this) {
330 continue;
331
332 if (SkipPseudoOp && isa<PseudoProbeInst>(I))
333 continue;
334
335 BasicBlock::const_iterator It = I.getIterator();
336 // This position comes after any debug records, the head bit should remain
337 // unset.
338 assert(!It.getHeadBit());
339 return It;
340 }
341 return end();
342}
343
345BasicBlock::getFirstNonPHIOrDbgOrLifetime(bool SkipPseudoOp) const {
346 for (const Instruction &I : *this) {
348 continue;
349
350 if (I.isLifetimeStartOrEnd())
351 continue;
352
353 if (SkipPseudoOp && isa<PseudoProbeInst>(I))
354 continue;
355
356 BasicBlock::const_iterator It = I.getIterator();
357 // This position comes after any debug records, the head bit should remain
358 // unset.
359 assert(!It.getHeadBit());
360
361 return It;
362 }
363 return end();
364}
365
367 const_iterator InsertPt = getFirstNonPHIIt();
368 if (InsertPt == end())
369 return end();
370
371 if (InsertPt->isEHPad()) ++InsertPt;
372 // Set the head-inclusive bit to indicate that this iterator includes
373 // any debug-info at the start of the block. This is a no-op unless the
374 // appropriate CMake flag is set.
375 InsertPt.setHeadBit(true);
376 return InsertPt;
377}
378
380 const_iterator InsertPt = getFirstNonPHIIt();
381 if (InsertPt == end())
382 return end();
383
384 if (InsertPt->isEHPad())
385 ++InsertPt;
386
387 if (isEntryBlock()) {
388 const_iterator End = end();
389 while (InsertPt != End &&
390 (isa<AllocaInst>(*InsertPt) || isa<DbgInfoIntrinsic>(*InsertPt) ||
391 isa<PseudoProbeInst>(*InsertPt))) {
392 if (const AllocaInst *AI = dyn_cast<AllocaInst>(&*InsertPt)) {
393 if (!AI->isStaticAlloca())
394 break;
395 }
396 ++InsertPt;
397 }
398 }
399
400 // Signal that this comes after any debug records.
401 InsertPt.setHeadBit(false);
402 return InsertPt;
403}
404
406 for (Instruction &I : *this)
407 I.dropAllReferences();
408}
409
411 const_pred_iterator PI = pred_begin(this), E = pred_end(this);
412 if (PI == E) return nullptr; // No preds.
413 const BasicBlock *ThePred = *PI;
414 ++PI;
415 return (PI == E) ? ThePred : nullptr /*multiple preds*/;
416}
417
419 const_pred_iterator PI = pred_begin(this), E = pred_end(this);
420 if (PI == E) return nullptr; // No preds.
421 const BasicBlock *PredBB = *PI;
422 ++PI;
423 for (;PI != E; ++PI) {
424 if (*PI != PredBB)
425 return nullptr;
426 // The same predecessor appears multiple times in the predecessor list.
427 // This is OK.
428 }
429 return PredBB;
430}
431
432bool BasicBlock::hasNPredecessors(unsigned N) const {
433 return hasNItems(pred_begin(this), pred_end(this), N);
434}
435
436bool BasicBlock::hasNPredecessorsOrMore(unsigned N) const {
437 return hasNItemsOrMore(pred_begin(this), pred_end(this), N);
438}
439
441 const_succ_iterator SI = succ_begin(this), E = succ_end(this);
442 if (SI == E) return nullptr; // no successors
443 const BasicBlock *TheSucc = *SI;
444 ++SI;
445 return (SI == E) ? TheSucc : nullptr /* multiple successors */;
446}
447
449 const_succ_iterator SI = succ_begin(this), E = succ_end(this);
450 if (SI == E) return nullptr; // No successors
451 const BasicBlock *SuccBB = *SI;
452 ++SI;
453 for (;SI != E; ++SI) {
454 if (*SI != SuccBB)
455 return nullptr;
456 // The same successor appears multiple times in the successor list.
457 // This is OK.
458 }
459 return SuccBB;
460}
461
463 PHINode *P = empty() ? nullptr : dyn_cast<PHINode>(&*begin());
464 return make_range<phi_iterator>(P, nullptr);
465}
466
468 bool KeepOneInputPHIs) {
469 // Use hasNUsesOrMore to bound the cost of this assertion for complex CFGs.
470 assert((hasNUsesOrMore(16) || llvm::is_contained(predecessors(this), Pred)) &&
471 "Pred is not a predecessor!");
472
473 // Return early if there are no PHI nodes to update.
474 if (empty() || !isa<PHINode>(begin()))
475 return;
476
477 unsigned NumPreds = cast<PHINode>(front()).getNumIncomingValues();
478 for (PHINode &Phi : make_early_inc_range(phis())) {
479 Phi.removeIncomingValue(Pred, !KeepOneInputPHIs);
480 if (KeepOneInputPHIs)
481 continue;
482
483 // If we have a single predecessor, removeIncomingValue may have erased the
484 // PHI node itself.
485 if (NumPreds == 1)
486 continue;
487
488 // Try to replace the PHI node with a constant value.
489 if (Value *PhiConstant = Phi.hasConstantValue()) {
490 Phi.replaceAllUsesWith(PhiConstant);
491 Phi.eraseFromParent();
492 }
493 }
494}
495
497 const_iterator FirstNonPHI = getFirstNonPHIIt();
498 if (isa<LandingPadInst>(FirstNonPHI))
499 return true;
500 // This is perhaps a little conservative because constructs like
501 // CleanupBlockInst are pretty easy to split. However, SplitBlockPredecessors
502 // cannot handle such things just yet.
503 if (FirstNonPHI->isEHPad())
504 return false;
505 return true;
506}
507
509 auto *Term = getTerminator();
510 // No terminator means the block is under construction.
511 if (!Term)
512 return true;
513
514 // If the block has no successors, there can be no instructions to hoist.
515 assert(Term->getNumSuccessors() > 0);
516
517 // Instructions should not be hoisted across special terminators, which may
518 // have side effects or return values.
519 return !Term->isSpecialTerminator();
520}
521
522bool BasicBlock::isEntryBlock() const {
523 const Function *F = getParent();
524 assert(F && "Block must have a parent function to use this API");
525 return this == &F->getEntryBlock();
526}
527
528BasicBlock *BasicBlock::splitBasicBlock(iterator I, const Twine &BBName) {
529 assert(getTerminator() && "Can't use splitBasicBlock on degenerate BB!");
530 assert(I != InstList.end() &&
531 "Trying to get me to create degenerate basic block!");
532
534 this->getNextNode());
535
536 // Save DebugLoc of split point before invalidating iterator.
537 DebugLoc Loc = I->getStableDebugLoc();
538 if (Loc)
539 Loc = Loc->getWithoutAtom();
540
541 // Move all of the specified instructions from the original basic block into
542 // the new basic block.
543 New->splice(New->end(), this, I, end());
544
545 // Add a branch instruction to the newly formed basic block.
546 UncondBrInst *BI = UncondBrInst::Create(New, this);
547 BI->setDebugLoc(Loc);
548
549 // Now we must loop through all of the successors of the New block (which
550 // _were_ the successors of the 'this' block), and update any PHI nodes in
551 // successors. If there were PHI nodes in the successors, then they need to
552 // know that incoming branches will be from New, not from Old (this).
553 //
554 New->replaceSuccessorsPhiUsesWith(this, New);
555 return New;
556}
557
558BasicBlock *BasicBlock::splitBasicBlockBefore(iterator I, const Twine &BBName) {
560 "Can't use splitBasicBlockBefore on degenerate BB!");
561 assert(I != InstList.end() &&
562 "Trying to get me to create degenerate basic block!");
563
564 assert((!isa<PHINode>(*I) || getSinglePredecessor()) &&
565 "cannot split on multi incoming phis");
566
568 // Save DebugLoc of split point before invalidating iterator.
569 DebugLoc Loc = I->getDebugLoc();
570 if (Loc)
571 Loc = Loc->getWithoutAtom();
572
573 // Move all of the specified instructions from the original basic block into
574 // the new basic block.
575 New->splice(New->end(), this, begin(), I);
576
577 // Loop through all of the predecessors of the 'this' block (which will be the
578 // predecessors of the New block), replace the specified successor 'this'
579 // block to point at the New block and update any PHI nodes in 'this' block.
580 // If there were PHI nodes in 'this' block, the PHI nodes are updated
581 // to reflect that the incoming branches will be from the New block and not
582 // from predecessors of the 'this' block.
583 // Save predecessors to separate vector before modifying them.
584 SmallVector<BasicBlock *, 4> Predecessors(predecessors(this));
585 for (BasicBlock *Pred : Predecessors) {
586 Instruction *TI = Pred->getTerminator();
587 TI->replaceSuccessorWith(this, New);
588 this->replacePhiUsesWith(Pred, New);
589 }
590 // Add a branch instruction from "New" to "this" Block.
591 UncondBrInst *BI = UncondBrInst::Create(this, New);
592 BI->setDebugLoc(Loc);
593
594 return New;
595}
596
599 for (Instruction &I : make_early_inc_range(make_range(FromIt, ToIt)))
600 I.eraseFromParent();
601 return ToIt;
602}
603
605 // N.B. This might not be a complete BasicBlock, so don't assume
606 // that it ends with a non-phi instruction.
607 for (Instruction &I : *this) {
609 if (!PN)
610 break;
611 PN->replaceIncomingBlockWith(Old, New);
612 }
613}
614
616 BasicBlock *New) {
618 if (!TI)
619 // Cope with being called on a BasicBlock that doesn't have a terminator
620 // yet. Clang's CodeGenFunction::EmitReturnBlock() likes to do this.
621 return;
622 for (BasicBlock *Succ : successors(TI))
623 Succ->replacePhiUsesWith(Old, New);
624}
625
627 this->replaceSuccessorsPhiUsesWith(this, New);
628}
629
630bool BasicBlock::isLandingPad() const {
631 return isa<LandingPadInst>(getFirstNonPHIIt());
632}
633
635 return dyn_cast<LandingPadInst>(getFirstNonPHIIt());
636}
637
638std::optional<uint64_t> BasicBlock::getIrrLoopHeaderWeight() const {
639 const Instruction *TI = getTerminator();
640 if (MDNode *MDIrrLoopHeader =
641 TI->getMetadata(LLVMContext::MD_irr_loop)) {
642 MDString *MDName = cast<MDString>(MDIrrLoopHeader->getOperand(0));
643 if (MDName->getString() == "loop_header_weight") {
644 auto *CI = mdconst::extract<ConstantInt>(MDIrrLoopHeader->getOperand(1));
645 return std::optional<uint64_t>(CI->getValue().getZExtValue());
646 }
647 }
648 return std::nullopt;
649}
650
652 while (isa<DbgInfoIntrinsic>(It))
653 ++It;
654 return It;
655}
656
658 unsigned Order = 0;
659 for (Instruction &I : *this)
660 I.Order = Order++;
661
662 // Set the bit to indicate that the instruction order valid and cached.
663 SubclassOptionalData |= InstrOrderValid;
664
665 NumInstrRenumberings++;
666}
667
669 // If we erase the terminator in a block, any DbgRecords will sink and "fall
670 // off the end", existing after any terminator that gets inserted. With
671 // dbg.value intrinsics we would just insert the terminator at end() and
672 // the dbg.values would come before the terminator. With DbgRecords, we must
673 // do this manually.
674 // To get out of this unfortunate form, whenever we insert a terminator,
675 // check whether there's anything trailing at the end and move those
676 // DbgRecords in front of the terminator.
677
678 // If there's no terminator, there's nothing to do.
680 if (!Term)
681 return;
682
683 // Are there any dangling DbgRecords?
684 DbgMarker *TrailingDbgRecords = getTrailingDbgRecords();
685 if (!TrailingDbgRecords)
686 return;
687
688 // Transfer DbgRecords from the trailing position onto the terminator.
689 createMarker(Term);
690 Term->DebugMarker->absorbDebugValues(*TrailingDbgRecords, false);
691 TrailingDbgRecords->eraseFromParent();
692 deleteTrailingDbgRecords();
693}
694
695void BasicBlock::spliceDebugInfoEmptyBlock(BasicBlock::iterator Dest,
696 BasicBlock *Src,
699 // Imagine the folowing:
700 //
701 // bb1:
702 // dbg.value(...
703 // ret i32 0
704 //
705 // If an optimisation pass attempts to splice the contents of the block from
706 // BB1->begin() to BB1->getTerminator(), then the dbg.value will be
707 // transferred to the destination.
708 // However, in the "new" DbgRecord format for debug-info, that range is empty:
709 // begin() returns an iterator to the terminator, as there will only be a
710 // single instruction in the block. We must piece together from the bits set
711 // in the iterators whether there was the intention to transfer any debug
712 // info.
713
714 assert(First == Last);
715 bool InsertAtHead = Dest.getHeadBit();
716 bool ReadFromHead = First.getHeadBit();
717
718 // If the source block is completely empty, including no terminator, then
719 // transfer any trailing DbgRecords that are still hanging around. This can
720 // occur when a block is optimised away and the terminator has been moved
721 // somewhere else.
722 if (Src->empty()) {
723 DbgMarker *SrcTrailingDbgRecords = Src->getTrailingDbgRecords();
724 if (!SrcTrailingDbgRecords)
725 return;
726
727 Dest->adoptDbgRecords(Src, Src->end(), InsertAtHead);
728 // adoptDbgRecords should have released the trailing DbgRecords.
729 assert(!Src->getTrailingDbgRecords());
730 return;
731 }
732
733 // There are instructions in this block; if the First iterator was
734 // with begin() / getFirstInsertionPt() then the caller intended debug-info
735 // at the start of the block to be transferred. Return otherwise.
736 if (Src->empty() || First != Src->begin() || !ReadFromHead)
737 return;
738
739 // Is there actually anything to transfer?
740 if (!First->hasDbgRecords())
741 return;
742
743 createMarker(Dest)->absorbDebugValues(*First->DebugMarker, InsertAtHead);
744}
745
746void BasicBlock::spliceDebugInfo(BasicBlock::iterator Dest, BasicBlock *Src,
749 /* Do a quick normalisation before calling the real splice implementation. We
750 might be operating on a degenerate basic block that has no instructions
751 in it, a legitimate transient state. In that case, Dest will be end() and
752 any DbgRecords temporarily stored in the TrailingDbgRecords map in
753 LLVMContext. We might illustrate it thus:
754
755 Dest
756 |
757 this-block: ~~~~~~~~
758 Src-block: ++++B---B---B---B:::C
759 | |
760 First Last
761
762 However: does the caller expect the "~" DbgRecords to end up before or
763 after the spliced segment? This is communciated in the "Head" bit of Dest,
764 which signals whether the caller called begin() or end() on this block.
765
766 If the head bit is set, then all is well, we leave DbgRecords trailing just
767 like how dbg.value instructions would trail after instructions spliced to
768 the beginning of this block.
769
770 If the head bit isn't set, then try to jam the "~" DbgRecords onto the
771 front of the First instruction, then splice like normal, which joins the
772 "~" DbgRecords with the "+" DbgRecords. However if the "+" DbgRecords are
773 supposed to be left behind in Src, then:
774 * detach the "+" DbgRecords,
775 * move the "~" DbgRecords onto First,
776 * splice like normal,
777 * replace the "+" DbgRecords onto the Last position.
778 Complicated, but gets the job done. */
779
780 // If we're inserting at end(), and not in front of dangling DbgRecords, then
781 // move the DbgRecords onto "First". They'll then be moved naturally in the
782 // splice process.
783 DbgMarker *MoreDanglingDbgRecords = nullptr;
784 DbgMarker *OurTrailingDbgRecords = getTrailingDbgRecords();
785 if (Dest == end() && !Dest.getHeadBit() && OurTrailingDbgRecords) {
786 // Are the "+" DbgRecords not supposed to move? If so, detach them
787 // temporarily.
788 if (!First.getHeadBit() && First->hasDbgRecords()) {
789 MoreDanglingDbgRecords = Src->getMarker(First);
790 MoreDanglingDbgRecords->removeFromParent();
791 }
792
793 if (First->hasDbgRecords()) {
794 // Place them at the front, it would look like this:
795 // Dest
796 // |
797 // this-block:
798 // Src-block: ~~~~~~~~++++B---B---B---B:::C
799 // | |
800 // First Last
801 First->adoptDbgRecords(this, end(), true);
802 } else {
803 // No current marker, create one and absorb in. (FIXME: we can avoid an
804 // allocation in the future).
805 DbgMarker *CurMarker = Src->createMarker(&*First);
806 CurMarker->absorbDebugValues(*OurTrailingDbgRecords, false);
807 OurTrailingDbgRecords->eraseFromParent();
808 }
809 deleteTrailingDbgRecords();
810 First.setHeadBit(true);
811 }
812
813 // Call the main debug-info-splicing implementation.
814 spliceDebugInfoImpl(Dest, Src, First, Last);
815
816 // Do we have some "+" DbgRecords hanging around that weren't supposed to
817 // move, and we detached to make things easier?
818 if (!MoreDanglingDbgRecords)
819 return;
820
821 // FIXME: we could avoid an allocation here sometimes. (adoptDbgRecords
822 // requires an iterator).
823 DbgMarker *LastMarker = Src->createMarker(Last);
824 LastMarker->absorbDebugValues(*MoreDanglingDbgRecords, true);
825 MoreDanglingDbgRecords->eraseFromParent();
826}
827
828void BasicBlock::spliceDebugInfoImpl(BasicBlock::iterator Dest, BasicBlock *Src,
831 // Find out where to _place_ these dbg.values; if InsertAtHead is specified,
832 // this will be at the start of Dest's debug value range, otherwise this is
833 // just Dest's marker.
834 bool InsertAtHead = Dest.getHeadBit();
835 bool ReadFromHead = First.getHeadBit();
836 // Use this flag to signal the abnormal case, where we don't want to copy the
837 // DbgRecords ahead of the "Last" position.
838 bool ReadFromTail = !Last.getTailBit();
839 bool LastIsEnd = (Last == Src->end());
840
841 /*
842 Here's an illustration of what we're about to do. We have two blocks, this
843 and Src, and two segments of list. Each instruction is marked by a capital
844 while potential DbgRecord debug-info is marked out by "-" characters and a
845 few other special characters (+:=) where I want to highlight what's going
846 on.
847
848 Dest
849 |
850 this-block: A----A----A ====A----A----A----A---A---A
851 Src-block ++++B---B---B---B:::C
852 | |
853 First Last
854
855 The splice method is going to take all the instructions from First up to
856 (but not including) Last and insert them in _front_ of Dest, forming one
857 long list. All the DbgRecords attached to instructions _between_ First and
858 Last need no maintenence. However, we have to do special things with the
859 DbgRecords marked with the +:= characters. We only have three positions:
860 should the "+" DbgRecords be transferred, and if so to where? Do we move the
861 ":" DbgRecords? Would they go in front of the "=" DbgRecords, or should the
862 "=" DbgRecords go before "+" DbgRecords?
863
864 We're told which way it should be by the bits carried in the iterators. The
865 "Head" bit indicates whether the specified position is supposed to be at the
866 front of the attached DbgRecords (true) or not (false). The Tail bit is true
867 on the other end of a range: is the range intended to include DbgRecords up
868 to the end (false) or not (true).
869
870 FIXME: the tail bit doesn't need to be distinct from the head bit, we could
871 combine them.
872
873 Here are some examples of different configurations:
874
875 Dest.Head = true, First.Head = true, Last.Tail = false
876
877 this-block: A----A----A++++B---B---B---B:::====A----A----A----A---A---A
878 | |
879 First Dest
880
881 Wheras if we didn't want to read from the Src list,
882
883 Dest.Head = true, First.Head = false, Last.Tail = false
884
885 this-block: A----A----AB---B---B---B:::====A----A----A----A---A---A
886 | |
887 First Dest
888
889 Or if we didn't want to insert at the head of Dest:
890
891 Dest.Head = false, First.Head = false, Last.Tail = false
892
893 this-block: A----A----A====B---B---B---B:::A----A----A----A---A---A
894 | |
895 First Dest
896
897 Tests for these various configurations can be found in the unit test file
898 BasicBlockDbgInfoTest.cpp.
899
900 */
901
902 // Detach the marker at Dest -- this lets us move the "====" DbgRecords
903 // around.
904 DbgMarker *DestMarker = nullptr;
905 if ((DestMarker = getMarker(Dest))) {
906 if (Dest == end()) {
907 assert(DestMarker == getTrailingDbgRecords());
908 deleteTrailingDbgRecords();
909 } else {
910 DestMarker->removeFromParent();
911 }
912 }
913
914 // If we're moving the tail range of DbgRecords (":::"), absorb them into the
915 // front of the DbgRecords at Dest.
916 if (ReadFromTail && Src->getMarker(Last)) {
917 DbgMarker *FromLast = Src->getMarker(Last);
918 if (LastIsEnd) {
919 if (Dest == end()) {
920 // Abosrb the trailing markers from Src.
921 assert(FromLast == Src->getTrailingDbgRecords());
922 createMarker(Dest)->absorbDebugValues(*FromLast, true);
923 FromLast->eraseFromParent();
924 Src->deleteTrailingDbgRecords();
925 } else {
926 // adoptDbgRecords will release any trailers.
927 Dest->adoptDbgRecords(Src, Last, true);
928 }
929 assert(!Src->getTrailingDbgRecords());
930 } else {
931 // FIXME: can we use adoptDbgRecords here to reduce allocations?
932 DbgMarker *OntoDest = createMarker(Dest);
933 OntoDest->absorbDebugValues(*FromLast, true);
934 }
935 }
936
937 // If we're _not_ reading from the head of First, i.e. the "++++" DbgRecords,
938 // move their markers onto Last. They remain in the Src block. No action
939 // needed.
940 if (!ReadFromHead && First->hasDbgRecords()) {
941 if (Last != Src->end()) {
942 Last->adoptDbgRecords(Src, First, true);
943 } else {
944 DbgMarker *OntoLast = Src->createMarker(Last);
945 DbgMarker *FromFirst = Src->createMarker(First);
946 // Always insert at front of Last.
947 OntoLast->absorbDebugValues(*FromFirst, true);
948 }
949 }
950
951 // Finally, do something with the "====" DbgRecords we detached.
952 if (DestMarker) {
953 if (InsertAtHead) {
954 // Insert them at the end of the DbgRecords at Dest. The "::::" DbgRecords
955 // might be in front of them.
956 DbgMarker *NewDestMarker = createMarker(Dest);
957 NewDestMarker->absorbDebugValues(*DestMarker, false);
958 } else {
959 // Insert them right at the start of the range we moved, ahead of First
960 // and the "++++" DbgRecords.
961 // This also covers the rare circumstance where we insert at end(), and we
962 // did not generate the iterator with begin() / getFirstInsertionPt(),
963 // meaning any trailing debug-info at the end of the block would
964 // "normally" have been pushed in front of "First". We move it there now.
965 DbgMarker *FirstMarker = createMarker(First);
966 FirstMarker->absorbDebugValues(*DestMarker, true);
967 }
968 DestMarker->eraseFromParent();
969 }
970}
971
972void BasicBlock::splice(iterator Dest, BasicBlock *Src, iterator First,
973 iterator Last) {
974#ifdef EXPENSIVE_CHECKS
975 // Check that First is before Last.
976 auto FromBBEnd = Src->end();
977 for (auto It = First; It != Last; ++It)
978 assert(It != FromBBEnd && "FromBeginIt not before FromEndIt!");
979#endif // EXPENSIVE_CHECKS
980
981 // Lots of horrible special casing for empty transfers: the dbg.values between
982 // two positions could be spliced in dbg.value mode.
983 if (First == Last) {
984 spliceDebugInfoEmptyBlock(Dest, Src, First, Last);
985 return;
986 }
987
988 spliceDebugInfo(Dest, Src, First, Last);
989
990 // And move the instructions.
991 getInstList().splice(Dest, Src->getInstList(), First, Last);
992
993 flushTerminatorDbgRecords();
994}
995
997 assert(I->getParent() == this);
998
999 iterator NextIt = std::next(I->getIterator());
1000 DbgMarker *NextMarker = createMarker(NextIt);
1001 NextMarker->insertDbgRecord(DR, true);
1002}
1003
1005 InstListType::iterator Where) {
1006 assert(Where == end() || Where->getParent() == this);
1007 bool InsertAtHead = Where.getHeadBit();
1008 DbgMarker *M = createMarker(Where);
1009 M->insertDbgRecord(DR, InsertAtHead);
1010}
1011
1013 return getMarker(std::next(I->getIterator()));
1014}
1015
1016DbgMarker *BasicBlock::getMarker(InstListType::iterator It) {
1017 if (It == end()) {
1018 DbgMarker *DM = getTrailingDbgRecords();
1019 return DM;
1020 }
1021 return It->DebugMarker;
1022}
1023
1025 Instruction *I, std::optional<DbgRecord::self_iterator> Pos) {
1026 // "I" was originally removed from a position where it was
1027 // immediately in front of Pos. Any DbgRecords on that position then "fell
1028 // down" onto Pos. "I" has been re-inserted at the front of that wedge of
1029 // DbgRecords, shuffle them around to represent the original positioning. To
1030 // illustrate:
1031 //
1032 // Instructions: I1---I---I0
1033 // DbgRecords: DDD DDD
1034 //
1035 // Instruction "I" removed,
1036 //
1037 // Instructions: I1------I0
1038 // DbgRecords: DDDDDD
1039 // ^Pos
1040 //
1041 // Instruction "I" re-inserted (now):
1042 //
1043 // Instructions: I1---I------I0
1044 // DbgRecords: DDDDDD
1045 // ^Pos
1046 //
1047 // After this method completes:
1048 //
1049 // Instructions: I1---I---I0
1050 // DbgRecords: DDD DDD
1051
1052 // This happens if there were no DbgRecords on I0. Are there now DbgRecords
1053 // there?
1054 if (!Pos) {
1055 DbgMarker *NextMarker = getNextMarker(I);
1056 if (!NextMarker)
1057 return;
1058 if (NextMarker->StoredDbgRecords.empty())
1059 return;
1060 // There are DbgMarkers there now -- they fell down from "I".
1061 DbgMarker *ThisMarker = createMarker(I);
1062 ThisMarker->absorbDebugValues(*NextMarker, false);
1063 return;
1064 }
1065
1066 // Is there even a range of DbgRecords to move?
1067 DbgMarker *DM = (*Pos)->getMarker();
1068 auto Range = make_range(DM->StoredDbgRecords.begin(), (*Pos));
1069 if (Range.begin() == Range.end())
1070 return;
1071
1072 // Otherwise: splice.
1073 DbgMarker *ThisMarker = createMarker(I);
1074 assert(ThisMarker->StoredDbgRecords.empty());
1075 ThisMarker->absorbDebugValues(Range, *DM, true);
1076}
1077
1078#ifndef NDEBUG
1079/// In asserts builds, this checks the numbering. In non-asserts builds, it
1080/// is defined as a no-op inline function in BasicBlock.h.
1082 if (!isInstrOrderValid())
1083 return;
1084 const Instruction *Prev = nullptr;
1085 for (const Instruction &I : *this) {
1086 assert((!Prev || Prev->comesBefore(&I)) &&
1087 "cached instruction ordering is incorrect");
1088 Prev = &I;
1089 }
1090}
1091#endif
1092
1094 getContext().pImpl->setTrailingDbgRecords(this, foo);
1095}
1096
1098 return getContext().pImpl->getTrailingDbgRecords(this);
1099}
1100
1102 getContext().pImpl->deleteTrailingDbgRecords(this);
1103}
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:518
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:722
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:376
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:647
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:1065
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)
This is an important base class in LLVM.
Definition Constant.h:43
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:123
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...
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
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:1080
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:313
Unconditional Branch instruction.
static UncondBrInst * Create(BasicBlock *IfTrue, 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:256
LLVM_ABI void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Definition Value.cpp:553
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.
Definition Types.h:26
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:634
PredIterator< const BasicBlock, Value::const_user_iterator > const_pred_iterator
Definition CFG.h:106
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:2638
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:2613
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:207
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:1947
Instruction::const_succ_iterator const_succ_iterator
Definition CFG.h:139
#define N
Option to add extra bits to the ilist_iterator.
Option to add a pointer to this list's owner in every node.