annotate polly/lib/CodeGen/CodegenCleanup.cpp @ 173:0572611fdcc8 llvm10 llvm12

reorgnization done
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 11:55:54 +0900
parents 1d019706d866
children c4bab56944e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 //===- CodegenCleanup.cpp -------------------------------------------------===//
anatofuz
parents:
diff changeset
2 //
anatofuz
parents:
diff changeset
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
anatofuz
parents:
diff changeset
4 // See https://llvm.org/LICENSE.txt for license information.
anatofuz
parents:
diff changeset
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
anatofuz
parents:
diff changeset
6 //
anatofuz
parents:
diff changeset
7 //===----------------------------------------------------------------------===//
anatofuz
parents:
diff changeset
8
anatofuz
parents:
diff changeset
9 #include "polly/CodeGen/CodegenCleanup.h"
anatofuz
parents:
diff changeset
10
anatofuz
parents:
diff changeset
11 #include "llvm/Analysis/ScopedNoAliasAA.h"
anatofuz
parents:
diff changeset
12 #include "llvm/Analysis/TypeBasedAliasAnalysis.h"
anatofuz
parents:
diff changeset
13 #include "llvm/IR/Function.h"
anatofuz
parents:
diff changeset
14 #include "llvm/IR/LegacyPassManager.h"
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
15 #include "llvm/Pass.h"
150
anatofuz
parents:
diff changeset
16 #include "llvm/Support/Debug.h"
anatofuz
parents:
diff changeset
17 #include "llvm/Transforms/InstCombine/InstCombine.h"
anatofuz
parents:
diff changeset
18 #include "llvm/Transforms/Scalar.h"
anatofuz
parents:
diff changeset
19 #include "llvm/Transforms/Scalar/GVN.h"
anatofuz
parents:
diff changeset
20 #include "llvm/Transforms/Utils.h"
anatofuz
parents:
diff changeset
21
anatofuz
parents:
diff changeset
22 #define DEBUG_TYPE "polly-cleanup"
anatofuz
parents:
diff changeset
23
anatofuz
parents:
diff changeset
24 using namespace llvm;
anatofuz
parents:
diff changeset
25 using namespace polly;
anatofuz
parents:
diff changeset
26
anatofuz
parents:
diff changeset
27 namespace {
anatofuz
parents:
diff changeset
28
anatofuz
parents:
diff changeset
29 class CodegenCleanup : public FunctionPass {
anatofuz
parents:
diff changeset
30 private:
anatofuz
parents:
diff changeset
31 CodegenCleanup(const CodegenCleanup &) = delete;
anatofuz
parents:
diff changeset
32 const CodegenCleanup &operator=(const CodegenCleanup &) = delete;
anatofuz
parents:
diff changeset
33
anatofuz
parents:
diff changeset
34 llvm::legacy::FunctionPassManager *FPM;
anatofuz
parents:
diff changeset
35
anatofuz
parents:
diff changeset
36 public:
anatofuz
parents:
diff changeset
37 static char ID;
anatofuz
parents:
diff changeset
38 explicit CodegenCleanup() : FunctionPass(ID), FPM(nullptr) {}
anatofuz
parents:
diff changeset
39
anatofuz
parents:
diff changeset
40 /// @name FunctionPass interface
anatofuz
parents:
diff changeset
41 //@{
anatofuz
parents:
diff changeset
42 virtual void getAnalysisUsage(llvm::AnalysisUsage &AU) const override {}
anatofuz
parents:
diff changeset
43
anatofuz
parents:
diff changeset
44 virtual bool doInitialization(Module &M) override {
anatofuz
parents:
diff changeset
45 assert(!FPM);
anatofuz
parents:
diff changeset
46
anatofuz
parents:
diff changeset
47 FPM = new llvm::legacy::FunctionPassManager(&M);
anatofuz
parents:
diff changeset
48
anatofuz
parents:
diff changeset
49 // TODO: How to make parent passes discoverable?
anatofuz
parents:
diff changeset
50 // TODO: Should be sensitive to compiler options in PassManagerBuilder, to
anatofuz
parents:
diff changeset
51 // which we do not have access here.
anatofuz
parents:
diff changeset
52 FPM->add(createScopedNoAliasAAWrapperPass());
anatofuz
parents:
diff changeset
53 FPM->add(createTypeBasedAAWrapperPass());
anatofuz
parents:
diff changeset
54 FPM->add(createAAResultsWrapperPass());
anatofuz
parents:
diff changeset
55
anatofuz
parents:
diff changeset
56 // TODO: These are non-conditional passes that run between
anatofuz
parents:
diff changeset
57 // EP_ModuleOptimizerEarly and EP_VectorizerStart just to ensure we do not
anatofuz
parents:
diff changeset
58 // miss any optimization that would have run after Polly with
anatofuz
parents:
diff changeset
59 // -polly-position=early. This can probably be reduced to a more compact set
anatofuz
parents:
diff changeset
60 // of passes.
anatofuz
parents:
diff changeset
61 FPM->add(createCFGSimplificationPass());
anatofuz
parents:
diff changeset
62 FPM->add(createSROAPass());
anatofuz
parents:
diff changeset
63 FPM->add(createEarlyCSEPass());
anatofuz
parents:
diff changeset
64
anatofuz
parents:
diff changeset
65 FPM->add(createPromoteMemoryToRegisterPass());
anatofuz
parents:
diff changeset
66 FPM->add(createInstructionCombiningPass(true));
anatofuz
parents:
diff changeset
67 FPM->add(createCFGSimplificationPass());
anatofuz
parents:
diff changeset
68 FPM->add(createSROAPass());
anatofuz
parents:
diff changeset
69 FPM->add(createEarlyCSEPass(true));
anatofuz
parents:
diff changeset
70 FPM->add(createSpeculativeExecutionIfHasBranchDivergencePass());
anatofuz
parents:
diff changeset
71 FPM->add(createJumpThreadingPass());
anatofuz
parents:
diff changeset
72 FPM->add(createCorrelatedValuePropagationPass());
anatofuz
parents:
diff changeset
73 FPM->add(createCFGSimplificationPass());
anatofuz
parents:
diff changeset
74 FPM->add(createInstructionCombiningPass(true));
anatofuz
parents:
diff changeset
75 FPM->add(createLibCallsShrinkWrapPass());
anatofuz
parents:
diff changeset
76 FPM->add(createTailCallEliminationPass());
anatofuz
parents:
diff changeset
77 FPM->add(createCFGSimplificationPass());
anatofuz
parents:
diff changeset
78 FPM->add(createReassociatePass());
anatofuz
parents:
diff changeset
79 FPM->add(createLoopRotatePass(-1));
anatofuz
parents:
diff changeset
80 FPM->add(createGVNPass());
anatofuz
parents:
diff changeset
81 FPM->add(createLICMPass());
anatofuz
parents:
diff changeset
82 FPM->add(createLoopUnswitchPass());
anatofuz
parents:
diff changeset
83 FPM->add(createCFGSimplificationPass());
anatofuz
parents:
diff changeset
84 FPM->add(createInstructionCombiningPass(true));
anatofuz
parents:
diff changeset
85 FPM->add(createIndVarSimplifyPass());
anatofuz
parents:
diff changeset
86 FPM->add(createLoopIdiomPass());
anatofuz
parents:
diff changeset
87 FPM->add(createLoopDeletionPass());
anatofuz
parents:
diff changeset
88 FPM->add(createCFGSimplificationPass());
anatofuz
parents:
diff changeset
89 FPM->add(createSimpleLoopUnrollPass(3));
anatofuz
parents:
diff changeset
90 FPM->add(createMergedLoadStoreMotionPass());
anatofuz
parents:
diff changeset
91 FPM->add(createGVNPass());
anatofuz
parents:
diff changeset
92 FPM->add(createMemCpyOptPass());
anatofuz
parents:
diff changeset
93 FPM->add(createSCCPPass());
anatofuz
parents:
diff changeset
94 FPM->add(createBitTrackingDCEPass());
anatofuz
parents:
diff changeset
95 FPM->add(createInstructionCombiningPass(true));
anatofuz
parents:
diff changeset
96 FPM->add(createJumpThreadingPass());
anatofuz
parents:
diff changeset
97 FPM->add(createCorrelatedValuePropagationPass());
anatofuz
parents:
diff changeset
98 FPM->add(createDeadStoreEliminationPass());
anatofuz
parents:
diff changeset
99 FPM->add(createLICMPass());
anatofuz
parents:
diff changeset
100 FPM->add(createAggressiveDCEPass());
anatofuz
parents:
diff changeset
101 FPM->add(createCFGSimplificationPass());
anatofuz
parents:
diff changeset
102 FPM->add(createInstructionCombiningPass(true));
anatofuz
parents:
diff changeset
103 FPM->add(createFloat2IntPass());
anatofuz
parents:
diff changeset
104
anatofuz
parents:
diff changeset
105 return FPM->doInitialization();
anatofuz
parents:
diff changeset
106 }
anatofuz
parents:
diff changeset
107
anatofuz
parents:
diff changeset
108 virtual bool doFinalization(Module &M) override {
anatofuz
parents:
diff changeset
109 bool Result = FPM->doFinalization();
anatofuz
parents:
diff changeset
110
anatofuz
parents:
diff changeset
111 delete FPM;
anatofuz
parents:
diff changeset
112 FPM = nullptr;
anatofuz
parents:
diff changeset
113
anatofuz
parents:
diff changeset
114 return Result;
anatofuz
parents:
diff changeset
115 }
anatofuz
parents:
diff changeset
116
anatofuz
parents:
diff changeset
117 virtual bool runOnFunction(llvm::Function &F) override {
anatofuz
parents:
diff changeset
118 if (!F.hasFnAttribute("polly-optimized")) {
anatofuz
parents:
diff changeset
119 LLVM_DEBUG(
anatofuz
parents:
diff changeset
120 dbgs() << F.getName()
anatofuz
parents:
diff changeset
121 << ": Skipping cleanup because Polly did not optimize it.");
anatofuz
parents:
diff changeset
122 return false;
anatofuz
parents:
diff changeset
123 }
anatofuz
parents:
diff changeset
124
anatofuz
parents:
diff changeset
125 LLVM_DEBUG(dbgs() << F.getName() << ": Running codegen cleanup...");
anatofuz
parents:
diff changeset
126 return FPM->run(F);
anatofuz
parents:
diff changeset
127 }
anatofuz
parents:
diff changeset
128 //@}
anatofuz
parents:
diff changeset
129 };
anatofuz
parents:
diff changeset
130
anatofuz
parents:
diff changeset
131 char CodegenCleanup::ID;
anatofuz
parents:
diff changeset
132 } // namespace
anatofuz
parents:
diff changeset
133
anatofuz
parents:
diff changeset
134 FunctionPass *polly::createCodegenCleanupPass() { return new CodegenCleanup(); }
anatofuz
parents:
diff changeset
135
anatofuz
parents:
diff changeset
136 INITIALIZE_PASS_BEGIN(CodegenCleanup, "polly-cleanup",
anatofuz
parents:
diff changeset
137 "Polly - Cleanup after code generation", false, false)
anatofuz
parents:
diff changeset
138 INITIALIZE_PASS_END(CodegenCleanup, "polly-cleanup",
anatofuz
parents:
diff changeset
139 "Polly - Cleanup after code generation", false, false)