LLVM 23.0.0git
BreakCriticalEdges.cpp
Go to the documentation of this file.
1//===- BreakCriticalEdges.cpp - Critical Edge Elimination Pass ------------===//
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// BreakCriticalEdges pass - Break all of the critical edges in the CFG by
10// inserting a dummy basic block. This pass may be "required" by passes that
11// cannot deal with critical edges. For this usage, the structure type is
12// forward declared. This pass obviously invalidates the CFG, but can update
13// dominator trees.
14//
15//===----------------------------------------------------------------------===//
16
18#include "llvm/ADT/SetVector.h"
20#include "llvm/ADT/Statistic.h"
23#include "llvm/Analysis/CFG.h"
28#include "llvm/IR/CFG.h"
29#include "llvm/IR/Dominators.h"
36using namespace llvm;
37
38#define DEBUG_TYPE "break-crit-edges"
39
40STATISTIC(NumBroken, "Number of blocks inserted");
41
42namespace {
43struct BreakCriticalEdges : public FunctionPass {
44 static char ID; // Pass identification, replacement for typeid
45 BreakCriticalEdges() : FunctionPass(ID) {
47 }
48
49 bool runOnFunction(Function &F) override {
50 auto *DTWP = getAnalysisIfAvailable<DominatorTreeWrapperPass>();
51 auto *DT = DTWP ? &DTWP->getDomTree() : nullptr;
52
53 auto *PDTWP = getAnalysisIfAvailable<PostDominatorTreeWrapperPass>();
54 auto *PDT = PDTWP ? &PDTWP->getPostDomTree() : nullptr;
55
56 auto *LIWP = getAnalysisIfAvailable<LoopInfoWrapperPass>();
57 auto *LI = LIWP ? &LIWP->getLoopInfo() : nullptr;
58 unsigned N = SplitAllCriticalEdges(
59 F, CriticalEdgeSplittingOptions(DT, LI, nullptr, PDT));
60 NumBroken += N;
61 return N > 0;
62 }
63
64 void getAnalysisUsage(AnalysisUsage &AU) const override {
65 AU.addPreserved<DominatorTreeWrapperPass>();
66 AU.addPreserved<LoopInfoWrapperPass>();
67
68 // No loop canonicalization guarantees are broken by this pass.
70 }
71};
72} // namespace
73
74char BreakCriticalEdges::ID = 0;
75INITIALIZE_PASS(BreakCriticalEdges, "break-crit-edges",
76 "Break critical edges in CFG", false, false)
77
78// Publicly exposed interface to pass...
79char &llvm::BreakCriticalEdgesID = BreakCriticalEdges::ID;
80
82 return new BreakCriticalEdges();
83}
84
98
99//===----------------------------------------------------------------------===//
100// Implementation of the external critical edge manipulation functions
101//===----------------------------------------------------------------------===//
102
105 const Twine &BBName) {
106 if (!isCriticalEdge(TI, SuccNum, Options.MergeIdenticalEdges))
107 return nullptr;
108
109 return SplitKnownCriticalEdge(TI, SuccNum, Options, BBName);
110}
111
115 const Twine &BBName) {
116 BasicBlock *TIBB = TI->getParent();
117 BasicBlock *DestBB = TI->getSuccessor(SuccNum);
118
119 // Splitting the critical edge to a pad block is non-trivial.
120 // And we cannot split block with IndirectBr as a terminator.
121 // Don't do it in this generic function.
122 if (DestBB->isEHPad() || isa<IndirectBrInst>(TI))
123 return nullptr;
124
125 if (Options.IgnoreUnreachableDests &&
127 return nullptr;
128
129 auto *LI = Options.LI;
131 // Check if extra modifications will be required to preserve loop-simplify
132 // form after splitting. If it would require splitting blocks with IndirectBr
133 // terminators, bail out if preserving loop-simplify form is requested.
134 if (LI) {
135 if (Loop *TIL = LI->getLoopFor(TIBB)) {
136
137 // The only way that we can break LoopSimplify form by splitting a
138 // critical edge is if after the split there exists some edge from TIL to
139 // DestBB *and* the only edge into DestBB from outside of TIL is that of
140 // NewBB. If the first isn't true, then LoopSimplify still holds, NewBB
141 // is the new exit block and it has no non-loop predecessors. If the
142 // second isn't true, then DestBB was not in LoopSimplify form prior to
143 // the split as it had a non-loop predecessor. In both of these cases,
144 // the predecessor must be directly in TIL, not in a subloop, or again
145 // LoopSimplify doesn't hold.
146 for (BasicBlock *P : predecessors(DestBB)) {
147 if (P == TIBB)
148 continue; // The new block is known.
149 if (LI->getLoopFor(P) != TIL) {
150 // No need to re-simplify, it wasn't to start with.
151 LoopPreds.clear();
152 break;
153 }
154 LoopPreds.push_back(P);
155 }
156 // Loop-simplify form can be preserved, if we can split all in-loop
157 // predecessors.
158 if (any_of(LoopPreds, [](BasicBlock *Pred) {
159 return isa<IndirectBrInst>(Pred->getTerminator());
160 })) {
161 if (Options.PreserveLoopSimplify)
162 return nullptr;
163 LoopPreds.clear();
164 }
165 }
166 }
167
168 // Create a new basic block, linking it into the CFG.
169 BasicBlock *NewBB = nullptr;
170 if (BBName.str() != "")
171 NewBB = BasicBlock::Create(TI->getContext(), BBName);
172 else
173 NewBB = BasicBlock::Create(TI->getContext(), TIBB->getName() + "." +
174 DestBB->getName() +
175 "_crit_edge");
176 // Create our unconditional branch.
177 UncondBrInst *NewBI = UncondBrInst::Create(DestBB, NewBB);
178 NewBI->setDebugLoc(TI->getDebugLoc());
179 if (auto *LoopMD = TI->getMetadata(LLVMContext::MD_loop))
180 NewBI->setMetadata(LLVMContext::MD_loop, LoopMD);
181
182 // Insert the block into the function... right after the block TI lives in.
183 Function &F = *TIBB->getParent();
184 Function::iterator FBBI = TIBB->getIterator();
185 F.insert(++FBBI, NewBB);
186
187 // Branch to the new block, breaking the edge.
188 TI->setSuccessor(SuccNum, NewBB);
189
190 // If there are any PHI nodes in DestBB, we need to update them so that they
191 // merge incoming values from NewBB instead of from TIBB.
192 {
193 unsigned BBIdx = 0;
194 for (BasicBlock::iterator I = DestBB->begin(); isa<PHINode>(I); ++I) {
195 // We no longer enter through TIBB, now we come in through NewBB.
196 // Revector exactly one entry in the PHI node that used to come from
197 // TIBB to come from NewBB.
198 PHINode *PN = cast<PHINode>(I);
199
200 // Reuse the previous value of BBIdx if it lines up. In cases where we
201 // have multiple phi nodes with *lots* of predecessors, this is a speed
202 // win because we don't have to scan the PHI looking for TIBB. This
203 // happens because the BB list of PHI nodes are usually in the same
204 // order.
205 if (PN->getIncomingBlock(BBIdx) != TIBB)
206 BBIdx = PN->getBasicBlockIndex(TIBB);
207 PN->setIncomingBlock(BBIdx, NewBB);
208 }
209 }
210
211 unsigned NumSplitIdenticalEdges = 1;
212
213 // If there are any other edges from TIBB to DestBB, update those to go
214 // through the split block, making those edges non-critical as well (and
215 // reducing the number of phi entries in the DestBB if relevant).
216 if (Options.MergeIdenticalEdges) {
217 for (unsigned i = SuccNum+1, e = TI->getNumSuccessors(); i != e; ++i) {
218 if (TI->getSuccessor(i) != DestBB) continue;
219
220 // Remove an entry for TIBB from DestBB phi nodes.
221 DestBB->removePredecessor(TIBB, Options.KeepOneInputPHIs);
222
223 // We found another edge to DestBB, go to NewBB instead.
224 TI->setSuccessor(i, NewBB);
225
226 // Record the number of split identical edges to DestBB.
227 NumSplitIdenticalEdges++;
228 }
229 }
230
231 // If we have nothing to update, just return.
232 auto *DT = Options.DT;
233 auto *PDT = Options.PDT;
234 auto *MSSAU = Options.MSSAU;
235 if (MSSAU)
236 MSSAU->wireOldPredecessorsToNewImmediatePredecessor(
237 DestBB, NewBB, {TIBB}, Options.MergeIdenticalEdges);
238
239 if (!DT && !PDT && !LI)
240 return NewBB;
241
242 if (DT || PDT) {
243 // Update the DominatorTree.
244 // ---> NewBB -----\
245 // / V
246 // TIBB -------\\------> DestBB
247 //
248 // First, inform the DT about the new path from TIBB to DestBB via NewBB,
249 // then delete the old edge from TIBB to DestBB. By doing this in that order
250 // DestBB stays reachable in the DT the whole time and its subtree doesn't
251 // get disconnected.
253 Updates.push_back({DominatorTree::Insert, TIBB, NewBB});
254 Updates.push_back({DominatorTree::Insert, NewBB, DestBB});
255 if (!llvm::is_contained(successors(TIBB), DestBB))
256 Updates.push_back({DominatorTree::Delete, TIBB, DestBB});
257
258 if (DT)
259 DT->applyUpdates(Updates);
260 if (PDT)
261 PDT->applyUpdates(Updates);
262 }
263
264 // Update LoopInfo if it is around.
265 if (LI) {
266 if (Loop *TIL = LI->getLoopFor(TIBB)) {
267 // If one or the other blocks were not in a loop, the new block is not
268 // either, and thus LI doesn't need to be updated.
269 if (Loop *DestLoop = LI->getLoopFor(DestBB)) {
270 if (TIL == DestLoop) {
271 // Both in the same loop, the NewBB joins loop.
272 DestLoop->addBasicBlockToLoop(NewBB, *LI);
273 } else if (TIL->contains(DestLoop)) {
274 // Edge from an outer loop to an inner loop. Add to the outer loop.
275 TIL->addBasicBlockToLoop(NewBB, *LI);
276 } else if (DestLoop->contains(TIL)) {
277 // Edge from an inner loop to an outer loop. Add to the outer loop.
278 DestLoop->addBasicBlockToLoop(NewBB, *LI);
279 } else {
280 // Edge from two loops with no containment relation. Because these
281 // are natural loops, we know that the destination block must be the
282 // header of its loop (adding a branch into a loop elsewhere would
283 // create an irreducible loop).
284 assert(DestLoop->getHeader() == DestBB &&
285 "Should not create irreducible loops!");
286 if (Loop *P = DestLoop->getParentLoop())
287 P->addBasicBlockToLoop(NewBB, *LI);
288 }
289 }
290
291 // If TIBB is in a loop and DestBB is outside of that loop, we may need
292 // to update LoopSimplify form and LCSSA form.
293 if (!TIL->contains(DestBB)) {
294 assert(!TIL->contains(NewBB) &&
295 "Split point for loop exit is contained in loop!");
296
297 // Update LCSSA form in the newly created exit block.
298 if (Options.PreserveLCSSA) {
299 // If > 1 identical edges to be split, we need to introduce the same
300 // number of the incoming blocks for the new PHINode.
302 SmallVector<BasicBlock *, 4>(NumSplitIdenticalEdges, TIBB), NewBB,
303 DestBB);
304 }
305
306 if (!LoopPreds.empty()) {
307 assert(!DestBB->isEHPad() && "We don't split edges to EH pads!");
309 DestBB, LoopPreds, "split", DT, LI, MSSAU, Options.PreserveLCSSA);
310 if (Options.PreserveLCSSA)
311 createPHIsForSplitLoopExit(LoopPreds, NewExitBB, DestBB);
312 }
313 }
314 }
315 }
316
317 return NewBB;
318}
319
320// Return the unique indirectbr predecessor of a block. This may return null
321// even if such a predecessor exists, if it's not useful for splitting.
322// If a predecessor is found, OtherPreds will contain all other (non-indirectbr)
323// predecessors of BB.
324static BasicBlock *
326 // Verify we have exactly one IBR predecessor.
327 // Conservatively bail out if one of the other predecessors is not a "regular"
328 // terminator (that is, not a switch or a br).
329 BasicBlock *IBB = nullptr;
330 for (BasicBlock *PredBB : predecessors(BB)) {
331 Instruction *PredTerm = PredBB->getTerminator();
332 switch (PredTerm->getOpcode()) {
333 case Instruction::IndirectBr:
334 if (IBB)
335 return nullptr;
336 IBB = PredBB;
337 break;
338 case Instruction::UncondBr:
339 case Instruction::CondBr:
340 case Instruction::Switch:
341 OtherPreds.push_back(PredBB);
342 continue;
343 default:
344 return nullptr;
345 }
346 }
347
348 return IBB;
349}
350
352 bool IgnoreBlocksWithoutPHI,
355 DomTreeUpdater *DTU) {
356 // Check whether the function has any indirectbrs, and collect which blocks
357 // they may jump to. Since most functions don't have indirect branches,
358 // this lowers the common case's overhead to O(Blocks) instead of O(Edges).
360 for (auto &BB : F) {
361 if (isa<IndirectBrInst>(BB.getTerminator()))
362 Targets.insert_range(successors(&BB));
363 }
364
365 if (Targets.empty())
366 return false;
367
368 bool ShouldUpdateAnalysis = BPI && BFI;
369 bool Changed = false;
370 for (BasicBlock *Target : Targets) {
371 if (IgnoreBlocksWithoutPHI && Target->phis().empty())
372 continue;
373
375 BasicBlock *IBRPred = findIBRPredecessor(Target, OtherPreds);
376 // If we did not found an indirectbr, or the indirectbr is the only
377 // incoming edge, this isn't the kind of edge we're looking for.
378 if (!IBRPred || OtherPreds.empty())
379 continue;
380
381 // Don't even think about ehpads/landingpads.
382 auto FirstNonPHIIt = Target->getFirstNonPHIIt();
383 if (FirstNonPHIIt->isEHPad() || Target->isLandingPad())
384 continue;
385
386 // Remember edge probabilities if needed.
387 SmallVector<BranchProbability, 4> EdgeProbabilities;
388 if (ShouldUpdateAnalysis) {
389 EdgeProbabilities.reserve(Target->getTerminator()->getNumSuccessors());
390 for (unsigned I = 0, E = Target->getTerminator()->getNumSuccessors();
391 I < E; ++I)
392 EdgeProbabilities.emplace_back(BPI->getEdgeProbability(Target, I));
393 BPI->eraseBlock(Target);
394 }
395
396 BasicBlock *BodyBlock =
397 SplitBlock(Target, FirstNonPHIIt, DTU, nullptr, nullptr, ".split");
398 if (ShouldUpdateAnalysis) {
399 // Copy the BFI/BPI from Target to BodyBlock.
400 BPI->setEdgeProbability(BodyBlock, EdgeProbabilities);
401 BFI->setBlockFreq(BodyBlock, BFI->getBlockFreq(Target));
402 }
403 // It's possible Target was its own successor through an indirectbr.
404 // In this case, the indirectbr now comes from BodyBlock.
405 if (IBRPred == Target)
406 IBRPred = BodyBlock;
407
408 // At this point Target only has PHIs, and BodyBlock has the rest of the
409 // block's body. Create a copy of Target that will be used by the "direct"
410 // preds.
412 BasicBlock *DirectSucc = CloneBasicBlock(Target, VMap, ".clone", &F);
413 if (!VMap.AtomMap.empty())
414 for (Instruction &I : *DirectSucc)
415 RemapSourceAtom(&I, VMap);
416
417 BlockFrequency BlockFreqForDirectSucc;
419 if (DTU)
420 DTUpdates.reserve(OtherPreds.size() * 2 + 1);
421 for (BasicBlock *Pred : OtherPreds) {
422 // If the target is a loop to itself, then the terminator of the split
423 // block (BodyBlock) needs to be updated.
424 BasicBlock *Src = Pred != Target ? Pred : BodyBlock;
425 Src->getTerminator()->replaceUsesOfWith(Target, DirectSucc);
426 if (ShouldUpdateAnalysis)
427 BlockFreqForDirectSucc += BFI->getBlockFreq(Src) *
428 BPI->getEdgeProbability(Src, DirectSucc);
429 if (DTU) {
430 DTUpdates.push_back({DominatorTree::Insert, Src, DirectSucc});
431 DTUpdates.push_back({DominatorTree::Delete, Src, Target});
432 }
433 }
434 if (ShouldUpdateAnalysis) {
435 BFI->setBlockFreq(DirectSucc, BlockFreqForDirectSucc);
436 BlockFrequency NewBlockFreqForTarget =
437 BFI->getBlockFreq(Target) - BlockFreqForDirectSucc;
438 BFI->setBlockFreq(Target, NewBlockFreqForTarget);
439 }
440 if (DTU) {
441 DTUpdates.push_back({DominatorTree::Insert, DirectSucc, BodyBlock});
442 DTU->applyUpdates(DTUpdates);
443 }
444
445 // Ok, now fix up the PHIs. We know the two blocks only have PHIs, and that
446 // they are clones, so the number of PHIs are the same.
447 // (a) Remove the edge coming from IBRPred from the "Direct" PHI
448 // (b) Leave that as the only edge in the "Indirect" PHI.
449 // (c) Merge the two in the body block.
450 BasicBlock::iterator Indirect = Target->begin(),
451 End = Target->getFirstNonPHIIt();
452 BasicBlock::iterator Direct = DirectSucc->begin();
453 BasicBlock::iterator MergeInsert = BodyBlock->getFirstInsertionPt();
454
455 assert(&*End == Target->getTerminator() &&
456 "Block was expected to only contain PHIs");
457
458 while (Indirect != End) {
459 PHINode *DirPHI = cast<PHINode>(Direct);
460 PHINode *IndPHI = cast<PHINode>(Indirect);
461 BasicBlock::iterator InsertPt = Indirect;
462
463 // Now, clean up - the direct block shouldn't get the indirect value,
464 // and vice versa.
465 DirPHI->removeIncomingValue(IBRPred);
466 Direct++;
467
468 // Advance the pointer here, to avoid invalidation issues when the old
469 // PHI is erased.
470 Indirect++;
471
472 PHINode *NewIndPHI = PHINode::Create(IndPHI->getType(), 1, "ind", InsertPt);
473 NewIndPHI->addIncoming(IndPHI->getIncomingValueForBlock(IBRPred),
474 IBRPred);
475 NewIndPHI->setDebugLoc(IndPHI->getDebugLoc());
476
477 // Create a PHI in the body block, to merge the direct and indirect
478 // predecessors.
479 PHINode *MergePHI = PHINode::Create(IndPHI->getType(), 2, "merge");
480 MergePHI->insertBefore(MergeInsert);
481 MergePHI->addIncoming(NewIndPHI, Target);
482 MergePHI->addIncoming(DirPHI, DirectSucc);
483 MergePHI->applyMergedLocation(DirPHI->getDebugLoc(),
484 IndPHI->getDebugLoc());
485
486 IndPHI->replaceAllUsesWith(MergePHI);
487 IndPHI->eraseFromParent();
488 }
489
490 Changed = true;
491 }
492
493 return Changed;
494}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static BasicBlock * findIBRPredecessor(BasicBlock *BB, SmallVectorImpl< BasicBlock * > &OtherPreds)
static bool runOnFunction(Function &F, bool PostInlining)
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
static LVOptions Options
Definition LVOptions.cpp:25
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
#define P(N)
static cl::opt< bool > SplitAllCriticalEdges("phi-elim-split-all-critical-edges", cl::init(false), cl::Hidden, cl::desc("Split all critical edges during " "PHI elimination"))
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition PassSupport.h:56
This file implements a set that has insertion order iteration characteristics.
This file defines the SmallVector class.
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
PassT::Result * getCachedResult(IRUnitT &IR) const
Get the cached result of an analysis pass for a given IR unit.
AnalysisUsage & addPreservedID(const void *ID)
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
LLVM Basic Block Representation.
Definition BasicBlock.h:62
iterator begin()
Instruction iterator methods.
Definition BasicBlock.h:461
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...
const Function * getParent() const
Return the enclosing method, or null if none.
Definition BasicBlock.h:213
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
Definition BasicBlock.h:206
InstListType::iterator iterator
Instruction iterators...
Definition BasicBlock.h:170
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,...
bool isEHPad() const
Return true if this basic block is an exception handling block.
Definition BasicBlock.h:704
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction; assumes that the block is well-formed.
Definition BasicBlock.h:237
LLVM_ABI void removePredecessor(BasicBlock *Pred, bool KeepOneInputPHIs=false)
Update PHI nodes in this BasicBlock before removal of predecessor Pred.
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
LLVM_ABI void setBlockFreq(const BasicBlock *BB, BlockFrequency Freq)
LLVM_ABI BlockFrequency getBlockFreq(const BasicBlock *BB) const
getblockFreq - Return block frequency.
Analysis providing branch probability information.
LLVM_ABI void eraseBlock(const BasicBlock *BB)
Forget analysis results for the given basic block.
LLVM_ABI void setEdgeProbability(const BasicBlock *Src, const SmallVectorImpl< BranchProbability > &Probs)
Set the raw probabilities for all edges from the given block.
LLVM_ABI BranchProbability getEdgeProbability(const BasicBlock *Src, unsigned IndexInSuccessors) const
Get an edge's probability, relative to other out-edges of the Src.
Analysis pass which computes a DominatorTree.
Definition Dominators.h:278
FunctionPass class - This class is used to implement most global optimizations.
Definition Pass.h:314
BasicBlockListType::iterator iterator
Definition Function.h:70
void applyUpdates(ArrayRef< UpdateT > Updates)
Submit updates to all available trees.
LLVM_ABI unsigned getNumSuccessors() const LLVM_READONLY
Return the number of successors that this instruction has.
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
LLVM_ABI void insertBefore(InstListType::iterator InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified position.
LLVM_ABI InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
LLVM_ABI BasicBlock * getSuccessor(unsigned Idx) const LLVM_READONLY
Return the specified successor. This instruction must be a terminator.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
LLVM_ABI void setSuccessor(unsigned Idx, BasicBlock *BB)
Update the specified successor to point at the provided block.
LLVM_ABI void applyMergedLocation(DebugLoc LocA, DebugLoc LocB)
Merge 2 debug locations and apply it to the Instruction.
Analysis pass that exposes the LoopInfo for a function.
Definition LoopInfo.h:569
Represents a single loop in the control flow graph.
Definition LoopInfo.h:40
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
void setIncomingBlock(unsigned i, BasicBlock *BB)
LLVM_ABI Value * removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty=true)
Remove an incoming value.
Value * getIncomingValueForBlock(const BasicBlock *BB) const
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
int getBasicBlockIndex(const BasicBlock *BB) const
Return the first index of the specified basic block in the value list for this PHI.
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...
static LLVM_ABI PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
PreservedAnalyses & preserve()
Mark an analysis as preserved.
Definition Analysis.h:132
void insert_range(Range &&R)
Definition SetVector.h:176
bool empty() const
Determine if the SetVector is empty or not.
Definition SetVector.h:100
A SetVector that performs no allocations if smaller than a certain size.
Definition SetVector.h:339
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
reference emplace_back(ArgTypes &&... Args)
void reserve(size_type N)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Target - Wrapper for Target specific information.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
LLVM_ABI std::string str() const
Return the twine contents as a std::string.
Definition Twine.cpp:17
Unconditional Branch instruction.
static UncondBrInst * Create(BasicBlock *Target, InsertPosition InsertBefore=nullptr)
LLVM_ABI bool replaceUsesOfWith(Value *From, Value *To)
Replace uses of one Value with another.
Definition User.cpp:25
DMAtomT AtomMap
Map {(InlinedAt, old atom number) -> new atom number}.
Definition ValueMap.h:123
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
LLVMContext & getContext() const
All values hold a context through their type.
Definition Value.h:259
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
Definition Value.cpp:322
const ParentTy * getParent() const
Definition ilist_node.h:34
self_iterator getIterator()
Definition ilist_node.h:123
Changed
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI BasicBlock * CloneBasicBlock(const BasicBlock *BB, ValueToValueMapTy &VMap, const Twine &NameSuffix="", Function *F=nullptr, ClonedCodeInfo *CodeInfo=nullptr, bool MapAtoms=true)
Return a copy of the specified basic block, but without embedding the block into a particular functio...
auto successors(const MachineBasicBlock *BB)
LLVM_ABI FunctionPass * createBreakCriticalEdgesPass()
LLVM_ABI bool SplitIndirectBrCriticalEdges(Function &F, bool IgnoreBlocksWithoutPHI, BranchProbabilityInfo *BPI=nullptr, BlockFrequencyInfo *BFI=nullptr, DomTreeUpdater *DTU=nullptr)
LLVM_ABI char & LoopSimplifyID
LLVM_ABI BasicBlock * SplitKnownCriticalEdge(Instruction *TI, unsigned SuccNum, const CriticalEdgeSplittingOptions &Options=CriticalEdgeSplittingOptions(), const Twine &BBName="")
If it is known that an edge is critical, SplitKnownCriticalEdge can be called directly,...
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1746
LLVM_ABI char & BreakCriticalEdgesID
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
LLVM_ABI BasicBlock * SplitBlockPredecessors(BasicBlock *BB, ArrayRef< BasicBlock * > Preds, const char *Suffix, DominatorTree *DT, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, bool PreserveLCSSA=false)
This method introduces at least one new basic block into the function and moves some of the predecess...
LLVM_ABI void createPHIsForSplitLoopExit(ArrayRef< BasicBlock * > Preds, BasicBlock *SplitBB, BasicBlock *DestBB)
When a loop exit edge is split, LCSSA form may require new PHIs in the new exit block.
LLVM_ABI void initializeBreakCriticalEdgesPass(PassRegistry &)
LLVM_ABI BasicBlock * SplitBlock(BasicBlock *Old, BasicBlock::iterator SplitPt, DominatorTree *DT, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, const Twine &BBName="")
Split the specified block at the specified instruction.
LLVM_ABI BasicBlock * SplitCriticalEdge(Instruction *TI, unsigned SuccNum, const CriticalEdgeSplittingOptions &Options=CriticalEdgeSplittingOptions(), const Twine &BBName="")
If this edge is a critical edge, insert a new node to split the critical edge.
LLVM_ABI bool isCriticalEdge(const Instruction *TI, unsigned SuccNum, bool AllowIdenticalEdges=false)
Return true if the specified edge is a critical edge.
Definition CFG.cpp:106
ValueMap< const Value *, WeakTrackingVH > ValueToValueMapTy
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
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
LLVM_ABI void RemapSourceAtom(Instruction *I, ValueToValueMapTy &VM)
Remap source location atom.
#define N
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
Option class for critical edge splitting.