Coverage Report

Created: 2017-10-03 07:32

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