1 //===- PruneUnprofitable.cpp ----------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Mark a SCoP as unfeasible if not deemed profitable to optimize.
12 //===----------------------------------------------------------------------===//
14 #include "polly/PruneUnprofitable.h"
15 #include "polly/ScopDetection.h"
16 #include "polly/ScopInfo.h"
17 #include "polly/ScopPass.h"
18 #include "llvm/ADT/Statistic.h"
19 #include "llvm/IR/DebugLoc.h"
20 #include "llvm/Pass.h"
21 #include "llvm/Support/Debug.h"
22 #include "llvm/Support/raw_ostream.h"
25 using namespace polly
;
27 #define DEBUG_TYPE "polly-prune-unprofitable"
31 STATISTIC(ScopsProcessed
,
32 "Number of SCoPs considered for unprofitability pruning");
33 STATISTIC(ScopsPruned
, "Number of pruned SCoPs because it they cannot be "
34 "optimized in a significant way");
35 STATISTIC(ScopsSurvived
, "Number of SCoPs after pruning");
37 STATISTIC(NumPrunedLoops
, "Number of pruned loops");
38 STATISTIC(NumPrunedBoxedLoops
, "Number of pruned boxed loops");
39 STATISTIC(NumPrunedAffineLoops
, "Number of pruned affine loops");
41 STATISTIC(NumLoopsInScop
, "Number of loops in scops after pruning");
42 STATISTIC(NumBoxedLoops
, "Number of boxed loops in SCoPs after pruning");
43 STATISTIC(NumAffineLoops
, "Number of affine loops in SCoPs after pruning");
45 class PruneUnprofitable
: public ScopPass
{
47 void updateStatistics(Scop
&S
, bool Pruned
) {
48 auto ScopStats
= S
.getStatistics();
51 NumPrunedLoops
+= ScopStats
.NumAffineLoops
+ ScopStats
.NumBoxedLoops
;
52 NumPrunedBoxedLoops
+= ScopStats
.NumBoxedLoops
;
53 NumPrunedAffineLoops
+= ScopStats
.NumAffineLoops
;
56 NumLoopsInScop
+= ScopStats
.NumAffineLoops
+ ScopStats
.NumBoxedLoops
;
57 NumBoxedLoops
+= ScopStats
.NumBoxedLoops
;
58 NumAffineLoops
+= ScopStats
.NumAffineLoops
;
65 explicit PruneUnprofitable() : ScopPass(ID
) {}
66 PruneUnprofitable(const PruneUnprofitable
&) = delete;
67 PruneUnprofitable
&operator=(const PruneUnprofitable
&) = delete;
69 void getAnalysisUsage(AnalysisUsage
&AU
) const override
{
70 AU
.addRequired
<ScopInfoRegionPass
>();
74 bool runOnScop(Scop
&S
) override
{
75 if (PollyProcessUnprofitable
) {
77 dbgs() << "NOTE: -polly-process-unprofitable active, won't prune "
84 if (!S
.isProfitable(true)) {
86 dbgs() << "SCoP pruned because it probably cannot be optimized in "
87 "a significant way\n");
88 S
.invalidate(PROFITABLE
, DebugLoc());
89 updateStatistics(S
, true);
91 updateStatistics(S
, false);
99 char PruneUnprofitable::ID
;
101 Pass
*polly::createPruneUnprofitablePass() { return new PruneUnprofitable(); }
103 INITIALIZE_PASS_BEGIN(PruneUnprofitable
, "polly-prune-unprofitable",
104 "Polly - Prune unprofitable SCoPs", false, false)
105 INITIALIZE_PASS_END(PruneUnprofitable
, "polly-prune-unprofitable",
106 "Polly - Prune unprofitable SCoPs", false, false)