Coverage Report

Created: 2019-02-15 18:59

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/polly/lib/Analysis/PruneUnprofitable.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- PruneUnprofitable.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
// Mark a SCoP as unfeasible if not deemed profitable to optimize.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#include "polly/PruneUnprofitable.h"
14
#include "polly/ScopDetection.h"
15
#include "polly/ScopInfo.h"
16
#include "polly/ScopPass.h"
17
#include "llvm/ADT/Statistic.h"
18
#include "llvm/IR/DebugLoc.h"
19
#include "llvm/Pass.h"
20
#include "llvm/Support/Debug.h"
21
#include "llvm/Support/raw_ostream.h"
22
23
using namespace llvm;
24
using namespace polly;
25
26
#define DEBUG_TYPE "polly-prune-unprofitable"
27
28
namespace {
29
30
STATISTIC(ScopsProcessed,
31
          "Number of SCoPs considered for unprofitability pruning");
32
STATISTIC(ScopsPruned, "Number of pruned SCoPs because it they cannot be "
33
                       "optimized in a significant way");
34
STATISTIC(ScopsSurvived, "Number of SCoPs after pruning");
35
36
STATISTIC(NumPrunedLoops, "Number of pruned loops");
37
STATISTIC(NumPrunedBoxedLoops, "Number of pruned boxed loops");
38
STATISTIC(NumPrunedAffineLoops, "Number of pruned affine loops");
39
40
STATISTIC(NumLoopsInScop, "Number of loops in scops after pruning");
41
STATISTIC(NumBoxedLoops, "Number of boxed loops in SCoPs after pruning");
42
STATISTIC(NumAffineLoops, "Number of affine loops in SCoPs after pruning");
43
44
class PruneUnprofitable : public ScopPass {
45
private:
46
0
  void updateStatistics(Scop &S, bool Pruned) {
47
0
    auto ScopStats = S.getStatistics();
48
0
    if (Pruned) {
49
0
      ScopsPruned++;
50
0
      NumPrunedLoops += ScopStats.NumAffineLoops + ScopStats.NumBoxedLoops;
51
0
      NumPrunedBoxedLoops += ScopStats.NumBoxedLoops;
52
0
      NumPrunedAffineLoops += ScopStats.NumAffineLoops;
53
0
    } else {
54
0
      ScopsSurvived++;
55
0
      NumLoopsInScop += ScopStats.NumAffineLoops + ScopStats.NumBoxedLoops;
56
0
      NumBoxedLoops += ScopStats.NumBoxedLoops;
57
0
      NumAffineLoops += ScopStats.NumAffineLoops;
58
0
    }
59
0
  }
60
61
public:
62
  static char ID;
63
64
0
  explicit PruneUnprofitable() : ScopPass(ID) {}
65
  PruneUnprofitable(const PruneUnprofitable &) = delete;
66
  PruneUnprofitable &operator=(const PruneUnprofitable &) = delete;
67
68
0
  void getAnalysisUsage(AnalysisUsage &AU) const override {
69
0
    AU.addRequired<ScopInfoRegionPass>();
70
0
    AU.setPreservesAll();
71
0
  }
72
73
0
  bool runOnScop(Scop &S) override {
74
0
    if (PollyProcessUnprofitable) {
75
0
      LLVM_DEBUG(
76
0
          dbgs() << "NOTE: -polly-process-unprofitable active, won't prune "
77
0
                    "anything\n");
78
0
      return false;
79
0
    }
80
0
81
0
    ScopsProcessed++;
82
0
83
0
    if (!S.isProfitable(true)) {
84
0
      LLVM_DEBUG(
85
0
          dbgs() << "SCoP pruned because it probably cannot be optimized in "
86
0
                    "a significant way\n");
87
0
      S.invalidate(PROFITABLE, DebugLoc());
88
0
      updateStatistics(S, true);
89
0
    } else {
90
0
      updateStatistics(S, false);
91
0
    }
92
0
93
0
    return false;
94
0
  }
95
};
96
} // namespace
97
98
char PruneUnprofitable::ID;
99
100
0
Pass *polly::createPruneUnprofitablePass() { return new PruneUnprofitable(); }
101
102
46.4k
INITIALIZE_PASS_BEGIN(PruneUnprofitable, "polly-prune-unprofitable",
103
46.4k
                      "Polly - Prune unprofitable SCoPs", false, false)
104
46.4k
INITIALIZE_PASS_END(PruneUnprofitable, "polly-prune-unprofitable",
105
                    "Polly - Prune unprofitable SCoPs", false, false)