Coverage Report

Created: 2019-07-24 05:18

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