130
130
#include " llvm/IR/Constant.h"
131
131
#include " llvm/IR/Instructions.h"
132
132
#include " llvm/IR/IntrinsicInst.h"
133
- #include " llvm/IR/Module.h"
134
133
#include " llvm/IR/Verifier.h"
135
134
#include " llvm/Support/Debug.h"
136
135
#include " llvm/Support/raw_ostream.h"
137
136
#include " llvm/Transforms/Scalar.h"
138
- #include " llvm/Transforms/Utils/BasicBlockUtils.h"
139
137
#include " llvm/Transforms/Utils/Local.h"
140
138
#include " llvm/Transforms/Utils/LoopUtils.h"
141
139
@@ -458,79 +456,6 @@ static SmallVector<Value_Info, 8> CollectExitValues(Value *new_exit_cond,
458
456
return exit_values;
459
457
}
460
458
461
- // Ensures the branch from exiting_block to outside L escapes exactly one
462
- // level of loop nesting, and does not immediately jump into an otherwise
463
- // unrelated loop. Creates a downstream block as needed. If the exiting edge is
464
- // critical, it will be split. Updates dominator tree and loop info. Returns
465
- // true if any changes were made.
466
- static bool EnsureSingleLevelExit (Loop *L, LoopInfo *LI, DominatorTree *DT,
467
- BasicBlock *exiting_block) {
468
- BasicBlock *exit_block = GetExitBlockForExitingBlock (L, exiting_block);
469
-
470
- Loop *exit_loop = LI->getLoopFor (exit_block);
471
- assert (L != exit_loop);
472
-
473
- Loop *parent_loop = L->getParentLoop ();
474
- if (parent_loop != exit_loop) {
475
- // Split the edge between the blocks, returning the newly created block.
476
- BasicBlock *new_bb = SplitEdge (exiting_block, exit_block, DT, LI);
477
- // The new block might be in the middle or at the end.
478
- BasicBlock *middle_bb;
479
- if (new_bb->getSingleSuccessor () == exit_block) {
480
- middle_bb = new_bb;
481
- } else {
482
- middle_bb = exit_block;
483
- exit_block = new_bb;
484
- }
485
-
486
- // What loop does middle_bb end up in? SplitEdge has these cases:
487
- // If the edge was critical:
488
- // if source block is not in a loop: ruled out already
489
- // if dest block is not in a loop --> not in any loop.
490
- // if going from outer loop to inner loop: ruled out already
491
- // if going from inner loop to outer loop --> outer loop
492
- // if loops unrelated by containment -> the parent loop of the
493
- // destination block (which must be a loop header because we
494
- // assume irreducible loops).
495
- // If the edge was non-critcial:
496
- // If the exit block only had one incominge edge --> same loop as
497
- // destination block.
498
- // otherwise the exiting block had a single successor.
499
- // This is ruled out because the the exiting block ends with a
500
- // conditional branch, and so has two successors.
501
-
502
- // Move the middle_block to the parent loop, if it exists.
503
- // If all goes well, the latch exit block will branch to it.
504
- // If the algorithm bails early, then there is no harm in putting
505
- // it in L's parent loop. At worst it will be an exiting block for
506
- // the parent loop.
507
- LI->removeBlock (middle_bb);
508
- if (parent_loop) {
509
- parent_loop->addBasicBlockToLoop (middle_bb, *LI);
510
-
511
- // middle_bb block is now an exiting block, going from parent_loop to
512
- // exit_loop, which we know are different. Make sure it ends in a
513
- // in a conditional branch, as expected by the rest of the algorithm.
514
- auto *br = cast<BranchInst>(middle_bb->getTerminator ());
515
- assert (!br->isConditional ());
516
- auto *true_val = ConstantInt::getTrue (br->getContext ());
517
- br->eraseFromParent ();
518
- BasicBlock *parent_latch = parent_loop->getLoopLatch ();
519
- BranchInst::Create (exit_block, parent_latch, true_val, middle_bb);
520
- // Fix phis in parent_latch
521
- for (Instruction &inst : *parent_latch) {
522
- PHINode *phi = dyn_cast<PHINode>(&inst);
523
- if (!phi)
524
- break ;
525
- // We don't care about the values. The path is never taken.
526
- phi->addIncoming (GetDefaultValue (phi->getType ()), middle_bb);
527
- }
528
- }
529
- return true ;
530
- }
531
- return false ;
532
- }
533
-
534
459
// Restructures exiting_block so its work, including its exit branch, is moved
535
460
// to a block B that dominates the latch block. Let's call B the
536
461
// newly-exiting-block.
@@ -540,15 +465,6 @@ static bool RemoveUnstructuredLoopExitsIteration(BasicBlock *exiting_block,
540
465
Loop *L, LoopInfo *LI,
541
466
DominatorTree *DT) {
542
467
BasicBlock *latch = L->getLoopLatch ();
543
-
544
- if (EnsureSingleLevelExit (L, LI, DT, latch)) {
545
- // Exit early so we're forced to recompute exit blocks.
546
- return true ;
547
- }
548
- if (EnsureSingleLevelExit (L, LI, DT, exiting_block)) {
549
- return true ;
550
- }
551
-
552
468
BasicBlock *latch_exit = GetExitBlockForExitingBlock (L, latch);
553
469
BasicBlock *exit_block = GetExitBlockForExitingBlock (L, exiting_block);
554
470
0 commit comments