Owen Anderson | 2306a1e | 2008-04-29 20:06:54 +0000 | [diff] [blame] | 1 | //===- LoopDeletion.cpp - Dead Loop Deletion Pass ---------------===// |
Owen Anderson | 94ad702 | 2008-04-29 00:38:34 +0000 | [diff] [blame] | 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Owen Anderson | 94ad702 | 2008-04-29 00:38:34 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
Gordon Henriksen | 829046b | 2008-05-08 17:46:35 +0000 | [diff] [blame] | 9 | // This file implements the Dead Loop Deletion Pass. This pass is responsible |
| 10 | // for eliminating loops with non-infinite computable trip counts that have no |
| 11 | // side effects or volatile instructions, and do not contribute to the |
| 12 | // computation of the function's return value. |
Owen Anderson | 94ad702 | 2008-04-29 00:38:34 +0000 | [diff] [blame] | 13 | // |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
Jun Bum Lim | c837af3 | 2016-07-14 18:28:29 +0000 | [diff] [blame] | 16 | #include "llvm/Transforms/Scalar/LoopDeletion.h" |
Owen Anderson | 94ad702 | 2008-04-29 00:38:34 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/SmallVector.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/Statistic.h" |
James Molloy | efbba72 | 2015-09-10 10:22:12 +0000 | [diff] [blame] | 19 | #include "llvm/Analysis/GlobalsModRef.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 20 | #include "llvm/Analysis/LoopPass.h" |
Chandler Carruth | 5ad5f15 | 2014-01-13 09:26:24 +0000 | [diff] [blame] | 21 | #include "llvm/IR/Dominators.h" |
Anna Thomas | 53c8d95 | 2017-05-03 11:47:11 +0000 | [diff] [blame] | 22 | #include "llvm/IR/PatternMatch.h" |
Jun Bum Lim | c837af3 | 2016-07-14 18:28:29 +0000 | [diff] [blame] | 23 | #include "llvm/Transforms/Scalar.h" |
Chandler Carruth | 3bab7e1 | 2017-01-11 09:43:56 +0000 | [diff] [blame] | 24 | #include "llvm/Transforms/Scalar/LoopPassManager.h" |
Chandler Carruth | 31088a9 | 2016-02-19 10:45:18 +0000 | [diff] [blame] | 25 | #include "llvm/Transforms/Utils/LoopUtils.h" |
Owen Anderson | 94ad702 | 2008-04-29 00:38:34 +0000 | [diff] [blame] | 26 | using namespace llvm; |
| 27 | |
Chandler Carruth | 964daaa | 2014-04-22 02:55:47 +0000 | [diff] [blame] | 28 | #define DEBUG_TYPE "loop-delete" |
| 29 | |
Owen Anderson | 94ad702 | 2008-04-29 00:38:34 +0000 | [diff] [blame] | 30 | STATISTIC(NumDeleted, "Number of loops deleted"); |
| 31 | |
Sanjoy Das | 8e8c1bc | 2017-09-27 21:45:21 +0000 | [diff] [blame] | 32 | enum class LoopDeletionResult { |
| 33 | Unmodified, |
| 34 | Modified, |
| 35 | Deleted, |
| 36 | }; |
| 37 | |
Chandler Carruth | 26169f00 | 2017-01-17 22:07:26 +0000 | [diff] [blame] | 38 | /// Determines if a loop is dead. |
| 39 | /// |
| 40 | /// This assumes that we've already checked for unique exit and exiting blocks, |
| 41 | /// and that the code is in LCSSA form. |
| 42 | static bool isLoopDead(Loop *L, ScalarEvolution &SE, |
| 43 | SmallVectorImpl<BasicBlock *> &ExitingBlocks, |
| 44 | BasicBlock *ExitBlock, bool &Changed, |
| 45 | BasicBlock *Preheader) { |
Owen Anderson | 94ad702 | 2008-04-29 00:38:34 +0000 | [diff] [blame] | 46 | // Make sure that all PHI entries coming from the loop are loop invariant. |
Owen Anderson | e674600 | 2008-04-29 20:59:33 +0000 | [diff] [blame] | 47 | // Because the code is in LCSSA form, any values used outside of the loop |
| 48 | // must pass through a PHI in the exit block, meaning that this check is |
| 49 | // sufficient to guarantee that no loop-variant values are used outside |
| 50 | // of the loop. |
Sanjoy Das | 905fc27 | 2016-05-03 17:50:02 +0000 | [diff] [blame] | 51 | bool AllEntriesInvariant = true; |
| 52 | bool AllOutgoingValuesSame = true; |
Benjamin Kramer | c7fc81e | 2017-12-30 15:27:33 +0000 | [diff] [blame] | 53 | for (PHINode &P : ExitBlock->phis()) { |
| 54 | Value *incoming = P.getIncomingValueForBlock(ExitingBlocks[0]); |
Cameron Zwarich | 8263085 | 2011-02-22 22:25:39 +0000 | [diff] [blame] | 55 | |
| 56 | // Make sure all exiting blocks produce the same incoming value for the exit |
| 57 | // block. If there are different incoming values for different exiting |
| 58 | // blocks, then it is impossible to statically determine which value should |
| 59 | // be used. |
Sanjoy Das | 7e7a5a0 | 2016-05-03 17:50:06 +0000 | [diff] [blame] | 60 | AllOutgoingValuesSame = |
Chandler Carruth | 04a7387 | 2017-01-17 21:51:39 +0000 | [diff] [blame] | 61 | all_of(makeArrayRef(ExitingBlocks).slice(1), [&](BasicBlock *BB) { |
Benjamin Kramer | c7fc81e | 2017-12-30 15:27:33 +0000 | [diff] [blame] | 62 | return incoming == P.getIncomingValueForBlock(BB); |
Sanjoy Das | 7e7a5a0 | 2016-05-03 17:50:06 +0000 | [diff] [blame] | 63 | }); |
Nadav Rotem | 465834c | 2012-07-24 10:51:42 +0000 | [diff] [blame] | 64 | |
Sanjoy Das | 905fc27 | 2016-05-03 17:50:02 +0000 | [diff] [blame] | 65 | if (!AllOutgoingValuesSame) |
| 66 | break; |
| 67 | |
Jakub Staszak | bc421ef | 2013-03-18 23:31:30 +0000 | [diff] [blame] | 68 | if (Instruction *I = dyn_cast<Instruction>(incoming)) |
Sanjoy Das | 905fc27 | 2016-05-03 17:50:02 +0000 | [diff] [blame] | 69 | if (!L->makeLoopInvariant(I, Changed, Preheader->getTerminator())) { |
| 70 | AllEntriesInvariant = false; |
| 71 | break; |
| 72 | } |
Owen Anderson | 94ad702 | 2008-04-29 00:38:34 +0000 | [diff] [blame] | 73 | } |
Nadav Rotem | 465834c | 2012-07-24 10:51:42 +0000 | [diff] [blame] | 74 | |
Sanjoy Das | 905fc27 | 2016-05-03 17:50:02 +0000 | [diff] [blame] | 75 | if (Changed) |
| 76 | SE.forgetLoopDispositions(L); |
| 77 | |
| 78 | if (!AllEntriesInvariant || !AllOutgoingValuesSame) |
| 79 | return false; |
| 80 | |
Owen Anderson | 94ad702 | 2008-04-29 00:38:34 +0000 | [diff] [blame] | 81 | // Make sure that no instructions in the block have potential side-effects. |
Owen Anderson | e674600 | 2008-04-29 20:59:33 +0000 | [diff] [blame] | 82 | // This includes instructions that could write to memory, and loads that are |
Xin Tong | df4dff3 | 2017-02-23 23:47:10 +0000 | [diff] [blame] | 83 | // marked volatile. |
Davide Italiano | 49a0aac | 2017-02-26 07:08:20 +0000 | [diff] [blame] | 84 | for (auto &I : L->blocks()) |
| 85 | if (any_of(*I, [](Instruction &I) { return I.mayHaveSideEffects(); })) |
| 86 | return false; |
Owen Anderson | 94ad702 | 2008-04-29 00:38:34 +0000 | [diff] [blame] | 87 | return true; |
| 88 | } |
| 89 | |
Anna Thomas | 53c8d95 | 2017-05-03 11:47:11 +0000 | [diff] [blame] | 90 | /// This function returns true if there is no viable path from the |
| 91 | /// entry block to the header of \p L. Right now, it only does |
| 92 | /// a local search to save compile time. |
| 93 | static bool isLoopNeverExecuted(Loop *L) { |
| 94 | using namespace PatternMatch; |
| 95 | |
| 96 | auto *Preheader = L->getLoopPreheader(); |
| 97 | // TODO: We can relax this constraint, since we just need a loop |
| 98 | // predecessor. |
| 99 | assert(Preheader && "Needs preheader!"); |
| 100 | |
| 101 | if (Preheader == &Preheader->getParent()->getEntryBlock()) |
| 102 | return false; |
| 103 | // All predecessors of the preheader should have a constant conditional |
| 104 | // branch, with the loop's preheader as not-taken. |
| 105 | for (auto *Pred: predecessors(Preheader)) { |
| 106 | BasicBlock *Taken, *NotTaken; |
| 107 | ConstantInt *Cond; |
| 108 | if (!match(Pred->getTerminator(), |
| 109 | m_Br(m_ConstantInt(Cond), Taken, NotTaken))) |
| 110 | return false; |
| 111 | if (!Cond->getZExtValue()) |
| 112 | std::swap(Taken, NotTaken); |
| 113 | if (Taken == Preheader) |
| 114 | return false; |
| 115 | } |
| 116 | assert(!pred_empty(Preheader) && |
| 117 | "Preheader should have predecessors at this point!"); |
| 118 | // All the predecessors have the loop preheader as not-taken target. |
| 119 | return true; |
| 120 | } |
| 121 | |
Chandler Carruth | 26169f00 | 2017-01-17 22:07:26 +0000 | [diff] [blame] | 122 | /// Remove a loop if it is dead. |
| 123 | /// |
| 124 | /// A loop is considered dead if it does not impact the observable behavior of |
| 125 | /// the program other than finite running time. This never removes a loop that |
Anna Thomas | 53c8d95 | 2017-05-03 11:47:11 +0000 | [diff] [blame] | 126 | /// might be infinite (unless it is never executed), as doing so could change |
| 127 | /// the halting/non-halting nature of a program. |
Chandler Carruth | 26169f00 | 2017-01-17 22:07:26 +0000 | [diff] [blame] | 128 | /// |
| 129 | /// This entire process relies pretty heavily on LoopSimplify form and LCSSA in |
| 130 | /// order to make various safety checks work. |
| 131 | /// |
Chandler Carruth | 027340f | 2017-02-11 00:09:30 +0000 | [diff] [blame] | 132 | /// \returns true if any changes were made. This may mutate the loop even if it |
| 133 | /// is unable to delete it due to hoisting trivially loop invariant |
| 134 | /// instructions out of the loop. |
Sanjoy Das | 8e8c1bc | 2017-09-27 21:45:21 +0000 | [diff] [blame] | 135 | static LoopDeletionResult deleteLoopIfDead(Loop *L, DominatorTree &DT, |
| 136 | ScalarEvolution &SE, LoopInfo &LI) { |
Sanjoy Das | 979a11d | 2016-02-21 17:11:59 +0000 | [diff] [blame] | 137 | assert(L->isLCSSAForm(DT) && "Expected LCSSA!"); |
| 138 | |
Anna Thomas | 90f69ab | 2017-07-04 14:05:19 +0000 | [diff] [blame] | 139 | // We can only remove the loop if there is a preheader that we can branch from |
| 140 | // after removing it. Also, if LoopSimplify form is not available, stay out |
| 141 | // of trouble. |
Chandler Carruth | aa885c9 | 2017-01-17 22:19:56 +0000 | [diff] [blame] | 142 | BasicBlock *Preheader = L->getLoopPreheader(); |
Anna Thomas | 90f69ab | 2017-07-04 14:05:19 +0000 | [diff] [blame] | 143 | if (!Preheader || !L->hasDedicatedExits()) { |
Nicola Zaghen | d34e60c | 2018-05-14 12:53:11 +0000 | [diff] [blame] | 144 | LLVM_DEBUG( |
| 145 | dbgs() |
| 146 | << "Deletion requires Loop with preheader and dedicated exits.\n"); |
Sanjoy Das | 8e8c1bc | 2017-09-27 21:45:21 +0000 | [diff] [blame] | 147 | return LoopDeletionResult::Unmodified; |
Anna Thomas | 90f69ab | 2017-07-04 14:05:19 +0000 | [diff] [blame] | 148 | } |
Owen Anderson | 94ad702 | 2008-04-29 00:38:34 +0000 | [diff] [blame] | 149 | // We can't remove loops that contain subloops. If the subloops were dead, |
| 150 | // they would already have been removed in earlier executions of this pass. |
Anna Thomas | 90f69ab | 2017-07-04 14:05:19 +0000 | [diff] [blame] | 151 | if (L->begin() != L->end()) { |
Nicola Zaghen | d34e60c | 2018-05-14 12:53:11 +0000 | [diff] [blame] | 152 | LLVM_DEBUG(dbgs() << "Loop contains subloops.\n"); |
Sanjoy Das | 8e8c1bc | 2017-09-27 21:45:21 +0000 | [diff] [blame] | 153 | return LoopDeletionResult::Unmodified; |
Anna Thomas | 90f69ab | 2017-07-04 14:05:19 +0000 | [diff] [blame] | 154 | } |
Nadav Rotem | 465834c | 2012-07-24 10:51:42 +0000 | [diff] [blame] | 155 | |
Anna Thomas | 53c8d95 | 2017-05-03 11:47:11 +0000 | [diff] [blame] | 156 | |
| 157 | BasicBlock *ExitBlock = L->getUniqueExitBlock(); |
| 158 | |
| 159 | if (ExitBlock && isLoopNeverExecuted(L)) { |
Nicola Zaghen | d34e60c | 2018-05-14 12:53:11 +0000 | [diff] [blame] | 160 | LLVM_DEBUG(dbgs() << "Loop is proven to never execute, delete it!"); |
Anna Thomas | e7cb633 | 2017-06-25 21:13:58 +0000 | [diff] [blame] | 161 | // Set incoming value to undef for phi nodes in the exit block. |
Benjamin Kramer | c7fc81e | 2017-12-30 15:27:33 +0000 | [diff] [blame] | 162 | for (PHINode &P : ExitBlock->phis()) { |
| 163 | std::fill(P.incoming_values().begin(), P.incoming_values().end(), |
| 164 | UndefValue::get(P.getType())); |
Anna Thomas | e7cb633 | 2017-06-25 21:13:58 +0000 | [diff] [blame] | 165 | } |
Marcello Maggioni | df3e71e | 2017-10-04 20:42:46 +0000 | [diff] [blame] | 166 | deleteDeadLoop(L, &DT, &SE, &LI); |
Anna Thomas | 53c8d95 | 2017-05-03 11:47:11 +0000 | [diff] [blame] | 167 | ++NumDeleted; |
Sanjoy Das | 8e8c1bc | 2017-09-27 21:45:21 +0000 | [diff] [blame] | 168 | return LoopDeletionResult::Deleted; |
Anna Thomas | 53c8d95 | 2017-05-03 11:47:11 +0000 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | // The remaining checks below are for a loop being dead because all statements |
| 172 | // in the loop are invariant. |
Chandler Carruth | 04a7387 | 2017-01-17 21:51:39 +0000 | [diff] [blame] | 173 | SmallVector<BasicBlock *, 4> ExitingBlocks; |
| 174 | L->getExitingBlocks(ExitingBlocks); |
Nadav Rotem | 465834c | 2012-07-24 10:51:42 +0000 | [diff] [blame] | 175 | |
Owen Anderson | ad5f211 | 2008-05-16 04:32:45 +0000 | [diff] [blame] | 176 | // We require that the loop only have a single exit block. Otherwise, we'd |
| 177 | // be in the situation of needing to be able to solve statically which exit |
| 178 | // block will be branched to, or trying to preserve the branching logic in |
| 179 | // a loop invariant manner. |
Anna Thomas | 90f69ab | 2017-07-04 14:05:19 +0000 | [diff] [blame] | 180 | if (!ExitBlock) { |
Nicola Zaghen | d34e60c | 2018-05-14 12:53:11 +0000 | [diff] [blame] | 181 | LLVM_DEBUG(dbgs() << "Deletion requires single exit block\n"); |
Sanjoy Das | 8e8c1bc | 2017-09-27 21:45:21 +0000 | [diff] [blame] | 182 | return LoopDeletionResult::Unmodified; |
Anna Thomas | 90f69ab | 2017-07-04 14:05:19 +0000 | [diff] [blame] | 183 | } |
Owen Anderson | 94ad702 | 2008-04-29 00:38:34 +0000 | [diff] [blame] | 184 | // Finally, we have to check that the loop really is dead. |
Chandler Carruth | 027340f | 2017-02-11 00:09:30 +0000 | [diff] [blame] | 185 | bool Changed = false; |
Anna Thomas | 90f69ab | 2017-07-04 14:05:19 +0000 | [diff] [blame] | 186 | if (!isLoopDead(L, SE, ExitingBlocks, ExitBlock, Changed, Preheader)) { |
Nicola Zaghen | d34e60c | 2018-05-14 12:53:11 +0000 | [diff] [blame] | 187 | LLVM_DEBUG(dbgs() << "Loop is not invariant, cannot delete.\n"); |
Sanjoy Das | 8e8c1bc | 2017-09-27 21:45:21 +0000 | [diff] [blame] | 188 | return Changed ? LoopDeletionResult::Modified |
| 189 | : LoopDeletionResult::Unmodified; |
Anna Thomas | 90f69ab | 2017-07-04 14:05:19 +0000 | [diff] [blame] | 190 | } |
Nadav Rotem | 465834c | 2012-07-24 10:51:42 +0000 | [diff] [blame] | 191 | |
Owen Anderson | ad5f211 | 2008-05-16 04:32:45 +0000 | [diff] [blame] | 192 | // Don't remove loops for which we can't solve the trip count. |
| 193 | // They could be infinite, in which case we'd be changing program behavior. |
Philip Reames | 7b05151 | 2019-08-14 21:58:13 +0000 | [diff] [blame] | 194 | const SCEV *S = SE.getConstantMaxBackedgeTakenCount(L); |
Anna Thomas | 90f69ab | 2017-07-04 14:05:19 +0000 | [diff] [blame] | 195 | if (isa<SCEVCouldNotCompute>(S)) { |
Nicola Zaghen | d34e60c | 2018-05-14 12:53:11 +0000 | [diff] [blame] | 196 | LLVM_DEBUG(dbgs() << "Could not compute SCEV MaxBackedgeTakenCount.\n"); |
Sanjoy Das | 8e8c1bc | 2017-09-27 21:45:21 +0000 | [diff] [blame] | 197 | return Changed ? LoopDeletionResult::Modified |
| 198 | : LoopDeletionResult::Unmodified; |
Anna Thomas | 90f69ab | 2017-07-04 14:05:19 +0000 | [diff] [blame] | 199 | } |
Nadav Rotem | 465834c | 2012-07-24 10:51:42 +0000 | [diff] [blame] | 200 | |
Nicola Zaghen | d34e60c | 2018-05-14 12:53:11 +0000 | [diff] [blame] | 201 | LLVM_DEBUG(dbgs() << "Loop is invariant, delete it!"); |
Marcello Maggioni | df3e71e | 2017-10-04 20:42:46 +0000 | [diff] [blame] | 202 | deleteDeadLoop(L, &DT, &SE, &LI); |
Anna Thomas | 53c8d95 | 2017-05-03 11:47:11 +0000 | [diff] [blame] | 203 | ++NumDeleted; |
| 204 | |
Sanjoy Das | 8e8c1bc | 2017-09-27 21:45:21 +0000 | [diff] [blame] | 205 | return LoopDeletionResult::Deleted; |
Anna Thomas | 53c8d95 | 2017-05-03 11:47:11 +0000 | [diff] [blame] | 206 | } |
| 207 | |
Chandler Carruth | 410eaeb | 2017-01-11 06:23:21 +0000 | [diff] [blame] | 208 | PreservedAnalyses LoopDeletionPass::run(Loop &L, LoopAnalysisManager &AM, |
| 209 | LoopStandardAnalysisResults &AR, |
Chandler Carruth | d50c5fb | 2017-01-18 02:41:26 +0000 | [diff] [blame] | 210 | LPMUpdater &Updater) { |
Anna Thomas | 90f69ab | 2017-07-04 14:05:19 +0000 | [diff] [blame] | 211 | |
Nicola Zaghen | d34e60c | 2018-05-14 12:53:11 +0000 | [diff] [blame] | 212 | LLVM_DEBUG(dbgs() << "Analyzing Loop for deletion: "); |
| 213 | LLVM_DEBUG(L.dump()); |
Sanjoy Das | def1729 | 2017-09-28 02:45:42 +0000 | [diff] [blame] | 214 | std::string LoopName = L.getName(); |
Sanjoy Das | 8e8c1bc | 2017-09-27 21:45:21 +0000 | [diff] [blame] | 215 | auto Result = deleteLoopIfDead(&L, AR.DT, AR.SE, AR.LI); |
| 216 | if (Result == LoopDeletionResult::Unmodified) |
Jun Bum Lim | c837af3 | 2016-07-14 18:28:29 +0000 | [diff] [blame] | 217 | return PreservedAnalyses::all(); |
| 218 | |
Sanjoy Das | 8e8c1bc | 2017-09-27 21:45:21 +0000 | [diff] [blame] | 219 | if (Result == LoopDeletionResult::Deleted) |
Sanjoy Das | def1729 | 2017-09-28 02:45:42 +0000 | [diff] [blame] | 220 | Updater.markLoopAsDeleted(L, LoopName); |
Sanjoy Das | 8e8c1bc | 2017-09-27 21:45:21 +0000 | [diff] [blame] | 221 | |
Jun Bum Lim | c837af3 | 2016-07-14 18:28:29 +0000 | [diff] [blame] | 222 | return getLoopPassPreservedAnalyses(); |
| 223 | } |
| 224 | |
| 225 | namespace { |
| 226 | class LoopDeletionLegacyPass : public LoopPass { |
| 227 | public: |
| 228 | static char ID; // Pass ID, replacement for typeid |
| 229 | LoopDeletionLegacyPass() : LoopPass(ID) { |
| 230 | initializeLoopDeletionLegacyPassPass(*PassRegistry::getPassRegistry()); |
| 231 | } |
| 232 | |
| 233 | // Possibly eliminate loop L if it is dead. |
| 234 | bool runOnLoop(Loop *L, LPPassManager &) override; |
| 235 | |
| 236 | void getAnalysisUsage(AnalysisUsage &AU) const override { |
| 237 | getLoopAnalysisUsage(AU); |
| 238 | } |
| 239 | }; |
| 240 | } |
| 241 | |
| 242 | char LoopDeletionLegacyPass::ID = 0; |
| 243 | INITIALIZE_PASS_BEGIN(LoopDeletionLegacyPass, "loop-deletion", |
| 244 | "Delete dead loops", false, false) |
| 245 | INITIALIZE_PASS_DEPENDENCY(LoopPass) |
| 246 | INITIALIZE_PASS_END(LoopDeletionLegacyPass, "loop-deletion", |
| 247 | "Delete dead loops", false, false) |
| 248 | |
| 249 | Pass *llvm::createLoopDeletionPass() { return new LoopDeletionLegacyPass(); } |
| 250 | |
Sanjoy Das | def1729 | 2017-09-28 02:45:42 +0000 | [diff] [blame] | 251 | bool LoopDeletionLegacyPass::runOnLoop(Loop *L, LPPassManager &LPM) { |
Jun Bum Lim | c837af3 | 2016-07-14 18:28:29 +0000 | [diff] [blame] | 252 | if (skipLoop(L)) |
| 253 | return false; |
Jun Bum Lim | c837af3 | 2016-07-14 18:28:29 +0000 | [diff] [blame] | 254 | DominatorTree &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree(); |
| 255 | ScalarEvolution &SE = getAnalysis<ScalarEvolutionWrapperPass>().getSE(); |
Chandler Carruth | 04a7387 | 2017-01-17 21:51:39 +0000 | [diff] [blame] | 256 | LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo(); |
Jun Bum Lim | c837af3 | 2016-07-14 18:28:29 +0000 | [diff] [blame] | 257 | |
Nicola Zaghen | d34e60c | 2018-05-14 12:53:11 +0000 | [diff] [blame] | 258 | LLVM_DEBUG(dbgs() << "Analyzing Loop for deletion: "); |
| 259 | LLVM_DEBUG(L->dump()); |
Sanjoy Das | def1729 | 2017-09-28 02:45:42 +0000 | [diff] [blame] | 260 | |
| 261 | LoopDeletionResult Result = deleteLoopIfDead(L, DT, SE, LI); |
| 262 | |
| 263 | if (Result == LoopDeletionResult::Deleted) |
| 264 | LPM.markLoopAsDeleted(*L); |
| 265 | |
| 266 | return Result != LoopDeletionResult::Unmodified; |
Jun Bum Lim | c837af3 | 2016-07-14 18:28:29 +0000 | [diff] [blame] | 267 | } |