LLVM  7.0.0svn
BasicBlockUtils.cpp
Go to the documentation of this file.
1 //===- BasicBlockUtils.cpp - BasicBlock Utilities --------------------------==//
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 // This family of functions perform manipulations on basic blocks, and
11 // instructions contained within basic blocks.
12 //
13 //===----------------------------------------------------------------------===//
14 
16 #include "llvm/ADT/ArrayRef.h"
17 #include "llvm/ADT/SmallPtrSet.h"
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/ADT/Twine.h"
20 #include "llvm/Analysis/CFG.h"
21 #include "llvm/Analysis/LoopInfo.h"
23 #include "llvm/IR/BasicBlock.h"
24 #include "llvm/IR/CFG.h"
25 #include "llvm/IR/Constants.h"
27 #include "llvm/IR/Dominators.h"
28 #include "llvm/IR/Function.h"
29 #include "llvm/IR/InstrTypes.h"
30 #include "llvm/IR/Instruction.h"
31 #include "llvm/IR/Instructions.h"
32 #include "llvm/IR/IntrinsicInst.h"
33 #include "llvm/IR/LLVMContext.h"
34 #include "llvm/IR/Type.h"
35 #include "llvm/IR/User.h"
36 #include "llvm/IR/Value.h"
37 #include "llvm/IR/ValueHandle.h"
38 #include "llvm/Support/Casting.h"
40 #include <cassert>
41 #include <cstdint>
42 #include <string>
43 #include <utility>
44 #include <vector>
45 
46 using namespace llvm;
47 
49  assert((pred_begin(BB) == pred_end(BB) ||
50  // Can delete self loop.
51  BB->getSinglePredecessor() == BB) && "Block is not dead!");
52  TerminatorInst *BBTerm = BB->getTerminator();
53  std::vector<DominatorTree::UpdateType> Updates;
54 
55  // Loop through all of our successors and make sure they know that one
56  // of their predecessors is going away.
57  if (DDT)
58  Updates.reserve(BBTerm->getNumSuccessors());
59  for (BasicBlock *Succ : BBTerm->successors()) {
60  Succ->removePredecessor(BB);
61  if (DDT)
62  Updates.push_back({DominatorTree::Delete, BB, Succ});
63  }
64 
65  // Zap all the instructions in the block.
66  while (!BB->empty()) {
67  Instruction &I = BB->back();
68  // If this instruction is used, replace uses with an arbitrary value.
69  // Because control flow can't get here, we don't care what we replace the
70  // value with. Note that since this block is unreachable, and all values
71  // contained within it must dominate their uses, that all uses will
72  // eventually be removed (they are themselves dead).
73  if (!I.use_empty())
75  BB->getInstList().pop_back();
76  }
77 
78  if (DDT) {
79  DDT->applyUpdates(Updates);
80  DDT->deleteBB(BB); // Deferred deletion of BB.
81  } else {
82  BB->eraseFromParent(); // Zap the block!
83  }
84 }
85 
87  MemoryDependenceResults *MemDep) {
88  if (!isa<PHINode>(BB->begin())) return;
89 
90  while (PHINode *PN = dyn_cast<PHINode>(BB->begin())) {
91  if (PN->getIncomingValue(0) != PN)
92  PN->replaceAllUsesWith(PN->getIncomingValue(0));
93  else
94  PN->replaceAllUsesWith(UndefValue::get(PN->getType()));
95 
96  if (MemDep)
97  MemDep->removeInstruction(PN); // Memdep updates AA itself.
98 
99  PN->eraseFromParent();
100  }
101 }
102 
104  // Recursively deleting a PHI may cause multiple PHIs to be deleted
105  // or RAUW'd undef, so use an array of WeakTrackingVH for the PHIs to delete.
107  for (PHINode &PN : BB->phis())
108  PHIs.push_back(&PN);
109 
110  bool Changed = false;
111  for (unsigned i = 0, e = PHIs.size(); i != e; ++i)
112  if (PHINode *PN = dyn_cast_or_null<PHINode>(PHIs[i].operator Value*()))
113  Changed |= RecursivelyDeleteDeadPHINode(PN, TLI);
114 
115  return Changed;
116 }
117 
119  LoopInfo *LI,
120  MemoryDependenceResults *MemDep) {
121  // Don't merge away blocks who have their address taken.
122  if (BB->hasAddressTaken()) return false;
123 
124  // Can't merge if there are multiple predecessors, or no predecessors.
125  BasicBlock *PredBB = BB->getUniquePredecessor();
126  if (!PredBB) return false;
127 
128  // Don't break self-loops.
129  if (PredBB == BB) return false;
130  // Don't break unwinding instructions.
131  if (PredBB->getTerminator()->isExceptional())
132  return false;
133 
134  succ_iterator SI(succ_begin(PredBB)), SE(succ_end(PredBB));
135  BasicBlock *OnlySucc = BB;
136  for (; SI != SE; ++SI)
137  if (*SI != OnlySucc) {
138  OnlySucc = nullptr; // There are multiple distinct successors!
139  break;
140  }
141 
142  // Can't merge if there are multiple successors.
143  if (!OnlySucc) return false;
144 
145  // Can't merge if there is PHI loop.
146  for (PHINode &PN : BB->phis())
147  for (Value *IncValue : PN.incoming_values())
148  if (IncValue == &PN)
149  return false;
150 
151  // Begin by getting rid of unneeded PHIs.
152  SmallVector<Value *, 4> IncomingValues;
153  if (isa<PHINode>(BB->front())) {
154  for (PHINode &PN : BB->phis())
155  if (PN.getIncomingValue(0) != &PN)
156  IncomingValues.push_back(PN.getIncomingValue(0));
157  FoldSingleEntryPHINodes(BB, MemDep);
158  }
159 
160  // Delete the unconditional branch from the predecessor...
161  PredBB->getInstList().pop_back();
162 
163  // Make all PHI nodes that referred to BB now refer to Pred as their
164  // source...
165  BB->replaceAllUsesWith(PredBB);
166 
167  // Move all definitions in the successor to the predecessor...
168  PredBB->getInstList().splice(PredBB->end(), BB->getInstList());
169 
170  // Eliminate duplicate dbg.values describing the entry PHI node post-splice.
171  for (auto *Incoming : IncomingValues) {
172  if (isa<Instruction>(Incoming)) {
175  DbgValueSet;
176  llvm::findDbgValues(DbgValues, Incoming);
177  for (auto &DVI : DbgValues) {
178  auto R = DbgValueSet.insert({DVI->getVariable(), DVI->getExpression()});
179  if (!R.second)
180  DVI->eraseFromParent();
181  }
182  }
183  }
184 
185  // Inherit predecessors name if it exists.
186  if (!PredBB->hasName())
187  PredBB->takeName(BB);
188 
189  // Finally, erase the old block and update dominator info.
190  if (DT)
191  if (DomTreeNode *DTN = DT->getNode(BB)) {
192  DomTreeNode *PredDTN = DT->getNode(PredBB);
193  SmallVector<DomTreeNode *, 8> Children(DTN->begin(), DTN->end());
194  for (DomTreeNode *DI : Children)
195  DT->changeImmediateDominator(DI, PredDTN);
196 
197  DT->eraseNode(BB);
198  }
199 
200  if (LI)
201  LI->removeBlock(BB);
202 
203  if (MemDep)
205 
206  BB->eraseFromParent();
207  return true;
208 }
209 
211  BasicBlock::iterator &BI, Value *V) {
212  Instruction &I = *BI;
213  // Replaces all of the uses of the instruction with uses of the value
214  I.replaceAllUsesWith(V);
215 
216  // Make sure to propagate a name if there is one already.
217  if (I.hasName() && !V->hasName())
218  V->takeName(&I);
219 
220  // Delete the unnecessary instruction now...
221  BI = BIL.erase(BI);
222 }
223 
226  assert(I->getParent() == nullptr &&
227  "ReplaceInstWithInst: Instruction already inserted into basic block!");
228 
229  // Copy debug location to newly added instruction, if it wasn't already set
230  // by the caller.
231  if (!I->getDebugLoc())
232  I->setDebugLoc(BI->getDebugLoc());
233 
234  // Insert the new instruction into the basic block...
235  BasicBlock::iterator New = BIL.insert(BI, I);
236 
237  // Replace all uses of the old instruction, and delete it.
238  ReplaceInstWithValue(BIL, BI, I);
239 
240  // Move BI back to point to the newly inserted instruction
241  BI = New;
242 }
243 
245  BasicBlock::iterator BI(From);
246  ReplaceInstWithInst(From->getParent()->getInstList(), BI, To);
247 }
248 
250  LoopInfo *LI) {
251  unsigned SuccNum = GetSuccessorNumber(BB, Succ);
252 
253  // If this is a critical edge, let SplitCriticalEdge do it.
254  TerminatorInst *LatchTerm = BB->getTerminator();
255  if (SplitCriticalEdge(LatchTerm, SuccNum, CriticalEdgeSplittingOptions(DT, LI)
256  .setPreserveLCSSA()))
257  return LatchTerm->getSuccessor(SuccNum);
258 
259  // If the edge isn't critical, then BB has a single successor or Succ has a
260  // single pred. Split the block.
261  if (BasicBlock *SP = Succ->getSinglePredecessor()) {
262  // If the successor only has a single pred, split the top of the successor
263  // block.
264  assert(SP == BB && "CFG broken");
265  SP = nullptr;
266  return SplitBlock(Succ, &Succ->front(), DT, LI);
267  }
268 
269  // Otherwise, if BB has a single successor, split it at the bottom of the
270  // block.
271  assert(BB->getTerminator()->getNumSuccessors() == 1 &&
272  "Should have a single succ!");
273  return SplitBlock(BB, BB->getTerminator(), DT, LI);
274 }
275 
276 unsigned
278  const CriticalEdgeSplittingOptions &Options) {
279  unsigned NumBroken = 0;
280  for (BasicBlock &BB : F) {
281  TerminatorInst *TI = BB.getTerminator();
282  if (TI->getNumSuccessors() > 1 && !isa<IndirectBrInst>(TI))
283  for (unsigned i = 0, e = TI->getNumSuccessors(); i != e; ++i)
284  if (SplitCriticalEdge(TI, i, Options))
285  ++NumBroken;
286  }
287  return NumBroken;
288 }
289 
291  DominatorTree *DT, LoopInfo *LI) {
292  BasicBlock::iterator SplitIt = SplitPt->getIterator();
293  while (isa<PHINode>(SplitIt) || SplitIt->isEHPad())
294  ++SplitIt;
295  BasicBlock *New = Old->splitBasicBlock(SplitIt, Old->getName()+".split");
296 
297  // The new block lives in whichever loop the old one did. This preserves
298  // LCSSA as well, because we force the split point to be after any PHI nodes.
299  if (LI)
300  if (Loop *L = LI->getLoopFor(Old))
301  L->addBasicBlockToLoop(New, *LI);
302 
303  if (DT)
304  // Old dominates New. New node dominates all other nodes dominated by Old.
305  if (DomTreeNode *OldNode = DT->getNode(Old)) {
306  std::vector<DomTreeNode *> Children(OldNode->begin(), OldNode->end());
307 
308  DomTreeNode *NewNode = DT->addNewBlock(New, Old);
309  for (DomTreeNode *I : Children)
310  DT->changeImmediateDominator(I, NewNode);
311  }
312 
313  return New;
314 }
315 
316 /// Update DominatorTree, LoopInfo, and LCCSA analysis information.
319  DominatorTree *DT, LoopInfo *LI,
320  bool PreserveLCSSA, bool &HasLoopExit) {
321  // Update dominator tree if available.
322  if (DT) {
323  if (OldBB == DT->getRootNode()->getBlock()) {
324  assert(NewBB == &NewBB->getParent()->getEntryBlock());
325  DT->setNewRoot(NewBB);
326  } else {
327  // Split block expects NewBB to have a non-empty set of predecessors.
328  DT->splitBlock(NewBB);
329  }
330  }
331 
332  // The rest of the logic is only relevant for updating the loop structures.
333  if (!LI)
334  return;
335 
336  assert(DT && "DT should be available to update LoopInfo!");
337  Loop *L = LI->getLoopFor(OldBB);
338 
339  // If we need to preserve loop analyses, collect some information about how
340  // this split will affect loops.
341  bool IsLoopEntry = !!L;
342  bool SplitMakesNewLoopHeader = false;
343  for (BasicBlock *Pred : Preds) {
344  // Preds that are not reachable from entry should not be used to identify if
345  // OldBB is a loop entry or if SplitMakesNewLoopHeader. Unreachable blocks
346  // are not within any loops, so we incorrectly mark SplitMakesNewLoopHeader
347  // as true and make the NewBB the header of some loop. This breaks LI.
348  if (!DT->isReachableFromEntry(Pred))
349  continue;
350  // If we need to preserve LCSSA, determine if any of the preds is a loop
351  // exit.
352  if (PreserveLCSSA)
353  if (Loop *PL = LI->getLoopFor(Pred))
354  if (!PL->contains(OldBB))
355  HasLoopExit = true;
356 
357  // If we need to preserve LoopInfo, note whether any of the preds crosses
358  // an interesting loop boundary.
359  if (!L)
360  continue;
361  if (L->contains(Pred))
362  IsLoopEntry = false;
363  else
364  SplitMakesNewLoopHeader = true;
365  }
366 
367  // Unless we have a loop for OldBB, nothing else to do here.
368  if (!L)
369  return;
370 
371  if (IsLoopEntry) {
372  // Add the new block to the nearest enclosing loop (and not an adjacent
373  // loop). To find this, examine each of the predecessors and determine which
374  // loops enclose them, and select the most-nested loop which contains the
375  // loop containing the block being split.
376  Loop *InnermostPredLoop = nullptr;
377  for (BasicBlock *Pred : Preds) {
378  if (Loop *PredLoop = LI->getLoopFor(Pred)) {
379  // Seek a loop which actually contains the block being split (to avoid
380  // adjacent loops).
381  while (PredLoop && !PredLoop->contains(OldBB))
382  PredLoop = PredLoop->getParentLoop();
383 
384  // Select the most-nested of these loops which contains the block.
385  if (PredLoop && PredLoop->contains(OldBB) &&
386  (!InnermostPredLoop ||
387  InnermostPredLoop->getLoopDepth() < PredLoop->getLoopDepth()))
388  InnermostPredLoop = PredLoop;
389  }
390  }
391 
392  if (InnermostPredLoop)
393  InnermostPredLoop->addBasicBlockToLoop(NewBB, *LI);
394  } else {
395  L->addBasicBlockToLoop(NewBB, *LI);
396  if (SplitMakesNewLoopHeader)
397  L->moveToHeader(NewBB);
398  }
399 }
400 
401 /// Update the PHI nodes in OrigBB to include the values coming from NewBB.
402 /// This also updates AliasAnalysis, if available.
403 static void UpdatePHINodes(BasicBlock *OrigBB, BasicBlock *NewBB,
405  bool HasLoopExit) {
406  // Otherwise, create a new PHI node in NewBB for each PHI node in OrigBB.
407  SmallPtrSet<BasicBlock *, 16> PredSet(Preds.begin(), Preds.end());
408  for (BasicBlock::iterator I = OrigBB->begin(); isa<PHINode>(I); ) {
409  PHINode *PN = cast<PHINode>(I++);
410 
411  // Check to see if all of the values coming in are the same. If so, we
412  // don't need to create a new PHI node, unless it's needed for LCSSA.
413  Value *InVal = nullptr;
414  if (!HasLoopExit) {
415  InVal = PN->getIncomingValueForBlock(Preds[0]);
416  for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) {
417  if (!PredSet.count(PN->getIncomingBlock(i)))
418  continue;
419  if (!InVal)
420  InVal = PN->getIncomingValue(i);
421  else if (InVal != PN->getIncomingValue(i)) {
422  InVal = nullptr;
423  break;
424  }
425  }
426  }
427 
428  if (InVal) {
429  // If all incoming values for the new PHI would be the same, just don't
430  // make a new PHI. Instead, just remove the incoming values from the old
431  // PHI.
432 
433  // NOTE! This loop walks backwards for a reason! First off, this minimizes
434  // the cost of removal if we end up removing a large number of values, and
435  // second off, this ensures that the indices for the incoming values
436  // aren't invalidated when we remove one.
437  for (int64_t i = PN->getNumIncomingValues() - 1; i >= 0; --i)
438  if (PredSet.count(PN->getIncomingBlock(i)))
439  PN->removeIncomingValue(i, false);
440 
441  // Add an incoming value to the PHI node in the loop for the preheader
442  // edge.
443  PN->addIncoming(InVal, NewBB);
444  continue;
445  }
446 
447  // If the values coming into the block are not the same, we need a new
448  // PHI.
449  // Create the new PHI node, insert it into NewBB at the end of the block
450  PHINode *NewPHI =
451  PHINode::Create(PN->getType(), Preds.size(), PN->getName() + ".ph", BI);
452 
453  // NOTE! This loop walks backwards for a reason! First off, this minimizes
454  // the cost of removal if we end up removing a large number of values, and
455  // second off, this ensures that the indices for the incoming values aren't
456  // invalidated when we remove one.
457  for (int64_t i = PN->getNumIncomingValues() - 1; i >= 0; --i) {
458  BasicBlock *IncomingBB = PN->getIncomingBlock(i);
459  if (PredSet.count(IncomingBB)) {
460  Value *V = PN->removeIncomingValue(i, false);
461  NewPHI->addIncoming(V, IncomingBB);
462  }
463  }
464 
465  PN->addIncoming(NewPHI, NewBB);
466  }
467 }
468 
471  const char *Suffix, DominatorTree *DT,
472  LoopInfo *LI, bool PreserveLCSSA) {
473  // Do not attempt to split that which cannot be split.
474  if (!BB->canSplitPredecessors())
475  return nullptr;
476 
477  // For the landingpads we need to act a bit differently.
478  // Delegate this work to the SplitLandingPadPredecessors.
479  if (BB->isLandingPad()) {
481  std::string NewName = std::string(Suffix) + ".split-lp";
482 
483  SplitLandingPadPredecessors(BB, Preds, Suffix, NewName.c_str(), NewBBs, DT,
484  LI, PreserveLCSSA);
485  return NewBBs[0];
486  }
487 
488  // Create new basic block, insert right before the original block.
490  BB->getContext(), BB->getName() + Suffix, BB->getParent(), BB);
491 
492  // The new block unconditionally branches to the old block.
493  BranchInst *BI = BranchInst::Create(BB, NewBB);
494  BI->setDebugLoc(BB->getFirstNonPHIOrDbg()->getDebugLoc());
495 
496  // Move the edges from Preds to point to NewBB instead of BB.
497  for (unsigned i = 0, e = Preds.size(); i != e; ++i) {
498  // This is slightly more strict than necessary; the minimum requirement
499  // is that there be no more than one indirectbr branching to BB. And
500  // all BlockAddress uses would need to be updated.
501  assert(!isa<IndirectBrInst>(Preds[i]->getTerminator()) &&
502  "Cannot split an edge from an IndirectBrInst");
503  Preds[i]->getTerminator()->replaceUsesOfWith(BB, NewBB);
504  }
505 
506  // Insert a new PHI node into NewBB for every PHI node in BB and that new PHI
507  // node becomes an incoming value for BB's phi node. However, if the Preds
508  // list is empty, we need to insert dummy entries into the PHI nodes in BB to
509  // account for the newly created predecessor.
510  if (Preds.empty()) {
511  // Insert dummy values as the incoming value.
512  for (BasicBlock::iterator I = BB->begin(); isa<PHINode>(I); ++I)
513  cast<PHINode>(I)->addIncoming(UndefValue::get(I->getType()), NewBB);
514  }
515 
516  // Update DominatorTree, LoopInfo, and LCCSA analysis information.
517  bool HasLoopExit = false;
518  UpdateAnalysisInformation(BB, NewBB, Preds, DT, LI, PreserveLCSSA,
519  HasLoopExit);
520 
521  if (!Preds.empty()) {
522  // Update the PHI nodes in BB with the values coming from NewBB.
523  UpdatePHINodes(BB, NewBB, Preds, BI, HasLoopExit);
524  }
525 
526  return NewBB;
527 }
528 
531  const char *Suffix1, const char *Suffix2,
533  DominatorTree *DT, LoopInfo *LI,
534  bool PreserveLCSSA) {
535  assert(OrigBB->isLandingPad() && "Trying to split a non-landing pad!");
536 
537  // Create a new basic block for OrigBB's predecessors listed in Preds. Insert
538  // it right before the original block.
539  BasicBlock *NewBB1 = BasicBlock::Create(OrigBB->getContext(),
540  OrigBB->getName() + Suffix1,
541  OrigBB->getParent(), OrigBB);
542  NewBBs.push_back(NewBB1);
543 
544  // The new block unconditionally branches to the old block.
545  BranchInst *BI1 = BranchInst::Create(OrigBB, NewBB1);
546  BI1->setDebugLoc(OrigBB->getFirstNonPHI()->getDebugLoc());
547 
548  // Move the edges from Preds to point to NewBB1 instead of OrigBB.
549  for (unsigned i = 0, e = Preds.size(); i != e; ++i) {
550  // This is slightly more strict than necessary; the minimum requirement
551  // is that there be no more than one indirectbr branching to BB. And
552  // all BlockAddress uses would need to be updated.
553  assert(!isa<IndirectBrInst>(Preds[i]->getTerminator()) &&
554  "Cannot split an edge from an IndirectBrInst");
555  Preds[i]->getTerminator()->replaceUsesOfWith(OrigBB, NewBB1);
556  }
557 
558  bool HasLoopExit = false;
559  UpdateAnalysisInformation(OrigBB, NewBB1, Preds, DT, LI, PreserveLCSSA,
560  HasLoopExit);
561 
562  // Update the PHI nodes in OrigBB with the values coming from NewBB1.
563  UpdatePHINodes(OrigBB, NewBB1, Preds, BI1, HasLoopExit);
564 
565  // Move the remaining edges from OrigBB to point to NewBB2.
566  SmallVector<BasicBlock*, 8> NewBB2Preds;
567  for (pred_iterator i = pred_begin(OrigBB), e = pred_end(OrigBB);
568  i != e; ) {
569  BasicBlock *Pred = *i++;
570  if (Pred == NewBB1) continue;
571  assert(!isa<IndirectBrInst>(Pred->getTerminator()) &&
572  "Cannot split an edge from an IndirectBrInst");
573  NewBB2Preds.push_back(Pred);
574  e = pred_end(OrigBB);
575  }
576 
577  BasicBlock *NewBB2 = nullptr;
578  if (!NewBB2Preds.empty()) {
579  // Create another basic block for the rest of OrigBB's predecessors.
580  NewBB2 = BasicBlock::Create(OrigBB->getContext(),
581  OrigBB->getName() + Suffix2,
582  OrigBB->getParent(), OrigBB);
583  NewBBs.push_back(NewBB2);
584 
585  // The new block unconditionally branches to the old block.
586  BranchInst *BI2 = BranchInst::Create(OrigBB, NewBB2);
587  BI2->setDebugLoc(OrigBB->getFirstNonPHI()->getDebugLoc());
588 
589  // Move the remaining edges from OrigBB to point to NewBB2.
590  for (BasicBlock *NewBB2Pred : NewBB2Preds)
591  NewBB2Pred->getTerminator()->replaceUsesOfWith(OrigBB, NewBB2);
592 
593  // Update DominatorTree, LoopInfo, and LCCSA analysis information.
594  HasLoopExit = false;
595  UpdateAnalysisInformation(OrigBB, NewBB2, NewBB2Preds, DT, LI,
596  PreserveLCSSA, HasLoopExit);
597 
598  // Update the PHI nodes in OrigBB with the values coming from NewBB2.
599  UpdatePHINodes(OrigBB, NewBB2, NewBB2Preds, BI2, HasLoopExit);
600  }
601 
602  LandingPadInst *LPad = OrigBB->getLandingPadInst();
603  Instruction *Clone1 = LPad->clone();
604  Clone1->setName(Twine("lpad") + Suffix1);
605  NewBB1->getInstList().insert(NewBB1->getFirstInsertionPt(), Clone1);
606 
607  if (NewBB2) {
608  Instruction *Clone2 = LPad->clone();
609  Clone2->setName(Twine("lpad") + Suffix2);
610  NewBB2->getInstList().insert(NewBB2->getFirstInsertionPt(), Clone2);
611 
612  // Create a PHI node for the two cloned landingpad instructions only
613  // if the original landingpad instruction has some uses.
614  if (!LPad->use_empty()) {
615  assert(!LPad->getType()->isTokenTy() &&
616  "Split cannot be applied if LPad is token type. Otherwise an "
617  "invalid PHINode of token type would be created.");
618  PHINode *PN = PHINode::Create(LPad->getType(), 2, "lpad.phi", LPad);
619  PN->addIncoming(Clone1, NewBB1);
620  PN->addIncoming(Clone2, NewBB2);
621  LPad->replaceAllUsesWith(PN);
622  }
623  LPad->eraseFromParent();
624  } else {
625  // There is no second clone. Just replace the landing pad with the first
626  // clone.
627  LPad->replaceAllUsesWith(Clone1);
628  LPad->eraseFromParent();
629  }
630 }
631 
633  BasicBlock *Pred) {
634  Instruction *UncondBranch = Pred->getTerminator();
635  // Clone the return and add it to the end of the predecessor.
636  Instruction *NewRet = RI->clone();
637  Pred->getInstList().push_back(NewRet);
638 
639  // If the return instruction returns a value, and if the value was a
640  // PHI node in "BB", propagate the right value into the return.
641  for (User::op_iterator i = NewRet->op_begin(), e = NewRet->op_end();
642  i != e; ++i) {
643  Value *V = *i;
644  Instruction *NewBC = nullptr;
645  if (BitCastInst *BCI = dyn_cast<BitCastInst>(V)) {
646  // Return value might be bitcasted. Clone and insert it before the
647  // return instruction.
648  V = BCI->getOperand(0);
649  NewBC = BCI->clone();
650  Pred->getInstList().insert(NewRet->getIterator(), NewBC);
651  *i = NewBC;
652  }
653  if (PHINode *PN = dyn_cast<PHINode>(V)) {
654  if (PN->getParent() == BB) {
655  if (NewBC)
656  NewBC->setOperand(0, PN->getIncomingValueForBlock(Pred));
657  else
658  *i = PN->getIncomingValueForBlock(Pred);
659  }
660  }
661  }
662 
663  // Update any PHI nodes in the returning block to realize that we no
664  // longer branch to them.
665  BB->removePredecessor(Pred);
666  UncondBranch->eraseFromParent();
667  return cast<ReturnInst>(NewRet);
668 }
669 
672  bool Unreachable, MDNode *BranchWeights,
673  DominatorTree *DT, LoopInfo *LI) {
674  BasicBlock *Head = SplitBefore->getParent();
675  BasicBlock *Tail = Head->splitBasicBlock(SplitBefore->getIterator());
676  TerminatorInst *HeadOldTerm = Head->getTerminator();
677  LLVMContext &C = Head->getContext();
678  BasicBlock *ThenBlock = BasicBlock::Create(C, "", Head->getParent(), Tail);
679  TerminatorInst *CheckTerm;
680  if (Unreachable)
681  CheckTerm = new UnreachableInst(C, ThenBlock);
682  else
683  CheckTerm = BranchInst::Create(Tail, ThenBlock);
684  CheckTerm->setDebugLoc(SplitBefore->getDebugLoc());
685  BranchInst *HeadNewTerm =
686  BranchInst::Create(/*ifTrue*/ThenBlock, /*ifFalse*/Tail, Cond);
687  HeadNewTerm->setMetadata(LLVMContext::MD_prof, BranchWeights);
688  ReplaceInstWithInst(HeadOldTerm, HeadNewTerm);
689 
690  if (DT) {
691  if (DomTreeNode *OldNode = DT->getNode(Head)) {
692  std::vector<DomTreeNode *> Children(OldNode->begin(), OldNode->end());
693 
694  DomTreeNode *NewNode = DT->addNewBlock(Tail, Head);
695  for (DomTreeNode *Child : Children)
696  DT->changeImmediateDominator(Child, NewNode);
697 
698  // Head dominates ThenBlock.
699  DT->addNewBlock(ThenBlock, Head);
700  }
701  }
702 
703  if (LI) {
704  if (Loop *L = LI->getLoopFor(Head)) {
705  L->addBasicBlockToLoop(ThenBlock, *LI);
706  L->addBasicBlockToLoop(Tail, *LI);
707  }
708  }
709 
710  return CheckTerm;
711 }
712 
714  TerminatorInst **ThenTerm,
715  TerminatorInst **ElseTerm,
716  MDNode *BranchWeights) {
717  BasicBlock *Head = SplitBefore->getParent();
718  BasicBlock *Tail = Head->splitBasicBlock(SplitBefore->getIterator());
719  TerminatorInst *HeadOldTerm = Head->getTerminator();
720  LLVMContext &C = Head->getContext();
721  BasicBlock *ThenBlock = BasicBlock::Create(C, "", Head->getParent(), Tail);
722  BasicBlock *ElseBlock = BasicBlock::Create(C, "", Head->getParent(), Tail);
723  *ThenTerm = BranchInst::Create(Tail, ThenBlock);
724  (*ThenTerm)->setDebugLoc(SplitBefore->getDebugLoc());
725  *ElseTerm = BranchInst::Create(Tail, ElseBlock);
726  (*ElseTerm)->setDebugLoc(SplitBefore->getDebugLoc());
727  BranchInst *HeadNewTerm =
728  BranchInst::Create(/*ifTrue*/ThenBlock, /*ifFalse*/ElseBlock, Cond);
729  HeadNewTerm->setMetadata(LLVMContext::MD_prof, BranchWeights);
730  ReplaceInstWithInst(HeadOldTerm, HeadNewTerm);
731 }
732 
734  BasicBlock *&IfFalse) {
735  PHINode *SomePHI = dyn_cast<PHINode>(BB->begin());
736  BasicBlock *Pred1 = nullptr;
737  BasicBlock *Pred2 = nullptr;
738 
739  if (SomePHI) {
740  if (SomePHI->getNumIncomingValues() != 2)
741  return nullptr;
742  Pred1 = SomePHI->getIncomingBlock(0);
743  Pred2 = SomePHI->getIncomingBlock(1);
744  } else {
745  pred_iterator PI = pred_begin(BB), PE = pred_end(BB);
746  if (PI == PE) // No predecessor
747  return nullptr;
748  Pred1 = *PI++;
749  if (PI == PE) // Only one predecessor
750  return nullptr;
751  Pred2 = *PI++;
752  if (PI != PE) // More than two predecessors
753  return nullptr;
754  }
755 
756  // We can only handle branches. Other control flow will be lowered to
757  // branches if possible anyway.
758  BranchInst *Pred1Br = dyn_cast<BranchInst>(Pred1->getTerminator());
759  BranchInst *Pred2Br = dyn_cast<BranchInst>(Pred2->getTerminator());
760  if (!Pred1Br || !Pred2Br)
761  return nullptr;
762 
763  // Eliminate code duplication by ensuring that Pred1Br is conditional if
764  // either are.
765  if (Pred2Br->isConditional()) {
766  // If both branches are conditional, we don't have an "if statement". In
767  // reality, we could transform this case, but since the condition will be
768  // required anyway, we stand no chance of eliminating it, so the xform is
769  // probably not profitable.
770  if (Pred1Br->isConditional())
771  return nullptr;
772 
773  std::swap(Pred1, Pred2);
774  std::swap(Pred1Br, Pred2Br);
775  }
776 
777  if (Pred1Br->isConditional()) {
778  // The only thing we have to watch out for here is to make sure that Pred2
779  // doesn't have incoming edges from other blocks. If it does, the condition
780  // doesn't dominate BB.
781  if (!Pred2->getSinglePredecessor())
782  return nullptr;
783 
784  // If we found a conditional branch predecessor, make sure that it branches
785  // to BB and Pred2Br. If it doesn't, this isn't an "if statement".
786  if (Pred1Br->getSuccessor(0) == BB &&
787  Pred1Br->getSuccessor(1) == Pred2) {
788  IfTrue = Pred1;
789  IfFalse = Pred2;
790  } else if (Pred1Br->getSuccessor(0) == Pred2 &&
791  Pred1Br->getSuccessor(1) == BB) {
792  IfTrue = Pred2;
793  IfFalse = Pred1;
794  } else {
795  // We know that one arm of the conditional goes to BB, so the other must
796  // go somewhere unrelated, and this must not be an "if statement".
797  return nullptr;
798  }
799 
800  return Pred1Br->getCondition();
801  }
802 
803  // Ok, if we got here, both predecessors end with an unconditional branch to
804  // BB. Don't panic! If both blocks only have a single (identical)
805  // predecessor, and THAT is a conditional branch, then we're all ok!
806  BasicBlock *CommonPred = Pred1->getSinglePredecessor();
807  if (CommonPred == nullptr || CommonPred != Pred2->getSinglePredecessor())
808  return nullptr;
809 
810  // Otherwise, if this is a conditional branch, then we can use it!
811  BranchInst *BI = dyn_cast<BranchInst>(CommonPred->getTerminator());
812  if (!BI) return nullptr;
813 
814  assert(BI->isConditional() && "Two successors but not conditional?");
815  if (BI->getSuccessor(0) == Pred1) {
816  IfTrue = Pred1;
817  IfFalse = Pred2;
818  } else {
819  IfTrue = Pred2;
820  IfFalse = Pred1;
821  }
822  return BI->getCondition();
823 }
uint64_t CallInst * C
DomTreeNodeBase< NodeT > * getNode(NodeT *BB) const
getNode - return the (Post)DominatorTree node for the specified basic block.
Return a value (possibly void), from a function.
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks &#39;this&#39; from the containing basic block and deletes it.
Definition: Instruction.cpp:67
bool canSplitPredecessors() const
Definition: BasicBlock.cpp:347
void invalidateCachedPredecessors()
Clears the PredIteratorCache info.
void ReplaceInstWithInst(BasicBlock::InstListType &BIL, BasicBlock::iterator &BI, Instruction *I)
Replace the instruction specified by BI with the instruction specified by I.
void removePredecessor(BasicBlock *Pred, bool DontDeleteUselessPHIs=false)
Notify the BasicBlock that the predecessor Pred is no longer able to reach it.
Definition: BasicBlock.cpp:277
Provides a lazy, caching interface for making common memory aliasing information queries, backed by LLVM&#39;s alias analysis passes.
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
void SplitBlockAndInsertIfThenElse(Value *Cond, Instruction *SplitBefore, TerminatorInst **ThenTerm, TerminatorInst **ElseTerm, MDNode *BranchWeights=nullptr)
SplitBlockAndInsertIfThenElse is similar to SplitBlockAndInsertIfThen, but also creates the ElseBlock...
void splitBlock(NodeT *NewBB)
splitBlock - BB is split and now it has one successor.
iterator erase(iterator where)
Definition: ilist.h:280
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
BasicBlock * SplitBlock(BasicBlock *Old, Instruction *SplitPt, DominatorTree *DT=nullptr, LoopInfo *LI=nullptr)
Split the specified block at the specified instruction - everything before SplitPt stays in Old and e...
iterator begin() const
Definition: ArrayRef.h:137
BasicBlock * getSuccessor(unsigned idx) const
Return the specified successor.
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
Definition: SmallVector.h:136
unsigned getLoopDepth() const
Return the nesting level of this loop.
Definition: LoopInfo.h:92
void moveToHeader(BlockT *BB)
This method is used to move BB (which must be part of this loop) to be the loop header of the loop (t...
Definition: LoopInfo.h:359
BasicBlock * getSuccessor(unsigned i) const
Metadata node.
Definition: Metadata.h:862
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. ...
Value * getCondition() const
LLVMContext & getContext() const
Get the context in which this basic block lives.
Definition: BasicBlock.cpp:33
bool isReachableFromEntry(const Use &U) const
Provide an overload for a Use.
Definition: Dominators.cpp:294
op_iterator op_begin()
Definition: User.h:214
void eraseNode(NodeT *BB)
eraseNode - Removes a node from the dominator tree.
iterator begin()
Instruction iterator methods.
Definition: BasicBlock.h:252
Value * removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty=true)
Remove an incoming value.
Option class for critical edge splitting.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
LoopT * getLoopFor(const BlockT *BB) const
Return the inner most loop that BB lives in.
Definition: LoopInfo.h:678
A Use represents the edge between a Value definition and its users.
Definition: Use.h:56
void setName(const Twine &Name)
Change the name of the value.
Definition: Value.cpp:295
Interval::succ_iterator succ_begin(Interval *I)
succ_begin/succ_end - define methods so that Intervals may be used just like BasicBlocks can with the...
Definition: Interval.h:103
bool empty() const
Definition: BasicBlock.h:263
Instruction * clone() const
Create a copy of &#39;this&#39; instruction that is identical in all ways except the following: ...
void findDbgValues(SmallVectorImpl< DbgValueInst *> &DbgValues, Value *V)
Finds the llvm.dbg.value intrinsics describing a value.
Definition: Local.cpp:1405
static void UpdatePHINodes(BasicBlock *OrigBB, BasicBlock *NewBB, ArrayRef< BasicBlock *> Preds, BranchInst *BI, bool HasLoopExit)
Update the PHI nodes in OrigBB to include the values coming from NewBB.
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:245
void addBasicBlockToLoop(BlockT *NewBB, LoopInfoBase< BlockT, LoopT > &LI)
This method is used by other analyses to update loop information.
Definition: LoopInfoImpl.h:183
void deleteBB(BasicBlock *DelBB)
Delays the deletion of a basic block until a flush() event.
Definition: Dominators.cpp:427
const BasicBlock * getUniquePredecessor() const
Return the predecessor of this block if it has a unique predecessor block.
Definition: BasicBlock.cpp:230
bool DeleteDeadPHIs(BasicBlock *BB, const TargetLibraryInfo *TLI=nullptr)
Examine each PHI in the given block and delete it if it is dead.
This class represents a no-op cast from one type to another.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Definition: Value.cpp:439
void SplitLandingPadPredecessors(BasicBlock *OrigBB, ArrayRef< BasicBlock *> Preds, const char *Suffix, const char *Suffix2, SmallVectorImpl< BasicBlock *> &NewBBs, DominatorTree *DT=nullptr, LoopInfo *LI=nullptr, bool PreserveLCSSA=false)
This method transforms the landing pad, OrigBB, by introducing two new basic blocks into the function...
DomTreeNodeBase< NodeT > * setNewRoot(NodeT *BB)
Add a new node to the forward dominator tree and make it a new root.
void ReplaceInstWithValue(BasicBlock::InstListType &BIL, BasicBlock::iterator &BI, Value *V)
Replace all uses of an instruction (specified by BI) with a value, then remove and delete the origina...
void takeName(Value *V)
Transfer the name from V to this value.
Definition: Value.cpp:301
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Definition: Dominators.h:142
void applyUpdates(ArrayRef< DominatorTree::UpdateType > Updates)
Queues multiple updates and discards duplicates.
Definition: Dominators.cpp:398
Interval::succ_iterator succ_end(Interval *I)
Definition: Interval.h:106
static void UpdateAnalysisInformation(BasicBlock *OldBB, BasicBlock *NewBB, ArrayRef< BasicBlock *> Preds, DominatorTree *DT, LoopInfo *LI, bool PreserveLCSSA, bool &HasLoopExit)
Update DominatorTree, LoopInfo, and LCCSA analysis information.
const BasicBlock & getEntryBlock() const
Definition: Function.h:618
NodeT * getBlock() const
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.
succ_range successors()
Definition: InstrTypes.h:267
The landingpad instruction holds all of the information necessary to generate correct exception handl...
const Instruction * getFirstNonPHI() const
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
Definition: BasicBlock.cpp:171
Subclasses of this class are all able to terminate a basic block.
Definition: InstrTypes.h:54
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:200
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
Definition: Instruction.h:282
const BasicBlock * getSinglePredecessor() const
Return the predecessor of this block if it has a single predecessor block.
Definition: BasicBlock.cpp:217
bool hasName() const
Definition: Value.h:251
LLVM Basic Block Representation.
Definition: BasicBlock.h:59
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:69
Conditional or Unconditional Branch instruction.
void changeImmediateDominator(DomTreeNodeBase< NodeT > *N, DomTreeNodeBase< NodeT > *NewIDom)
changeImmediateDominator - This method is used to update the dominator tree information when a node&#39;s...
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:149
This function has undefined behavior.
Value * getIncomingValueForBlock(const BasicBlock *BB) const
This file contains the declarations for the subclasses of Constant, which represent the different fla...
const Instruction & front() const
Definition: BasicBlock.h:264
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
op_iterator op_end()
Definition: User.h:216
void splice(iterator where, iplist_impl &L2)
Definition: ilist.h:342
const Instruction & back() const
Definition: BasicBlock.h:266
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
DomTreeNodeBase< NodeT > * getRootNode()
getRootNode - This returns the entry node for the CFG of the function.
static UndefValue * get(Type *T)
Static factory methods - Return an &#39;undef&#39; object of the specified type.
Definition: Constants.cpp:1356
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
Definition: Metadata.cpp:1222
bool isLandingPad() const
Return true if this basic block is a landing pad.
Definition: BasicBlock.cpp:443
bool hasAddressTaken() const
Returns true if there are any uses of this basic block other than direct branches, switches, etc.
Definition: BasicBlock.h:376
const InstListType & getInstList() const
Return the underlying instruction list container.
Definition: BasicBlock.h:317
bool contains(const LoopT *L) const
Return true if the specified loop is contained within in this loop.
Definition: LoopInfo.h:110
Iterator for intrusive lists based on ilist_node.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
Definition: SmallPtrSet.h:418
iterator end()
Definition: BasicBlock.h:254
bool isExceptional() const
Definition: InstrTypes.h:84
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:862
Provides information about what library functions are available for the current target.
iterator end() const
Definition: ArrayRef.h:138
bool RecursivelyDeleteDeadPHINode(PHINode *PN, const TargetLibraryInfo *TLI=nullptr)
If the specified value is an effectively dead PHI node, due to being a def-use chain of single-use no...
Definition: Local.cpp:480
Value * GetIfCondition(BasicBlock *BB, BasicBlock *&IfTrue, BasicBlock *&IfFalse)
Check whether BB is the merge point of a if-region.
TerminatorInst * SplitBlockAndInsertIfThen(Value *Cond, Instruction *SplitBefore, bool Unreachable, MDNode *BranchWeights=nullptr, DominatorTree *DT=nullptr, LoopInfo *LI=nullptr)
Split the containing block at the specified instruction - everything before SplitBefore stays in the ...
static BranchInst * Create(BasicBlock *IfTrue, Instruction *InsertBefore=nullptr)
bool isConditional() const
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.
void setOperand(unsigned i, Value *Val)
Definition: User.h:159
Implements a dense probed hash-table based set with some number of buckets stored inline...
Definition: DenseSet.h:239
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition: BitVector.h:923
void push_back(pointer val)
Definition: ilist.h:326
Class to defer updates to a DominatorTree.
Definition: Dominators.h:313
void FoldSingleEntryPHINodes(BasicBlock *BB, MemoryDependenceResults *MemDep=nullptr)
We know that BB has one predecessor.
LoopT * getParentLoop() const
Definition: LoopInfo.h:101
unsigned GetSuccessorNumber(const BasicBlock *BB, const BasicBlock *Succ)
Search for the specified successor of basic block BB and return its position in the terminator instru...
Definition: CFG.cpp:72
iterator insert(iterator where, pointer New)
Definition: ilist.h:241
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
Definition: Instruction.h:285
bool MergeBlockIntoPredecessor(BasicBlock *BB, DominatorTree *DT=nullptr, LoopInfo *LI=nullptr, MemoryDependenceResults *MemDep=nullptr)
Attempts to merge a block into its predecessor, if possible.
LLVM_NODISCARD bool empty() const
Definition: SmallVector.h:61
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:439
bool isTokenTy() const
Return true if this is &#39;token&#39;.
Definition: Type.h:194
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
SymbolTableList< BasicBlock >::iterator eraseFromParent()
Unlink &#39;this&#39; from the containing function and delete it.
Definition: BasicBlock.cpp:97
#define I(x, y, z)
Definition: MD5.cpp:58
DomTreeNodeBase< NodeT > * addNewBlock(NodeT *BB, NodeT *DomBB)
Add a new node to the dominator tree information.
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
ReturnInst * FoldReturnIntoUncondBranch(ReturnInst *RI, BasicBlock *BB, BasicBlock *Pred)
This method duplicates the specified return instruction into a predecessor which ends in an unconditi...
iterator_range< const_phi_iterator > phis() const
Returns a range that iterates over the phis in the basic block.
Definition: BasicBlock.h:308
BasicBlock * splitBasicBlock(iterator I, const Twine &BBName="")
Split the basic block into two basic blocks at the specified instruction.
Definition: BasicBlock.cpp:383
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
unsigned getNumSuccessors() const
Return the number of successors that this terminator has.
void DeleteDeadBlock(BasicBlock *BB, DeferredDominance *DDT=nullptr)
Delete the specified block, which must have no predecessors.
LLVM Value Representation.
Definition: Value.h:73
void removeInstruction(Instruction *InstToRemove)
Removes an instruction from the dependence analysis, updating the dependence of instructions that pre...
BasicBlock * SplitEdge(BasicBlock *From, BasicBlock *To, DominatorTree *DT=nullptr, LoopInfo *LI=nullptr)
Split the edge connecting specified block.
const LandingPadInst * getLandingPadInst() const
Return the landingpad instruction associated with the landing pad.
Definition: BasicBlock.cpp:448
const Instruction * getFirstNonPHIOrDbg() const
Returns a pointer to the first instruction in this block that is not a PHINode or a debug intrinsic...
Definition: BasicBlock.cpp:178
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:120
void pop_back()
Definition: ilist.h:331
bool use_empty() const
Definition: Value.h:328
void removeBlock(BlockT *BB)
This method completely removes BB from all data structures, including all of the Loop objects it is n...
Definition: LoopInfo.h:737
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:144
const BasicBlock * getParent() const
Definition: Instruction.h:67