llvm.org GIT mirror llvm / 33933df
[PM] Port LCSSA to the new PM. Differential Revision: http://reviews.llvm.org/D21090 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272294 91177308-0d34-0410-b5e6-96231b3b80d8 Easwaran Raman 3 years ago
17 changed file(s) with 103 addition(s) and 28 deletion(s). Raw diff Collapse all Expand all
162162 void initializeIntervalPartitionPass(PassRegistry&);
163163 void initializeIRTranslatorPass(PassRegistry &);
164164 void initializeJumpThreadingPass(PassRegistry&);
165 void initializeLCSSAPass(PassRegistry&);
165 void initializeLCSSAWrapperPassPass(PassRegistry &);
166166 void initializeLICMPass(PassRegistry&);
167167 void initializeLazyValueInfoPass(PassRegistry&);
168168 void initializeLintPass(PassRegistry&);
0 //===- LCSSA.h - Loop-closed SSA transform Pass -----------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This pass transforms loops by placing phi nodes at the end of the loops for
10 // all values that are live across the loop boundary. For example, it turns
11 // the left into the right code:
12 //
13 // for (...) for (...)
14 // if (c) if (c)
15 // X1 = ... X1 = ...
16 // else else
17 // X2 = ... X2 = ...
18 // X3 = phi(X1, X2) X3 = phi(X1, X2)
19 // ... = X3 + 4 X4 = phi(X3)
20 // ... = X4 + 4
21 //
22 // This is still valid LLVM; the extra phi nodes are purely redundant, and will
23 // be trivially eliminated by InstCombine. The major benefit of this
24 // transformation is that it makes many other loop optimizations, such as
25 // LoopUnswitching, simpler.
26 //
27 //===----------------------------------------------------------------------===//
28
29 #ifndef LLVM_TRANSFORMS_UTILS_LCSSA_H
30 #define LLVM_TRANSFORMS_UTILS_LCSSA_H
31
32 #include "llvm/IR/PassManager.h"
33
34 namespace llvm {
35
36 /// Converts loops into loop-closed SSA form.
37 class LCSSAPass : public PassInfoMixin {
38 public:
39 PreservedAnalyses run(Function &F, AnalysisManager &AM);
40 };
41 } // end namespace llvm
42
43 #endif // LLVM_TRANSFORMS_UTILS_LCSSA_H
8282 #include "llvm/Transforms/Scalar/SROA.h"
8383 #include "llvm/Transforms/Scalar/SimplifyCFG.h"
8484 #include "llvm/Transforms/Scalar/Sink.h"
85 #include "llvm/Transforms/Utils/LCSSA.h"
8586 #include "llvm/Transforms/Utils/MemorySSA.h"
8687 #include
8788
126126 FUNCTION_PASS("guard-widening", GuardWideningPass())
127127 FUNCTION_PASS("gvn", GVN())
128128 FUNCTION_PASS("partially-inline-libcalls", PartiallyInlineLibCallsPass())
129 FUNCTION_PASS("lcssa", LCSSAPass())
129130 FUNCTION_PASS("print", PrintFunctionPass(dbgs()))
130131 FUNCTION_PASS("print", AssumptionPrinterPass(dbgs()))
131132 FUNCTION_PASS("print", BlockFrequencyPrinterPass(dbgs()))
12991299 INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
13001300 INITIALIZE_PASS_DEPENDENCY(ScalarEvolutionWrapperPass)
13011301 INITIALIZE_PASS_DEPENDENCY(LoopSimplify)
1302 INITIALIZE_PASS_DEPENDENCY(LCSSA)
1302 INITIALIZE_PASS_DEPENDENCY(LCSSAWrapperPass)
13031303 INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
13041304
13051305 INITIALIZE_PASS_END(LoopInterchange, "loop-interchange",
584584 INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass)
585585 INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
586586 INITIALIZE_PASS_DEPENDENCY(GlobalsAAWrapperPass)
587 INITIALIZE_PASS_DEPENDENCY(LCSSA)
587 INITIALIZE_PASS_DEPENDENCY(LCSSAWrapperPass)
588588 INITIALIZE_PASS_DEPENDENCY(LoopAccessAnalysis)
589589 INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
590590 INITIALIZE_PASS_DEPENDENCY(LoopSimplify)
2626 //
2727 //===----------------------------------------------------------------------===//
2828
29 #include "llvm/Transforms/Scalar.h"
29 #include "llvm/Transforms/Utils/LCSSA.h"
3030 #include "llvm/ADT/STLExtras.h"
3131 #include "llvm/ADT/Statistic.h"
3232 #include "llvm/Analysis/AliasAnalysis.h"
4141 #include "llvm/IR/Instructions.h"
4242 #include "llvm/IR/PredIteratorCache.h"
4343 #include "llvm/Pass.h"
44 #include "llvm/Transforms/Scalar.h"
4445 #include "llvm/Transforms/Utils/LoopUtils.h"
4546 #include "llvm/Transforms/Utils/SSAUpdater.h"
4647 using namespace llvm;
269270 return Changed;
270271 }
271272
273 /// Process all loops in the function, inner-most out.
274 static bool formLCSSAOnAllLoops(LoopInfo *LI, DominatorTree &DT,
275 ScalarEvolution *SE) {
276 bool Changed = false;
277 for (auto &L : *LI)
278 Changed |= formLCSSARecursively(*L, DT, LI, SE);
279 return Changed;
280 }
281
272282 namespace {
273 struct LCSSA : public FunctionPass {
283 struct LCSSAWrapperPass : public FunctionPass {
274284 static char ID; // Pass identification, replacement for typeid
275 LCSSA() : FunctionPass(ID) {
276 initializeLCSSAPass(*PassRegistry::getPassRegistry());
285 LCSSAWrapperPass() : FunctionPass(ID) {
286 initializeLCSSAWrapperPassPass(*PassRegistry::getPassRegistry());
277287 }
278288
279289 // Cached analysis information for the current function.
301311 };
302312 }
303313
304 char LCSSA::ID = 0;
305 INITIALIZE_PASS_BEGIN(LCSSA, "lcssa", "Loop-Closed SSA Form Pass", false, false)
314 char LCSSAWrapperPass::ID = 0;
315 INITIALIZE_PASS_BEGIN(LCSSAWrapperPass, "lcssa", "Loop-Closed SSA Form Pass",
316 false, false)
306317 INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
307318 INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
308 INITIALIZE_PASS_END(LCSSA, "lcssa", "Loop-Closed SSA Form Pass", false, false)
309
310 Pass *llvm::createLCSSAPass() { return new LCSSA(); }
311 char &llvm::LCSSAID = LCSSA::ID;
312
313
314 /// Process all loops in the function, inner-most out.
315 bool LCSSA::runOnFunction(Function &F) {
316 bool Changed = false;
319 INITIALIZE_PASS_END(LCSSAWrapperPass, "lcssa", "Loop-Closed SSA Form Pass",
320 false, false)
321
322 Pass *llvm::createLCSSAPass() { return new LCSSAWrapperPass(); }
323 char &llvm::LCSSAID = LCSSAWrapperPass::ID;
324
325 /// Transform \p F into loop-closed SSA form.
326 bool LCSSAWrapperPass::runOnFunction(Function &F) {
317327 LI = &getAnalysis().getLoopInfo();
318328 DT = &getAnalysis().getDomTree();
319329 auto *SEWP = getAnalysisIfAvailable();
320330 SE = SEWP ? &SEWP->getSE() : nullptr;
321331
322 // Simplify each loop nest in the function.
323 for (LoopInfo::iterator I = LI->begin(), E = LI->end(); I != E; ++I)
324 Changed |= formLCSSARecursively(**I, *DT, LI, SE);
325
326 return Changed;
327 }
328
332 return formLCSSAOnAllLoops(LI, *DT, SE);
333 }
334
335 PreservedAnalyses LCSSAPass::run(Function &F, AnalysisManager &AM) {
336 auto &LI = AM.getResult(F);
337 auto &DT = AM.getResult(F);
338 auto *SE = AM.getCachedResult(F);
339 if (!formLCSSAOnAllLoops(&LI, DT, SE))
340 return PreservedAnalyses::all();
341
342 // FIXME: There is no setPreservesCFG in the new PM. When that becomes
343 // available, it should be used here.
344 PreservedAnalyses PA;
345 PA.preserve();
346 PA.preserve();
347 PA.preserve();
348 PA.preserve();
349 return PA;
350 }
879879 INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
880880 INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
881881 INITIALIZE_PASS_DEPENDENCY(LoopSimplify)
882 INITIALIZE_PASS_DEPENDENCY(LCSSA)
882 INITIALIZE_PASS_DEPENDENCY(LCSSAWrapperPass)
883883 INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass)
884884 INITIALIZE_PASS_DEPENDENCY(BasicAAWrapperPass)
885885 INITIALIZE_PASS_DEPENDENCY(GlobalsAAWrapperPass)
2323 initializeAddDiscriminatorsPass(Registry);
2424 initializeBreakCriticalEdgesPass(Registry);
2525 initializeInstNamerPass(Registry);
26 initializeLCSSAPass(Registry);
26 initializeLCSSAWrapperPassPass(Registry);
2727 initializeLoopSimplifyPass(Registry);
2828 initializeLowerInvokePass(Registry);
2929 initializeLowerSwitchPass(Registry);
61926192 INITIALIZE_PASS_DEPENDENCY(BlockFrequencyInfoWrapperPass)
61936193 INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
61946194 INITIALIZE_PASS_DEPENDENCY(ScalarEvolutionWrapperPass)
6195 INITIALIZE_PASS_DEPENDENCY(LCSSA)
6195 INITIALIZE_PASS_DEPENDENCY(LCSSAWrapperPass)
61966196 INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
61976197 INITIALIZE_PASS_DEPENDENCY(LoopSimplify)
61986198 INITIALIZE_PASS_DEPENDENCY(LoopAccessAnalysis)
0 ; RUN: opt < %s -lcssa -S | FileCheck %s
1 ; RUN: opt < %s -passes=lcssa -S | FileCheck %s
12
23 declare i1 @c1()
34
0 ; RUN: opt < %s -lcssa
1 ; RUN: opt < %s -passes=lcssa
12
23 %struct.SetJmpMapEntry = type { i8*, i32, %struct.SetJmpMapEntry* }
34
0 ; RUN: opt < %s -lcssa -disable-output
1 ; RUN: opt < %s -passes=lcssa -disable-output
12 ; PR977
23 ; END.
34
0 ; RUN: opt < %s -lcssa -S | FileCheck %s
1 ; RUN: opt < %s -passes=lcssa -S | FileCheck %s
12
23 define void @lcssa(i1 %S2) {
34 ; CHECK-LABEL: @lcssa
0 ; RUN: opt < %s -lcssa
1 ; RUN: opt < %s -passes=lcssa
12
23 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32"
34
0 ; RUN: opt -lcssa -S < %s | FileCheck %s
1 ; RUN: opt -passes=lcssa -S < %s | FileCheck %s
12
23 ; This test is based on the following C++ code:
34 ;
0 ; RUN: opt < %s -lcssa -S | FileCheck %s
1 ; RUN: opt < %s -passes=lcssa -S | FileCheck %s
12 ; CHECK: exit1:
23 ; CHECK: .lcssa =
34 ; CHECK: exit2: