Fiona Glaser | b417d46 | 2016-01-29 22:35:36 +0000 | [diff] [blame] | 1 | //===--------- LoopSimplifyCFG.cpp - Loop CFG Simplification 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 | // This file implements the Loop SimplifyCFG Pass. This pass is responsible for |
| 11 | // basic loop CFG cleanup, primarily to assist other loop passes. If you |
| 12 | // encounter a noncanonical CFG construct that causes another loop pass to |
| 13 | // perform suboptimally, this is the place to fix it up. |
| 14 | // |
| 15 | //===----------------------------------------------------------------------===// |
| 16 | |
Justin Bogner | ab6a513 | 2016-05-03 21:47:32 +0000 | [diff] [blame] | 17 | #include "llvm/Transforms/Scalar/LoopSimplifyCFG.h" |
Fiona Glaser | b417d46 | 2016-01-29 22:35:36 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/SmallVector.h" |
| 19 | #include "llvm/ADT/Statistic.h" |
| 20 | #include "llvm/Analysis/AliasAnalysis.h" |
Daniel Jasper | aec2fa3 | 2016-12-19 08:22:17 +0000 | [diff] [blame] | 21 | #include "llvm/Analysis/AssumptionCache.h" |
Chandler Carruth | 3bab7e1 | 2017-01-11 09:43:56 +0000 | [diff] [blame] | 22 | #include "llvm/Analysis/BasicAliasAnalysis.h" |
Fiona Glaser | b417d46 | 2016-01-29 22:35:36 +0000 | [diff] [blame] | 23 | #include "llvm/Analysis/DependenceAnalysis.h" |
| 24 | #include "llvm/Analysis/GlobalsModRef.h" |
| 25 | #include "llvm/Analysis/LoopInfo.h" |
| 26 | #include "llvm/Analysis/LoopPass.h" |
Alina Sbirlea | 8b83d68 | 2018-08-22 20:10:21 +0000 | [diff] [blame] | 27 | #include "llvm/Analysis/MemorySSA.h" |
| 28 | #include "llvm/Analysis/MemorySSAUpdater.h" |
Fiona Glaser | b417d46 | 2016-01-29 22:35:36 +0000 | [diff] [blame] | 29 | #include "llvm/Analysis/ScalarEvolution.h" |
| 30 | #include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h" |
| 31 | #include "llvm/Analysis/TargetTransformInfo.h" |
Chijun Sima | 21a8b60 | 2018-08-03 05:08:17 +0000 | [diff] [blame] | 32 | #include "llvm/IR/DomTreeUpdater.h" |
Fiona Glaser | b417d46 | 2016-01-29 22:35:36 +0000 | [diff] [blame] | 33 | #include "llvm/IR/Dominators.h" |
Justin Bogner | ab6a513 | 2016-05-03 21:47:32 +0000 | [diff] [blame] | 34 | #include "llvm/Transforms/Scalar.h" |
Chandler Carruth | 3bab7e1 | 2017-01-11 09:43:56 +0000 | [diff] [blame] | 35 | #include "llvm/Transforms/Scalar/LoopPassManager.h" |
David Blaikie | a373d18 | 2018-03-28 17:44:36 +0000 | [diff] [blame] | 36 | #include "llvm/Transforms/Utils.h" |
Alina Sbirlea | dfd14ad | 2018-06-20 22:01:04 +0000 | [diff] [blame] | 37 | #include "llvm/Transforms/Utils/BasicBlockUtils.h" |
| 38 | #include "llvm/Transforms/Utils/Local.h" |
Chandler Carruth | 31088a9 | 2016-02-19 10:45:18 +0000 | [diff] [blame] | 39 | #include "llvm/Transforms/Utils/LoopUtils.h" |
Fiona Glaser | b417d46 | 2016-01-29 22:35:36 +0000 | [diff] [blame] | 40 | using namespace llvm; |
| 41 | |
| 42 | #define DEBUG_TYPE "loop-simplifycfg" |
| 43 | |
Max Kazantsev | e1c2dc2 | 2018-11-23 09:14:53 +0000 | [diff] [blame] | 44 | static cl::opt<bool> EnableTermFolding("enable-loop-simplifycfg-term-folding", |
Max Kazantsev | 530ff8f | 2018-12-28 06:22:39 +0000 | [diff] [blame] | 45 | cl::init(false)); |
Max Kazantsev | e1c2dc2 | 2018-11-23 09:14:53 +0000 | [diff] [blame] | 46 | |
Max Kazantsev | c04b530 | 2018-11-20 05:43:32 +0000 | [diff] [blame] | 47 | STATISTIC(NumTerminatorsFolded, |
| 48 | "Number of terminators folded to unconditional branches"); |
Max Kazantsev | 347c583 | 2018-12-24 06:06:17 +0000 | [diff] [blame] | 49 | STATISTIC(NumLoopBlocksDeleted, |
| 50 | "Number of loop blocks deleted"); |
Max Kazantsev | edabb9a | 2018-12-24 07:41:33 +0000 | [diff] [blame] | 51 | STATISTIC(NumLoopExitsDeleted, |
| 52 | "Number of loop exiting edges deleted"); |
Max Kazantsev | c04b530 | 2018-11-20 05:43:32 +0000 | [diff] [blame] | 53 | |
| 54 | /// If \p BB is a switch or a conditional branch, but only one of its successors |
| 55 | /// can be reached from this block in runtime, return this successor. Otherwise, |
| 56 | /// return nullptr. |
| 57 | static BasicBlock *getOnlyLiveSuccessor(BasicBlock *BB) { |
| 58 | Instruction *TI = BB->getTerminator(); |
| 59 | if (BranchInst *BI = dyn_cast<BranchInst>(TI)) { |
| 60 | if (BI->isUnconditional()) |
| 61 | return nullptr; |
| 62 | if (BI->getSuccessor(0) == BI->getSuccessor(1)) |
| 63 | return BI->getSuccessor(0); |
| 64 | ConstantInt *Cond = dyn_cast<ConstantInt>(BI->getCondition()); |
| 65 | if (!Cond) |
| 66 | return nullptr; |
| 67 | return Cond->isZero() ? BI->getSuccessor(1) : BI->getSuccessor(0); |
| 68 | } |
| 69 | |
| 70 | if (SwitchInst *SI = dyn_cast<SwitchInst>(TI)) { |
| 71 | auto *CI = dyn_cast<ConstantInt>(SI->getCondition()); |
| 72 | if (!CI) |
| 73 | return nullptr; |
| 74 | for (auto Case : SI->cases()) |
| 75 | if (Case.getCaseValue() == CI) |
| 76 | return Case.getCaseSuccessor(); |
| 77 | return SI->getDefaultDest(); |
| 78 | } |
| 79 | |
| 80 | return nullptr; |
| 81 | } |
| 82 | |
Benjamin Kramer | b17d213 | 2019-01-12 18:36:22 +0000 | [diff] [blame] | 83 | namespace { |
Max Kazantsev | c04b530 | 2018-11-20 05:43:32 +0000 | [diff] [blame] | 84 | /// Helper class that can turn branches and switches with constant conditions |
| 85 | /// into unconditional branches. |
| 86 | class ConstantTerminatorFoldingImpl { |
| 87 | private: |
| 88 | Loop &L; |
| 89 | LoopInfo &LI; |
| 90 | DominatorTree &DT; |
Max Kazantsev | 201534d | 2018-12-29 04:26:22 +0000 | [diff] [blame] | 91 | ScalarEvolution &SE; |
Max Kazantsev | 9cf417d | 2018-11-30 10:06:23 +0000 | [diff] [blame] | 92 | MemorySSAUpdater *MSSAU; |
Max Kazantsev | c04b530 | 2018-11-20 05:43:32 +0000 | [diff] [blame] | 93 | |
Max Kazantsev | a523a21 | 2018-12-07 05:44:45 +0000 | [diff] [blame] | 94 | // Whether or not the current loop has irreducible CFG. |
| 95 | bool HasIrreducibleCFG = false; |
Max Kazantsev | c04b530 | 2018-11-20 05:43:32 +0000 | [diff] [blame] | 96 | // Whether or not the current loop will still exist after terminator constant |
| 97 | // folding will be done. In theory, there are two ways how it can happen: |
| 98 | // 1. Loop's latch(es) become unreachable from loop header; |
| 99 | // 2. Loop's header becomes unreachable from method entry. |
| 100 | // In practice, the second situation is impossible because we only modify the |
| 101 | // current loop and its preheader and do not affect preheader's reachibility |
| 102 | // from any other block. So this variable set to true means that loop's latch |
| 103 | // has become unreachable from loop header. |
| 104 | bool DeleteCurrentLoop = false; |
| 105 | |
| 106 | // The blocks of the original loop that will still be reachable from entry |
| 107 | // after the constant folding. |
| 108 | SmallPtrSet<BasicBlock *, 8> LiveLoopBlocks; |
| 109 | // The blocks of the original loop that will become unreachable from entry |
| 110 | // after the constant folding. |
Max Kazantsev | 80e4b40 | 2018-12-28 06:08:51 +0000 | [diff] [blame] | 111 | SmallVector<BasicBlock *, 8> DeadLoopBlocks; |
Max Kazantsev | c04b530 | 2018-11-20 05:43:32 +0000 | [diff] [blame] | 112 | // The exits of the original loop that will still be reachable from entry |
| 113 | // after the constant folding. |
| 114 | SmallPtrSet<BasicBlock *, 8> LiveExitBlocks; |
| 115 | // The exits of the original loop that will become unreachable from entry |
| 116 | // after the constant folding. |
Max Kazantsev | 56a2443 | 2018-11-22 12:33:41 +0000 | [diff] [blame] | 117 | SmallVector<BasicBlock *, 8> DeadExitBlocks; |
Max Kazantsev | c04b530 | 2018-11-20 05:43:32 +0000 | [diff] [blame] | 118 | // The blocks that will still be a part of the current loop after folding. |
| 119 | SmallPtrSet<BasicBlock *, 8> BlocksInLoopAfterFolding; |
| 120 | // The blocks that have terminators with constant condition that can be |
| 121 | // folded. Note: fold candidates should be in L but not in any of its |
| 122 | // subloops to avoid complex LI updates. |
| 123 | SmallVector<BasicBlock *, 8> FoldCandidates; |
| 124 | |
| 125 | void dump() const { |
| 126 | dbgs() << "Constant terminator folding for loop " << L << "\n"; |
| 127 | dbgs() << "After terminator constant-folding, the loop will"; |
| 128 | if (!DeleteCurrentLoop) |
| 129 | dbgs() << " not"; |
| 130 | dbgs() << " be destroyed\n"; |
Max Kazantsev | 56a2443 | 2018-11-22 12:33:41 +0000 | [diff] [blame] | 131 | auto PrintOutVector = [&](const char *Message, |
| 132 | const SmallVectorImpl<BasicBlock *> &S) { |
| 133 | dbgs() << Message << "\n"; |
| 134 | for (const BasicBlock *BB : S) |
| 135 | dbgs() << "\t" << BB->getName() << "\n"; |
| 136 | }; |
Max Kazantsev | c04b530 | 2018-11-20 05:43:32 +0000 | [diff] [blame] | 137 | auto PrintOutSet = [&](const char *Message, |
| 138 | const SmallPtrSetImpl<BasicBlock *> &S) { |
| 139 | dbgs() << Message << "\n"; |
| 140 | for (const BasicBlock *BB : S) |
| 141 | dbgs() << "\t" << BB->getName() << "\n"; |
| 142 | }; |
Max Kazantsev | 56a2443 | 2018-11-22 12:33:41 +0000 | [diff] [blame] | 143 | PrintOutVector("Blocks in which we can constant-fold terminator:", |
| 144 | FoldCandidates); |
Max Kazantsev | c04b530 | 2018-11-20 05:43:32 +0000 | [diff] [blame] | 145 | PrintOutSet("Live blocks from the original loop:", LiveLoopBlocks); |
Max Kazantsev | 80e4b40 | 2018-12-28 06:08:51 +0000 | [diff] [blame] | 146 | PrintOutVector("Dead blocks from the original loop:", DeadLoopBlocks); |
Max Kazantsev | c04b530 | 2018-11-20 05:43:32 +0000 | [diff] [blame] | 147 | PrintOutSet("Live exit blocks:", LiveExitBlocks); |
Max Kazantsev | 56a2443 | 2018-11-22 12:33:41 +0000 | [diff] [blame] | 148 | PrintOutVector("Dead exit blocks:", DeadExitBlocks); |
Max Kazantsev | c04b530 | 2018-11-20 05:43:32 +0000 | [diff] [blame] | 149 | if (!DeleteCurrentLoop) |
| 150 | PrintOutSet("The following blocks will still be part of the loop:", |
| 151 | BlocksInLoopAfterFolding); |
| 152 | } |
| 153 | |
Max Kazantsev | a523a21 | 2018-12-07 05:44:45 +0000 | [diff] [blame] | 154 | /// Whether or not the current loop has irreducible CFG. |
| 155 | bool hasIrreducibleCFG(LoopBlocksDFS &DFS) { |
| 156 | assert(DFS.isComplete() && "DFS is expected to be finished"); |
| 157 | // Index of a basic block in RPO traversal. |
| 158 | DenseMap<const BasicBlock *, unsigned> RPO; |
| 159 | unsigned Current = 0; |
| 160 | for (auto I = DFS.beginRPO(), E = DFS.endRPO(); I != E; ++I) |
| 161 | RPO[*I] = Current++; |
| 162 | |
| 163 | for (auto I = DFS.beginRPO(), E = DFS.endRPO(); I != E; ++I) { |
| 164 | BasicBlock *BB = *I; |
| 165 | for (auto *Succ : successors(BB)) |
| 166 | if (L.contains(Succ) && !LI.isLoopHeader(Succ) && RPO[BB] > RPO[Succ]) |
| 167 | // If an edge goes from a block with greater order number into a block |
| 168 | // with lesses number, and it is not a loop backedge, then it can only |
| 169 | // be a part of irreducible non-loop cycle. |
| 170 | return true; |
| 171 | } |
| 172 | return false; |
| 173 | } |
| 174 | |
Max Kazantsev | c04b530 | 2018-11-20 05:43:32 +0000 | [diff] [blame] | 175 | /// Fill all information about status of blocks and exits of the current loop |
| 176 | /// if constant folding of all branches will be done. |
| 177 | void analyze() { |
| 178 | LoopBlocksDFS DFS(&L); |
| 179 | DFS.perform(&LI); |
| 180 | assert(DFS.isComplete() && "DFS is expected to be finished"); |
| 181 | |
Max Kazantsev | a523a21 | 2018-12-07 05:44:45 +0000 | [diff] [blame] | 182 | // TODO: The algorithm below relies on both RPO and Postorder traversals. |
| 183 | // When the loop has only reducible CFG inside, then the invariant "all |
| 184 | // predecessors of X are processed before X in RPO" is preserved. However |
| 185 | // an irreducible loop can break this invariant (e.g. latch does not have to |
| 186 | // be the last block in the traversal in this case, and the algorithm relies |
| 187 | // on this). We can later decide to support such cases by altering the |
| 188 | // algorithms, but so far we just give up analyzing them. |
| 189 | if (hasIrreducibleCFG(DFS)) { |
| 190 | HasIrreducibleCFG = true; |
| 191 | return; |
| 192 | } |
| 193 | |
Max Kazantsev | c04b530 | 2018-11-20 05:43:32 +0000 | [diff] [blame] | 194 | // Collect live and dead loop blocks and exits. |
Max Kazantsev | c04b530 | 2018-11-20 05:43:32 +0000 | [diff] [blame] | 195 | LiveLoopBlocks.insert(L.getHeader()); |
| 196 | for (auto I = DFS.beginRPO(), E = DFS.endRPO(); I != E; ++I) { |
| 197 | BasicBlock *BB = *I; |
| 198 | |
| 199 | // If a loop block wasn't marked as live so far, then it's dead. |
| 200 | if (!LiveLoopBlocks.count(BB)) { |
Max Kazantsev | 80e4b40 | 2018-12-28 06:08:51 +0000 | [diff] [blame] | 201 | DeadLoopBlocks.push_back(BB); |
Max Kazantsev | c04b530 | 2018-11-20 05:43:32 +0000 | [diff] [blame] | 202 | continue; |
| 203 | } |
| 204 | |
| 205 | BasicBlock *TheOnlySucc = getOnlyLiveSuccessor(BB); |
| 206 | |
| 207 | // If a block has only one live successor, it's a candidate on constant |
| 208 | // folding. Only handle blocks from current loop: branches in child loops |
| 209 | // are skipped because if they can be folded, they should be folded during |
| 210 | // the processing of child loops. |
| 211 | if (TheOnlySucc && LI.getLoopFor(BB) == &L) |
| 212 | FoldCandidates.push_back(BB); |
| 213 | |
| 214 | // Handle successors. |
Max Kazantsev | c04b530 | 2018-11-20 05:43:32 +0000 | [diff] [blame] | 215 | for (BasicBlock *Succ : successors(BB)) |
Max Kazantsev | d9f59f8 | 2018-11-22 10:48:30 +0000 | [diff] [blame] | 216 | if (!TheOnlySucc || TheOnlySucc == Succ) { |
| 217 | if (L.contains(Succ)) |
| 218 | LiveLoopBlocks.insert(Succ); |
| 219 | else |
| 220 | LiveExitBlocks.insert(Succ); |
| 221 | } |
Max Kazantsev | c04b530 | 2018-11-20 05:43:32 +0000 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | // Sanity check: amount of dead and live loop blocks should match the total |
| 225 | // number of blocks in loop. |
| 226 | assert(L.getNumBlocks() == LiveLoopBlocks.size() + DeadLoopBlocks.size() && |
| 227 | "Malformed block sets?"); |
| 228 | |
| 229 | // Now, all exit blocks that are not marked as live are dead. |
Max Kazantsev | d9f59f8 | 2018-11-22 10:48:30 +0000 | [diff] [blame] | 230 | SmallVector<BasicBlock *, 8> ExitBlocks; |
| 231 | L.getExitBlocks(ExitBlocks); |
Max Kazantsev | c04b530 | 2018-11-20 05:43:32 +0000 | [diff] [blame] | 232 | for (auto *ExitBlock : ExitBlocks) |
| 233 | if (!LiveExitBlocks.count(ExitBlock)) |
Max Kazantsev | 56a2443 | 2018-11-22 12:33:41 +0000 | [diff] [blame] | 234 | DeadExitBlocks.push_back(ExitBlock); |
Max Kazantsev | c04b530 | 2018-11-20 05:43:32 +0000 | [diff] [blame] | 235 | |
| 236 | // Whether or not the edge From->To will still be present in graph after the |
| 237 | // folding. |
| 238 | auto IsEdgeLive = [&](BasicBlock *From, BasicBlock *To) { |
| 239 | if (!LiveLoopBlocks.count(From)) |
| 240 | return false; |
| 241 | BasicBlock *TheOnlySucc = getOnlyLiveSuccessor(From); |
| 242 | return !TheOnlySucc || TheOnlySucc == To; |
| 243 | }; |
| 244 | |
| 245 | // The loop will not be destroyed if its latch is live. |
| 246 | DeleteCurrentLoop = !IsEdgeLive(L.getLoopLatch(), L.getHeader()); |
| 247 | |
| 248 | // If we are going to delete the current loop completely, no extra analysis |
| 249 | // is needed. |
| 250 | if (DeleteCurrentLoop) |
| 251 | return; |
| 252 | |
| 253 | // Otherwise, we should check which blocks will still be a part of the |
| 254 | // current loop after the transform. |
| 255 | BlocksInLoopAfterFolding.insert(L.getLoopLatch()); |
| 256 | // If the loop is live, then we should compute what blocks are still in |
| 257 | // loop after all branch folding has been done. A block is in loop if |
| 258 | // it has a live edge to another block that is in the loop; by definition, |
| 259 | // latch is in the loop. |
| 260 | auto BlockIsInLoop = [&](BasicBlock *BB) { |
| 261 | return any_of(successors(BB), [&](BasicBlock *Succ) { |
| 262 | return BlocksInLoopAfterFolding.count(Succ) && IsEdgeLive(BB, Succ); |
| 263 | }); |
| 264 | }; |
| 265 | for (auto I = DFS.beginPostorder(), E = DFS.endPostorder(); I != E; ++I) { |
| 266 | BasicBlock *BB = *I; |
| 267 | if (BlockIsInLoop(BB)) |
| 268 | BlocksInLoopAfterFolding.insert(BB); |
| 269 | } |
| 270 | |
| 271 | // Sanity check: header must be in loop. |
| 272 | assert(BlocksInLoopAfterFolding.count(L.getHeader()) && |
| 273 | "Header not in loop?"); |
Max Kazantsev | b565e60 | 2018-11-22 12:43:27 +0000 | [diff] [blame] | 274 | assert(BlocksInLoopAfterFolding.size() <= LiveLoopBlocks.size() && |
| 275 | "All blocks that stay in loop should be live!"); |
Max Kazantsev | c04b530 | 2018-11-20 05:43:32 +0000 | [diff] [blame] | 276 | } |
| 277 | |
Max Kazantsev | edabb9a | 2018-12-24 07:41:33 +0000 | [diff] [blame] | 278 | /// We need to preserve static reachibility of all loop exit blocks (this is) |
| 279 | /// required by loop pass manager. In order to do it, we make the following |
| 280 | /// trick: |
| 281 | /// |
| 282 | /// preheader: |
| 283 | /// <preheader code> |
| 284 | /// br label %loop_header |
| 285 | /// |
| 286 | /// loop_header: |
| 287 | /// ... |
| 288 | /// br i1 false, label %dead_exit, label %loop_block |
| 289 | /// ... |
| 290 | /// |
| 291 | /// We cannot simply remove edge from the loop to dead exit because in this |
| 292 | /// case dead_exit (and its successors) may become unreachable. To avoid that, |
| 293 | /// we insert the following fictive preheader: |
| 294 | /// |
| 295 | /// preheader: |
| 296 | /// <preheader code> |
| 297 | /// switch i32 0, label %preheader-split, |
| 298 | /// [i32 1, label %dead_exit_1], |
| 299 | /// [i32 2, label %dead_exit_2], |
| 300 | /// ... |
| 301 | /// [i32 N, label %dead_exit_N], |
| 302 | /// |
| 303 | /// preheader-split: |
| 304 | /// br label %loop_header |
| 305 | /// |
| 306 | /// loop_header: |
| 307 | /// ... |
| 308 | /// br i1 false, label %dead_exit_N, label %loop_block |
| 309 | /// ... |
| 310 | /// |
| 311 | /// Doing so, we preserve static reachibility of all dead exits and can later |
| 312 | /// remove edges from the loop to these blocks. |
| 313 | void handleDeadExits() { |
| 314 | // If no dead exits, nothing to do. |
| 315 | if (DeadExitBlocks.empty()) |
| 316 | return; |
| 317 | |
| 318 | // Construct split preheader and the dummy switch to thread edges from it to |
| 319 | // dead exits. |
| 320 | DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Eager); |
| 321 | BasicBlock *Preheader = L.getLoopPreheader(); |
| 322 | BasicBlock *NewPreheader = Preheader->splitBasicBlock( |
| 323 | Preheader->getTerminator(), |
| 324 | Twine(Preheader->getName()).concat("-split")); |
| 325 | DTU.deleteEdge(Preheader, L.getHeader()); |
| 326 | DTU.insertEdge(NewPreheader, L.getHeader()); |
| 327 | DTU.insertEdge(Preheader, NewPreheader); |
| 328 | IRBuilder<> Builder(Preheader->getTerminator()); |
| 329 | SwitchInst *DummySwitch = |
| 330 | Builder.CreateSwitch(Builder.getInt32(0), NewPreheader); |
| 331 | Preheader->getTerminator()->eraseFromParent(); |
| 332 | |
| 333 | unsigned DummyIdx = 1; |
| 334 | for (BasicBlock *BB : DeadExitBlocks) { |
| 335 | SmallVector<Instruction *, 4> DeadPhis; |
| 336 | for (auto &PN : BB->phis()) |
| 337 | DeadPhis.push_back(&PN); |
| 338 | |
| 339 | // Eliminate all Phis from dead exits. |
| 340 | for (Instruction *PN : DeadPhis) { |
| 341 | PN->replaceAllUsesWith(UndefValue::get(PN->getType())); |
| 342 | PN->eraseFromParent(); |
| 343 | } |
| 344 | assert(DummyIdx != 0 && "Too many dead exits!"); |
| 345 | DummySwitch->addCase(Builder.getInt32(DummyIdx++), BB); |
| 346 | DTU.insertEdge(Preheader, BB); |
| 347 | ++NumLoopExitsDeleted; |
| 348 | } |
| 349 | |
| 350 | assert(L.getLoopPreheader() == NewPreheader && "Malformed CFG?"); |
| 351 | if (Loop *OuterLoop = LI.getLoopFor(Preheader)) { |
| 352 | OuterLoop->addBasicBlockToLoop(NewPreheader, LI); |
| 353 | |
| 354 | // When we break dead edges, the outer loop may become unreachable from |
| 355 | // the current loop. We need to fix loop info accordingly. For this, we |
| 356 | // find the most nested loop that still contains L and remove L from all |
| 357 | // loops that are inside of it. |
| 358 | Loop *StillReachable = nullptr; |
| 359 | for (BasicBlock *BB : LiveExitBlocks) { |
| 360 | Loop *BBL = LI.getLoopFor(BB); |
| 361 | if (BBL && BBL->contains(L.getHeader())) |
| 362 | if (!StillReachable || |
| 363 | BBL->getLoopDepth() > StillReachable->getLoopDepth()) |
| 364 | StillReachable = BBL; |
| 365 | } |
| 366 | |
| 367 | // Okay, our loop is no longer in the outer loop (and maybe not in some of |
| 368 | // its parents as well). Make the fixup. |
| 369 | if (StillReachable != OuterLoop) { |
| 370 | LI.changeLoopFor(NewPreheader, StillReachable); |
| 371 | for (Loop *NotContaining = OuterLoop; NotContaining != StillReachable; |
| 372 | NotContaining = NotContaining->getParentLoop()) { |
| 373 | NotContaining->removeBlockFromLoop(NewPreheader); |
| 374 | for (auto *BB : L.blocks()) |
| 375 | NotContaining->removeBlockFromLoop(BB); |
| 376 | } |
| 377 | OuterLoop->removeChildLoop(&L); |
| 378 | if (StillReachable) |
| 379 | StillReachable->addChildLoop(&L); |
| 380 | else |
| 381 | LI.addTopLevelLoop(&L); |
Max Kazantsev | 61a8d3f | 2019-01-17 12:51:10 +0000 | [diff] [blame^] | 382 | |
| 383 | // Some values from loops in [OuterLoop, StillReachable) could be used |
| 384 | // in the current loop. Now it is not their child anymore, so such uses |
| 385 | // require LCSSA Phis. |
| 386 | Loop *FixLCSSALoop = OuterLoop; |
| 387 | while (FixLCSSALoop->getParentLoop() != StillReachable) |
| 388 | FixLCSSALoop = FixLCSSALoop->getParentLoop(); |
| 389 | assert(FixLCSSALoop && "Should be a loop!"); |
| 390 | formLCSSARecursively(*FixLCSSALoop, DT, &LI, &SE); |
Max Kazantsev | edabb9a | 2018-12-24 07:41:33 +0000 | [diff] [blame] | 391 | } |
| 392 | } |
| 393 | } |
| 394 | |
Max Kazantsev | 347c583 | 2018-12-24 06:06:17 +0000 | [diff] [blame] | 395 | /// Delete loop blocks that have become unreachable after folding. Make all |
| 396 | /// relevant updates to DT and LI. |
| 397 | void deleteDeadLoopBlocks() { |
| 398 | DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Eager); |
Max Kazantsev | 80e4b40 | 2018-12-28 06:08:51 +0000 | [diff] [blame] | 399 | if (MSSAU) { |
| 400 | SmallPtrSet<BasicBlock *, 8> DeadLoopBlocksSet(DeadLoopBlocks.begin(), |
| 401 | DeadLoopBlocks.end()); |
| 402 | MSSAU->removeBlocks(DeadLoopBlocksSet); |
| 403 | } |
Max Kazantsev | 347c583 | 2018-12-24 06:06:17 +0000 | [diff] [blame] | 404 | for (auto *BB : DeadLoopBlocks) { |
| 405 | assert(BB != L.getHeader() && |
| 406 | "Header of the current loop cannot be dead!"); |
| 407 | LLVM_DEBUG(dbgs() << "Deleting dead loop block " << BB->getName() |
| 408 | << "\n"); |
| 409 | if (LI.isLoopHeader(BB)) { |
| 410 | assert(LI.getLoopFor(BB) != &L && "Attempt to remove current loop!"); |
| 411 | LI.erase(LI.getLoopFor(BB)); |
| 412 | } |
| 413 | LI.removeBlock(BB); |
Max Kazantsev | 347c583 | 2018-12-24 06:06:17 +0000 | [diff] [blame] | 414 | } |
Max Kazantsev | 8b13416 | 2019-01-17 12:25:40 +0000 | [diff] [blame] | 415 | |
| 416 | DeleteDeadBlocks(DeadLoopBlocks, &DTU); |
| 417 | NumLoopBlocksDeleted += DeadLoopBlocks.size(); |
Max Kazantsev | 347c583 | 2018-12-24 06:06:17 +0000 | [diff] [blame] | 418 | } |
| 419 | |
Max Kazantsev | c04b530 | 2018-11-20 05:43:32 +0000 | [diff] [blame] | 420 | /// Constant-fold terminators of blocks acculumated in FoldCandidates into the |
| 421 | /// unconditional branches. |
| 422 | void foldTerminators() { |
| 423 | DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Eager); |
| 424 | |
| 425 | for (BasicBlock *BB : FoldCandidates) { |
| 426 | assert(LI.getLoopFor(BB) == &L && "Should be a loop block!"); |
| 427 | BasicBlock *TheOnlySucc = getOnlyLiveSuccessor(BB); |
| 428 | assert(TheOnlySucc && "Should have one live successor!"); |
| 429 | |
| 430 | LLVM_DEBUG(dbgs() << "Replacing terminator of " << BB->getName() |
| 431 | << " with an unconditional branch to the block " |
| 432 | << TheOnlySucc->getName() << "\n"); |
| 433 | |
| 434 | SmallPtrSet<BasicBlock *, 2> DeadSuccessors; |
| 435 | // Remove all BB's successors except for the live one. |
Max Kazantsev | c4e4d64 | 2018-11-27 06:17:21 +0000 | [diff] [blame] | 436 | unsigned TheOnlySuccDuplicates = 0; |
Max Kazantsev | c04b530 | 2018-11-20 05:43:32 +0000 | [diff] [blame] | 437 | for (auto *Succ : successors(BB)) |
| 438 | if (Succ != TheOnlySucc) { |
| 439 | DeadSuccessors.insert(Succ); |
Max Kazantsev | cb8e240 | 2018-11-23 07:56:47 +0000 | [diff] [blame] | 440 | // If our successor lies in a different loop, we don't want to remove |
| 441 | // the one-input Phi because it is a LCSSA Phi. |
| 442 | bool PreserveLCSSAPhi = !L.contains(Succ); |
| 443 | Succ->removePredecessor(BB, PreserveLCSSAPhi); |
Max Kazantsev | 9cf417d | 2018-11-30 10:06:23 +0000 | [diff] [blame] | 444 | if (MSSAU) |
| 445 | MSSAU->removeEdge(BB, Succ); |
Max Kazantsev | c4e4d64 | 2018-11-27 06:17:21 +0000 | [diff] [blame] | 446 | } else |
| 447 | ++TheOnlySuccDuplicates; |
| 448 | |
| 449 | assert(TheOnlySuccDuplicates > 0 && "Should be!"); |
| 450 | // If TheOnlySucc was BB's successor more than once, after transform it |
| 451 | // will be its successor only once. Remove redundant inputs from |
| 452 | // TheOnlySucc's Phis. |
| 453 | bool PreserveLCSSAPhi = !L.contains(TheOnlySucc); |
| 454 | for (unsigned Dup = 1; Dup < TheOnlySuccDuplicates; ++Dup) |
| 455 | TheOnlySucc->removePredecessor(BB, PreserveLCSSAPhi); |
Max Kazantsev | 9cf417d | 2018-11-30 10:06:23 +0000 | [diff] [blame] | 456 | if (MSSAU && TheOnlySuccDuplicates > 1) |
| 457 | MSSAU->removeDuplicatePhiEdgesBetween(BB, TheOnlySucc); |
Max Kazantsev | c04b530 | 2018-11-20 05:43:32 +0000 | [diff] [blame] | 458 | |
| 459 | IRBuilder<> Builder(BB->getContext()); |
| 460 | Instruction *Term = BB->getTerminator(); |
| 461 | Builder.SetInsertPoint(Term); |
| 462 | Builder.CreateBr(TheOnlySucc); |
| 463 | Term->eraseFromParent(); |
| 464 | |
| 465 | for (auto *DeadSucc : DeadSuccessors) |
| 466 | DTU.deleteEdge(BB, DeadSucc); |
| 467 | |
| 468 | ++NumTerminatorsFolded; |
| 469 | } |
| 470 | } |
| 471 | |
| 472 | public: |
Max Kazantsev | 9cf417d | 2018-11-30 10:06:23 +0000 | [diff] [blame] | 473 | ConstantTerminatorFoldingImpl(Loop &L, LoopInfo &LI, DominatorTree &DT, |
Max Kazantsev | 201534d | 2018-12-29 04:26:22 +0000 | [diff] [blame] | 474 | ScalarEvolution &SE, |
Max Kazantsev | 9cf417d | 2018-11-30 10:06:23 +0000 | [diff] [blame] | 475 | MemorySSAUpdater *MSSAU) |
Max Kazantsev | 201534d | 2018-12-29 04:26:22 +0000 | [diff] [blame] | 476 | : L(L), LI(LI), DT(DT), SE(SE), MSSAU(MSSAU) {} |
Max Kazantsev | c04b530 | 2018-11-20 05:43:32 +0000 | [diff] [blame] | 477 | bool run() { |
| 478 | assert(L.getLoopLatch() && "Should be single latch!"); |
| 479 | |
| 480 | // Collect all available information about status of blocks after constant |
| 481 | // folding. |
| 482 | analyze(); |
| 483 | |
| 484 | LLVM_DEBUG(dbgs() << "In function " << L.getHeader()->getParent()->getName() |
| 485 | << ": "); |
| 486 | |
Max Kazantsev | a523a21 | 2018-12-07 05:44:45 +0000 | [diff] [blame] | 487 | if (HasIrreducibleCFG) { |
| 488 | LLVM_DEBUG(dbgs() << "Loops with irreducible CFG are not supported!\n"); |
| 489 | return false; |
| 490 | } |
| 491 | |
Max Kazantsev | c04b530 | 2018-11-20 05:43:32 +0000 | [diff] [blame] | 492 | // Nothing to constant-fold. |
| 493 | if (FoldCandidates.empty()) { |
| 494 | LLVM_DEBUG( |
| 495 | dbgs() << "No constant terminator folding candidates found in loop " |
| 496 | << L.getHeader()->getName() << "\n"); |
| 497 | return false; |
| 498 | } |
| 499 | |
| 500 | // TODO: Support deletion of the current loop. |
| 501 | if (DeleteCurrentLoop) { |
| 502 | LLVM_DEBUG( |
| 503 | dbgs() |
| 504 | << "Give up constant terminator folding in loop " |
| 505 | << L.getHeader()->getName() |
| 506 | << ": we don't currently support deletion of the current loop.\n"); |
| 507 | return false; |
| 508 | } |
| 509 | |
Max Kazantsev | c04b530 | 2018-11-20 05:43:32 +0000 | [diff] [blame] | 510 | // TODO: Support blocks that are not dead, but also not in loop after the |
| 511 | // folding. |
Max Kazantsev | 347c583 | 2018-12-24 06:06:17 +0000 | [diff] [blame] | 512 | if (BlocksInLoopAfterFolding.size() + DeadLoopBlocks.size() != |
| 513 | L.getNumBlocks()) { |
Max Kazantsev | c04b530 | 2018-11-20 05:43:32 +0000 | [diff] [blame] | 514 | LLVM_DEBUG( |
| 515 | dbgs() << "Give up constant terminator folding in loop " |
| 516 | << L.getHeader()->getName() |
| 517 | << ": we don't currently" |
| 518 | " support blocks that are not dead, but will stop " |
| 519 | "being a part of the loop after constant-folding.\n"); |
| 520 | return false; |
| 521 | } |
| 522 | |
Max Kazantsev | 201534d | 2018-12-29 04:26:22 +0000 | [diff] [blame] | 523 | SE.forgetTopmostLoop(&L); |
Max Kazantsev | c04b530 | 2018-11-20 05:43:32 +0000 | [diff] [blame] | 524 | // Dump analysis results. |
| 525 | LLVM_DEBUG(dump()); |
| 526 | |
| 527 | LLVM_DEBUG(dbgs() << "Constant-folding " << FoldCandidates.size() |
| 528 | << " terminators in loop " << L.getHeader()->getName() |
| 529 | << "\n"); |
| 530 | |
| 531 | // Make the actual transforms. |
Max Kazantsev | edabb9a | 2018-12-24 07:41:33 +0000 | [diff] [blame] | 532 | handleDeadExits(); |
Max Kazantsev | c04b530 | 2018-11-20 05:43:32 +0000 | [diff] [blame] | 533 | foldTerminators(); |
| 534 | |
Max Kazantsev | 347c583 | 2018-12-24 06:06:17 +0000 | [diff] [blame] | 535 | if (!DeadLoopBlocks.empty()) { |
| 536 | LLVM_DEBUG(dbgs() << "Deleting " << DeadLoopBlocks.size() |
| 537 | << " dead blocks in loop " << L.getHeader()->getName() |
| 538 | << "\n"); |
| 539 | deleteDeadLoopBlocks(); |
| 540 | } |
| 541 | |
Max Kazantsev | c04b530 | 2018-11-20 05:43:32 +0000 | [diff] [blame] | 542 | #ifndef NDEBUG |
| 543 | // Make sure that we have preserved all data structures after the transform. |
| 544 | DT.verify(); |
| 545 | assert(DT.isReachableFromEntry(L.getHeader())); |
| 546 | LI.verify(DT); |
| 547 | #endif |
| 548 | |
| 549 | return true; |
| 550 | } |
| 551 | }; |
Benjamin Kramer | b17d213 | 2019-01-12 18:36:22 +0000 | [diff] [blame] | 552 | } // namespace |
Max Kazantsev | c04b530 | 2018-11-20 05:43:32 +0000 | [diff] [blame] | 553 | |
| 554 | /// Turn branches and switches with known constant conditions into unconditional |
| 555 | /// branches. |
Max Kazantsev | 9cf417d | 2018-11-30 10:06:23 +0000 | [diff] [blame] | 556 | static bool constantFoldTerminators(Loop &L, DominatorTree &DT, LoopInfo &LI, |
Max Kazantsev | 201534d | 2018-12-29 04:26:22 +0000 | [diff] [blame] | 557 | ScalarEvolution &SE, |
Max Kazantsev | 9cf417d | 2018-11-30 10:06:23 +0000 | [diff] [blame] | 558 | MemorySSAUpdater *MSSAU) { |
Max Kazantsev | e1c2dc2 | 2018-11-23 09:14:53 +0000 | [diff] [blame] | 559 | if (!EnableTermFolding) |
| 560 | return false; |
| 561 | |
Max Kazantsev | c04b530 | 2018-11-20 05:43:32 +0000 | [diff] [blame] | 562 | // To keep things simple, only process loops with single latch. We |
| 563 | // canonicalize most loops to this form. We can support multi-latch if needed. |
| 564 | if (!L.getLoopLatch()) |
| 565 | return false; |
| 566 | |
Max Kazantsev | 201534d | 2018-12-29 04:26:22 +0000 | [diff] [blame] | 567 | ConstantTerminatorFoldingImpl BranchFolder(L, LI, DT, SE, MSSAU); |
Max Kazantsev | c04b530 | 2018-11-20 05:43:32 +0000 | [diff] [blame] | 568 | return BranchFolder.run(); |
| 569 | } |
| 570 | |
Max Kazantsev | 46955b5 | 2018-11-01 09:42:50 +0000 | [diff] [blame] | 571 | static bool mergeBlocksIntoPredecessors(Loop &L, DominatorTree &DT, |
| 572 | LoopInfo &LI, MemorySSAUpdater *MSSAU) { |
Fiona Glaser | b417d46 | 2016-01-29 22:35:36 +0000 | [diff] [blame] | 573 | bool Changed = false; |
Chijun Sima | 21a8b60 | 2018-08-03 05:08:17 +0000 | [diff] [blame] | 574 | DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Eager); |
Fiona Glaser | b417d46 | 2016-01-29 22:35:36 +0000 | [diff] [blame] | 575 | // Copy blocks into a temporary array to avoid iterator invalidation issues |
| 576 | // as we remove them. |
Sanjoy Das | e6bca0e | 2017-05-01 17:07:49 +0000 | [diff] [blame] | 577 | SmallVector<WeakTrackingVH, 16> Blocks(L.blocks()); |
Fiona Glaser | b417d46 | 2016-01-29 22:35:36 +0000 | [diff] [blame] | 578 | |
| 579 | for (auto &Block : Blocks) { |
| 580 | // Attempt to merge blocks in the trivial case. Don't modify blocks which |
| 581 | // belong to other loops. |
Fiona Glaser | 36e8230 | 2016-01-29 23:12:52 +0000 | [diff] [blame] | 582 | BasicBlock *Succ = cast_or_null<BasicBlock>(Block); |
Fiona Glaser | b417d46 | 2016-01-29 22:35:36 +0000 | [diff] [blame] | 583 | if (!Succ) |
| 584 | continue; |
| 585 | |
| 586 | BasicBlock *Pred = Succ->getSinglePredecessor(); |
Justin Bogner | ab6a513 | 2016-05-03 21:47:32 +0000 | [diff] [blame] | 587 | if (!Pred || !Pred->getSingleSuccessor() || LI.getLoopFor(Pred) != &L) |
Fiona Glaser | b417d46 | 2016-01-29 22:35:36 +0000 | [diff] [blame] | 588 | continue; |
| 589 | |
Alina Sbirlea | dfd14ad | 2018-06-20 22:01:04 +0000 | [diff] [blame] | 590 | // Merge Succ into Pred and delete it. |
Alina Sbirlea | 8b83d68 | 2018-08-22 20:10:21 +0000 | [diff] [blame] | 591 | MergeBlockIntoPredecessor(Succ, &DTU, &LI, MSSAU); |
David Green | e6a9c24 | 2018-06-19 09:43:36 +0000 | [diff] [blame] | 592 | |
Fiona Glaser | b417d46 | 2016-01-29 22:35:36 +0000 | [diff] [blame] | 593 | Changed = true; |
| 594 | } |
| 595 | |
| 596 | return Changed; |
| 597 | } |
| 598 | |
Max Kazantsev | 46955b5 | 2018-11-01 09:42:50 +0000 | [diff] [blame] | 599 | static bool simplifyLoopCFG(Loop &L, DominatorTree &DT, LoopInfo &LI, |
| 600 | ScalarEvolution &SE, MemorySSAUpdater *MSSAU) { |
| 601 | bool Changed = false; |
| 602 | |
Max Kazantsev | c04b530 | 2018-11-20 05:43:32 +0000 | [diff] [blame] | 603 | // Constant-fold terminators with known constant conditions. |
Max Kazantsev | 201534d | 2018-12-29 04:26:22 +0000 | [diff] [blame] | 604 | Changed |= constantFoldTerminators(L, DT, LI, SE, MSSAU); |
Max Kazantsev | c04b530 | 2018-11-20 05:43:32 +0000 | [diff] [blame] | 605 | |
Max Kazantsev | 46955b5 | 2018-11-01 09:42:50 +0000 | [diff] [blame] | 606 | // Eliminate unconditional branches by merging blocks into their predecessors. |
| 607 | Changed |= mergeBlocksIntoPredecessors(L, DT, LI, MSSAU); |
| 608 | |
| 609 | if (Changed) |
| 610 | SE.forgetTopmostLoop(&L); |
| 611 | |
| 612 | return Changed; |
| 613 | } |
| 614 | |
Chandler Carruth | 410eaeb | 2017-01-11 06:23:21 +0000 | [diff] [blame] | 615 | PreservedAnalyses LoopSimplifyCFGPass::run(Loop &L, LoopAnalysisManager &AM, |
| 616 | LoopStandardAnalysisResults &AR, |
| 617 | LPMUpdater &) { |
Alina Sbirlea | 8b83d68 | 2018-08-22 20:10:21 +0000 | [diff] [blame] | 618 | Optional<MemorySSAUpdater> MSSAU; |
| 619 | if (EnableMSSALoopDependency && AR.MSSA) |
| 620 | MSSAU = MemorySSAUpdater(AR.MSSA); |
| 621 | if (!simplifyLoopCFG(L, AR.DT, AR.LI, AR.SE, |
| 622 | MSSAU.hasValue() ? MSSAU.getPointer() : nullptr)) |
Justin Bogner | ab6a513 | 2016-05-03 21:47:32 +0000 | [diff] [blame] | 623 | return PreservedAnalyses::all(); |
Chandler Carruth | ca68a3e | 2017-01-15 06:32:49 +0000 | [diff] [blame] | 624 | |
Justin Bogner | ab6a513 | 2016-05-03 21:47:32 +0000 | [diff] [blame] | 625 | return getLoopPassPreservedAnalyses(); |
| 626 | } |
| 627 | |
| 628 | namespace { |
| 629 | class LoopSimplifyCFGLegacyPass : public LoopPass { |
| 630 | public: |
| 631 | static char ID; // Pass ID, replacement for typeid |
| 632 | LoopSimplifyCFGLegacyPass() : LoopPass(ID) { |
| 633 | initializeLoopSimplifyCFGLegacyPassPass(*PassRegistry::getPassRegistry()); |
| 634 | } |
| 635 | |
| 636 | bool runOnLoop(Loop *L, LPPassManager &) override { |
| 637 | if (skipLoop(L)) |
| 638 | return false; |
| 639 | |
| 640 | DominatorTree &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree(); |
| 641 | LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo(); |
David Green | e6a9c24 | 2018-06-19 09:43:36 +0000 | [diff] [blame] | 642 | ScalarEvolution &SE = getAnalysis<ScalarEvolutionWrapperPass>().getSE(); |
Alina Sbirlea | 8b83d68 | 2018-08-22 20:10:21 +0000 | [diff] [blame] | 643 | Optional<MemorySSAUpdater> MSSAU; |
| 644 | if (EnableMSSALoopDependency) { |
| 645 | MemorySSA *MSSA = &getAnalysis<MemorySSAWrapperPass>().getMSSA(); |
| 646 | MSSAU = MemorySSAUpdater(MSSA); |
| 647 | if (VerifyMemorySSA) |
| 648 | MSSA->verifyMemorySSA(); |
| 649 | } |
| 650 | return simplifyLoopCFG(*L, DT, LI, SE, |
| 651 | MSSAU.hasValue() ? MSSAU.getPointer() : nullptr); |
Justin Bogner | ab6a513 | 2016-05-03 21:47:32 +0000 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | void getAnalysisUsage(AnalysisUsage &AU) const override { |
Alina Sbirlea | 8b83d68 | 2018-08-22 20:10:21 +0000 | [diff] [blame] | 655 | if (EnableMSSALoopDependency) { |
| 656 | AU.addRequired<MemorySSAWrapperPass>(); |
| 657 | AU.addPreserved<MemorySSAWrapperPass>(); |
| 658 | } |
Chandler Carruth | 49c2219 | 2016-05-12 22:19:39 +0000 | [diff] [blame] | 659 | AU.addPreserved<DependenceAnalysisWrapperPass>(); |
Justin Bogner | ab6a513 | 2016-05-03 21:47:32 +0000 | [diff] [blame] | 660 | getLoopAnalysisUsage(AU); |
| 661 | } |
| 662 | }; |
| 663 | } |
| 664 | |
| 665 | char LoopSimplifyCFGLegacyPass::ID = 0; |
| 666 | INITIALIZE_PASS_BEGIN(LoopSimplifyCFGLegacyPass, "loop-simplifycfg", |
| 667 | "Simplify loop CFG", false, false) |
| 668 | INITIALIZE_PASS_DEPENDENCY(LoopPass) |
Alina Sbirlea | 8b83d68 | 2018-08-22 20:10:21 +0000 | [diff] [blame] | 669 | INITIALIZE_PASS_DEPENDENCY(MemorySSAWrapperPass) |
Justin Bogner | ab6a513 | 2016-05-03 21:47:32 +0000 | [diff] [blame] | 670 | INITIALIZE_PASS_END(LoopSimplifyCFGLegacyPass, "loop-simplifycfg", |
| 671 | "Simplify loop CFG", false, false) |
| 672 | |
| 673 | Pass *llvm::createLoopSimplifyCFGPass() { |
| 674 | return new LoopSimplifyCFGLegacyPass(); |
Fiona Glaser | b417d46 | 2016-01-29 22:35:36 +0000 | [diff] [blame] | 675 | } |