Polly 20.0.0git
PruneUnprofitable.cpp
Go to the documentation of this file.
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
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
22using namespace llvm;
23using namespace polly;
24
26#define DEBUG_TYPE "polly-prune-unprofitable"
27
28namespace {
29
30STATISTIC(ScopsProcessed,
31 "Number of SCoPs considered for unprofitability pruning");
32STATISTIC(ScopsPruned, "Number of pruned SCoPs because it they cannot be "
33 "optimized in a significant way");
34STATISTIC(ScopsSurvived, "Number of SCoPs after pruning");
35
36STATISTIC(NumPrunedLoops, "Number of pruned loops");
37STATISTIC(NumPrunedBoxedLoops, "Number of pruned boxed loops");
38STATISTIC(NumPrunedAffineLoops, "Number of pruned affine loops");
39
40STATISTIC(NumLoopsInScop, "Number of loops in scops after pruning");
41STATISTIC(NumBoxedLoops, "Number of boxed loops in SCoPs after pruning");
42STATISTIC(NumAffineLoops, "Number of affine loops in SCoPs after pruning");
43
44static void updateStatistics(Scop &S, bool Pruned) {
45 Scop::ScopStatistics ScopStats = S.getStatistics();
46 if (Pruned) {
47 ScopsPruned++;
48 NumPrunedLoops += ScopStats.NumAffineLoops + ScopStats.NumBoxedLoops;
49 NumPrunedBoxedLoops += ScopStats.NumBoxedLoops;
50 NumPrunedAffineLoops += ScopStats.NumAffineLoops;
51 } else {
52 ScopsSurvived++;
53 NumLoopsInScop += ScopStats.NumAffineLoops + ScopStats.NumBoxedLoops;
54 NumBoxedLoops += ScopStats.NumBoxedLoops;
55 NumAffineLoops += ScopStats.NumAffineLoops;
56 }
57}
58
59static bool runPruneUnprofitable(Scop &S) {
62 dbgs() << "NOTE: -polly-process-unprofitable active, won't prune "
63 "anything\n");
64 return false;
65 }
66
67 ScopsProcessed++;
68
69 if (!S.isProfitable(true)) {
71 dbgs() << "SCoP pruned because it probably cannot be optimized in "
72 "a significant way\n");
73 S.invalidate(PROFITABLE, DebugLoc());
74 updateStatistics(S, true);
75 } else {
76 updateStatistics(S, false);
77 }
78
79 return false;
80}
81
82class PruneUnprofitableWrapperPass final : public ScopPass {
83public:
84 static char ID;
85
86 explicit PruneUnprofitableWrapperPass() : ScopPass(ID) {}
87 PruneUnprofitableWrapperPass(const PruneUnprofitableWrapperPass &) = delete;
88 PruneUnprofitableWrapperPass &
89 operator=(const PruneUnprofitableWrapperPass &) = delete;
90
91 void getAnalysisUsage(AnalysisUsage &AU) const override {
92 AU.addRequired<ScopInfoRegionPass>();
93 AU.setPreservesAll();
94 }
95
96 bool runOnScop(Scop &S) override { return runPruneUnprofitable(S); }
97};
98} // namespace
99
100char PruneUnprofitableWrapperPass::ID;
101
103 return new PruneUnprofitableWrapperPass();
104}
105
106INITIALIZE_PASS_BEGIN(PruneUnprofitableWrapperPass, "polly-prune-unprofitable",
107 "Polly - Prune unprofitable SCoPs", false, false)
108INITIALIZE_PASS_END(PruneUnprofitableWrapperPass, "polly-prune-unprofitable",
109 "Polly - Prune unprofitable SCoPs", false, false)
110
111llvm::PreservedAnalyses
114 bool Changed = runPruneUnprofitable(S);
115
116 if (!Changed)
117 return PreservedAnalyses::all();
118
119 PreservedAnalyses PA;
120 PA.preserveSet<AllAnalysesOn<Module>>();
121 PA.preserveSet<AllAnalysesOn<Function>>();
122 PA.preserveSet<AllAnalysesOn<Loop>>();
123 return PA;
124}
INITIALIZE_PASS_END(DependenceInfo, "polly-dependences", "Polly - Calculate dependences", false, false) namespace
#define POLLY_DEBUG(X)
Definition: PollyDebug.h:23
INITIALIZE_PASS_BEGIN(PruneUnprofitableWrapperPass, "polly-prune-unprofitable", "Polly - Prune unprofitable SCoPs", false, false) INITIALIZE_PASS_END(PruneUnprofitableWrapperPass
polly prune unprofitable
polly prune Polly Prune unprofitable SCoPs
STATISTIC(ScopFound, "Number of valid Scops")
The legacy pass manager's analysis pass to compute scop information for a region.
Definition: ScopInfo.h:2679
ScopPass - This class adapts the RegionPass interface to allow convenient creation of passes that ope...
Definition: ScopPass.h:161
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Definition: ScopPass.cpp:44
virtual bool runOnScop(Scop &S)=0
runOnScop - This method must be overloaded to perform the desired Polyhedral transformation or analys...
Static Control Part.
Definition: ScopInfo.h:1630
This file contains the declaration of the PolyhedralInfo class, which will provide an interface to ex...
bool PollyProcessUnprofitable
llvm::Pass * createPruneUnprofitableWrapperPass()
@ PROFITABLE
Definition: ScopHelper.h:48
AnalysisManager< Scop, ScopStandardAnalysisResults & > ScopAnalysisManager
Definition: ScopPass.h:46