Coverage Report

Created: 2018-04-23 18:20

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/polly/lib/CodeGen/CodegenCleanup.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- CodegenCleanup.cpp -------------------------------------------------===//
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
#include "polly/CodeGen/CodegenCleanup.h"
11
12
#include "llvm/Analysis/ScopedNoAliasAA.h"
13
#include "llvm/Analysis/TypeBasedAliasAnalysis.h"
14
#include "llvm/IR/Function.h"
15
#include "llvm/IR/LegacyPassManager.h"
16
#include "llvm/PassInfo.h"
17
#include "llvm/PassRegistry.h"
18
#include "llvm/PassSupport.h"
19
#include "llvm/Support/Debug.h"
20
#include "llvm/Transforms/Scalar.h"
21
#include "llvm/Transforms/Scalar/GVN.h"
22
#include "llvm/Transforms/Utils.h"
23
24
#define DEBUG_TYPE "polly-cleanup"
25
26
using namespace llvm;
27
using namespace polly;
28
29
namespace {
30
31
class CodegenCleanup : public FunctionPass {
32
private:
33
  CodegenCleanup(const CodegenCleanup &) = delete;
34
  const CodegenCleanup &operator=(const CodegenCleanup &) = delete;
35
36
  llvm::legacy::FunctionPassManager *FPM;
37
38
public:
39
  static char ID;
40
0
  explicit CodegenCleanup() : FunctionPass(ID), FPM(nullptr) {}
41
42
  /// @name FunctionPass interface
43
  //@{
44
0
  virtual void getAnalysisUsage(llvm::AnalysisUsage &AU) const override {}
45
46
0
  virtual bool doInitialization(Module &M) override {
47
0
    assert(!FPM);
48
0
49
0
    FPM = new llvm::legacy::FunctionPassManager(&M);
50
0
51
0
    // TODO: How to make parent passes discoverable?
52
0
    // TODO: Should be sensitive to compiler options in PassManagerBuilder, to
53
0
    // which we do not have access here.
54
0
    FPM->add(createScopedNoAliasAAWrapperPass());
55
0
    FPM->add(createTypeBasedAAWrapperPass());
56
0
    FPM->add(createAAResultsWrapperPass());
57
0
58
0
    // TODO: These are non-conditional passes that run between
59
0
    // EP_ModuleOptimizerEarly and EP_VectorizerStart just to ensure we do not
60
0
    // miss any optimization that would have run after Polly with
61
0
    // -polly-position=early. This can probably be reduced to a more compact set
62
0
    // of passes.
63
0
    FPM->add(createCFGSimplificationPass());
64
0
    FPM->add(createSROAPass());
65
0
    FPM->add(createEarlyCSEPass());
66
0
67
0
    FPM->add(createPromoteMemoryToRegisterPass());
68
0
    FPM->add(createInstructionCombiningPass(true));
69
0
    FPM->add(createCFGSimplificationPass());
70
0
    FPM->add(createSROAPass());
71
0
    FPM->add(createEarlyCSEPass(true));
72
0
    FPM->add(createSpeculativeExecutionIfHasBranchDivergencePass());
73
0
    FPM->add(createJumpThreadingPass());
74
0
    FPM->add(createCorrelatedValuePropagationPass());
75
0
    FPM->add(createCFGSimplificationPass());
76
0
    FPM->add(createInstructionCombiningPass(true));
77
0
    FPM->add(createLibCallsShrinkWrapPass());
78
0
    FPM->add(createTailCallEliminationPass());
79
0
    FPM->add(createCFGSimplificationPass());
80
0
    FPM->add(createReassociatePass());
81
0
    FPM->add(createLoopRotatePass(-1));
82
0
    FPM->add(createGVNPass());
83
0
    FPM->add(createLICMPass());
84
0
    FPM->add(createLoopUnswitchPass());
85
0
    FPM->add(createCFGSimplificationPass());
86
0
    FPM->add(createInstructionCombiningPass(true));
87
0
    FPM->add(createIndVarSimplifyPass());
88
0
    FPM->add(createLoopIdiomPass());
89
0
    FPM->add(createLoopDeletionPass());
90
0
    FPM->add(createCFGSimplificationPass());
91
0
    FPM->add(createSimpleLoopUnrollPass(3));
92
0
    FPM->add(createMergedLoadStoreMotionPass());
93
0
    FPM->add(createGVNPass());
94
0
    FPM->add(createMemCpyOptPass());
95
0
    FPM->add(createSCCPPass());
96
0
    FPM->add(createBitTrackingDCEPass());
97
0
    FPM->add(createInstructionCombiningPass(true));
98
0
    FPM->add(createJumpThreadingPass());
99
0
    FPM->add(createCorrelatedValuePropagationPass());
100
0
    FPM->add(createDeadStoreEliminationPass());
101
0
    FPM->add(createLICMPass());
102
0
    FPM->add(createAggressiveDCEPass());
103
0
    FPM->add(createCFGSimplificationPass());
104
0
    FPM->add(createInstructionCombiningPass(true));
105
0
    FPM->add(createFloat2IntPass());
106
0
107
0
    return FPM->doInitialization();
108
0
  }
109
110
0
  virtual bool doFinalization(Module &M) override {
111
0
    bool Result = FPM->doFinalization();
112
0
113
0
    delete FPM;
114
0
    FPM = nullptr;
115
0
116
0
    return Result;
117
0
  }
118
119
0
  virtual bool runOnFunction(llvm::Function &F) override {
120
0
    if (!F.hasFnAttribute("polly-optimized")) {
121
0
      DEBUG(dbgs() << F.getName()
122
0
                   << ": Skipping cleanup because Polly did not optimize it.");
123
0
      return false;
124
0
    }
125
0
126
0
    DEBUG(dbgs() << F.getName() << ": Running codegen cleanup...");
127
0
    return FPM->run(F);
128
0
  }
129
  //@}
130
};
131
132
char CodegenCleanup::ID;
133
} // namespace
134
135
0
FunctionPass *polly::createCodegenCleanupPass() { return new CodegenCleanup(); }
136
137
43.0k
INITIALIZE_PASS_BEGIN(CodegenCleanup, "polly-cleanup",
138
43.0k
                      "Polly - Cleanup after code generation", false, false)
139
43.0k
INITIALIZE_PASS_END(CodegenCleanup, "polly-cleanup",
140
                    "Polly - Cleanup after code generation", false, false)