Skip to content

Commit 601d7ea

Browse files
authored
[polly] Add polly-debug flag to print debug info from all parts of polly (#78549)
This flag enable the user to print debug Info from all the passes and helpers inside polly at once. This will help a novice user as well to work in polly without explicitly having to know which parts of polly has actually kicked in and pass them via -debug-only.
1 parent 148a557 commit 601d7ea

24 files changed

+412
-236
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//===-PollyDebug.h -Provide support for debugging Polly passes-*- C++ -*-===//
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+
// Functions to aid printing Debug Info of all polly passes.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef POLLY_DEBUG_H
14+
#define POLLY_DEBUG_H
15+
16+
#include "llvm/Support/Debug.h"
17+
18+
namespace polly {
19+
using namespace llvm;
20+
bool getPollyDebugFlag();
21+
22+
#ifndef NDEBUG
23+
#define POLLY_DEBUG(X) \
24+
do { \
25+
if (polly::getPollyDebugFlag()) { \
26+
X; \
27+
} else { \
28+
DEBUG_WITH_TYPE(DEBUG_TYPE, X); \
29+
} \
30+
} while (0)
31+
#else
32+
#define POLLY_DEBUG(X) \
33+
do { \
34+
} while (false)
35+
#endif
36+
37+
} // namespace polly
38+
#endif

polly/lib/Analysis/DependenceInfo.cpp

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
using namespace polly;
4040
using namespace llvm;
4141

42+
#include "polly/Support/PollyDebug.h"
4243
#define DEBUG_TYPE "polly-dependence"
4344

4445
static cl::opt<int> OptComputeOut(
@@ -300,10 +301,10 @@ static __isl_give isl_union_flow *buildFlow(__isl_keep isl_union_map *Snk,
300301
AI = isl_union_access_info_set_kill(AI, isl_union_map_copy(Kill));
301302
AI = isl_union_access_info_set_schedule(AI, isl_schedule_copy(Schedule));
302303
auto Flow = isl_union_access_info_compute_flow(AI);
303-
LLVM_DEBUG(if (!Flow) dbgs()
304-
<< "last error: "
305-
<< isl_ctx_last_error(isl_schedule_get_ctx(Schedule))
306-
<< '\n';);
304+
POLLY_DEBUG(if (!Flow) dbgs()
305+
<< "last error: "
306+
<< isl_ctx_last_error(isl_schedule_get_ctx(Schedule))
307+
<< '\n';);
307308
return Flow;
308309
}
309310

@@ -312,18 +313,18 @@ void Dependences::calculateDependences(Scop &S) {
312313
isl_schedule *Schedule;
313314
isl_union_set *TaggedStmtDomain;
314315

315-
LLVM_DEBUG(dbgs() << "Scop: \n" << S << "\n");
316+
POLLY_DEBUG(dbgs() << "Scop: \n" << S << "\n");
316317

317318
collectInfo(S, Read, MustWrite, MayWrite, ReductionTagMap, TaggedStmtDomain,
318319
Level);
319320

320321
bool HasReductions = !isl_union_map_is_empty(ReductionTagMap);
321322

322-
LLVM_DEBUG(dbgs() << "Read: " << Read << '\n';
323-
dbgs() << "MustWrite: " << MustWrite << '\n';
324-
dbgs() << "MayWrite: " << MayWrite << '\n';
325-
dbgs() << "ReductionTagMap: " << ReductionTagMap << '\n';
326-
dbgs() << "TaggedStmtDomain: " << TaggedStmtDomain << '\n';);
323+
POLLY_DEBUG(dbgs() << "Read: " << Read << '\n';
324+
dbgs() << "MustWrite: " << MustWrite << '\n';
325+
dbgs() << "MayWrite: " << MayWrite << '\n';
326+
dbgs() << "ReductionTagMap: " << ReductionTagMap << '\n';
327+
dbgs() << "TaggedStmtDomain: " << TaggedStmtDomain << '\n';);
327328

328329
Schedule = S.getScheduleTree().release();
329330

@@ -360,10 +361,10 @@ void Dependences::calculateDependences(Scop &S) {
360361
Schedule = isl_schedule_pullback_union_pw_multi_aff(Schedule, Tags);
361362
}
362363

363-
LLVM_DEBUG(dbgs() << "Read: " << Read << "\n";
364-
dbgs() << "MustWrite: " << MustWrite << "\n";
365-
dbgs() << "MayWrite: " << MayWrite << "\n";
366-
dbgs() << "Schedule: " << Schedule << "\n");
364+
POLLY_DEBUG(dbgs() << "Read: " << Read << "\n";
365+
dbgs() << "MustWrite: " << MustWrite << "\n";
366+
dbgs() << "MayWrite: " << MayWrite << "\n";
367+
dbgs() << "Schedule: " << Schedule << "\n");
367368

368369
isl_union_map *StrictWAW = nullptr;
369370
{
@@ -504,7 +505,7 @@ void Dependences::calculateDependences(Scop &S) {
504505
isl_union_map_copy(WAW), isl_union_set_copy(TaggedStmtDomain));
505506
STMT_WAR =
506507
isl_union_map_intersect_domain(isl_union_map_copy(WAR), TaggedStmtDomain);
507-
LLVM_DEBUG({
508+
POLLY_DEBUG({
508509
dbgs() << "Wrapped Dependences:\n";
509510
dump();
510511
dbgs() << "\n";
@@ -553,7 +554,7 @@ void Dependences::calculateDependences(Scop &S) {
553554
} else
554555
TC_RED = isl_union_map_empty(isl_union_map_get_space(RED));
555556

556-
LLVM_DEBUG({
557+
POLLY_DEBUG({
557558
dbgs() << "Final Wrapped Dependences:\n";
558559
dump();
559560
dbgs() << "\n";
@@ -603,7 +604,7 @@ void Dependences::calculateDependences(Scop &S) {
603604
RED = isl_union_map_zip(RED);
604605
TC_RED = isl_union_map_zip(TC_RED);
605606

606-
LLVM_DEBUG({
607+
POLLY_DEBUG({
607608
dbgs() << "Zipped Dependences:\n";
608609
dump();
609610
dbgs() << "\n";
@@ -615,7 +616,7 @@ void Dependences::calculateDependences(Scop &S) {
615616
RED = isl_union_set_unwrap(isl_union_map_domain(RED));
616617
TC_RED = isl_union_set_unwrap(isl_union_map_domain(TC_RED));
617618

618-
LLVM_DEBUG({
619+
POLLY_DEBUG({
619620
dbgs() << "Unwrapped Dependences:\n";
620621
dump();
621622
dbgs() << "\n";
@@ -631,7 +632,7 @@ void Dependences::calculateDependences(Scop &S) {
631632
RED = isl_union_map_coalesce(RED);
632633
TC_RED = isl_union_map_coalesce(TC_RED);
633634

634-
LLVM_DEBUG(dump());
635+
POLLY_DEBUG(dump());
635636
}
636637

637638
bool Dependences::isValidSchedule(Scop &S, isl::schedule NewSched) const {

polly/lib/Analysis/PolyhedralInfo.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
using namespace llvm;
3333
using namespace polly;
3434

35+
#include "polly/Support/PollyDebug.h"
3536
#define DEBUG_TYPE "polyhedral-info"
3637

3738
static cl::opt<bool> CheckParallel("polly-check-parallel",
@@ -77,19 +78,19 @@ bool PolyhedralInfo::checkParallel(Loop *L, isl_pw_aff **MinDepDistPtr) const {
7778
DI->getDependences(const_cast<Scop *>(S), Dependences::AL_Access);
7879
if (!D.hasValidDependences())
7980
return false;
80-
LLVM_DEBUG(dbgs() << "Loop :\t" << L->getHeader()->getName() << ":\n");
81+
POLLY_DEBUG(dbgs() << "Loop :\t" << L->getHeader()->getName() << ":\n");
8182

8283
isl_union_map *Deps =
8384
D.getDependences(Dependences::TYPE_RAW | Dependences::TYPE_WAW |
8485
Dependences::TYPE_WAR | Dependences::TYPE_RED)
8586
.release();
8687

87-
LLVM_DEBUG(dbgs() << "Dependences :\t" << stringFromIslObj(Deps, "null")
88-
<< "\n");
88+
POLLY_DEBUG(dbgs() << "Dependences :\t" << stringFromIslObj(Deps, "null")
89+
<< "\n");
8990

9091
isl_union_map *Schedule = getScheduleForLoop(S, L);
91-
LLVM_DEBUG(dbgs() << "Schedule: \t" << stringFromIslObj(Schedule, "null")
92-
<< "\n");
92+
POLLY_DEBUG(dbgs() << "Schedule: \t" << stringFromIslObj(Schedule, "null")
93+
<< "\n");
9394

9495
IsParallel = D.isParallel(Schedule, Deps, MinDepDistPtr);
9596
isl_union_map_free(Schedule);
@@ -125,14 +126,14 @@ __isl_give isl_union_map *PolyhedralInfo::getScheduleForLoop(const Scop *S,
125126
Loop *L) const {
126127
isl_union_map *Schedule = isl_union_map_empty(S->getParamSpace().release());
127128
int CurrDim = S->getRelativeLoopDepth(L);
128-
LLVM_DEBUG(dbgs() << "Relative loop depth:\t" << CurrDim << "\n");
129+
POLLY_DEBUG(dbgs() << "Relative loop depth:\t" << CurrDim << "\n");
129130
assert(CurrDim >= 0 && "Loop in region should have at least depth one");
130131

131132
for (auto &SS : *S) {
132133
if (L->contains(SS.getSurroundingLoop())) {
133134

134135
unsigned int MaxDim = SS.getNumIterators();
135-
LLVM_DEBUG(dbgs() << "Maximum depth of Stmt:\t" << MaxDim << "\n");
136+
POLLY_DEBUG(dbgs() << "Maximum depth of Stmt:\t" << MaxDim << "\n");
136137
isl_map *ScheduleMap = SS.getSchedule().release();
137138
assert(
138139
ScheduleMap &&

polly/lib/Analysis/PruneUnprofitable.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
using namespace llvm;
2323
using namespace polly;
2424

25+
#include "polly/Support/PollyDebug.h"
2526
#define DEBUG_TYPE "polly-prune-unprofitable"
2627

2728
namespace {
@@ -57,7 +58,7 @@ static void updateStatistics(Scop &S, bool Pruned) {
5758

5859
static bool runPruneUnprofitable(Scop &S) {
5960
if (PollyProcessUnprofitable) {
60-
LLVM_DEBUG(
61+
POLLY_DEBUG(
6162
dbgs() << "NOTE: -polly-process-unprofitable active, won't prune "
6263
"anything\n");
6364
return false;
@@ -66,7 +67,7 @@ static bool runPruneUnprofitable(Scop &S) {
6667
ScopsProcessed++;
6768

6869
if (!S.isProfitable(true)) {
69-
LLVM_DEBUG(
70+
POLLY_DEBUG(
7071
dbgs() << "SCoP pruned because it probably cannot be optimized in "
7172
"a significant way\n");
7273
S.invalidate(PROFITABLE, DebugLoc());

polly/lib/Analysis/ScopBuilder.cpp

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
using namespace llvm;
6161
using namespace polly;
6262

63+
#include "polly/Support/PollyDebug.h"
6364
#define DEBUG_TYPE "polly-scops"
6465

6566
STATISTIC(ScopFound, "Number of valid Scops");
@@ -2544,9 +2545,9 @@ bool checkCandidatePairAccesses(MemoryAccess *LoadMA, MemoryAccess *StoreMA,
25442545
isl::map LoadAccs = LoadMA->getAccessRelation();
25452546
isl::map StoreAccs = StoreMA->getAccessRelation();
25462547
bool Valid = LoadAccs.has_equal_space(StoreAccs);
2547-
LLVM_DEBUG(dbgs() << " == The accessed space below is "
2548-
<< (Valid ? "" : "not ") << "equal!\n");
2549-
LLVM_DEBUG(LoadMA->dump(); StoreMA->dump());
2548+
POLLY_DEBUG(dbgs() << " == The accessed space below is "
2549+
<< (Valid ? "" : "not ") << "equal!\n");
2550+
POLLY_DEBUG(LoadMA->dump(); StoreMA->dump());
25502551

25512552
if (Valid) {
25522553
// Then check if they actually access the same memory.
@@ -2560,8 +2561,8 @@ bool checkCandidatePairAccesses(MemoryAccess *LoadMA, MemoryAccess *StoreMA,
25602561
isl::set InterAccs =
25612562
isl::manage(RS.copy()).intersect(isl::manage(WS.copy()));
25622563
Valid = !InterAccs.is_empty();
2563-
LLVM_DEBUG(dbgs() << " == The accessed memory is " << (Valid ? "" : "not ")
2564-
<< "overlapping!\n");
2564+
POLLY_DEBUG(dbgs() << " == The accessed memory is " << (Valid ? "" : "not ")
2565+
<< "overlapping!\n");
25652566
}
25662567

25672568
if (Valid) {
@@ -2571,8 +2572,8 @@ bool checkCandidatePairAccesses(MemoryAccess *LoadMA, MemoryAccess *StoreMA,
25712572
isl::set AllAccs = AllAccsRel.range();
25722573
Valid = !hasIntersectingAccesses(AllAccs, LoadMA, StoreMA, Domain, MemAccs);
25732574

2574-
LLVM_DEBUG(dbgs() << " == The accessed memory is " << (Valid ? "not " : "")
2575-
<< "accessed by other instructions!\n");
2575+
POLLY_DEBUG(dbgs() << " == The accessed memory is " << (Valid ? "not " : "")
2576+
<< "accessed by other instructions!\n");
25762577
}
25772578
return Valid;
25782579
}
@@ -3240,8 +3241,8 @@ bool ScopBuilder::buildAliasChecks() {
32403241
// we make the assumed context infeasible.
32413242
scop->invalidate(ALIASING, DebugLoc());
32423243

3243-
LLVM_DEBUG(dbgs() << "\n\nNOTE: Run time checks for " << scop->getNameStr()
3244-
<< " could not be created. This SCoP has been dismissed.");
3244+
POLLY_DEBUG(dbgs() << "\n\nNOTE: Run time checks for " << scop->getNameStr()
3245+
<< " could not be created. This SCoP has been dismissed.");
32453246
return false;
32463247
}
32473248

@@ -3562,7 +3563,7 @@ void ScopBuilder::buildScop(Region &R, AssumptionCache &AC) {
35623563
DenseMap<BasicBlock *, isl::set> InvalidDomainMap;
35633564

35643565
if (!buildDomains(&R, InvalidDomainMap)) {
3565-
LLVM_DEBUG(
3566+
POLLY_DEBUG(
35663567
dbgs() << "Bailing-out because buildDomains encountered problems\n");
35673568
return;
35683569
}
@@ -3582,7 +3583,7 @@ void ScopBuilder::buildScop(Region &R, AssumptionCache &AC) {
35823583
scop->removeStmtNotInDomainMap();
35833584
scop->simplifySCoP(false);
35843585
if (scop->isEmpty()) {
3585-
LLVM_DEBUG(dbgs() << "Bailing-out because SCoP is empty\n");
3586+
POLLY_DEBUG(dbgs() << "Bailing-out because SCoP is empty\n");
35863587
return;
35873588
}
35883589

@@ -3599,15 +3600,16 @@ void ScopBuilder::buildScop(Region &R, AssumptionCache &AC) {
35993600

36003601
// Check early for a feasible runtime context.
36013602
if (!scop->hasFeasibleRuntimeContext()) {
3602-
LLVM_DEBUG(dbgs() << "Bailing-out because of unfeasible context (early)\n");
3603+
POLLY_DEBUG(
3604+
dbgs() << "Bailing-out because of unfeasible context (early)\n");
36033605
return;
36043606
}
36053607

36063608
// Check early for profitability. Afterwards it cannot change anymore,
36073609
// only the runtime context could become infeasible.
36083610
if (!scop->isProfitable(UnprofitableScalarAccs)) {
36093611
scop->invalidate(PROFITABLE, DebugLoc());
3610-
LLVM_DEBUG(
3612+
POLLY_DEBUG(
36113613
dbgs() << "Bailing-out because SCoP is not considered profitable\n");
36123614
return;
36133615
}
@@ -3626,7 +3628,7 @@ void ScopBuilder::buildScop(Region &R, AssumptionCache &AC) {
36263628

36273629
scop->simplifyContexts();
36283630
if (!buildAliasChecks()) {
3629-
LLVM_DEBUG(dbgs() << "Bailing-out because could not build alias checks\n");
3631+
POLLY_DEBUG(dbgs() << "Bailing-out because could not build alias checks\n");
36303632
return;
36313633
}
36323634

@@ -3638,7 +3640,7 @@ void ScopBuilder::buildScop(Region &R, AssumptionCache &AC) {
36383640
// Check late for a feasible runtime context because profitability did not
36393641
// change.
36403642
if (!scop->hasFeasibleRuntimeContext()) {
3641-
LLVM_DEBUG(dbgs() << "Bailing-out because of unfeasible context (late)\n");
3643+
POLLY_DEBUG(dbgs() << "Bailing-out because of unfeasible context (late)\n");
36423644
return;
36433645
}
36443646

@@ -3662,12 +3664,12 @@ ScopBuilder::ScopBuilder(Region *R, AssumptionCache &AC, AAResults &AA,
36623664

36633665
buildScop(*R, AC);
36643666

3665-
LLVM_DEBUG(dbgs() << *scop);
3667+
POLLY_DEBUG(dbgs() << *scop);
36663668

36673669
if (!scop->hasFeasibleRuntimeContext()) {
36683670
InfeasibleScops++;
36693671
Msg = "SCoP ends here but was dismissed.";
3670-
LLVM_DEBUG(dbgs() << "SCoP detected but dismissed\n");
3672+
POLLY_DEBUG(dbgs() << "SCoP detected but dismissed\n");
36713673
RecordedAssumptions.clear();
36723674
scop.reset();
36733675
} else {

0 commit comments

Comments
 (0)