[polly] [polly] Add polly-debug flag to print debug info from all parts of polly (PR #78549)

Karthika Devi C via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 19 20:56:56 PST 2024


https://github.com/kartcq updated https://github.com/llvm/llvm-project/pull/78549

>From 1aeb149cb15e83c8880a99aa94db224737331aa6 Mon Sep 17 00:00:00 2001
From: kartcq <quic_kartc at quicinc.com>
Date: Fri, 15 Dec 2023 02:58:40 -0800
Subject: [PATCH 1/3] [polly] Add polly-debug flag to print debug info from all
 parts of polly

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.

Change-Id: I6ddb03d5e7debac16413fb364afb8811139c8073
---
 polly/include/polly/Support/PollyDebug.inc    | 33 +++++++++++++++++++
 polly/lib/Analysis/DependenceInfo.cpp         |  1 +
 polly/lib/Analysis/PolyhedralInfo.cpp         |  1 +
 polly/lib/Analysis/PruneUnprofitable.cpp      |  1 +
 polly/lib/Analysis/ScopBuilder.cpp            |  1 +
 polly/lib/Analysis/ScopDetection.cpp          |  1 +
 polly/lib/Analysis/ScopInfo.cpp               |  1 +
 polly/lib/CMakeLists.txt                      |  1 +
 polly/lib/CodeGen/CodeGeneration.cpp          |  1 +
 polly/lib/CodeGen/IslAst.cpp                  |  1 +
 polly/lib/Support/PollyDebug.cpp              | 27 +++++++++++++++
 polly/lib/Support/SCEVValidator.cpp           |  1 +
 polly/lib/Transform/DeLICM.cpp                |  1 +
 polly/lib/Transform/FlattenAlgo.cpp           |  1 +
 polly/lib/Transform/FlattenSchedule.cpp       |  1 +
 polly/lib/Transform/ForwardOpTree.cpp         |  1 +
 polly/lib/Transform/ManualOptimizer.cpp       |  1 +
 polly/lib/Transform/MatmulOptimizer.cpp       |  1 +
 polly/lib/Transform/ScheduleOptimizer.cpp     |  1 +
 polly/lib/Transform/ScheduleTreeTransform.cpp |  1 +
 polly/lib/Transform/ScopInliner.cpp           |  1 +
 polly/lib/Transform/Simplify.cpp              |  1 +
 polly/lib/Transform/ZoneAlgo.cpp              |  1 +
 23 files changed, 81 insertions(+)
 create mode 100644 polly/include/polly/Support/PollyDebug.inc
 create mode 100644 polly/lib/Support/PollyDebug.cpp

diff --git a/polly/include/polly/Support/PollyDebug.inc b/polly/include/polly/Support/PollyDebug.inc
new file mode 100644
index 00000000000000..84f13991251d90
--- /dev/null
+++ b/polly/include/polly/Support/PollyDebug.inc
@@ -0,0 +1,33 @@
+//===-PollyDebug.inc -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
+#undef LLVM_DEBUG
+#define LLVM_DEBUG(X)                                                          \
+  do {                                                                         \
+    if (polly::getPollyDebugFlag()) {                                          \
+      X;                                                                       \
+    } else {                                                                   \
+      DEBUG_WITH_TYPE(DEBUG_TYPE, X);                                          \
+    }                                                                          \
+  } while (0)
+#endif
+} // namespace polly
+#endif
diff --git a/polly/lib/Analysis/DependenceInfo.cpp b/polly/lib/Analysis/DependenceInfo.cpp
index 69257c603877ea..5df2e1329687c0 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.inc"
 #define DEBUG_TYPE "polly-dependence"
 
 static cl::opt<int> OptComputeOut(
diff --git a/polly/lib/Analysis/PolyhedralInfo.cpp b/polly/lib/Analysis/PolyhedralInfo.cpp
index 5c77be0a9a1fa9..5c7e61f0531d9a 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.inc"
 #define DEBUG_TYPE "polyhedral-info"
 
 static cl::opt<bool> CheckParallel("polly-check-parallel",
diff --git a/polly/lib/Analysis/PruneUnprofitable.cpp b/polly/lib/Analysis/PruneUnprofitable.cpp
index db4a3d73dc33aa..c73de1c143ac6d 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.inc"
 #define DEBUG_TYPE "polly-prune-unprofitable"
 
 namespace {
diff --git a/polly/lib/Analysis/ScopBuilder.cpp b/polly/lib/Analysis/ScopBuilder.cpp
index c62cb2a85c835c..b94b36bb22aa23 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.inc"
 #define DEBUG_TYPE "polly-scops"
 
 STATISTIC(ScopFound, "Number of valid Scops");
diff --git a/polly/lib/Analysis/ScopDetection.cpp b/polly/lib/Analysis/ScopDetection.cpp
index 938d3f149677ba..c96311314830fd 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.inc"
 #define DEBUG_TYPE "polly-detect"
 
 // This option is set to a very high value, as analyzing such loops increases
diff --git a/polly/lib/Analysis/ScopInfo.cpp b/polly/lib/Analysis/ScopInfo.cpp
index 3e78cc8937fbf0..2a9eb5d24f55bd 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.inc"
 #define DEBUG_TYPE "polly-scops"
 
 STATISTIC(AssumptionsAliasing, "Number of aliasing assumptions taken.");
diff --git a/polly/lib/CMakeLists.txt b/polly/lib/CMakeLists.txt
index 9780f24d5d36a7..4557878e515e66 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 3792d995fd9904..523b89c04eaf43 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.inc"
 #define DEBUG_TYPE "polly-codegen"
 
 static cl::opt<bool> Verify("polly-codegen-verify",
diff --git a/polly/lib/CodeGen/IslAst.cpp b/polly/lib/CodeGen/IslAst.cpp
index fe2b5d9104d7d0..6f5651abb3a857 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.inc"
 #define DEBUG_TYPE "polly-ast"
 
 using namespace llvm;
diff --git a/polly/lib/Support/PollyDebug.cpp b/polly/lib/Support/PollyDebug.cpp
new file mode 100644
index 00000000000000..c51a7a47372881
--- /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 "llvm/Support/CommandLine.h"
+
+#include "polly/Support/PollyDebug.inc"
+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 e3d9818597ea69..3f24f1b3c67cbf 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.inc"
 #define DEBUG_TYPE "polly-scev-validator"
 
 namespace SCEVType {
diff --git a/polly/lib/Transform/DeLICM.cpp b/polly/lib/Transform/DeLICM.cpp
index 51e701346563a1..a0b01f7a05cf8f 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.inc"
 #define DEBUG_TYPE "polly-delicm"
 
 using namespace polly;
diff --git a/polly/lib/Transform/FlattenAlgo.cpp b/polly/lib/Transform/FlattenAlgo.cpp
index f8ed332348ab1f..ddf542436487b7 100644
--- a/polly/lib/Transform/FlattenAlgo.cpp
+++ b/polly/lib/Transform/FlattenAlgo.cpp
@@ -15,6 +15,7 @@
 #include "polly/Support/ISLOStream.h"
 #include "polly/Support/ISLTools.h"
 #include "llvm/Support/Debug.h"
+#include "polly/Support/PollyDebug.inc"
 #define DEBUG_TYPE "polly-flatten-algo"
 
 using namespace polly;
diff --git a/polly/lib/Transform/FlattenSchedule.cpp b/polly/lib/Transform/FlattenSchedule.cpp
index 53e230be7a6945..193a357d9193e8 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.inc"
 #define DEBUG_TYPE "polly-flatten-schedule"
 
 using namespace polly;
diff --git a/polly/lib/Transform/ForwardOpTree.cpp b/polly/lib/Transform/ForwardOpTree.cpp
index 2bed3e35412d76..32567c7fa81b2b 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.inc"
 #define DEBUG_TYPE "polly-optree"
 
 using namespace llvm;
diff --git a/polly/lib/Transform/ManualOptimizer.cpp b/polly/lib/Transform/ManualOptimizer.cpp
index 264491b7577b34..89e2a7d763a972 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.inc"
 #define DEBUG_TYPE "polly-opt-manual"
 
 using namespace polly;
diff --git a/polly/lib/Transform/MatmulOptimizer.cpp b/polly/lib/Transform/MatmulOptimizer.cpp
index 05578bd9ed11e5..59ca15f82ea940 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.inc"
 #define DEBUG_TYPE "polly-opt-isl"
 
 using namespace llvm;
diff --git a/polly/lib/Transform/ScheduleOptimizer.cpp b/polly/lib/Transform/ScheduleOptimizer.cpp
index 8ee2b66339adbc..90f11311175da8 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.inc"
 #define DEBUG_TYPE "polly-opt-isl"
 
 static cl::opt<std::string>
diff --git a/polly/lib/Transform/ScheduleTreeTransform.cpp b/polly/lib/Transform/ScheduleTreeTransform.cpp
index e42b3d1c24604b..d87fd2c154e4b4 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.inc"
 #define DEBUG_TYPE "polly-opt-isl"
 
 using namespace polly;
diff --git a/polly/lib/Transform/ScopInliner.cpp b/polly/lib/Transform/ScopInliner.cpp
index ca61407d258739..41f7d5edd64d94 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.inc"
 #define DEBUG_TYPE "polly-scop-inliner"
 
 using namespace llvm;
diff --git a/polly/lib/Transform/Simplify.cpp b/polly/lib/Transform/Simplify.cpp
index 41a155a41de83d..f3e839af126c65 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.inc"
 #define DEBUG_TYPE "polly-simplify"
 
 using namespace llvm;
diff --git a/polly/lib/Transform/ZoneAlgo.cpp b/polly/lib/Transform/ZoneAlgo.cpp
index 4c86891d2cf7de..cdb1ad102b6e7b 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.inc"
 #define DEBUG_TYPE "polly-zone"
 
 STATISTIC(NumIncompatibleArrays, "Number of not zone-analyzable arrays");

>From 7b7f0f672ab43fdfd56d7af23e2bbb475d3fb319 Mon Sep 17 00:00:00 2001
From: Karthika Devi C <quic_kartc at quicinc.com>
Date: Thu, 18 Jan 2024 13:43:41 +0530
Subject: [PATCH 2/3] Update PollyDebug.inc

---
 polly/include/polly/Support/PollyDebug.inc | 1 -
 1 file changed, 1 deletion(-)

diff --git a/polly/include/polly/Support/PollyDebug.inc b/polly/include/polly/Support/PollyDebug.inc
index 84f13991251d90..bf087b1b7d6f63 100644
--- a/polly/include/polly/Support/PollyDebug.inc
+++ b/polly/include/polly/Support/PollyDebug.inc
@@ -10,7 +10,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-
 #ifndef POLLY_DEBUG_H
 #define POLLY_DEBUG_H
 

>From 82ae57e97330bf35acd3b9d06c86159fe6d4432a Mon Sep 17 00:00:00 2001
From: Karthika Devi C <quic_kartc at quicinc.com>
Date: Thu, 18 Jan 2024 14:22:29 +0530
Subject: [PATCH 3/3] Update FlattenAlgo.cpp

---
 polly/lib/Transform/FlattenAlgo.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/polly/lib/Transform/FlattenAlgo.cpp b/polly/lib/Transform/FlattenAlgo.cpp
index ddf542436487b7..a74025fd218f72 100644
--- a/polly/lib/Transform/FlattenAlgo.cpp
+++ b/polly/lib/Transform/FlattenAlgo.cpp
@@ -14,8 +14,8 @@
 #include "polly/FlattenAlgo.h"
 #include "polly/Support/ISLOStream.h"
 #include "polly/Support/ISLTools.h"
-#include "llvm/Support/Debug.h"
 #include "polly/Support/PollyDebug.inc"
+#include "llvm/Support/Debug.h"
 #define DEBUG_TYPE "polly-flatten-algo"
 
 using namespace polly;



More information about the llvm-commits mailing list