Coverage Report

Created: 2018-06-24 14:39

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