LLVM  7.0.0svn
BreakCriticalEdges.cpp
Go to the documentation of this file.
1 //===- BreakCriticalEdges.cpp - Critical Edge Elimination Pass ------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // BreakCriticalEdges pass - Break all of the critical edges in the CFG by
11 // inserting a dummy basic block. This pass may be "required" by passes that
12 // cannot deal with critical edges. For this usage, the structure type is
13 // forward declared. This pass obviously invalidates the CFG, but can update
14 // dominator trees.
15 //
16 //===----------------------------------------------------------------------===//
17 
19 #include "llvm/ADT/SetVector.h"
20 #include "llvm/ADT/SmallVector.h"
21 #include "llvm/ADT/Statistic.h"
24 #include "llvm/Analysis/CFG.h"
25 #include "llvm/Analysis/LoopInfo.h"
26 #include "llvm/IR/CFG.h"
27 #include "llvm/IR/Dominators.h"
28 #include "llvm/IR/Instructions.h"
29 #include "llvm/IR/Type.h"
31 #include "llvm/Transforms/Utils.h"
35 using namespace llvm;
36 
37 #define DEBUG_TYPE "break-crit-edges"
38 
39 STATISTIC(NumBroken, "Number of blocks inserted");
40 
41 namespace {
42  struct BreakCriticalEdges : public FunctionPass {
43  static char ID; // Pass identification, replacement for typeid
44  BreakCriticalEdges() : FunctionPass(ID) {
46  }
47 
48  bool runOnFunction(Function &F) override {
49  auto *DTWP = getAnalysisIfAvailable<DominatorTreeWrapperPass>();
50  auto *DT = DTWP ? &DTWP->getDomTree() : nullptr;
51  auto *LIWP = getAnalysisIfAvailable<LoopInfoWrapperPass>();
52  auto *LI = LIWP ? &LIWP->getLoopInfo() : nullptr;
53  unsigned N =
55  NumBroken += N;
56  return N > 0;
57  }
58 
59  void getAnalysisUsage(AnalysisUsage &AU) const override {
62 
63  // No loop canonicalization guarantees are broken by this pass.
65  }
66  };
67 }
68 
69 char BreakCriticalEdges::ID = 0;
70 INITIALIZE_PASS(BreakCriticalEdges, "break-crit-edges",
71  "Break critical edges in CFG", false, false)
72 
73 // Publicly exposed interface to pass...
74 char &llvm::BreakCriticalEdgesID = BreakCriticalEdges::ID;
76  return new BreakCriticalEdges();
77 }
78 
81  auto *DT = AM.getCachedResult<DominatorTreeAnalysis>(F);
82  auto *LI = AM.getCachedResult<LoopAnalysis>(F);
84  NumBroken += N;
85  if (N == 0)
86  return PreservedAnalyses::all();
89  PA.preserve<LoopAnalysis>();
90  return PA;
91 }
92 
93 //===----------------------------------------------------------------------===//
94 // Implementation of the external critical edge manipulation functions
95 //===----------------------------------------------------------------------===//
96 
97 /// When a loop exit edge is split, LCSSA form may require new PHIs in the new
98 /// exit block. This function inserts the new PHIs, as needed. Preds is a list
99 /// of preds inside the loop, SplitBB is the new loop exit block, and DestBB is
100 /// the old loop exit, now the successor of SplitBB.
102  BasicBlock *SplitBB,
103  BasicBlock *DestBB) {
104  // SplitBB shouldn't have anything non-trivial in it yet.
105  assert((SplitBB->getFirstNonPHI() == SplitBB->getTerminator() ||
106  SplitBB->isLandingPad()) && "SplitBB has non-PHI nodes!");
107 
108  // For each PHI in the destination block.
109  for (PHINode &PN : DestBB->phis()) {
110  unsigned Idx = PN.getBasicBlockIndex(SplitBB);
111  Value *V = PN.getIncomingValue(Idx);
112 
113  // If the input is a PHI which already satisfies LCSSA, don't create
114  // a new one.
115  if (const PHINode *VP = dyn_cast<PHINode>(V))
116  if (VP->getParent() == SplitBB)
117  continue;
118 
119  // Otherwise a new PHI is needed. Create one and populate it.
120  PHINode *NewPN = PHINode::Create(
121  PN.getType(), Preds.size(), "split",
122  SplitBB->isLandingPad() ? &SplitBB->front() : SplitBB->getTerminator());
123  for (unsigned i = 0, e = Preds.size(); i != e; ++i)
124  NewPN->addIncoming(V, Preds[i]);
125 
126  // Update the original PHI.
127  PN.setIncomingValue(Idx, NewPN);
128  }
129 }
130 
131 BasicBlock *
133  const CriticalEdgeSplittingOptions &Options) {
134  if (!isCriticalEdge(TI, SuccNum, Options.MergeIdenticalEdges))
135  return nullptr;
136 
137  assert(!isa<IndirectBrInst>(TI) &&
138  "Cannot split critical edge from IndirectBrInst");
139 
140  BasicBlock *TIBB = TI->getParent();
141  BasicBlock *DestBB = TI->getSuccessor(SuccNum);
142 
143  // Splitting the critical edge to a pad block is non-trivial. Don't do
144  // it in this generic function.
145  if (DestBB->isEHPad()) return nullptr;
146 
147  // Create a new basic block, linking it into the CFG.
149  TIBB->getName() + "." + DestBB->getName() + "_crit_edge");
150  // Create our unconditional branch.
151  BranchInst *NewBI = BranchInst::Create(DestBB, NewBB);
152  NewBI->setDebugLoc(TI->getDebugLoc());
153 
154  // Branch to the new block, breaking the edge.
155  TI->setSuccessor(SuccNum, NewBB);
156 
157  // Insert the block into the function... right after the block TI lives in.
158  Function &F = *TIBB->getParent();
159  Function::iterator FBBI = TIBB->getIterator();
160  F.getBasicBlockList().insert(++FBBI, NewBB);
161 
162  // If there are any PHI nodes in DestBB, we need to update them so that they
163  // merge incoming values from NewBB instead of from TIBB.
164  {
165  unsigned BBIdx = 0;
166  for (BasicBlock::iterator I = DestBB->begin(); isa<PHINode>(I); ++I) {
167  // We no longer enter through TIBB, now we come in through NewBB.
168  // Revector exactly one entry in the PHI node that used to come from
169  // TIBB to come from NewBB.
170  PHINode *PN = cast<PHINode>(I);
171 
172  // Reuse the previous value of BBIdx if it lines up. In cases where we
173  // have multiple phi nodes with *lots* of predecessors, this is a speed
174  // win because we don't have to scan the PHI looking for TIBB. This
175  // happens because the BB list of PHI nodes are usually in the same
176  // order.
177  if (PN->getIncomingBlock(BBIdx) != TIBB)
178  BBIdx = PN->getBasicBlockIndex(TIBB);
179  PN->setIncomingBlock(BBIdx, NewBB);
180  }
181  }
182 
183  // If there are any other edges from TIBB to DestBB, update those to go
184  // through the split block, making those edges non-critical as well (and
185  // reducing the number of phi entries in the DestBB if relevant).
186  if (Options.MergeIdenticalEdges) {
187  for (unsigned i = SuccNum+1, e = TI->getNumSuccessors(); i != e; ++i) {
188  if (TI->getSuccessor(i) != DestBB) continue;
189 
190  // Remove an entry for TIBB from DestBB phi nodes.
191  DestBB->removePredecessor(TIBB, Options.DontDeleteUselessPHIs);
192 
193  // We found another edge to DestBB, go to NewBB instead.
194  TI->setSuccessor(i, NewBB);
195  }
196  }
197 
198  // If we have nothing to update, just return.
199  auto *DT = Options.DT;
200  auto *LI = Options.LI;
201  if (!DT && !LI)
202  return NewBB;
203 
204  if (DT) {
205  // Update the DominatorTree.
206  // ---> NewBB -----\
207  // / V
208  // TIBB -------\\------> DestBB
209  //
210  // First, inform the DT about the new path from TIBB to DestBB via NewBB,
211  // then delete the old edge from TIBB to DestBB. By doing this in that order
212  // DestBB stays reachable in the DT the whole time and its subtree doesn't
213  // get disconnected.
215  Updates.push_back({DominatorTree::Insert, TIBB, NewBB});
216  Updates.push_back({DominatorTree::Insert, NewBB, DestBB});
217  if (llvm::find(successors(TIBB), DestBB) == succ_end(TIBB))
218  Updates.push_back({DominatorTree::Delete, TIBB, DestBB});
219 
220  DT->applyUpdates(Updates);
221  }
222 
223  // Update LoopInfo if it is around.
224  if (LI) {
225  if (Loop *TIL = LI->getLoopFor(TIBB)) {
226  // If one or the other blocks were not in a loop, the new block is not
227  // either, and thus LI doesn't need to be updated.
228  if (Loop *DestLoop = LI->getLoopFor(DestBB)) {
229  if (TIL == DestLoop) {
230  // Both in the same loop, the NewBB joins loop.
231  DestLoop->addBasicBlockToLoop(NewBB, *LI);
232  } else if (TIL->contains(DestLoop)) {
233  // Edge from an outer loop to an inner loop. Add to the outer loop.
234  TIL->addBasicBlockToLoop(NewBB, *LI);
235  } else if (DestLoop->contains(TIL)) {
236  // Edge from an inner loop to an outer loop. Add to the outer loop.
237  DestLoop->addBasicBlockToLoop(NewBB, *LI);
238  } else {
239  // Edge from two loops with no containment relation. Because these
240  // are natural loops, we know that the destination block must be the
241  // header of its loop (adding a branch into a loop elsewhere would
242  // create an irreducible loop).
243  assert(DestLoop->getHeader() == DestBB &&
244  "Should not create irreducible loops!");
245  if (Loop *P = DestLoop->getParentLoop())
246  P->addBasicBlockToLoop(NewBB, *LI);
247  }
248  }
249 
250  // If TIBB is in a loop and DestBB is outside of that loop, we may need
251  // to update LoopSimplify form and LCSSA form.
252  if (!TIL->contains(DestBB)) {
253  assert(!TIL->contains(NewBB) &&
254  "Split point for loop exit is contained in loop!");
255 
256  // Update LCSSA form in the newly created exit block.
257  if (Options.PreserveLCSSA) {
258  createPHIsForSplitLoopExit(TIBB, NewBB, DestBB);
259  }
260 
261  // The only that we can break LoopSimplify form by splitting a critical
262  // edge is if after the split there exists some edge from TIL to DestBB
263  // *and* the only edge into DestBB from outside of TIL is that of
264  // NewBB. If the first isn't true, then LoopSimplify still holds, NewBB
265  // is the new exit block and it has no non-loop predecessors. If the
266  // second isn't true, then DestBB was not in LoopSimplify form prior to
267  // the split as it had a non-loop predecessor. In both of these cases,
268  // the predecessor must be directly in TIL, not in a subloop, or again
269  // LoopSimplify doesn't hold.
271  for (pred_iterator I = pred_begin(DestBB), E = pred_end(DestBB); I != E;
272  ++I) {
273  BasicBlock *P = *I;
274  if (P == NewBB)
275  continue; // The new block is known.
276  if (LI->getLoopFor(P) != TIL) {
277  // No need to re-simplify, it wasn't to start with.
278  LoopPreds.clear();
279  break;
280  }
281  LoopPreds.push_back(P);
282  }
283  if (!LoopPreds.empty()) {
284  assert(!DestBB->isEHPad() && "We don't split edges to EH pads!");
285  BasicBlock *NewExitBB = SplitBlockPredecessors(
286  DestBB, LoopPreds, "split", DT, LI, Options.PreserveLCSSA);
287  if (Options.PreserveLCSSA)
288  createPHIsForSplitLoopExit(LoopPreds, NewExitBB, DestBB);
289  }
290  }
291  }
292  }
293 
294  return NewBB;
295 }
296 
297 // Return the unique indirectbr predecessor of a block. This may return null
298 // even if such a predecessor exists, if it's not useful for splitting.
299 // If a predecessor is found, OtherPreds will contain all other (non-indirectbr)
300 // predecessors of BB.
301 static BasicBlock *
303  // If the block doesn't have any PHIs, we don't care about it, since there's
304  // no point in splitting it.
305  PHINode *PN = dyn_cast<PHINode>(BB->begin());
306  if (!PN)
307  return nullptr;
308 
309  // Verify we have exactly one IBR predecessor.
310  // Conservatively bail out if one of the other predecessors is not a "regular"
311  // terminator (that is, not a switch or a br).
312  BasicBlock *IBB = nullptr;
313  for (unsigned Pred = 0, E = PN->getNumIncomingValues(); Pred != E; ++Pred) {
314  BasicBlock *PredBB = PN->getIncomingBlock(Pred);
315  TerminatorInst *PredTerm = PredBB->getTerminator();
316  switch (PredTerm->getOpcode()) {
317  case Instruction::IndirectBr:
318  if (IBB)
319  return nullptr;
320  IBB = PredBB;
321  break;
322  case Instruction::Br:
323  case Instruction::Switch:
324  OtherPreds.push_back(PredBB);
325  continue;
326  default:
327  return nullptr;
328  }
329  }
330 
331  return IBB;
332 }
333 
337  // Check whether the function has any indirectbrs, and collect which blocks
338  // they may jump to. Since most functions don't have indirect branches,
339  // this lowers the common case's overhead to O(Blocks) instead of O(Edges).
341  for (auto &BB : F) {
342  auto *IBI = dyn_cast<IndirectBrInst>(BB.getTerminator());
343  if (!IBI)
344  continue;
345 
346  for (unsigned Succ = 0, E = IBI->getNumSuccessors(); Succ != E; ++Succ)
347  Targets.insert(IBI->getSuccessor(Succ));
348  }
349 
350  if (Targets.empty())
351  return false;
352 
353  bool ShouldUpdateAnalysis = BPI && BFI;
354  bool Changed = false;
355  for (BasicBlock *Target : Targets) {
357  BasicBlock *IBRPred = findIBRPredecessor(Target, OtherPreds);
358  // If we did not found an indirectbr, or the indirectbr is the only
359  // incoming edge, this isn't the kind of edge we're looking for.
360  if (!IBRPred || OtherPreds.empty())
361  continue;
362 
363  // Don't even think about ehpads/landingpads.
364  Instruction *FirstNonPHI = Target->getFirstNonPHI();
365  if (FirstNonPHI->isEHPad() || Target->isLandingPad())
366  continue;
367 
368  BasicBlock *BodyBlock = Target->splitBasicBlock(FirstNonPHI, ".split");
369  if (ShouldUpdateAnalysis) {
370  // Copy the BFI/BPI from Target to BodyBlock.
371  for (unsigned I = 0, E = BodyBlock->getTerminator()->getNumSuccessors();
372  I < E; ++I)
373  BPI->setEdgeProbability(BodyBlock, I,
374  BPI->getEdgeProbability(Target, I));
375  BFI->setBlockFreq(BodyBlock, BFI->getBlockFreq(Target).getFrequency());
376  }
377  // It's possible Target was its own successor through an indirectbr.
378  // In this case, the indirectbr now comes from BodyBlock.
379  if (IBRPred == Target)
380  IBRPred = BodyBlock;
381 
382  // At this point Target only has PHIs, and BodyBlock has the rest of the
383  // block's body. Create a copy of Target that will be used by the "direct"
384  // preds.
385  ValueToValueMapTy VMap;
386  BasicBlock *DirectSucc = CloneBasicBlock(Target, VMap, ".clone", &F);
387 
388  BlockFrequency BlockFreqForDirectSucc;
389  for (BasicBlock *Pred : OtherPreds) {
390  // If the target is a loop to itself, then the terminator of the split
391  // block (BodyBlock) needs to be updated.
392  BasicBlock *Src = Pred != Target ? Pred : BodyBlock;
393  Src->getTerminator()->replaceUsesOfWith(Target, DirectSucc);
394  if (ShouldUpdateAnalysis)
395  BlockFreqForDirectSucc += BFI->getBlockFreq(Src) *
396  BPI->getEdgeProbability(Src, DirectSucc);
397  }
398  if (ShouldUpdateAnalysis) {
399  BFI->setBlockFreq(DirectSucc, BlockFreqForDirectSucc.getFrequency());
400  BlockFrequency NewBlockFreqForTarget =
401  BFI->getBlockFreq(Target) - BlockFreqForDirectSucc;
402  BFI->setBlockFreq(Target, NewBlockFreqForTarget.getFrequency());
403  BPI->eraseBlock(Target);
404  }
405 
406  // Ok, now fix up the PHIs. We know the two blocks only have PHIs, and that
407  // they are clones, so the number of PHIs are the same.
408  // (a) Remove the edge coming from IBRPred from the "Direct" PHI
409  // (b) Leave that as the only edge in the "Indirect" PHI.
410  // (c) Merge the two in the body block.
411  BasicBlock::iterator Indirect = Target->begin(),
412  End = Target->getFirstNonPHI()->getIterator();
413  BasicBlock::iterator Direct = DirectSucc->begin();
414  BasicBlock::iterator MergeInsert = BodyBlock->getFirstInsertionPt();
415 
416  assert(&*End == Target->getTerminator() &&
417  "Block was expected to only contain PHIs");
418 
419  while (Indirect != End) {
420  PHINode *DirPHI = cast<PHINode>(Direct);
421  PHINode *IndPHI = cast<PHINode>(Indirect);
422 
423  // Now, clean up - the direct block shouldn't get the indirect value,
424  // and vice versa.
425  DirPHI->removeIncomingValue(IBRPred);
426  Direct++;
427 
428  // Advance the pointer here, to avoid invalidation issues when the old
429  // PHI is erased.
430  Indirect++;
431 
432  PHINode *NewIndPHI = PHINode::Create(IndPHI->getType(), 1, "ind", IndPHI);
433  NewIndPHI->addIncoming(IndPHI->getIncomingValueForBlock(IBRPred),
434  IBRPred);
435 
436  // Create a PHI in the body block, to merge the direct and indirect
437  // predecessors.
438  PHINode *MergePHI =
439  PHINode::Create(IndPHI->getType(), 2, "merge", &*MergeInsert);
440  MergePHI->addIncoming(NewIndPHI, Target);
441  MergePHI->addIncoming(DirPHI, DirectSucc);
442 
443  IndPHI->replaceAllUsesWith(MergePHI);
444  IndPHI->eraseFromParent();
445  }
446 
447  Changed = true;
448  }
449 
450  return Changed;
451 }
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
void removePredecessor(BasicBlock *Pred, bool DontDeleteUselessPHIs=false)
Notify the BasicBlock that the predecessor Pred is no longer able to reach it.
Definition: BasicBlock.cpp:295
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
BasicBlock * getSuccessor(unsigned idx) const
Return the specified successor.
uint64_t getFrequency() const
Returns the frequency as a fixpoint number scaled by the entry frequency.
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:713
STATISTIC(NumFunctions, "Total number of functions")
Analysis pass which computes a DominatorTree.
Definition: Dominators.h:225
F(f)
unsigned SplitAllCriticalEdges(Function &F, const CriticalEdgeSplittingOptions &Options=CriticalEdgeSplittingOptions())
Loop over all of the edges in the CFG, breaking critical edges as they are found. ...
void initializeBreakCriticalEdgesPass(PassRegistry &)
static BasicBlock * findIBRPredecessor(BasicBlock *BB, SmallVectorImpl< BasicBlock *> &OtherPreds)
iterator begin()
Instruction iterator methods.
Definition: BasicBlock.h:264
Value * removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty=true)
Remove an incoming value.
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
Option class for critical edge splitting.
int getBasicBlockIndex(const BasicBlock *BB) const
Return the first index of the specified basic block in the value list for this PHI.
Analysis pass that exposes the LoopInfo for a function.
Definition: LoopInfo.h:939
bool insert(const value_type &X)
Insert a new element into the SetVector.
Definition: SetVector.h:142
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
Definition: Instruction.h:126
AnalysisUsage & addPreservedID(const void *ID)
Interval::succ_iterator succ_end(Interval *I)
Definition: Interval.h:106
void replaceUsesOfWith(Value *From, Value *To)
Replace uses of one Value with another.
Definition: User.cpp:21
BasicBlock * SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum, const CriticalEdgeSplittingOptions &Options=CriticalEdgeSplittingOptions())
If this edge is a critical edge, insert a new node to split the critical edge.
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
static bool runOnFunction(Function &F, bool PostInlining)
#define P(N)
const Instruction * getFirstNonPHI() const
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
Definition: BasicBlock.cpp:189
Subclasses of this class are all able to terminate a basic block.
Definition: InstrTypes.h:55
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:153
const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
Definition: BasicBlock.cpp:218
void setSuccessor(unsigned idx, BasicBlock *B)
Update the specified successor to point at the provided block.
LLVM Basic Block Representation.
Definition: BasicBlock.h:59
Conditional or Unconditional Branch instruction.
char & BreakCriticalEdgesID
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:149
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
const Instruction & front() const
Definition: BasicBlock.h:276
Indirect Branch Instruction.
FunctionPass * createBreakCriticalEdgesPass()
Interval::pred_iterator pred_begin(Interval *I)
pred_begin/pred_end - define methods so that Intervals may be used just like BasicBlocks can with the...
Definition: Interval.h:113
void eraseBlock(const BasicBlock *BB)
Forget analysis results for the given basic block.
Represent the analysis usage information of a pass.
static const unsigned End
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:285
Interval::pred_iterator pred_end(Interval *I)
Definition: Interval.h:116
BasicBlock * SplitBlockPredecessors(BasicBlock *BB, ArrayRef< BasicBlock *> Preds, const char *Suffix, DominatorTree *DT=nullptr, LoopInfo *LI=nullptr, bool PreserveLCSSA=false)
This method introduces at least one new basic block into the function and moves some of the predecess...
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
Definition: BasicBlock.h:101
self_iterator getIterator()
Definition: ilist_node.h:82
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: PassManager.h:159
auto find(R &&Range, const T &Val) -> decltype(adl_begin(Range))
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:929
BranchProbability getEdgeProbability(const BasicBlock *Src, unsigned IndexInSuccessors) const
Get an edge&#39;s probability, relative to other out-edges of the Src.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:34
char & LoopSimplifyID
bool isLandingPad() const
Return true if this basic block is a landing pad.
Definition: BasicBlock.cpp:461
A SetVector that performs no allocations if smaller than a certain size.
Definition: SetVector.h:298
Iterator for intrusive lists based on ilist_node.
void setIncomingBlock(unsigned i, BasicBlock *BB)
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:861
void setEdgeProbability(const BasicBlock *Src, unsigned IndexInSuccessors, BranchProbability Prob)
Set the raw edge probability for the given edge.
static BranchInst * Create(BasicBlock *IfTrue, Instruction *InsertBefore=nullptr)
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...
unsigned getNumIncomingValues() const
Return the number of incoming edges.
Target - Wrapper for Target specific information.
BasicBlock * CloneBasicBlock(const BasicBlock *BB, ValueToValueMapTy &VMap, const Twine &NameSuffix="", Function *F=nullptr, ClonedCodeInfo *CodeInfo=nullptr, DebugInfoFinder *DIFinder=nullptr)
CloneBasicBlock - Return a copy of the specified basic block, but without embedding the block into a ...
Analysis providing branch probability information.
iterator insert(iterator where, pointer New)
Definition: ilist.h:228
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
Definition: Instruction.h:290
static 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_NODISCARD bool empty() const
Definition: SmallVector.h:62
bool SplitIndirectBrCriticalEdges(Function &F, BranchProbabilityInfo *BPI=nullptr, BlockFrequencyInfo *BFI=nullptr)
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:445
StringRef getName() const
Return a constant reference to the value&#39;s name.
Definition: Value.cpp:224
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:108
#define I(x, y, z)
Definition: MD5.cpp:58
#define N
bool empty() const
Determine if the SetVector is empty or not.
Definition: SetVector.h:73
PassT::Result * getCachedResult(IRUnitT &IR) const
Get the cached result of an analysis pass for a given IR unit.
Definition: PassManager.h:706
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:323
const BasicBlockListType & getBasicBlockList() const
Get the underlying elements of the Function...
Definition: Function.h:619
void preserve()
Mark an analysis as preserved.
Definition: PassManager.h:174
iterator_range< const_phi_iterator > phis() const
Returns a range that iterates over the phis in the basic block.
Definition: BasicBlock.h:320
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
unsigned getNumSuccessors() const
Return the number of successors that this terminator has.
bool isEHPad() const
Return true if this basic block is an exception handling block.
Definition: BasicBlock.h:394
LLVM Value Representation.
Definition: Value.h:73
succ_range successors(BasicBlock *BB)
Definition: CFG.h:149
bool isEHPad() const
Return true if the instruction is a variety of EH-block.
Definition: Instruction.h:552
The legacy pass manager&#39;s analysis pass to compute loop information.
Definition: LoopInfo.h:964
A container for analyses that lazily runs them and caches their results.
Legacy analysis pass which computes a DominatorTree.
Definition: Dominators.h:254
const TerminatorInst * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
Definition: BasicBlock.cpp:138
const BasicBlock * getParent() const
Definition: Instruction.h:67
bool isCriticalEdge(const TerminatorInst *TI, unsigned SuccNum, bool AllowIdenticalEdges=false)
Return true if the specified edge is a critical edge.
Definition: CFG.cpp:88