Coverage Report

Created: 2019-07-24 05:18

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