aboutsummaryrefslogtreecommitdiff
path: root/polly
diff options
context:
space:
mode:
authorKarthika Devi C <quic_kartc@quicinc.com>2024-03-27 00:32:27 +0530
committerGitHub <noreply@github.com>2024-03-26 12:02:27 -0700
commit601d7eab0665ba298d81952da11593124fd893a0 (patch)
treeb313ccccc816aca1d7f7fabea1cd886faf6b2253 /polly
parent148a55795de7ac465a8e494d5d382e100da643f6 (diff)
downloadllvm-601d7eab0665ba298d81952da11593124fd893a0.zip
llvm-601d7eab0665ba298d81952da11593124fd893a0.tar.gz
llvm-601d7eab0665ba298d81952da11593124fd893a0.tar.bz2
[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.
Diffstat (limited to 'polly')
-rw-r--r--polly/include/polly/Support/PollyDebug.h38
-rw-r--r--polly/lib/Analysis/DependenceInfo.cpp39
-rw-r--r--polly/lib/Analysis/PolyhedralInfo.cpp15
-rw-r--r--polly/lib/Analysis/PruneUnprofitable.cpp5
-rw-r--r--polly/lib/Analysis/ScopBuilder.cpp36
-rw-r--r--polly/lib/Analysis/ScopDetection.cpp27
-rw-r--r--polly/lib/Analysis/ScopInfo.cpp3
-rw-r--r--polly/lib/CMakeLists.txt1
-rw-r--r--polly/lib/CodeGen/CodeGeneration.cpp5
-rw-r--r--polly/lib/CodeGen/IslAst.cpp7
-rw-r--r--polly/lib/Support/PollyDebug.cpp27
-rw-r--r--polly/lib/Support/SCEVValidator.cpp34
-rw-r--r--polly/lib/Transform/DeLICM.cpp93
-rw-r--r--polly/lib/Transform/FlattenAlgo.cpp37
-rw-r--r--polly/lib/Transform/FlattenSchedule.cpp17
-rw-r--r--polly/lib/Transform/ForwardOpTree.cpp56
-rw-r--r--polly/lib/Transform/ManualOptimizer.cpp9
-rw-r--r--polly/lib/Transform/MatmulOptimizer.cpp5
-rw-r--r--polly/lib/Transform/ScheduleOptimizer.cpp31
-rw-r--r--polly/lib/Transform/ScheduleTreeTransform.cpp11
-rw-r--r--polly/lib/Transform/ScopInliner.cpp13
-rw-r--r--polly/lib/Transform/Simplify.cpp47
-rw-r--r--polly/lib/Transform/ZoneAlgo.cpp7
-rw-r--r--polly/test/Support/pollyDebug.ll85
24 files changed, 412 insertions, 236 deletions
diff --git a/polly/include/polly/Support/PollyDebug.h b/polly/include/polly/Support/PollyDebug.h
new file mode 100644
index 0000000..5cea68e
--- /dev/null
+++ b/polly/include/polly/Support/PollyDebug.h
@@ -0,0 +1,38 @@
+//===-PollyDebug.h -Provide support for debugging Polly passes-*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Functions to aid printing Debug Info of all polly passes.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef POLLY_DEBUG_H
+#define POLLY_DEBUG_H
+
+#include "llvm/Support/Debug.h"
+
+namespace polly {
+using namespace llvm;
+bool getPollyDebugFlag();
+
+#ifndef NDEBUG
+#define POLLY_DEBUG(X) \
+ do { \
+ if (polly::getPollyDebugFlag()) { \
+ X; \
+ } else { \
+ DEBUG_WITH_TYPE(DEBUG_TYPE, X); \
+ } \
+ } while (0)
+#else
+#define POLLY_DEBUG(X) \
+ do { \
+ } while (false)
+#endif
+
+} // namespace polly
+#endif
diff --git a/polly/lib/Analysis/DependenceInfo.cpp b/polly/lib/Analysis/DependenceInfo.cpp
index 69257c6..9ee004f 100644
--- a/polly/lib/Analysis/DependenceInfo.cpp
+++ b/polly/lib/Analysis/DependenceInfo.cpp
@@ -39,6 +39,7 @@
using namespace polly;
using namespace llvm;
+#include "polly/Support/PollyDebug.h"
#define DEBUG_TYPE "polly-dependence"
static cl::opt<int> OptComputeOut(
@@ -300,10 +301,10 @@ static __isl_give isl_union_flow *buildFlow(__isl_keep isl_union_map *Snk,
AI = isl_union_access_info_set_kill(AI, isl_union_map_copy(Kill));
AI = isl_union_access_info_set_schedule(AI, isl_schedule_copy(Schedule));
auto Flow = isl_union_access_info_compute_flow(AI);
- LLVM_DEBUG(if (!Flow) dbgs()
- << "last error: "
- << isl_ctx_last_error(isl_schedule_get_ctx(Schedule))
- << '\n';);
+ POLLY_DEBUG(if (!Flow) dbgs()
+ << "last error: "
+ << isl_ctx_last_error(isl_schedule_get_ctx(Schedule))
+ << '\n';);
return Flow;
}
@@ -312,18 +313,18 @@ void Dependences::calculateDependences(Scop &S) {
isl_schedule *Schedule;
isl_union_set *TaggedStmtDomain;
- LLVM_DEBUG(dbgs() << "Scop: \n" << S << "\n");
+ POLLY_DEBUG(dbgs() << "Scop: \n" << S << "\n");
collectInfo(S, Read, MustWrite, MayWrite, ReductionTagMap, TaggedStmtDomain,
Level);
bool HasReductions = !isl_union_map_is_empty(ReductionTagMap);
- LLVM_DEBUG(dbgs() << "Read: " << Read << '\n';
- dbgs() << "MustWrite: " << MustWrite << '\n';
- dbgs() << "MayWrite: " << MayWrite << '\n';
- dbgs() << "ReductionTagMap: " << ReductionTagMap << '\n';
- dbgs() << "TaggedStmtDomain: " << TaggedStmtDomain << '\n';);
+ POLLY_DEBUG(dbgs() << "Read: " << Read << '\n';
+ dbgs() << "MustWrite: " << MustWrite << '\n';
+ dbgs() << "MayWrite: " << MayWrite << '\n';
+ dbgs() << "ReductionTagMap: " << ReductionTagMap << '\n';
+ dbgs() << "TaggedStmtDomain: " << TaggedStmtDomain << '\n';);
Schedule = S.getScheduleTree().release();
@@ -360,10 +361,10 @@ void Dependences::calculateDependences(Scop &S) {
Schedule = isl_schedule_pullback_union_pw_multi_aff(Schedule, Tags);
}
- LLVM_DEBUG(dbgs() << "Read: " << Read << "\n";
- dbgs() << "MustWrite: " << MustWrite << "\n";
- dbgs() << "MayWrite: " << MayWrite << "\n";
- dbgs() << "Schedule: " << Schedule << "\n");
+ POLLY_DEBUG(dbgs() << "Read: " << Read << "\n";
+ dbgs() << "MustWrite: " << MustWrite << "\n";
+ dbgs() << "MayWrite: " << MayWrite << "\n";
+ dbgs() << "Schedule: " << Schedule << "\n");
isl_union_map *StrictWAW = nullptr;
{
@@ -504,7 +505,7 @@ void Dependences::calculateDependences(Scop &S) {
isl_union_map_copy(WAW), isl_union_set_copy(TaggedStmtDomain));
STMT_WAR =
isl_union_map_intersect_domain(isl_union_map_copy(WAR), TaggedStmtDomain);
- LLVM_DEBUG({
+ POLLY_DEBUG({
dbgs() << "Wrapped Dependences:\n";
dump();
dbgs() << "\n";
@@ -553,7 +554,7 @@ void Dependences::calculateDependences(Scop &S) {
} else
TC_RED = isl_union_map_empty(isl_union_map_get_space(RED));
- LLVM_DEBUG({
+ POLLY_DEBUG({
dbgs() << "Final Wrapped Dependences:\n";
dump();
dbgs() << "\n";
@@ -603,7 +604,7 @@ void Dependences::calculateDependences(Scop &S) {
RED = isl_union_map_zip(RED);
TC_RED = isl_union_map_zip(TC_RED);
- LLVM_DEBUG({
+ POLLY_DEBUG({
dbgs() << "Zipped Dependences:\n";
dump();
dbgs() << "\n";
@@ -615,7 +616,7 @@ void Dependences::calculateDependences(Scop &S) {
RED = isl_union_set_unwrap(isl_union_map_domain(RED));
TC_RED = isl_union_set_unwrap(isl_union_map_domain(TC_RED));
- LLVM_DEBUG({
+ POLLY_DEBUG({
dbgs() << "Unwrapped Dependences:\n";
dump();
dbgs() << "\n";
@@ -631,7 +632,7 @@ void Dependences::calculateDependences(Scop &S) {
RED = isl_union_map_coalesce(RED);
TC_RED = isl_union_map_coalesce(TC_RED);
- LLVM_DEBUG(dump());
+ POLLY_DEBUG(dump());
}
bool Dependences::isValidSchedule(Scop &S, isl::schedule NewSched) const {
diff --git a/polly/lib/Analysis/PolyhedralInfo.cpp b/polly/lib/Analysis/PolyhedralInfo.cpp
index 5c77be0..8d8e81a 100644
--- a/polly/lib/Analysis/PolyhedralInfo.cpp
+++ b/polly/lib/Analysis/PolyhedralInfo.cpp
@@ -32,6 +32,7 @@
using namespace llvm;
using namespace polly;
+#include "polly/Support/PollyDebug.h"
#define DEBUG_TYPE "polyhedral-info"
static cl::opt<bool> CheckParallel("polly-check-parallel",
@@ -77,19 +78,19 @@ bool PolyhedralInfo::checkParallel(Loop *L, isl_pw_aff **MinDepDistPtr) const {
DI->getDependences(const_cast<Scop *>(S), Dependences::AL_Access);
if (!D.hasValidDependences())
return false;
- LLVM_DEBUG(dbgs() << "Loop :\t" << L->getHeader()->getName() << ":\n");
+ POLLY_DEBUG(dbgs() << "Loop :\t" << L->getHeader()->getName() << ":\n");
isl_union_map *Deps =
D.getDependences(Dependences::TYPE_RAW | Dependences::TYPE_WAW |
Dependences::TYPE_WAR | Dependences::TYPE_RED)
.release();
- LLVM_DEBUG(dbgs() << "Dependences :\t" << stringFromIslObj(Deps, "null")
- << "\n");
+ POLLY_DEBUG(dbgs() << "Dependences :\t" << stringFromIslObj(Deps, "null")
+ << "\n");
isl_union_map *Schedule = getScheduleForLoop(S, L);
- LLVM_DEBUG(dbgs() << "Schedule: \t" << stringFromIslObj(Schedule, "null")
- << "\n");
+ POLLY_DEBUG(dbgs() << "Schedule: \t" << stringFromIslObj(Schedule, "null")
+ << "\n");
IsParallel = D.isParallel(Schedule, Deps, MinDepDistPtr);
isl_union_map_free(Schedule);
@@ -125,14 +126,14 @@ __isl_give isl_union_map *PolyhedralInfo::getScheduleForLoop(const Scop *S,
Loop *L) const {
isl_union_map *Schedule = isl_union_map_empty(S->getParamSpace().release());
int CurrDim = S->getRelativeLoopDepth(L);
- LLVM_DEBUG(dbgs() << "Relative loop depth:\t" << CurrDim << "\n");
+ POLLY_DEBUG(dbgs() << "Relative loop depth:\t" << CurrDim << "\n");
assert(CurrDim >= 0 && "Loop in region should have at least depth one");
for (auto &SS : *S) {
if (L->contains(SS.getSurroundingLoop())) {
unsigned int MaxDim = SS.getNumIterators();
- LLVM_DEBUG(dbgs() << "Maximum depth of Stmt:\t" << MaxDim << "\n");
+ POLLY_DEBUG(dbgs() << "Maximum depth of Stmt:\t" << MaxDim << "\n");
isl_map *ScheduleMap = SS.getSchedule().release();
assert(
ScheduleMap &&
diff --git a/polly/lib/Analysis/PruneUnprofitable.cpp b/polly/lib/Analysis/PruneUnprofitable.cpp
index db4a3d7..f8469c0 100644
--- a/polly/lib/Analysis/PruneUnprofitable.cpp
+++ b/polly/lib/Analysis/PruneUnprofitable.cpp
@@ -22,6 +22,7 @@
using namespace llvm;
using namespace polly;
+#include "polly/Support/PollyDebug.h"
#define DEBUG_TYPE "polly-prune-unprofitable"
namespace {
@@ -57,7 +58,7 @@ static void updateStatistics(Scop &S, bool Pruned) {
static bool runPruneUnprofitable(Scop &S) {
if (PollyProcessUnprofitable) {
- LLVM_DEBUG(
+ POLLY_DEBUG(
dbgs() << "NOTE: -polly-process-unprofitable active, won't prune "
"anything\n");
return false;
@@ -66,7 +67,7 @@ static bool runPruneUnprofitable(Scop &S) {
ScopsProcessed++;
if (!S.isProfitable(true)) {
- LLVM_DEBUG(
+ POLLY_DEBUG(
dbgs() << "SCoP pruned because it probably cannot be optimized in "
"a significant way\n");
S.invalidate(PROFITABLE, DebugLoc());
diff --git a/polly/lib/Analysis/ScopBuilder.cpp b/polly/lib/Analysis/ScopBuilder.cpp
index 0edc41d..214e4d3 100644
--- a/polly/lib/Analysis/ScopBuilder.cpp
+++ b/polly/lib/Analysis/ScopBuilder.cpp
@@ -60,6 +60,7 @@
using namespace llvm;
using namespace polly;
+#include "polly/Support/PollyDebug.h"
#define DEBUG_TYPE "polly-scops"
STATISTIC(ScopFound, "Number of valid Scops");
@@ -2544,9 +2545,9 @@ bool checkCandidatePairAccesses(MemoryAccess *LoadMA, MemoryAccess *StoreMA,
isl::map LoadAccs = LoadMA->getAccessRelation();
isl::map StoreAccs = StoreMA->getAccessRelation();
bool Valid = LoadAccs.has_equal_space(StoreAccs);
- LLVM_DEBUG(dbgs() << " == The accessed space below is "
- << (Valid ? "" : "not ") << "equal!\n");
- LLVM_DEBUG(LoadMA->dump(); StoreMA->dump());
+ POLLY_DEBUG(dbgs() << " == The accessed space below is "
+ << (Valid ? "" : "not ") << "equal!\n");
+ POLLY_DEBUG(LoadMA->dump(); StoreMA->dump());
if (Valid) {
// Then check if they actually access the same memory.
@@ -2560,8 +2561,8 @@ bool checkCandidatePairAccesses(MemoryAccess *LoadMA, MemoryAccess *StoreMA,
isl::set InterAccs =
isl::manage(RS.copy()).intersect(isl::manage(WS.copy()));
Valid = !InterAccs.is_empty();
- LLVM_DEBUG(dbgs() << " == The accessed memory is " << (Valid ? "" : "not ")
- << "overlapping!\n");
+ POLLY_DEBUG(dbgs() << " == The accessed memory is " << (Valid ? "" : "not ")
+ << "overlapping!\n");
}
if (Valid) {
@@ -2571,8 +2572,8 @@ bool checkCandidatePairAccesses(MemoryAccess *LoadMA, MemoryAccess *StoreMA,
isl::set AllAccs = AllAccsRel.range();
Valid = !hasIntersectingAccesses(AllAccs, LoadMA, StoreMA, Domain, MemAccs);
- LLVM_DEBUG(dbgs() << " == The accessed memory is " << (Valid ? "not " : "")
- << "accessed by other instructions!\n");
+ POLLY_DEBUG(dbgs() << " == The accessed memory is " << (Valid ? "not " : "")
+ << "accessed by other instructions!\n");
}
return Valid;
}
@@ -3240,8 +3241,8 @@ bool ScopBuilder::buildAliasChecks() {
// we make the assumed context infeasible.
scop->invalidate(ALIASING, DebugLoc());
- LLVM_DEBUG(dbgs() << "\n\nNOTE: Run time checks for " << scop->getNameStr()
- << " could not be created. This SCoP has been dismissed.");
+ POLLY_DEBUG(dbgs() << "\n\nNOTE: Run time checks for " << scop->getNameStr()
+ << " could not be created. This SCoP has been dismissed.");
return false;
}
@@ -3562,7 +3563,7 @@ void ScopBuilder::buildScop(Region &R, AssumptionCache &AC) {
DenseMap<BasicBlock *, isl::set> InvalidDomainMap;
if (!buildDomains(&R, InvalidDomainMap)) {
- LLVM_DEBUG(
+ POLLY_DEBUG(
dbgs() << "Bailing-out because buildDomains encountered problems\n");
return;
}
@@ -3582,7 +3583,7 @@ void ScopBuilder::buildScop(Region &R, AssumptionCache &AC) {
scop->removeStmtNotInDomainMap();
scop->simplifySCoP(false);
if (scop->isEmpty()) {
- LLVM_DEBUG(dbgs() << "Bailing-out because SCoP is empty\n");
+ POLLY_DEBUG(dbgs() << "Bailing-out because SCoP is empty\n");
return;
}
@@ -3599,7 +3600,8 @@ void ScopBuilder::buildScop(Region &R, AssumptionCache &AC) {
// Check early for a feasible runtime context.
if (!scop->hasFeasibleRuntimeContext()) {
- LLVM_DEBUG(dbgs() << "Bailing-out because of unfeasible context (early)\n");
+ POLLY_DEBUG(
+ dbgs() << "Bailing-out because of unfeasible context (early)\n");
return;
}
@@ -3607,7 +3609,7 @@ void ScopBuilder::buildScop(Region &R, AssumptionCache &AC) {
// only the runtime context could become infeasible.
if (!scop->isProfitable(UnprofitableScalarAccs)) {
scop->invalidate(PROFITABLE, DebugLoc());
- LLVM_DEBUG(
+ POLLY_DEBUG(
dbgs() << "Bailing-out because SCoP is not considered profitable\n");
return;
}
@@ -3626,7 +3628,7 @@ void ScopBuilder::buildScop(Region &R, AssumptionCache &AC) {
scop->simplifyContexts();
if (!buildAliasChecks()) {
- LLVM_DEBUG(dbgs() << "Bailing-out because could not build alias checks\n");
+ POLLY_DEBUG(dbgs() << "Bailing-out because could not build alias checks\n");
return;
}
@@ -3638,7 +3640,7 @@ void ScopBuilder::buildScop(Region &R, AssumptionCache &AC) {
// Check late for a feasible runtime context because profitability did not
// change.
if (!scop->hasFeasibleRuntimeContext()) {
- LLVM_DEBUG(dbgs() << "Bailing-out because of unfeasible context (late)\n");
+ POLLY_DEBUG(dbgs() << "Bailing-out because of unfeasible context (late)\n");
return;
}
@@ -3662,12 +3664,12 @@ ScopBuilder::ScopBuilder(Region *R, AssumptionCache &AC, AAResults &AA,
buildScop(*R, AC);
- LLVM_DEBUG(dbgs() << *scop);
+ POLLY_DEBUG(dbgs() << *scop);
if (!scop->hasFeasibleRuntimeContext()) {
InfeasibleScops++;
Msg = "SCoP ends here but was dismissed.";
- LLVM_DEBUG(dbgs() << "SCoP detected but dismissed\n");
+ POLLY_DEBUG(dbgs() << "SCoP detected but dismissed\n");
RecordedAssumptions.clear();
scop.reset();
} else {
diff --git a/polly/lib/Analysis/ScopDetection.cpp b/polly/lib/Analysis/ScopDetection.cpp
index 938d3f1..eab7bd8 100644
--- a/polly/lib/Analysis/ScopDetection.cpp
+++ b/polly/lib/Analysis/ScopDetection.cpp
@@ -91,6 +91,7 @@
using namespace llvm;
using namespace polly;
+#include "polly/Support/PollyDebug.h"
#define DEBUG_TYPE "polly-detect"
// This option is set to a very high value, as analyzing such loops increases
@@ -406,8 +407,8 @@ inline bool ScopDetection::invalid(DetectionContext &Context, bool Assert,
// canUseISLTripCount().
Log.report(RejectReason);
- LLVM_DEBUG(dbgs() << RejectReason->getMessage());
- LLVM_DEBUG(dbgs() << "\n");
+ POLLY_DEBUG(dbgs() << RejectReason->getMessage());
+ POLLY_DEBUG(dbgs() << "\n");
} else {
assert(!Assert && "Verification of detected scop failed");
}
@@ -704,8 +705,8 @@ bool ScopDetection::isValidCallInst(CallInst &CI,
return false;
if (isDebugCall(&CI)) {
- LLVM_DEBUG(dbgs() << "Allow call to debug function: "
- << CalledFunction->getName() << '\n');
+ POLLY_DEBUG(dbgs() << "Allow call to debug function: "
+ << CalledFunction->getName() << '\n');
return true;
}
@@ -1486,7 +1487,7 @@ Region *ScopDetection::expandRegion(Region &R) {
std::unique_ptr<Region> LastValidRegion;
auto ExpandedRegion = std::unique_ptr<Region>(R.getExpandedRegion());
- LLVM_DEBUG(dbgs() << "\tExpanding " << R.getNameStr() << "\n");
+ POLLY_DEBUG(dbgs() << "\tExpanding " << R.getNameStr() << "\n");
while (ExpandedRegion) {
BBPair P = getBBPairForRegion(ExpandedRegion.get());
@@ -1495,7 +1496,8 @@ Region *ScopDetection::expandRegion(Region &R) {
/*Verifying=*/false);
DetectionContext &Context = *Entry.get();
- LLVM_DEBUG(dbgs() << "\t\tTrying " << ExpandedRegion->getNameStr() << "\n");
+ POLLY_DEBUG(dbgs() << "\t\tTrying " << ExpandedRegion->getNameStr()
+ << "\n");
// Only expand when we did not collect errors.
if (!Context.Log.hasErrors()) {
@@ -1529,7 +1531,7 @@ Region *ScopDetection::expandRegion(Region &R) {
}
}
- LLVM_DEBUG({
+ POLLY_DEBUG({
if (LastValidRegion)
dbgs() << "\tto " << LastValidRegion->getNameStr() << "\n";
else
@@ -1750,10 +1752,11 @@ bool ScopDetection::isProfitableRegion(DetectionContext &Context) const {
bool ScopDetection::isValidRegion(DetectionContext &Context) {
Region &CurRegion = Context.CurRegion;
- LLVM_DEBUG(dbgs() << "Checking region: " << CurRegion.getNameStr() << "\n\t");
+ POLLY_DEBUG(dbgs() << "Checking region: " << CurRegion.getNameStr()
+ << "\n\t");
if (!PollyAllowFullFunction && CurRegion.isTopLevelRegion()) {
- LLVM_DEBUG(dbgs() << "Top level region is invalid\n");
+ POLLY_DEBUG(dbgs() << "Top level region is invalid\n");
Context.IsInvalid = true;
return false;
}
@@ -1761,14 +1764,14 @@ bool ScopDetection::isValidRegion(DetectionContext &Context) {
DebugLoc DbgLoc;
if (CurRegion.getExit() &&
isa<UnreachableInst>(CurRegion.getExit()->getTerminator())) {
- LLVM_DEBUG(dbgs() << "Unreachable in exit\n");
+ POLLY_DEBUG(dbgs() << "Unreachable in exit\n");
return invalid<ReportUnreachableInExit>(Context, /*Assert=*/true,
CurRegion.getExit(), DbgLoc);
}
if (!OnlyRegion.empty() &&
!CurRegion.getEntry()->getName().count(OnlyRegion)) {
- LLVM_DEBUG({
+ POLLY_DEBUG({
dbgs() << "Region entry does not match -polly-only-region";
dbgs() << "\n";
});
@@ -1802,7 +1805,7 @@ bool ScopDetection::isValidRegion(DetectionContext &Context) {
return invalid<ReportIrreducibleRegion>(Context, /*Assert=*/true,
&CurRegion, DbgLoc);
- LLVM_DEBUG(dbgs() << "OK\n");
+ POLLY_DEBUG(dbgs() << "OK\n");
return true;
}
diff --git a/polly/lib/Analysis/ScopInfo.cpp b/polly/lib/Analysis/ScopInfo.cpp
index 3e78cc8..fa35fae 100644
--- a/polly/lib/Analysis/ScopInfo.cpp
+++ b/polly/lib/Analysis/ScopInfo.cpp
@@ -73,6 +73,7 @@
using namespace llvm;
using namespace polly;
+#include "polly/Support/PollyDebug.h"
#define DEBUG_TYPE "polly-scops"
STATISTIC(AssumptionsAliasing, "Number of aliasing assumptions taken.");
@@ -2042,7 +2043,7 @@ void Scop::intersectDefinedBehavior(isl::set Set, AssumptionSign Sign) {
}
void Scop::invalidate(AssumptionKind Kind, DebugLoc Loc, BasicBlock *BB) {
- LLVM_DEBUG(dbgs() << "Invalidate SCoP because of reason " << Kind << "\n");
+ POLLY_DEBUG(dbgs() << "Invalidate SCoP because of reason " << Kind << "\n");
addAssumption(Kind, isl::set::empty(getParamSpace()), Loc, AS_ASSUMPTION, BB);
}
diff --git a/polly/lib/CMakeLists.txt b/polly/lib/CMakeLists.txt
index 9780f24..4557878 100644
--- a/polly/lib/CMakeLists.txt
+++ b/polly/lib/CMakeLists.txt
@@ -62,6 +62,7 @@ add_llvm_pass_plugin(Polly
CodeGen/PerfMonitor.cpp
Exchange/JSONExporter.cpp
Support/GICHelper.cpp
+ Support/PollyDebug.cpp
Support/SCEVAffinator.cpp
Support/SCEVValidator.cpp
Support/RegisterPasses.cpp
diff --git a/polly/lib/CodeGen/CodeGeneration.cpp b/polly/lib/CodeGen/CodeGeneration.cpp
index 3792d99..c4ca3f2 100644
--- a/polly/lib/CodeGen/CodeGeneration.cpp
+++ b/polly/lib/CodeGen/CodeGeneration.cpp
@@ -47,6 +47,7 @@
using namespace llvm;
using namespace polly;
+#include "polly/Support/PollyDebug.h"
#define DEBUG_TYPE "polly-codegen"
static cl::opt<bool> Verify("polly-codegen-verify",
@@ -86,7 +87,7 @@ static void verifyGeneratedFunction(Scop &S, Function &F, IslAstInfo &AI) {
if (!Verify || !verifyFunction(F, &errs()))
return;
- LLVM_DEBUG({
+ POLLY_DEBUG({
errs() << "== ISL Codegen created an invalid function ==\n\n== The "
"SCoP ==\n";
errs() << S;
@@ -183,7 +184,7 @@ static bool generateCode(Scop &S, IslAstInfo &AI, LoopInfo &LI,
// DependenceInfo or IslAstInfo around.
IslAst &Ast = AI.getIslAst();
if (Ast.getSharedIslCtx() != S.getSharedIslCtx()) {
- LLVM_DEBUG(dbgs() << "Got an IstAst for a different Scop/isl_ctx\n");
+ POLLY_DEBUG(dbgs() << "Got an IstAst for a different Scop/isl_ctx\n");
return false;
}
diff --git a/polly/lib/CodeGen/IslAst.cpp b/polly/lib/CodeGen/IslAst.cpp
index fe2b5d9..142a19d 100644
--- a/polly/lib/CodeGen/IslAst.cpp
+++ b/polly/lib/CodeGen/IslAst.cpp
@@ -52,6 +52,7 @@
#include <cassert>
#include <cstdlib>
+#include "polly/Support/PollyDebug.h"
#define DEBUG_TYPE "polly-ast"
using namespace llvm;
@@ -643,14 +644,14 @@ static std::unique_ptr<IslAstInfo> runIslAst(
const Dependences &D = GetDeps(Dependences::AL_Statement);
if (D.getSharedIslCtx() != Scop.getSharedIslCtx()) {
- LLVM_DEBUG(
+ POLLY_DEBUG(
dbgs() << "Got dependence analysis for different SCoP/isl_ctx\n");
return {};
}
std::unique_ptr<IslAstInfo> Ast = std::make_unique<IslAstInfo>(Scop, D);
- LLVM_DEBUG({
+ POLLY_DEBUG({
if (Ast)
Ast->print(dbgs());
});
@@ -751,7 +752,7 @@ void IslAstInfo::print(raw_ostream &OS) {
P = isl_ast_node_print(RootNode.get(), P, Options);
AstStr = isl_printer_get_str(P);
- LLVM_DEBUG({
+ POLLY_DEBUG({
dbgs() << S.getContextStr() << "\n";
dbgs() << stringFromIslObj(S.getScheduleTree(), "null");
});
diff --git a/polly/lib/Support/PollyDebug.cpp b/polly/lib/Support/PollyDebug.cpp
new file mode 100644
index 0000000..9dcd8ed
--- /dev/null
+++ b/polly/lib/Support/PollyDebug.cpp
@@ -0,0 +1,27 @@
+//===-PollyDebug.cpp -Provide support for debugging Polly passes-*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Functions to aid printing Debug Info of all polly passes.
+//
+//===----------------------------------------------------------------------===//
+
+#include "polly/Support/PollyDebug.h"
+#include "llvm/Support/CommandLine.h"
+
+using namespace polly;
+using namespace llvm;
+
+bool PollyDebugFlag;
+bool polly::getPollyDebugFlag() { return PollyDebugFlag; }
+
+// -debug - Command line option to enable the DEBUG statements in the passes.
+// This flag may only be enabled in debug builds.
+static cl::opt<bool, true>
+ PollyDebug("polly-debug",
+ cl::desc("Enable debug output for only polly passes."),
+ cl::Hidden, cl::location(PollyDebugFlag), cl::ZeroOrMore);
diff --git a/polly/lib/Support/SCEVValidator.cpp b/polly/lib/Support/SCEVValidator.cpp
index e3d9818..5bb8262 100644
--- a/polly/lib/Support/SCEVValidator.cpp
+++ b/polly/lib/Support/SCEVValidator.cpp
@@ -9,6 +9,7 @@
using namespace llvm;
using namespace polly;
+#include "polly/Support/PollyDebug.h"
#define DEBUG_TYPE "polly-scev-validator"
namespace SCEVType {
@@ -136,7 +137,7 @@ public:
ValidatorResult visitVScale(const SCEVVScale *VScale) {
// We do not support VScale constants.
- LLVM_DEBUG(dbgs() << "INVALID: VScale is not supported");
+ POLLY_DEBUG(dbgs() << "INVALID: VScale is not supported");
return ValidatorResult(SCEVType::INVALID);
}
@@ -203,7 +204,7 @@ public:
}
if ((Op.isIV() || Op.isPARAM()) && !Return.isINT()) {
- LLVM_DEBUG(
+ POLLY_DEBUG(
dbgs() << "INVALID: More than one non-int operand in MulExpr\n"
<< "\tExpr: " << *Expr << "\n"
<< "\tPrevious expression type: " << Return << "\n"
@@ -224,7 +225,7 @@ public:
ValidatorResult visitAddRecExpr(const SCEVAddRecExpr *Expr) {
if (!Expr->isAffine()) {
- LLVM_DEBUG(dbgs() << "INVALID: AddRec is not affine");
+ POLLY_DEBUG(dbgs() << "INVALID: AddRec is not affine");
return ValidatorResult(SCEVType::INVALID);
}
@@ -239,7 +240,7 @@ public:
auto *L = Expr->getLoop();
if (R->contains(L) && (!Scope || !L->contains(Scope))) {
- LLVM_DEBUG(
+ POLLY_DEBUG(
dbgs() << "INVALID: Loop of AddRec expression boxed in an a "
"non-affine subregion or has a non-synthesizable exit "
"value.");
@@ -253,8 +254,8 @@ public:
return Result;
}
- LLVM_DEBUG(dbgs() << "INVALID: AddRec within scop has non-int"
- "recurrence part");
+ POLLY_DEBUG(dbgs() << "INVALID: AddRec within scop has non-int"
+ "recurrence part");
return ValidatorResult(SCEVType::INVALID);
}
@@ -314,7 +315,7 @@ public:
ValidatorResult Op = visit(Expr->getOperand(i));
if (!Op.isConstant()) {
- LLVM_DEBUG(dbgs() << "INVALID: UMaxExpr has a non-constant operand");
+ POLLY_DEBUG(dbgs() << "INVALID: UMaxExpr has a non-constant operand");
return ValidatorResult(SCEVType::INVALID);
}
}
@@ -329,7 +330,7 @@ public:
ValidatorResult Op = visit(Expr->getOperand(i));
if (!Op.isConstant()) {
- LLVM_DEBUG(dbgs() << "INVALID: UMinExpr has a non-constant operand");
+ POLLY_DEBUG(dbgs() << "INVALID: UMinExpr has a non-constant operand");
return ValidatorResult(SCEVType::INVALID);
}
}
@@ -344,7 +345,7 @@ public:
ValidatorResult Op = visit(Expr->getOperand(i));
if (!Op.isConstant()) {
- LLVM_DEBUG(
+ POLLY_DEBUG(
dbgs()
<< "INVALID: SCEVSequentialUMinExpr has a non-constant operand");
return ValidatorResult(SCEVType::INVALID);
@@ -356,8 +357,8 @@ public:
ValidatorResult visitGenericInst(Instruction *I, const SCEV *S) {
if (R->contains(I)) {
- LLVM_DEBUG(dbgs() << "INVALID: UnknownExpr references an instruction "
- "within the region\n");
+ POLLY_DEBUG(dbgs() << "INVALID: UnknownExpr references an instruction "
+ "within the region\n");
return ValidatorResult(SCEVType::INVALID);
}
@@ -393,7 +394,7 @@ public:
if (LHS.isConstant() && RHS.isConstant())
return ValidatorResult(SCEVType::PARAM, DivExpr);
- LLVM_DEBUG(
+ POLLY_DEBUG(
dbgs() << "INVALID: unsigned division of non-constant expressions");
return ValidatorResult(SCEVType::INVALID);
}
@@ -434,12 +435,13 @@ public:
Value *V = Expr->getValue();
if (!Expr->getType()->isIntegerTy() && !Expr->getType()->isPointerTy()) {
- LLVM_DEBUG(dbgs() << "INVALID: UnknownExpr is not an integer or pointer");
+ POLLY_DEBUG(
+ dbgs() << "INVALID: UnknownExpr is not an integer or pointer");
return ValidatorResult(SCEVType::INVALID);
}
if (isa<UndefValue>(V)) {
- LLVM_DEBUG(dbgs() << "INVALID: UnknownExpr references an undef value");
+ POLLY_DEBUG(dbgs() << "INVALID: UnknownExpr references an undef value");
return ValidatorResult(SCEVType::INVALID);
}
@@ -601,7 +603,7 @@ bool polly::isAffineExpr(const Region *R, llvm::Loop *Scope, const SCEV *Expr,
return false;
SCEVValidator Validator(R, Scope, SE, ILS);
- LLVM_DEBUG({
+ POLLY_DEBUG({
dbgs() << "\n";
dbgs() << "Expr: " << *Expr << "\n";
dbgs() << "Region: " << R->getNameStr() << "\n";
@@ -610,7 +612,7 @@ bool polly::isAffineExpr(const Region *R, llvm::Loop *Scope, const SCEV *Expr,
ValidatorResult Result = Validator.visit(Expr);
- LLVM_DEBUG({
+ POLLY_DEBUG({
if (Result.isValid())
dbgs() << "VALID\n";
dbgs() << "\n";
diff --git a/polly/lib/Transform/DeLICM.cpp b/polly/lib/Transform/DeLICM.cpp
index dae5e79..8afa637 100644
--- a/polly/lib/Transform/DeLICM.cpp
+++ b/polly/lib/Transform/DeLICM.cpp
@@ -26,6 +26,7 @@
#include "llvm/ADT/Statistic.h"
#include "llvm/InitializePasses.h"
+#include "polly/Support/PollyDebug.h"
#define DEBUG_TYPE "polly-delicm"
using namespace polly;
@@ -547,7 +548,7 @@ private:
/// @see Knowledge::isConflicting
bool isConflicting(const Knowledge &Proposed) {
raw_ostream *OS = nullptr;
- LLVM_DEBUG(OS = &llvm::dbgs());
+ POLLY_DEBUG(OS = &llvm::dbgs());
return Knowledge::isConflicting(Zone, Proposed, OS, 4);
}
@@ -559,7 +560,7 @@ private:
if (SAI->isValueKind()) {
auto *MA = S->getValueDef(SAI);
if (!MA) {
- LLVM_DEBUG(
+ POLLY_DEBUG(
dbgs()
<< " Reject because value is read-only within the scop\n");
return false;
@@ -576,7 +577,7 @@ private:
auto UserInst = cast<Instruction>(User);
if (!S->contains(UserInst)) {
- LLVM_DEBUG(dbgs() << " Reject because value is escaping\n");
+ POLLY_DEBUG(dbgs() << " Reject because value is escaping\n");
return false;
}
}
@@ -593,9 +594,9 @@ private:
auto PHI = cast<PHINode>(MA->getAccessInstruction());
for (auto Incoming : PHI->blocks()) {
if (!S->contains(Incoming)) {
- LLVM_DEBUG(dbgs()
- << " Reject because at least one incoming block is "
- "not in the scop region\n");
+ POLLY_DEBUG(dbgs()
+ << " Reject because at least one incoming block is "
+ "not in the scop region\n");
return false;
}
}
@@ -603,7 +604,7 @@ private:
return true;
}
- LLVM_DEBUG(dbgs() << " Reject ExitPHI or other non-value\n");
+ POLLY_DEBUG(dbgs() << " Reject ExitPHI or other non-value\n");
return false;
}
@@ -686,12 +687,12 @@ private:
// { DomainDef[] -> Element[] }
auto DefTarget = TargetElt.apply_domain(DefSched.reverse());
simplify(DefTarget);
- LLVM_DEBUG(dbgs() << " Def Mapping: " << DefTarget << '\n');
+ POLLY_DEBUG(dbgs() << " Def Mapping: " << DefTarget << '\n');
auto OrigDomain = getDomainFor(DefMA);
auto MappedDomain = DefTarget.domain();
if (!OrigDomain.is_subset(MappedDomain)) {
- LLVM_DEBUG(
+ POLLY_DEBUG(
dbgs()
<< " Reject because mapping does not encompass all instances\n");
return false;
@@ -704,7 +705,7 @@ private:
isl::union_map DefUses;
std::tie(DefUses, Lifetime) = computeValueUses(SAI);
- LLVM_DEBUG(dbgs() << " Lifetime: " << Lifetime << '\n');
+ POLLY_DEBUG(dbgs() << " Lifetime: " << Lifetime << '\n');
/// { [Element[] -> Zone[]] }
auto EltZone = Lifetime.apply_domain(DefTarget).wrap();
@@ -858,12 +859,12 @@ private:
// { DomainRead[] -> Element[] }
auto PHITarget = PHISched.apply_range(TargetElt);
simplify(PHITarget);
- LLVM_DEBUG(dbgs() << " Mapping: " << PHITarget << '\n');
+ POLLY_DEBUG(dbgs() << " Mapping: " << PHITarget << '\n');
auto OrigDomain = getDomainFor(PHIRead);
auto MappedDomain = PHITarget.domain();
if (!OrigDomain.is_subset(MappedDomain)) {
- LLVM_DEBUG(
+ POLLY_DEBUG(
dbgs()
<< " Reject because mapping does not encompass all instances\n");
return false;
@@ -872,7 +873,7 @@ private:
// { DomainRead[] -> DomainWrite[] }
auto PerPHIWrites = computePerPHI(SAI);
if (PerPHIWrites.is_null()) {
- LLVM_DEBUG(
+ POLLY_DEBUG(
dbgs() << " Reject because cannot determine incoming values\n");
return false;
}
@@ -894,17 +895,17 @@ private:
auto ExpandedWritesDom = WritesTarget.domain();
if (!DelicmPartialWrites &&
!UniverseWritesDom.is_subset(ExpandedWritesDom)) {
- LLVM_DEBUG(
+ POLLY_DEBUG(
dbgs() << " Reject because did not find PHI write mapping for "
"all instances\n");
if (DelicmOverapproximateWrites)
- LLVM_DEBUG(dbgs() << " Relevant Mapping: "
- << RelevantWritesTarget << '\n');
- LLVM_DEBUG(dbgs() << " Deduced Mapping: " << WritesTarget
- << '\n');
- LLVM_DEBUG(dbgs() << " Missing instances: "
- << UniverseWritesDom.subtract(ExpandedWritesDom)
- << '\n');
+ POLLY_DEBUG(dbgs() << " Relevant Mapping: "
+ << RelevantWritesTarget << '\n');
+ POLLY_DEBUG(dbgs() << " Deduced Mapping: " << WritesTarget
+ << '\n');
+ POLLY_DEBUG(dbgs() << " Missing instances: "
+ << UniverseWritesDom.subtract(ExpandedWritesDom)
+ << '\n');
return false;
}
@@ -916,7 +917,7 @@ private:
// { DomainRead[] -> Zone[] }
auto Lifetime = betweenScatter(PerPHIWriteScatter, PHISched, false, true);
simplify(Lifetime);
- LLVM_DEBUG(dbgs() << " Lifetime: " << Lifetime << "\n");
+ POLLY_DEBUG(dbgs() << " Lifetime: " << Lifetime << "\n");
// { DomainWrite[] -> Zone[] }
auto WriteLifetime = isl::union_map(Lifetime).apply_domain(PerPHIWrites);
@@ -1029,7 +1030,7 @@ private:
// Use the target store's write location as a suggestion to map scalars to.
auto EltTarget = Target.apply_range(TargetAccRel);
simplify(EltTarget);
- LLVM_DEBUG(dbgs() << " Target mapping is " << EltTarget << '\n');
+ POLLY_DEBUG(dbgs() << " Target mapping is " << EltTarget << '\n');
// Stack of elements not yet processed.
SmallVector<MemoryAccess *, 16> Worklist;
@@ -1067,8 +1068,8 @@ private:
if (Closed.count(SAI))
continue;
Closed.insert(SAI);
- LLVM_DEBUG(dbgs() << "\n Trying to map " << MA << " (SAI: " << SAI
- << ")\n");
+ POLLY_DEBUG(dbgs() << "\n Trying to map " << MA << " (SAI: " << SAI
+ << ")\n");
// Skip non-mappable scalars.
if (!isMappable(SAI))
@@ -1076,7 +1077,7 @@ private:
auto MASize = DL.getTypeAllocSize(MA->getAccessValue()->getType());
if (MASize > StoreSize) {
- LLVM_DEBUG(
+ POLLY_DEBUG(
dbgs() << " Reject because storage size is insufficient\n");
continue;
}
@@ -1212,7 +1213,7 @@ public:
"The only reason that these things have not been computed should "
"be if the max-operations limit hit");
DeLICMOutOfQuota++;
- LLVM_DEBUG(dbgs() << "DeLICM analysis exceeded max_operations\n");
+ POLLY_DEBUG(dbgs() << "DeLICM analysis exceeded max_operations\n");
DebugLoc Begin, End;
getDebugLocations(getBBPairForRegion(&S->getRegion()), Begin, End);
OptimizationRemarkAnalysis R(DEBUG_TYPE, "OutOfQuota", Begin,
@@ -1223,7 +1224,7 @@ public:
}
Zone = OriginalZone = Knowledge({}, EltUnused, EltKnown, EltWritten);
- LLVM_DEBUG(dbgs() << "Computed Zone:\n"; OriginalZone.print(dbgs(), 4));
+ POLLY_DEBUG(dbgs() << "Computed Zone:\n"; OriginalZone.print(dbgs(), 4));
assert(Zone.isUsable() && OriginalZone.isUsable());
return true;
@@ -1245,8 +1246,8 @@ public:
continue;
if (MA->isMayWrite()) {
- LLVM_DEBUG(dbgs() << "Access " << MA
- << " pruned because it is a MAY_WRITE\n");
+ POLLY_DEBUG(dbgs() << "Access " << MA
+ << " pruned because it is a MAY_WRITE\n");
OptimizationRemarkMissed R(DEBUG_TYPE, "TargetMayWrite",
MA->getAccessInstruction());
R << "Skipped possible mapping target because it is not an "
@@ -1256,8 +1257,8 @@ public:
}
if (Stmt.getNumIterators() == 0) {
- LLVM_DEBUG(dbgs() << "Access " << MA
- << " pruned because it is not in a loop\n");
+ POLLY_DEBUG(dbgs() << "Access " << MA
+ << " pruned because it is not in a loop\n");
OptimizationRemarkMissed R(DEBUG_TYPE, "WriteNotInLoop",
MA->getAccessInstruction());
R << "skipped possible mapping target because it is not in a loop";
@@ -1266,9 +1267,9 @@ public:
}
if (isScalarAccess(MA)) {
- LLVM_DEBUG(dbgs()
- << "Access " << MA
- << " pruned because it writes only a single element\n");
+ POLLY_DEBUG(dbgs()
+ << "Access " << MA
+ << " pruned because it writes only a single element\n");
OptimizationRemarkMissed R(DEBUG_TYPE, "ScalarWrite",
MA->getAccessInstruction());
R << "skipped possible mapping target because the memory location "
@@ -1278,8 +1279,8 @@ public:
}
if (!isa<StoreInst>(MA->getAccessInstruction())) {
- LLVM_DEBUG(dbgs() << "Access " << MA
- << " pruned because it is not a StoreInst\n");
+ POLLY_DEBUG(dbgs() << "Access " << MA
+ << " pruned because it is not a StoreInst\n");
OptimizationRemarkMissed R(DEBUG_TYPE, "NotAStore",
MA->getAccessInstruction());
R << "skipped possible mapping target because non-store instructions "
@@ -1301,9 +1302,9 @@ public:
// arguments.
isl::union_map AccRel = MA->getLatestAccessRelation();
if (!AccRel.is_single_valued().is_true()) {
- LLVM_DEBUG(dbgs() << "Access " << MA
- << " is incompatible because it writes multiple "
- "elements per instance\n");
+ POLLY_DEBUG(dbgs() << "Access " << MA
+ << " is incompatible because it writes multiple "
+ "elements per instance\n");
OptimizationRemarkMissed R(DEBUG_TYPE, "NonFunctionalAccRel",
MA->getAccessInstruction());
R << "skipped possible mapping target because it writes more than "
@@ -1314,7 +1315,7 @@ public:
isl::union_set TouchedElts = AccRel.range();
if (!TouchedElts.is_subset(CompatibleElts)) {
- LLVM_DEBUG(
+ POLLY_DEBUG(
dbgs()
<< "Access " << MA
<< " is incompatible because it touches incompatible elements\n");
@@ -1328,7 +1329,7 @@ public:
assert(isCompatibleAccess(MA));
NumberOfCompatibleTargets++;
- LLVM_DEBUG(dbgs() << "Analyzing target access " << MA << "\n");
+ POLLY_DEBUG(dbgs() << "Analyzing target access " << MA << "\n");
if (collapseScalarsToStore(MA))
Modified = true;
}
@@ -1361,15 +1362,15 @@ static std::unique_ptr<DeLICMImpl> collapseToUnused(Scop &S, LoopInfo &LI) {
std::unique_ptr<DeLICMImpl> Impl = std::make_unique<DeLICMImpl>(&S, &LI);
if (!Impl->computeZone()) {
- LLVM_DEBUG(dbgs() << "Abort because cannot reliably compute lifetimes\n");
+ POLLY_DEBUG(dbgs() << "Abort because cannot reliably compute lifetimes\n");
return Impl;
}
- LLVM_DEBUG(dbgs() << "Collapsing scalars to unused array elements...\n");
+ POLLY_DEBUG(dbgs() << "Collapsing scalars to unused array elements...\n");
Impl->greedyCollapse();
- LLVM_DEBUG(dbgs() << "\nFinal Scop:\n");
- LLVM_DEBUG(dbgs() << S);
+ POLLY_DEBUG(dbgs() << "\nFinal Scop:\n");
+ POLLY_DEBUG(dbgs() << S);
return Impl;
}
diff --git a/polly/lib/Transform/FlattenAlgo.cpp b/polly/lib/Transform/FlattenAlgo.cpp
index f8ed332..27a699e 100644
--- a/polly/lib/Transform/FlattenAlgo.cpp
+++ b/polly/lib/Transform/FlattenAlgo.cpp
@@ -14,6 +14,7 @@
#include "polly/FlattenAlgo.h"
#include "polly/Support/ISLOStream.h"
#include "polly/Support/ISLTools.h"
+#include "polly/Support/PollyDebug.h"
#include "llvm/Support/Debug.h"
#define DEBUG_TYPE "polly-flatten-algo"
@@ -171,7 +172,7 @@ isl::union_map tryFlattenSequence(isl::union_map Schedule) {
// Would cause an infinite loop.
if (!isDimBoundedByConstant(ScatterSet, 0)) {
- LLVM_DEBUG(dbgs() << "Abort; dimension is not of fixed size\n");
+ POLLY_DEBUG(dbgs() << "Abort; dimension is not of fixed size\n");
return {};
}
@@ -182,8 +183,8 @@ isl::union_map tryFlattenSequence(isl::union_map Schedule) {
auto Counter = isl::pw_aff(isl::local_space(ParamSpace.set_from_params()));
while (!ScatterSet.is_empty()) {
- LLVM_DEBUG(dbgs() << "Next counter:\n " << Counter << "\n");
- LLVM_DEBUG(dbgs() << "Remaining scatter set:\n " << ScatterSet << "\n");
+ POLLY_DEBUG(dbgs() << "Next counter:\n " << Counter << "\n");
+ POLLY_DEBUG(dbgs() << "Remaining scatter set:\n " << ScatterSet << "\n");
auto ThisSet = ScatterSet.project_out(isl::dim::set, 1, Dims - 1);
auto ThisFirst = ThisSet.lexmin();
auto ScatterFirst = ThisFirst.add_dims(isl::dim::set, Dims - 1);
@@ -199,11 +200,11 @@ isl::union_map tryFlattenSequence(isl::union_map Schedule) {
auto RemainingSubSchedule = scheduleProjectOut(SubSchedule, 0, 1);
auto FirstSubScatter = isl::set(FirstSubSchedule.range());
- LLVM_DEBUG(dbgs() << "Next step in sequence is:\n " << FirstSubScatter
- << "\n");
+ POLLY_DEBUG(dbgs() << "Next step in sequence is:\n " << FirstSubScatter
+ << "\n");
if (!isDimBoundedByParameter(FirstSubScatter, 0)) {
- LLVM_DEBUG(dbgs() << "Abort; sequence step is not bounded\n");
+ POLLY_DEBUG(dbgs() << "Abort; sequence step is not bounded\n");
return {};
}
@@ -236,8 +237,8 @@ isl::union_map tryFlattenSequence(isl::union_map Schedule) {
Counter = Counter.add(PartLen);
}
- LLVM_DEBUG(dbgs() << "Sequence-flatten result is:\n " << NewSchedule
- << "\n");
+ POLLY_DEBUG(dbgs() << "Sequence-flatten result is:\n " << NewSchedule
+ << "\n");
return NewSchedule;
}
@@ -266,20 +267,20 @@ isl::union_map tryFlattenLoop(isl::union_map Schedule) {
SubExtent = SubExtent.project_out(isl::dim::set, 1, SubDims - 1);
if (!isDimBoundedByConstant(SubExtent, 0)) {
- LLVM_DEBUG(dbgs() << "Abort; dimension not bounded by constant\n");
+ POLLY_DEBUG(dbgs() << "Abort; dimension not bounded by constant\n");
return {};
}
auto Min = SubExtent.dim_min(0);
- LLVM_DEBUG(dbgs() << "Min bound:\n " << Min << "\n");
+ POLLY_DEBUG(dbgs() << "Min bound:\n " << Min << "\n");
auto MinVal = getConstant(Min, false, true);
auto Max = SubExtent.dim_max(0);
- LLVM_DEBUG(dbgs() << "Max bound:\n " << Max << "\n");
+ POLLY_DEBUG(dbgs() << "Max bound:\n " << Max << "\n");
auto MaxVal = getConstant(Max, true, false);
if (MinVal.is_null() || MaxVal.is_null() || MinVal.is_nan() ||
MaxVal.is_nan()) {
- LLVM_DEBUG(dbgs() << "Abort; dimension bounds could not be determined\n");
+ POLLY_DEBUG(dbgs() << "Abort; dimension bounds could not be determined\n");
return {};
}
@@ -297,15 +298,15 @@ isl::union_map tryFlattenLoop(isl::union_map Schedule) {
auto IndexMap = isl::union_map::from(Index);
auto Result = IndexMap.flat_range_product(RemainingSubSchedule);
- LLVM_DEBUG(dbgs() << "Loop-flatten result is:\n " << Result << "\n");
+ POLLY_DEBUG(dbgs() << "Loop-flatten result is:\n " << Result << "\n");
return Result;
}
} // anonymous namespace
isl::union_map polly::flattenSchedule(isl::union_map Schedule) {
unsigned Dims = getNumScatterDims(Schedule);
- LLVM_DEBUG(dbgs() << "Recursive schedule to process:\n " << Schedule
- << "\n");
+ POLLY_DEBUG(dbgs() << "Recursive schedule to process:\n " << Schedule
+ << "\n");
// Base case; no dimensions left
if (Dims == 0) {
@@ -319,20 +320,20 @@ isl::union_map polly::flattenSchedule(isl::union_map Schedule) {
// Fixed dimension; no need to preserve variabledness.
if (!isVariableDim(Schedule)) {
- LLVM_DEBUG(dbgs() << "Fixed dimension; try sequence flattening\n");
+ POLLY_DEBUG(dbgs() << "Fixed dimension; try sequence flattening\n");
auto NewScheduleSequence = tryFlattenSequence(Schedule);
if (!NewScheduleSequence.is_null())
return NewScheduleSequence;
}
// Constant stride
- LLVM_DEBUG(dbgs() << "Try loop flattening\n");
+ POLLY_DEBUG(dbgs() << "Try loop flattening\n");
auto NewScheduleLoop = tryFlattenLoop(Schedule);
if (!NewScheduleLoop.is_null())
return NewScheduleLoop;
// Try again without loop condition (may blow up the number of pieces!!)
- LLVM_DEBUG(dbgs() << "Try sequence flattening again\n");
+ POLLY_DEBUG(dbgs() << "Try sequence flattening again\n");
auto NewScheduleSequence = tryFlattenSequence(Schedule);
if (!NewScheduleSequence.is_null())
return NewScheduleSequence;
diff --git a/polly/lib/Transform/FlattenSchedule.cpp b/polly/lib/Transform/FlattenSchedule.cpp
index 87bf642..f514ef3 100644
--- a/polly/lib/Transform/FlattenSchedule.cpp
+++ b/polly/lib/Transform/FlattenSchedule.cpp
@@ -18,6 +18,7 @@
#include "polly/ScopPass.h"
#include "polly/Support/ISLOStream.h"
#include "polly/Support/ISLTools.h"
+#include "polly/Support/PollyDebug.h"
#define DEBUG_TYPE "polly-flatten-schedule"
using namespace polly;
@@ -57,23 +58,23 @@ public:
// OldSchedule.
IslCtx = S.getSharedIslCtx();
- LLVM_DEBUG(dbgs() << "Going to flatten old schedule:\n");
+ POLLY_DEBUG(dbgs() << "Going to flatten old schedule:\n");
OldSchedule = S.getSchedule();
- LLVM_DEBUG(printSchedule(dbgs(), OldSchedule, 2));
+ POLLY_DEBUG(printSchedule(dbgs(), OldSchedule, 2));
auto Domains = S.getDomains();
auto RestrictedOldSchedule = OldSchedule.intersect_domain(Domains);
- LLVM_DEBUG(dbgs() << "Old schedule with domains:\n");
- LLVM_DEBUG(printSchedule(dbgs(), RestrictedOldSchedule, 2));
+ POLLY_DEBUG(dbgs() << "Old schedule with domains:\n");
+ POLLY_DEBUG(printSchedule(dbgs(), RestrictedOldSchedule, 2));
auto NewSchedule = flattenSchedule(RestrictedOldSchedule);
- LLVM_DEBUG(dbgs() << "Flattened new schedule:\n");
- LLVM_DEBUG(printSchedule(dbgs(), NewSchedule, 2));
+ POLLY_DEBUG(dbgs() << "Flattened new schedule:\n");
+ POLLY_DEBUG(printSchedule(dbgs(), NewSchedule, 2));
NewSchedule = NewSchedule.gist_domain(Domains);
- LLVM_DEBUG(dbgs() << "Gisted, flattened new schedule:\n");
- LLVM_DEBUG(printSchedule(dbgs(), NewSchedule, 2));
+ POLLY_DEBUG(dbgs() << "Gisted, flattened new schedule:\n");
+ POLLY_DEBUG(printSchedule(dbgs(), NewSchedule, 2));
S.setSchedule(NewSchedule);
return false;
diff --git a/polly/lib/Transform/ForwardOpTree.cpp b/polly/lib/Transform/ForwardOpTree.cpp
index 5e6de2e..e9be6c9 100644
--- a/polly/lib/Transform/ForwardOpTree.cpp
+++ b/polly/lib/Transform/ForwardOpTree.cpp
@@ -40,6 +40,7 @@
#include <cassert>
#include <memory>
+#include "polly/Support/PollyDebug.h"
#define DEBUG_TYPE "polly-optree"
using namespace llvm;
@@ -171,7 +172,7 @@ struct ForwardingAction {
Result.Decision =
IsProfitable ? FD_CanForwardProfitably : FD_CanForwardLeaf;
Result.Execute = [=]() {
- LLVM_DEBUG(dbgs() << " trivially forwarded: " << *Val << "\n");
+ POLLY_DEBUG(dbgs() << " trivially forwarded: " << *Val << "\n");
return true;
};
return Result;
@@ -368,12 +369,12 @@ public:
Known = {};
Translator = {};
NormalizeMap = {};
- LLVM_DEBUG(dbgs() << "Known analysis exceeded max_operations\n");
+ POLLY_DEBUG(dbgs() << "Known analysis exceeded max_operations\n");
return false;
}
KnownAnalyzed++;
- LLVM_DEBUG(dbgs() << "All known: " << Known << "\n");
+ POLLY_DEBUG(dbgs() << "All known: " << Known << "\n");
return true;
}
@@ -490,7 +491,7 @@ public:
// do not add another MemoryAccess.
auto ExecAction = [this, TargetStmt, LI, Access]() -> bool {
TargetStmt->prependInstruction(LI);
- LLVM_DEBUG(
+ POLLY_DEBUG(
dbgs() << " forwarded known load with preexisting MemoryAccess"
<< Access << "\n");
(void)Access;
@@ -528,10 +529,10 @@ public:
if (SameVal.is_null())
return ForwardingAction::notApplicable();
- LLVM_DEBUG(dbgs() << " expected values where " << TargetExpectedVal
- << "\n");
- LLVM_DEBUG(dbgs() << " candidate elements where " << Candidates
- << "\n");
+ POLLY_DEBUG(dbgs() << " expected values where " << TargetExpectedVal
+ << "\n");
+ POLLY_DEBUG(dbgs() << " candidate elements where " << Candidates
+ << "\n");
// { ValInst[] }
isl::space ValInstSpace = ExpectedVal.get_space().range();
@@ -568,8 +569,8 @@ public:
// { [TargetDomain[] -> Value[]] -> [DefDomain[] -> Value] }
LocalTranslator = DefToTarget.reverse().product(ValToVal);
- LLVM_DEBUG(dbgs() << " local translator is " << LocalTranslator
- << "\n");
+ POLLY_DEBUG(dbgs() << " local translator is " << LocalTranslator
+ << "\n");
if (LocalTranslator.is_null())
return ForwardingAction::notApplicable();
@@ -579,8 +580,8 @@ public:
LocalTranslator]() -> bool {
TargetStmt->prependInstruction(LI);
MemoryAccess *Access = makeReadArrayAccess(TargetStmt, LI, SameVal);
- LLVM_DEBUG(dbgs() << " forwarded known load with new MemoryAccess"
- << Access << "\n");
+ POLLY_DEBUG(dbgs() << " forwarded known load with new MemoryAccess"
+ << Access << "\n");
(void)Access;
if (!LocalTranslator.is_null())
@@ -643,8 +644,8 @@ public:
Access = TargetStmt->ensureValueRead(Inst);
Access->setNewAccessRelation(SameVal);
- LLVM_DEBUG(dbgs() << " forwarded known content of " << *Inst
- << " which is " << SameVal << "\n");
+ POLLY_DEBUG(dbgs() << " forwarded known content of " << *Inst
+ << " which is " << SameVal << "\n");
TotalReloads++;
NumReloads++;
return false;
@@ -712,8 +713,8 @@ public:
// instruction using them.
TargetStmt->prependInstruction(UseInst);
- LLVM_DEBUG(dbgs() << " forwarded speculable instruction: " << *UseInst
- << "\n");
+ POLLY_DEBUG(dbgs() << " forwarded speculable instruction: " << *UseInst
+ << "\n");
NumInstructionsCopied++;
TotalInstructionsCopied++;
return true;
@@ -765,7 +766,7 @@ public:
if (TargetUse.getKind() == VirtualUse::Synthesizable)
return ForwardingAction::triviallyForwardable(false, UseVal);
- LLVM_DEBUG(
+ POLLY_DEBUG(
dbgs() << " Synthesizable would not be synthesizable anymore: "
<< *UseVal << "\n");
return ForwardingAction::cannotForward();
@@ -779,8 +780,8 @@ public:
auto ExecAction = [this, TargetStmt, UseVal]() {
TargetStmt->ensureValueRead(UseVal);
- LLVM_DEBUG(dbgs() << " forwarded read-only value " << *UseVal
- << "\n");
+ POLLY_DEBUG(dbgs() << " forwarded read-only value " << *UseVal
+ << "\n");
NumReadOnlyCopied++;
TotalReadOnlyCopied++;
@@ -830,7 +831,8 @@ public:
// When no method is found to forward the operand tree, we effectively
// cannot handle it.
- LLVM_DEBUG(dbgs() << " Cannot forward instruction: " << *Inst << "\n");
+ POLLY_DEBUG(dbgs() << " Cannot forward instruction: " << *Inst
+ << "\n");
return ForwardingAction::cannotForward();
}
@@ -945,7 +947,7 @@ public:
/// Try to forward an operand tree rooted in @p RA.
bool tryForwardTree(MemoryAccess *RA) {
assert(RA->isLatestScalarKind());
- LLVM_DEBUG(dbgs() << "Trying to forward operand tree " << RA << "...\n");
+ POLLY_DEBUG(dbgs() << "Trying to forward operand tree " << RA << "...\n");
ScopStmt *Stmt = RA->getStatement();
Loop *InLoop = Stmt->getSurroundingLoop();
@@ -1036,22 +1038,22 @@ static std::unique_ptr<ForwardOpTreeImpl> runForwardOpTree(Scop &S,
Impl = std::make_unique<ForwardOpTreeImpl>(&S, &LI, MaxOpGuard);
if (AnalyzeKnown) {
- LLVM_DEBUG(dbgs() << "Prepare forwarders...\n");
+ POLLY_DEBUG(dbgs() << "Prepare forwarders...\n");
Impl->computeKnownValues();
}
- LLVM_DEBUG(dbgs() << "Forwarding operand trees...\n");
+ POLLY_DEBUG(dbgs() << "Forwarding operand trees...\n");
Impl->forwardOperandTrees();
if (MaxOpGuard.hasQuotaExceeded()) {
- LLVM_DEBUG(dbgs() << "Not all operations completed because of "
- "max_operations exceeded\n");
+ POLLY_DEBUG(dbgs() << "Not all operations completed because of "
+ "max_operations exceeded\n");
KnownOutOfQuota++;
}
}
- LLVM_DEBUG(dbgs() << "\nFinal Scop:\n");
- LLVM_DEBUG(dbgs() << S);
+ POLLY_DEBUG(dbgs() << "\nFinal Scop:\n");
+ POLLY_DEBUG(dbgs() << S);
// Update statistics
Scop::ScopStatistics ScopStats = S.getStatistics();
diff --git a/polly/lib/Transform/ManualOptimizer.cpp b/polly/lib/Transform/ManualOptimizer.cpp
index 264491b..0e330f2 100644
--- a/polly/lib/Transform/ManualOptimizer.cpp
+++ b/polly/lib/Transform/ManualOptimizer.cpp
@@ -22,6 +22,7 @@
#include "llvm/Transforms/Utils/LoopUtils.h"
#include <optional>
+#include "polly/Support/PollyDebug.h"
#define DEBUG_TYPE "polly-opt-manual"
using namespace polly;
@@ -159,13 +160,13 @@ private:
return Result;
LLVMContext &Ctx = LoopMD->getContext();
- LLVM_DEBUG(dbgs() << "Dependency violation detected\n");
+ POLLY_DEBUG(dbgs() << "Dependency violation detected\n");
DebugLoc TransformLoc = findTransformationDebugLoc(LoopMD, DebugLocAttr);
if (IgnoreDepcheck) {
- LLVM_DEBUG(dbgs() << "Still accepting transformation due to "
- "-polly-pragma-ignore-depcheck\n");
+ POLLY_DEBUG(dbgs() << "Still accepting transformation due to "
+ "-polly-pragma-ignore-depcheck\n");
if (ORE) {
ORE->emit(
OptimizationRemark(DEBUG_TYPE, RemarkName, TransformLoc, CodeRegion)
@@ -177,7 +178,7 @@ private:
return Result;
}
- LLVM_DEBUG(dbgs() << "Rolling back transformation\n");
+ POLLY_DEBUG(dbgs() << "Rolling back transformation\n");
if (ORE) {
ORE->emit(DiagnosticInfoOptimizationFailure(DEBUG_TYPE, RemarkName,
diff --git a/polly/lib/Transform/MatmulOptimizer.cpp b/polly/lib/Transform/MatmulOptimizer.cpp
index 05578bd..51ae5a7 100644
--- a/polly/lib/Transform/MatmulOptimizer.cpp
+++ b/polly/lib/Transform/MatmulOptimizer.cpp
@@ -42,6 +42,7 @@
#include <string>
#include <vector>
+#include "polly/Support/PollyDebug.h"
#define DEBUG_TYPE "polly-opt-isl"
using namespace llvm;
@@ -1825,10 +1826,10 @@ polly::tryOptimizeMatMulPattern(isl::schedule_node Node,
const Dependences *D) {
TCInfoTy TCI;
if (PMBasedTCOpts && isTCPattern(Node, D, TCI))
- LLVM_DEBUG(dbgs() << "The tensor contraction pattern was detected\n");
+ POLLY_DEBUG(dbgs() << "The tensor contraction pattern was detected\n");
MatMulInfoTy MMI;
if (PMBasedMMMOpts && isMatrMultPattern(Node, D, MMI)) {
- LLVM_DEBUG(dbgs() << "The matrix multiplication pattern was detected\n");
+ POLLY_DEBUG(dbgs() << "The matrix multiplication pattern was detected\n");
return optimizeMatMulPattern(Node, TTI, MMI);
}
return {};
diff --git a/polly/lib/Transform/ScheduleOptimizer.cpp b/polly/lib/Transform/ScheduleOptimizer.cpp
index 5a0ea3b..55d5198 100644
--- a/polly/lib/Transform/ScheduleOptimizer.cpp
+++ b/polly/lib/Transform/ScheduleOptimizer.cpp
@@ -69,6 +69,7 @@ class Loop;
class Module;
} // namespace llvm
+#include "polly/Support/PollyDebug.h"
#define DEBUG_TYPE "polly-opt-isl"
static cl::opt<std::string>
@@ -730,14 +731,14 @@ static void runIslScheduleOptimizer(
// Schedule without optimizations.
isl::schedule Schedule = S.getScheduleTree();
walkScheduleTreeForStatistics(S.getScheduleTree(), 0);
- LLVM_DEBUG(printSchedule(dbgs(), Schedule, "Original schedule tree"));
+ POLLY_DEBUG(printSchedule(dbgs(), Schedule, "Original schedule tree"));
bool HasUserTransformation = false;
if (PragmaBasedOpts) {
isl::schedule ManuallyTransformed = applyManualTransformations(
&S, Schedule, GetDeps(Dependences::AL_Statement), ORE);
if (ManuallyTransformed.is_null()) {
- LLVM_DEBUG(dbgs() << "Error during manual optimization\n");
+ POLLY_DEBUG(dbgs() << "Error during manual optimization\n");
return;
}
@@ -745,7 +746,7 @@ static void runIslScheduleOptimizer(
// User transformations have precedence over other transformations.
HasUserTransformation = true;
Schedule = std::move(ManuallyTransformed);
- LLVM_DEBUG(
+ POLLY_DEBUG(
printSchedule(dbgs(), Schedule, "After manual transformations"));
}
}
@@ -755,18 +756,18 @@ static void runIslScheduleOptimizer(
// TODO: Detect disabled heuristics and no user-directed transformation
// metadata earlier in ScopDetection.
if (!HasUserTransformation && S.hasDisableHeuristicsHint()) {
- LLVM_DEBUG(dbgs() << "Heuristic optimizations disabled by metadata\n");
+ POLLY_DEBUG(dbgs() << "Heuristic optimizations disabled by metadata\n");
return;
}
// Get dependency analysis.
const Dependences &D = GetDeps(Dependences::AL_Statement);
if (D.getSharedIslCtx() != S.getSharedIslCtx()) {
- LLVM_DEBUG(dbgs() << "DependenceInfo for another SCoP/isl_ctx\n");
+ POLLY_DEBUG(dbgs() << "DependenceInfo for another SCoP/isl_ctx\n");
return;
}
if (!D.hasValidDependences()) {
- LLVM_DEBUG(dbgs() << "Dependency information not available\n");
+ POLLY_DEBUG(dbgs() << "Dependency information not available\n");
return;
}
@@ -776,9 +777,9 @@ static void runIslScheduleOptimizer(
// are added by the rescheduling analyzer. Therefore, disabling the
// rescheduler implicitly also disables these optimizations.
if (!EnableReschedule) {
- LLVM_DEBUG(dbgs() << "Skipping rescheduling due to command line option\n");
+ POLLY_DEBUG(dbgs() << "Skipping rescheduling due to command line option\n");
} else if (HasUserTransformation) {
- LLVM_DEBUG(
+ POLLY_DEBUG(
dbgs() << "Skipping rescheduling due to manual transformation\n");
} else {
// Build input data.
@@ -824,10 +825,10 @@ static void runIslScheduleOptimizer(
"or 'no'. Falling back to default: 'yes'\n";
}
- LLVM_DEBUG(dbgs() << "\n\nCompute schedule from: ");
- LLVM_DEBUG(dbgs() << "Domain := " << Domain << ";\n");
- LLVM_DEBUG(dbgs() << "Proximity := " << Proximity << ";\n");
- LLVM_DEBUG(dbgs() << "Validity := " << Validity << ";\n");
+ POLLY_DEBUG(dbgs() << "\n\nCompute schedule from: ");
+ POLLY_DEBUG(dbgs() << "Domain := " << Domain << ";\n");
+ POLLY_DEBUG(dbgs() << "Proximity := " << Proximity << ";\n");
+ POLLY_DEBUG(dbgs() << "Validity := " << Validity << ";\n");
int IslMaximizeBands;
if (MaximizeBandDepth == "yes") {
@@ -873,14 +874,14 @@ static void runIslScheduleOptimizer(
Schedule = SC.compute_schedule();
if (MaxOpGuard.hasQuotaExceeded())
- LLVM_DEBUG(
+ POLLY_DEBUG(
dbgs() << "Schedule optimizer calculation exceeds ISL quota\n");
}
isl_options_set_on_error(Ctx, OnErrorStatus);
ScopsRescheduled++;
- LLVM_DEBUG(printSchedule(dbgs(), Schedule, "After rescheduling"));
+ POLLY_DEBUG(printSchedule(dbgs(), Schedule, "After rescheduling"));
}
walkScheduleTreeForStatistics(Schedule, 1);
@@ -908,7 +909,7 @@ static void runIslScheduleOptimizer(
if (OAI.PatternOpts || OAI.Postopts || OAI.Prevect) {
Schedule = ScheduleTreeOptimizer::optimizeSchedule(Schedule, &OAI);
Schedule = hoistExtensionNodes(Schedule);
- LLVM_DEBUG(printSchedule(dbgs(), Schedule, "After post-optimizations"));
+ POLLY_DEBUG(printSchedule(dbgs(), Schedule, "After post-optimizations"));
walkScheduleTreeForStatistics(Schedule, 2);
}
diff --git a/polly/lib/Transform/ScheduleTreeTransform.cpp b/polly/lib/Transform/ScheduleTreeTransform.cpp
index e42b3d1..f0684de 100644
--- a/polly/lib/Transform/ScheduleTreeTransform.cpp
+++ b/polly/lib/Transform/ScheduleTreeTransform.cpp
@@ -21,6 +21,7 @@
#include "llvm/IR/Metadata.h"
#include "llvm/Transforms/Utils/UnrollLoop.h"
+#include "polly/Support/PollyDebug.h"
#define DEBUG_TYPE "polly-opt-isl"
using namespace polly;
@@ -599,7 +600,7 @@ public:
if (Nest.size() <= 1)
return getBase().visitBand(Band);
- LLVM_DEBUG({
+ POLLY_DEBUG({
dbgs() << "Found loops to collapse between\n";
dumpIslObj(RootBand, dbgs());
dbgs() << "and\n";
@@ -644,7 +645,7 @@ public:
};
static isl::schedule collapseBands(isl::schedule Sched) {
- LLVM_DEBUG(dbgs() << "Collapse bands in schedule\n");
+ POLLY_DEBUG(dbgs() << "Collapse bands in schedule\n");
BandCollapseRewriter Rewriter;
return Rewriter.visit(Sched);
}
@@ -773,7 +774,7 @@ static isl::schedule tryGreedyFuse(isl::schedule_node_band LHS,
if (!canFuseOutermost(LHS, RHS, Deps))
return {};
- LLVM_DEBUG({
+ POLLY_DEBUG({
dbgs() << "Found loops for greedy fusion:\n";
dumpIslObj(LHS, dbgs());
dbgs() << "and\n";
@@ -1228,12 +1229,12 @@ isl::schedule polly::applyMaxFission(isl::schedule_node BandToFission) {
isl::schedule polly::applyGreedyFusion(isl::schedule Sched,
const isl::union_map &Deps) {
- LLVM_DEBUG(dbgs() << "Greedy loop fusion\n");
+ POLLY_DEBUG(dbgs() << "Greedy loop fusion\n");
GreedyFusionRewriter Rewriter;
isl::schedule Result = Rewriter.visit(Sched, Deps);
if (!Rewriter.AnyChange) {
- LLVM_DEBUG(dbgs() << "Found nothing to fuse\n");
+ POLLY_DEBUG(dbgs() << "Found nothing to fuse\n");
return Sched;
}
diff --git a/polly/lib/Transform/ScopInliner.cpp b/polly/lib/Transform/ScopInliner.cpp
index ca61407..b78206c 100644
--- a/polly/lib/Transform/ScopInliner.cpp
+++ b/polly/lib/Transform/ScopInliner.cpp
@@ -21,6 +21,7 @@
#include "llvm/Passes/PassBuilder.h"
#include "llvm/Transforms/IPO/AlwaysInliner.h"
+#include "polly/Support/PollyDebug.h"
#define DEBUG_TYPE "polly-scop-inliner"
using namespace llvm;
@@ -60,8 +61,8 @@ public:
if (!F)
return false;
if (F->isDeclaration()) {
- LLVM_DEBUG(dbgs() << "Skipping " << F->getName()
- << "because it is a declaration.\n");
+ POLLY_DEBUG(dbgs() << "Skipping " << F->getName()
+ << "because it is a declaration.\n");
return false;
}
@@ -86,8 +87,8 @@ public:
bool Changed = false;
if (HasScopAsTopLevelRegion) {
- LLVM_DEBUG(dbgs() << "Skipping " << F->getName()
- << " has scop as top level region");
+ POLLY_DEBUG(dbgs() << "Skipping " << F->getName()
+ << " has scop as top level region");
F->addFnAttr(llvm::Attribute::AlwaysInline);
ModulePassManager MPM;
@@ -98,8 +99,8 @@ public:
if (!PA.areAllPreserved())
Changed = true;
} else {
- LLVM_DEBUG(dbgs() << F->getName()
- << " does NOT have scop as top level region\n");
+ POLLY_DEBUG(dbgs() << F->getName()
+ << " does NOT have scop as top level region\n");
}
return Changed;
diff --git a/polly/lib/Transform/Simplify.cpp b/polly/lib/Transform/Simplify.cpp
index 41a155a..75e91cd 100644
--- a/polly/lib/Transform/Simplify.cpp
+++ b/polly/lib/Transform/Simplify.cpp
@@ -22,6 +22,7 @@
#include "llvm/Support/Debug.h"
#include <optional>
+#include "polly/Support/PollyDebug.h"
#define DEBUG_TYPE "polly-simplify"
using namespace llvm;
@@ -237,8 +238,8 @@ void SimplifyImpl::removeEmptyDomainStmts() {
assert(NumStmtsBefore >= S->getSize());
EmptyDomainsRemoved = NumStmtsBefore - S->getSize();
- LLVM_DEBUG(dbgs() << "Removed " << EmptyDomainsRemoved << " (of "
- << NumStmtsBefore << ") statements with empty domains \n");
+ POLLY_DEBUG(dbgs() << "Removed " << EmptyDomainsRemoved << " (of "
+ << NumStmtsBefore << ") statements with empty domains \n");
TotalEmptyDomainsRemoved[CallNo] += EmptyDomainsRemoved;
}
@@ -280,8 +281,8 @@ void SimplifyImpl::removeOverwrites() {
// If all of a write's elements are overwritten, remove it.
isl::union_map AccRelUnion = AccRel;
if (AccRelUnion.is_subset(WillBeOverwritten)) {
- LLVM_DEBUG(dbgs() << "Removing " << MA
- << " which will be overwritten anyway\n");
+ POLLY_DEBUG(dbgs() << "Removing " << MA
+ << " which will be overwritten anyway\n");
Stmt.removeSingleMemoryAccess(MA);
OverwritesRemoved++;
@@ -532,9 +533,9 @@ void SimplifyImpl::removeRedundantWrites() {
isl::map AccRelStoredVal = isl::map::from_domain_and_range(
AccRelWrapped, makeValueSet(StoredVal));
if (isl::union_map(AccRelStoredVal).is_subset(Known)) {
- LLVM_DEBUG(dbgs() << "Cleanup of " << MA << ":\n");
- LLVM_DEBUG(dbgs() << " Scalar: " << *StoredVal << "\n");
- LLVM_DEBUG(dbgs() << " AccRel: " << AccRel << "\n");
+ POLLY_DEBUG(dbgs() << "Cleanup of " << MA << ":\n");
+ POLLY_DEBUG(dbgs() << " Scalar: " << *StoredVal << "\n");
+ POLLY_DEBUG(dbgs() << " AccRel: " << AccRel << "\n");
Stmt.removeSingleMemoryAccess(MA);
@@ -576,8 +577,8 @@ void SimplifyImpl::removeUnnecessaryStmts() {
S->simplifySCoP(true);
assert(NumStmtsBefore >= S->getSize());
StmtsRemoved = NumStmtsBefore - S->getSize();
- LLVM_DEBUG(dbgs() << "Removed " << StmtsRemoved << " (of " << NumStmtsBefore
- << ") statements\n");
+ POLLY_DEBUG(dbgs() << "Removed " << StmtsRemoved << " (of " << NumStmtsBefore
+ << ") statements\n");
TotalStmtsRemoved[CallNo] += StmtsRemoved;
}
@@ -595,7 +596,7 @@ void SimplifyImpl::removeEmptyPartialAccesses() {
if (!AccRel.is_empty().is_true())
continue;
- LLVM_DEBUG(
+ POLLY_DEBUG(
dbgs() << "Removing " << MA
<< " because it's a partial access that never occurs\n");
DeferredRemove.push_back(MA);
@@ -628,8 +629,8 @@ void SimplifyImpl::markAndSweep(LoopInfo *LI) {
for (MemoryAccess *MA : AllMAs) {
if (UsedMA.count(MA))
continue;
- LLVM_DEBUG(dbgs() << "Removing " << MA
- << " because its value is not used\n");
+ POLLY_DEBUG(dbgs() << "Removing " << MA
+ << " because its value is not used\n");
ScopStmt *Stmt = MA->getStatement();
Stmt->removeSingleMemoryAccess(MA);
@@ -650,8 +651,8 @@ void SimplifyImpl::markAndSweep(LoopInfo *LI) {
for (Instruction *Inst : AllInsts) {
auto It = UsedInsts.find({&Stmt, Inst});
if (It == UsedInsts.end()) {
- LLVM_DEBUG(dbgs() << "Removing "; Inst->print(dbgs());
- dbgs() << " because it is not used\n");
+ POLLY_DEBUG(dbgs() << "Removing "; Inst->print(dbgs());
+ dbgs() << " because it is not used\n");
DeadInstructionsRemoved++;
TotalDeadInstructionsRemoved[CallNo]++;
continue;
@@ -708,31 +709,31 @@ void SimplifyImpl::run(Scop &S, LoopInfo *LI) {
this->S = &S;
ScopsProcessed[CallNo]++;
- LLVM_DEBUG(dbgs() << "Removing statements that are never executed...\n");
+ POLLY_DEBUG(dbgs() << "Removing statements that are never executed...\n");
removeEmptyDomainStmts();
- LLVM_DEBUG(dbgs() << "Removing partial writes that never happen...\n");
+ POLLY_DEBUG(dbgs() << "Removing partial writes that never happen...\n");
removeEmptyPartialAccesses();
- LLVM_DEBUG(dbgs() << "Removing overwrites...\n");
+ POLLY_DEBUG(dbgs() << "Removing overwrites...\n");
removeOverwrites();
- LLVM_DEBUG(dbgs() << "Coalesce partial writes...\n");
+ POLLY_DEBUG(dbgs() << "Coalesce partial writes...\n");
coalesceWrites();
- LLVM_DEBUG(dbgs() << "Removing redundant writes...\n");
+ POLLY_DEBUG(dbgs() << "Removing redundant writes...\n");
removeRedundantWrites();
- LLVM_DEBUG(dbgs() << "Cleanup unused accesses...\n");
+ POLLY_DEBUG(dbgs() << "Cleanup unused accesses...\n");
markAndSweep(LI);
- LLVM_DEBUG(dbgs() << "Removing statements without side effects...\n");
+ POLLY_DEBUG(dbgs() << "Removing statements without side effects...\n");
removeUnnecessaryStmts();
if (isModified())
ScopsModified[CallNo]++;
- LLVM_DEBUG(dbgs() << "\nFinal Scop:\n");
- LLVM_DEBUG(dbgs() << S);
+ POLLY_DEBUG(dbgs() << "\nFinal Scop:\n");
+ POLLY_DEBUG(dbgs() << S);
auto ScopStats = S.getStatistics();
NumValueWrites[CallNo] += ScopStats.NumValueWrites;
diff --git a/polly/lib/Transform/ZoneAlgo.cpp b/polly/lib/Transform/ZoneAlgo.cpp
index 4c86891..a114a24 100644
--- a/polly/lib/Transform/ZoneAlgo.cpp
+++ b/polly/lib/Transform/ZoneAlgo.cpp
@@ -156,6 +156,7 @@
#include "llvm/ADT/Statistic.h"
#include "llvm/Support/raw_ostream.h"
+#include "polly/Support/PollyDebug.h"
#define DEBUG_TYPE "polly-zone"
STATISTIC(NumIncompatibleArrays, "Number of not zone-analyzable arrays");
@@ -342,7 +343,7 @@ void ZoneAlgorithm::collectIncompatibleElts(ScopStmt *Stmt,
if (MA->isRead()) {
// Reject load after store to same location.
if (!Stores.is_disjoint(AccRel)) {
- LLVM_DEBUG(
+ POLLY_DEBUG(
dbgs() << "Load after store of same element in same statement\n");
OptimizationRemarkMissed R(PassName, "LoadAfterStore",
MA->getAccessInstruction());
@@ -362,7 +363,7 @@ void ZoneAlgorithm::collectIncompatibleElts(ScopStmt *Stmt,
// In region statements the order is less clear, eg. the load and store
// might be in a boxed loop.
if (Stmt->isRegionStmt() && !Loads.is_disjoint(AccRel)) {
- LLVM_DEBUG(dbgs() << "WRITE in non-affine subregion not supported\n");
+ POLLY_DEBUG(dbgs() << "WRITE in non-affine subregion not supported\n");
OptimizationRemarkMissed R(PassName, "StoreInSubregion",
MA->getAccessInstruction());
R << "store is in a non-affine subregion";
@@ -373,7 +374,7 @@ void ZoneAlgorithm::collectIncompatibleElts(ScopStmt *Stmt,
// Do not allow more than one store to the same location.
if (!Stores.is_disjoint(AccRel) && !onlySameValueWrites(Stmt)) {
- LLVM_DEBUG(dbgs() << "WRITE after WRITE to same element\n");
+ POLLY_DEBUG(dbgs() << "WRITE after WRITE to same element\n");
OptimizationRemarkMissed R(PassName, "StoreAfterStore",
MA->getAccessInstruction());
R << "store after store of same element in same statement";
diff --git a/polly/test/Support/pollyDebug.ll b/polly/test/Support/pollyDebug.ll
new file mode 100644
index 0000000..ada0790
--- /dev/null
+++ b/polly/test/Support/pollyDebug.ll
@@ -0,0 +1,85 @@
+; Test if "polly-debug" flag enables debug prints from different parts of polly
+; RUN: opt %loadNPMPolly -O3 -polly -polly-debug --disable-output < %s 2>&1 | FileCheck %s
+;
+; REQUIRES: asserts
+
+; void callee(int n, double A[], int i) {
+; for (int j = 0; j < n; j += 1)
+; A[i+j] = 42.0;
+; }
+;
+; void caller(int n, double A[]) {
+; for (int i = 0; i < n; i += 1)
+; callee(n, A, i);
+; }
+
+
+%unrelated_type = type { i32 }
+
+define internal void @callee(i32 %n, ptr noalias nonnull %A, i32 %i) #0 {
+entry:
+ br label %for
+
+for:
+ %j = phi i32 [0, %entry], [%j.inc, %inc]
+ %j.cmp = icmp slt i32 %j, %n
+ br i1 %j.cmp, label %body, label %exit
+
+ body:
+ %idx = add i32 %i, %j
+ %arrayidx = getelementptr inbounds double, ptr %A, i32 %idx
+ store double 42.0, ptr %arrayidx
+ br label %inc
+
+inc:
+ %j.inc = add nuw nsw i32 %j, 1
+ br label %for
+
+exit:
+ br label %return
+
+return:
+ ret void
+}
+
+
+define void @caller(i32 %n, ptr noalias nonnull %A) #0 {
+entry:
+ br label %for
+
+for:
+ %i = phi i32 [0, %entry], [%j.inc, %inc]
+ %i.cmp = icmp slt i32 %i, %n
+ br i1 %i.cmp, label %body, label %exit
+
+ body:
+ call void @callee(i32 %n, ptr %A, i32 %i)
+ br label %inc
+
+inc:
+ %j.inc = add nuw nsw i32 %i, 1
+ br label %for
+
+exit:
+ br label %return
+
+return:
+ ret void
+}
+
+
+declare void @unrelated_decl()
+
+
+attributes #0 = { noinline }
+
+!llvm.ident = !{!8}
+!8 = !{!"xyxxy"}
+
+; CHECK: Checking region: entry => <Function Return>
+; CHECK: Removing statements that are never executed...
+; CHECK: Final Scop:
+; CHECK: Forwarding operand trees...
+; CHECK: Final Scop:
+; CHECK: Collapsing scalars to unused array elements...
+; CHECK: Final Scop: