[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 26 22:52:20 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/7] [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/7] 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/7] 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;

>From 58141351f70b72ca06e55cc08e14a532d06ef48a Mon Sep 17 00:00:00 2001
From: Karthika Devi C <quic_kartc at quicinc.com>
Date: Thu, 22 Feb 2024 11:06:35 +0530
Subject: [PATCH 4/7] Update pollyDebug.ll

---
 polly/test/Support/pollyDebug.ll | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/polly/test/Support/pollyDebug.ll b/polly/test/Support/pollyDebug.ll
index b53fa243018c6e..d2496a4e94ea52 100644
--- a/polly/test/Support/pollyDebug.ll
+++ b/polly/test/Support/pollyDebug.ll
@@ -1,5 +1,5 @@
 ; 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
+; RUN: opt %loadPolly -O3 -polly -polly-debug --disable-output %s 2>&1 | FileCheck %s
 ;
 ; REQUIRES: asserts
 

>From 863d8e09125dd749a7b0ab209b4481d9606e1151 Mon Sep 17 00:00:00 2001
From: Karthika Devi C <quic_kartc at quicinc.com>
Date: Mon, 26 Feb 2024 14:12:37 +0530
Subject: [PATCH 5/7] Update pollyDebug.ll

---
 polly/test/Support/pollyDebug.ll | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/polly/test/Support/pollyDebug.ll b/polly/test/Support/pollyDebug.ll
index d2496a4e94ea52..ada079023b6c30 100644
--- a/polly/test/Support/pollyDebug.ll
+++ b/polly/test/Support/pollyDebug.ll
@@ -1,5 +1,5 @@
 ; Test if "polly-debug" flag enables debug prints from different parts of polly
-; RUN: opt %loadPolly -O3 -polly -polly-debug --disable-output %s 2>&1 | FileCheck %s
+; RUN: opt %loadNPMPolly -O3 -polly -polly-debug --disable-output < %s 2>&1 | FileCheck %s
 ;
 ; REQUIRES: asserts
 

>From ea2919ec4213dc33054f52aa2c1b72f19d2eee00 Mon Sep 17 00:00:00 2001
From: Karthika Devi C <quic_kartc at quicinc.com>
Date: Mon, 26 Feb 2024 22:09:39 -0800
Subject: [PATCH 6/7] Replace LLVM_DEBUG with POLLY_DEBUG in multiple polly
 files

---
 polly/lib/Analysis/DependenceInfo.cpp         | 18 +++---
 polly/lib/Analysis/PolyhedralInfo.cpp         | 10 +--
 polly/lib/Analysis/PruneUnprofitable.cpp      |  4 +-
 polly/lib/Analysis/ScopBuilder.cpp            | 26 ++++----
 polly/lib/Analysis/ScopDetection.cpp          | 22 +++----
 polly/lib/Analysis/ScopInfo.cpp               |  2 +-
 polly/lib/CodeGen/CodeGeneration.cpp          |  4 +-
 polly/lib/CodeGen/IslAst.cpp                  |  6 +-
 polly/lib/Support/DumpFunctionPass.cpp        |  8 +--
 polly/lib/Support/DumpModulePass.cpp          |  2 +-
 polly/lib/Support/SCEVValidator.cpp           | 28 ++++----
 polly/lib/Transform/DeLICM.cpp                | 64 +++++++++----------
 polly/lib/Transform/FlattenAlgo.cpp           | 30 ++++-----
 polly/lib/Transform/FlattenSchedule.cpp       | 16 ++---
 polly/lib/Transform/ForwardOpTree.cpp         | 38 +++++------
 polly/lib/Transform/ManualOptimizer.cpp       |  6 +-
 polly/lib/Transform/MatmulOptimizer.cpp       |  4 +-
 polly/lib/Transform/ScheduleOptimizer.cpp     | 30 ++++-----
 polly/lib/Transform/ScheduleTreeTransform.cpp | 10 +--
 polly/lib/Transform/ScopInliner.cpp           |  6 +-
 polly/lib/Transform/Simplify.cpp              | 36 +++++------
 polly/lib/Transform/ZoneAlgo.cpp              |  6 +-
 22 files changed, 188 insertions(+), 188 deletions(-)

diff --git a/polly/lib/Analysis/DependenceInfo.cpp b/polly/lib/Analysis/DependenceInfo.cpp
index fd2becec2bb215..05bafed737c3a1 100644
--- a/polly/lib/Analysis/DependenceInfo.cpp
+++ b/polly/lib/Analysis/DependenceInfo.cpp
@@ -301,7 +301,7 @@ 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()
+  POLLY_DEBUG(if (!Flow) dbgs()
                  << "last error: "
                  << isl_ctx_last_error(isl_schedule_get_ctx(Schedule))
                  << '\n';);
@@ -313,14 +313,14 @@ 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';
+  POLLY_DEBUG(dbgs() << "Read: " << Read << '\n';
              dbgs() << "MustWrite: " << MustWrite << '\n';
              dbgs() << "MayWrite: " << MayWrite << '\n';
              dbgs() << "ReductionTagMap: " << ReductionTagMap << '\n';
@@ -361,7 +361,7 @@ void Dependences::calculateDependences(Scop &S) {
     Schedule = isl_schedule_pullback_union_pw_multi_aff(Schedule, Tags);
   }
 
-  LLVM_DEBUG(dbgs() << "Read: " << Read << "\n";
+  POLLY_DEBUG(dbgs() << "Read: " << Read << "\n";
              dbgs() << "MustWrite: " << MustWrite << "\n";
              dbgs() << "MayWrite: " << MayWrite << "\n";
              dbgs() << "Schedule: " << Schedule << "\n");
@@ -505,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";
@@ -554,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";
@@ -604,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";
@@ -616,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";
@@ -632,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 6fc77ee84ce334..156441855aae18 100644
--- a/polly/lib/Analysis/PolyhedralInfo.cpp
+++ b/polly/lib/Analysis/PolyhedralInfo.cpp
@@ -78,18 +78,18 @@ 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")
+  POLLY_DEBUG(dbgs() << "Dependences :\t" << stringFromIslObj(Deps, "null")
                     << "\n");
 
   isl_union_map *Schedule = getScheduleForLoop(S, L);
-  LLVM_DEBUG(dbgs() << "Schedule: \t" << stringFromIslObj(Schedule, "null")
+  POLLY_DEBUG(dbgs() << "Schedule: \t" << stringFromIslObj(Schedule, "null")
                     << "\n");
 
   IsParallel = D.isParallel(Schedule, Deps, MinDepDistPtr);
@@ -126,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 0ca84d7662066a..f8469c03fe55bd 100644
--- a/polly/lib/Analysis/PruneUnprofitable.cpp
+++ b/polly/lib/Analysis/PruneUnprofitable.cpp
@@ -58,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;
@@ -67,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 434d5ede20f9e6..e21699ef904da2 100644
--- a/polly/lib/Analysis/ScopBuilder.cpp
+++ b/polly/lib/Analysis/ScopBuilder.cpp
@@ -2545,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 "
+  POLLY_DEBUG(dbgs() << " == The accessed space below is "
                     << (Valid ? "" : "not ") << "equal!\n");
-  LLVM_DEBUG(LoadMA->dump(); StoreMA->dump());
+  POLLY_DEBUG(LoadMA->dump(); StoreMA->dump());
 
   if (Valid) {
     // Then check if they actually access the same memory.
@@ -2561,7 +2561,7 @@ 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 ")
+    POLLY_DEBUG(dbgs() << " == The accessed memory is " << (Valid ? "" : "not ")
                       << "overlapping!\n");
   }
 
@@ -2572,7 +2572,7 @@ 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 " : "")
+    POLLY_DEBUG(dbgs() << " == The accessed memory is " << (Valid ? "not " : "")
                       << "accessed by other instructions!\n");
   }
   return Valid;
@@ -3241,7 +3241,7 @@ bool ScopBuilder::buildAliasChecks() {
   // we make the assumed context infeasible.
   scop->invalidate(ALIASING, DebugLoc());
 
-  LLVM_DEBUG(dbgs() << "\n\nNOTE: Run time checks for " << scop->getNameStr()
+  POLLY_DEBUG(dbgs() << "\n\nNOTE: Run time checks for " << scop->getNameStr()
                     << " could not be created. This SCoP has been dismissed.");
   return false;
 }
@@ -3563,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;
   }
@@ -3583,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;
   }
 
@@ -3600,7 +3600,7 @@ 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;
   }
 
@@ -3608,7 +3608,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;
   }
@@ -3627,7 +3627,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;
   }
 
@@ -3639,7 +3639,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;
   }
 
@@ -3663,12 +3663,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 d6c3cf4bc579bb..7045543f9c3651 100644
--- a/polly/lib/Analysis/ScopDetection.cpp
+++ b/polly/lib/Analysis/ScopDetection.cpp
@@ -407,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");
   }
@@ -705,7 +705,7 @@ bool ScopDetection::isValidCallInst(CallInst &CI,
     return false;
 
   if (isDebugCall(&CI)) {
-    LLVM_DEBUG(dbgs() << "Allow call to debug function: "
+    POLLY_DEBUG(dbgs() << "Allow call to debug function: "
                       << CalledFunction->getName() << '\n');
     return true;
   }
@@ -1487,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());
@@ -1496,7 +1496,7 @@ 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()) {
@@ -1530,7 +1530,7 @@ Region *ScopDetection::expandRegion(Region &R) {
     }
   }
 
-  LLVM_DEBUG({
+  POLLY_DEBUG({
     if (LastValidRegion)
       dbgs() << "\tto " << LastValidRegion->getNameStr() << "\n";
     else
@@ -1751,10 +1751,10 @@ 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;
   }
@@ -1762,14 +1762,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";
     });
@@ -1803,7 +1803,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 a236ba733c4108..fa35fae84aceb2 100644
--- a/polly/lib/Analysis/ScopInfo.cpp
+++ b/polly/lib/Analysis/ScopInfo.cpp
@@ -2043,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/CodeGen/CodeGeneration.cpp b/polly/lib/CodeGen/CodeGeneration.cpp
index 2c5d232023d3e5..c4ca3f2e0f0f0e 100644
--- a/polly/lib/CodeGen/CodeGeneration.cpp
+++ b/polly/lib/CodeGen/CodeGeneration.cpp
@@ -87,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;
@@ -184,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 af8edcaf0b4e22..142a19d5e069ba 100644
--- a/polly/lib/CodeGen/IslAst.cpp
+++ b/polly/lib/CodeGen/IslAst.cpp
@@ -644,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());
   });
@@ -752,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/DumpFunctionPass.cpp b/polly/lib/Support/DumpFunctionPass.cpp
index b4a10ab6849d3c..7ef2275503486c 100644
--- a/polly/lib/Support/DumpFunctionPass.cpp
+++ b/polly/lib/Support/DumpFunctionPass.cpp
@@ -35,7 +35,7 @@ static void runDumpFunction(llvm::Function &F, StringRef Suffix) {
   StringRef ModuleName = M->getName();
   StringRef Stem = sys::path::stem(ModuleName);
   std::string Dumpfile = (Twine(Stem) + "-" + FName + Suffix + ".ll").str();
-  LLVM_DEBUG(dbgs() << "Dumping function '" << FName << "' to '" << Dumpfile
+  POLLY_DEBUG(dbgs() << "Dumping function '" << FName << "' to '" << Dumpfile
                     << "'...\n");
 
   ValueToValueMapTy VMap;
@@ -46,7 +46,7 @@ static void runDumpFunction(llvm::Function &F, StringRef Suffix) {
   Function *NewF = cast<Function>(VMap.lookup(&F));
   assert(NewF && "Expected selected function to be cloned");
 
-  LLVM_DEBUG(dbgs() << "Global DCE...\n");
+  POLLY_DEBUG(dbgs() << "Global DCE...\n");
 
   // Stop F itself from being pruned
   GlobalValue::LinkageTypes OrigLinkage = NewF->getLinkage();
@@ -67,7 +67,7 @@ static void runDumpFunction(llvm::Function &F, StringRef Suffix) {
   // Restore old linkage
   NewF->setLinkage(OrigLinkage);
 
-  LLVM_DEBUG(dbgs() << "Write to file '" << Dumpfile << "'...\n");
+  POLLY_DEBUG(dbgs() << "Write to file '" << Dumpfile << "'...\n");
 
   std::unique_ptr<ToolOutputFile> Out;
   std::error_code EC;
@@ -79,7 +79,7 @@ static void runDumpFunction(llvm::Function &F, StringRef Suffix) {
 
   CM->print(Out->os(), nullptr);
   Out->keep();
-  LLVM_DEBUG(dbgs() << "Dump file " << Dumpfile << " written successfully\n");
+  POLLY_DEBUG(dbgs() << "Dump file " << Dumpfile << " written successfully\n");
 }
 
 class DumpFunctionWrapperPass final : public FunctionPass {
diff --git a/polly/lib/Support/DumpModulePass.cpp b/polly/lib/Support/DumpModulePass.cpp
index c1c27ef6ac757a..11cdf8160e9dd6 100644
--- a/polly/lib/Support/DumpModulePass.cpp
+++ b/polly/lib/Support/DumpModulePass.cpp
@@ -34,7 +34,7 @@ static void runDumpModule(llvm::Module &M, StringRef Filename, bool IsSuffix) {
   } else {
     Dumpfile = Filename.str();
   }
-  LLVM_DEBUG(dbgs() << "Dumping module to " << Dumpfile << '\n');
+  POLLY_DEBUG(dbgs() << "Dumping module to " << Dumpfile << '\n');
 
   std::unique_ptr<ToolOutputFile> Out;
   std::error_code EC;
diff --git a/polly/lib/Support/SCEVValidator.cpp b/polly/lib/Support/SCEVValidator.cpp
index a6cfc418aea07d..3a8c99119b56f1 100644
--- a/polly/lib/Support/SCEVValidator.cpp
+++ b/polly/lib/Support/SCEVValidator.cpp
@@ -137,7 +137,7 @@ class SCEVValidator : public SCEVVisitor<SCEVValidator, ValidatorResult> {
 
   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);
   }
 
@@ -204,7 +204,7 @@ class SCEVValidator : public SCEVVisitor<SCEVValidator, ValidatorResult> {
       }
 
       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"
@@ -225,7 +225,7 @@ class SCEVValidator : public SCEVVisitor<SCEVValidator, ValidatorResult> {
 
   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);
     }
 
@@ -240,7 +240,7 @@ class SCEVValidator : public SCEVVisitor<SCEVValidator, ValidatorResult> {
 
     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.");
@@ -254,7 +254,7 @@ class SCEVValidator : public SCEVVisitor<SCEVValidator, ValidatorResult> {
         return Result;
       }
 
-      LLVM_DEBUG(dbgs() << "INVALID: AddRec within scop has non-int"
+      POLLY_DEBUG(dbgs() << "INVALID: AddRec within scop has non-int"
                            "recurrence part");
       return ValidatorResult(SCEVType::INVALID);
     }
@@ -315,7 +315,7 @@ class SCEVValidator : public SCEVVisitor<SCEVValidator, ValidatorResult> {
       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);
       }
     }
@@ -330,7 +330,7 @@ class SCEVValidator : public SCEVVisitor<SCEVValidator, ValidatorResult> {
       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);
       }
     }
@@ -345,7 +345,7 @@ class SCEVValidator : public SCEVVisitor<SCEVValidator, ValidatorResult> {
       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);
@@ -357,7 +357,7 @@ class SCEVValidator : public SCEVVisitor<SCEVValidator, ValidatorResult> {
 
   ValidatorResult visitGenericInst(Instruction *I, const SCEV *S) {
     if (R->contains(I)) {
-      LLVM_DEBUG(dbgs() << "INVALID: UnknownExpr references an instruction "
+      POLLY_DEBUG(dbgs() << "INVALID: UnknownExpr references an instruction "
                            "within the region\n");
       return ValidatorResult(SCEVType::INVALID);
     }
@@ -394,7 +394,7 @@ class SCEVValidator : public SCEVVisitor<SCEVValidator, ValidatorResult> {
     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);
   }
@@ -435,12 +435,12 @@ class SCEVValidator : public SCEVVisitor<SCEVValidator, ValidatorResult> {
     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);
     }
 
@@ -602,7 +602,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";
@@ -611,7 +611,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 781e3852de22a8..5ac1a028132ca7 100644
--- a/polly/lib/Transform/DeLICM.cpp
+++ b/polly/lib/Transform/DeLICM.cpp
@@ -548,7 +548,7 @@ class DeLICMImpl final : public ZoneAlgorithm {
   /// @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);
   }
 
@@ -560,7 +560,7 @@ class DeLICMImpl final : public ZoneAlgorithm {
     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;
@@ -577,7 +577,7 @@ class DeLICMImpl final : public ZoneAlgorithm {
         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;
         }
       }
@@ -594,7 +594,7 @@ class DeLICMImpl final : public ZoneAlgorithm {
       auto PHI = cast<PHINode>(MA->getAccessInstruction());
       for (auto Incoming : PHI->blocks()) {
         if (!S->contains(Incoming)) {
-          LLVM_DEBUG(dbgs()
+          POLLY_DEBUG(dbgs()
                      << "    Reject because at least one incoming block is "
                         "not in the scop region\n");
           return false;
@@ -604,7 +604,7 @@ class DeLICMImpl final : public ZoneAlgorithm {
       return true;
     }
 
-    LLVM_DEBUG(dbgs() << "    Reject ExitPHI or other non-value\n");
+    POLLY_DEBUG(dbgs() << "    Reject ExitPHI or other non-value\n");
     return false;
   }
 
@@ -687,12 +687,12 @@ class DeLICMImpl final : public ZoneAlgorithm {
     // { 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;
@@ -705,7 +705,7 @@ class DeLICMImpl final : public ZoneAlgorithm {
     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();
@@ -859,12 +859,12 @@ class DeLICMImpl final : public ZoneAlgorithm {
     // { 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;
@@ -873,7 +873,7 @@ class DeLICMImpl final : public ZoneAlgorithm {
     // { DomainRead[] -> DomainWrite[] }
     auto PerPHIWrites = computePerPHI(SAI);
     if (PerPHIWrites.is_null()) {
-      LLVM_DEBUG(
+      POLLY_DEBUG(
           dbgs() << "    Reject because cannot determine incoming values\n");
       return false;
     }
@@ -895,15 +895,15 @@ class DeLICMImpl final : public ZoneAlgorithm {
     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:    "
+        POLLY_DEBUG(dbgs() << "      Relevant Mapping:    "
                           << RelevantWritesTarget << '\n');
-      LLVM_DEBUG(dbgs() << "      Deduced Mapping:     " << WritesTarget
+      POLLY_DEBUG(dbgs() << "      Deduced Mapping:     " << WritesTarget
                         << '\n');
-      LLVM_DEBUG(dbgs() << "      Missing instances:    "
+      POLLY_DEBUG(dbgs() << "      Missing instances:    "
                         << UniverseWritesDom.subtract(ExpandedWritesDom)
                         << '\n');
       return false;
@@ -917,7 +917,7 @@ class DeLICMImpl final : public ZoneAlgorithm {
     // { 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);
@@ -1030,7 +1030,7 @@ class DeLICMImpl final : public ZoneAlgorithm {
     // 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;
@@ -1068,7 +1068,7 @@ class DeLICMImpl final : public ZoneAlgorithm {
       if (Closed.count(SAI))
         continue;
       Closed.insert(SAI);
-      LLVM_DEBUG(dbgs() << "\n    Trying to map " << MA << " (SAI: " << SAI
+      POLLY_DEBUG(dbgs() << "\n    Trying to map " << MA << " (SAI: " << SAI
                         << ")\n");
 
       // Skip non-mappable scalars.
@@ -1077,7 +1077,7 @@ class DeLICMImpl final : public ZoneAlgorithm {
 
       auto MASize = DL.getTypeAllocSize(MA->getAccessValue()->getType());
       if (MASize > StoreSize) {
-        LLVM_DEBUG(
+        POLLY_DEBUG(
             dbgs() << "    Reject because storage size is insufficient\n");
         continue;
       }
@@ -1213,7 +1213,7 @@ class DeLICMImpl final : public ZoneAlgorithm {
              "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,
@@ -1224,7 +1224,7 @@ class DeLICMImpl final : public ZoneAlgorithm {
     }
 
     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;
@@ -1246,7 +1246,7 @@ class DeLICMImpl final : public ZoneAlgorithm {
           continue;
 
         if (MA->isMayWrite()) {
-          LLVM_DEBUG(dbgs() << "Access " << MA
+          POLLY_DEBUG(dbgs() << "Access " << MA
                             << " pruned because it is a MAY_WRITE\n");
           OptimizationRemarkMissed R(DEBUG_TYPE, "TargetMayWrite",
                                      MA->getAccessInstruction());
@@ -1257,7 +1257,7 @@ class DeLICMImpl final : public ZoneAlgorithm {
         }
 
         if (Stmt.getNumIterators() == 0) {
-          LLVM_DEBUG(dbgs() << "Access " << MA
+          POLLY_DEBUG(dbgs() << "Access " << MA
                             << " pruned because it is not in a loop\n");
           OptimizationRemarkMissed R(DEBUG_TYPE, "WriteNotInLoop",
                                      MA->getAccessInstruction());
@@ -1267,7 +1267,7 @@ class DeLICMImpl final : public ZoneAlgorithm {
         }
 
         if (isScalarAccess(MA)) {
-          LLVM_DEBUG(dbgs()
+          POLLY_DEBUG(dbgs()
                      << "Access " << MA
                      << " pruned because it writes only a single element\n");
           OptimizationRemarkMissed R(DEBUG_TYPE, "ScalarWrite",
@@ -1279,7 +1279,7 @@ class DeLICMImpl final : public ZoneAlgorithm {
         }
 
         if (!isa<StoreInst>(MA->getAccessInstruction())) {
-          LLVM_DEBUG(dbgs() << "Access " << MA
+          POLLY_DEBUG(dbgs() << "Access " << MA
                             << " pruned because it is not a StoreInst\n");
           OptimizationRemarkMissed R(DEBUG_TYPE, "NotAStore",
                                      MA->getAccessInstruction());
@@ -1302,7 +1302,7 @@ class DeLICMImpl final : public ZoneAlgorithm {
         // arguments.
         isl::union_map AccRel = MA->getLatestAccessRelation();
         if (!AccRel.is_single_valued().is_true()) {
-          LLVM_DEBUG(dbgs() << "Access " << MA
+          POLLY_DEBUG(dbgs() << "Access " << MA
                             << " is incompatible because it writes multiple "
                                "elements per instance\n");
           OptimizationRemarkMissed R(DEBUG_TYPE, "NonFunctionalAccRel",
@@ -1315,7 +1315,7 @@ class DeLICMImpl final : public ZoneAlgorithm {
 
         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");
@@ -1329,7 +1329,7 @@ class DeLICMImpl final : public ZoneAlgorithm {
 
         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;
       }
@@ -1362,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 20d4ef27e93b1f..c59d392f163ae2 100644
--- a/polly/lib/Transform/FlattenAlgo.cpp
+++ b/polly/lib/Transform/FlattenAlgo.cpp
@@ -172,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 {};
   }
 
@@ -183,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);
@@ -200,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
+    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 {};
     }
 
@@ -237,7 +237,7 @@ isl::union_map tryFlattenSequence(isl::union_map Schedule) {
     Counter = Counter.add(PartLen);
   }
 
-  LLVM_DEBUG(dbgs() << "Sequence-flatten result is:\n  " << NewSchedule
+  POLLY_DEBUG(dbgs() << "Sequence-flatten result is:\n  " << NewSchedule
                     << "\n");
   return NewSchedule;
 }
@@ -267,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 {};
   }
 
@@ -298,14 +298,14 @@ 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
+  POLLY_DEBUG(dbgs() << "Recursive schedule to process:\n  " << Schedule
                     << "\n");
 
   // Base case; no dimensions left
@@ -320,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 3f1aa94ef89eaa..f514ef359ba078 100644
--- a/polly/lib/Transform/FlattenSchedule.cpp
+++ b/polly/lib/Transform/FlattenSchedule.cpp
@@ -58,23 +58,23 @@ class FlattenSchedule final : public ScopPass {
     // 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 b398f5f3f9727c..1e5be9d324179c 100644
--- a/polly/lib/Transform/ForwardOpTree.cpp
+++ b/polly/lib/Transform/ForwardOpTree.cpp
@@ -172,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;
@@ -369,12 +369,12 @@ class ForwardOpTreeImpl final : ZoneAlgorithm {
       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;
   }
@@ -491,7 +491,7 @@ class ForwardOpTreeImpl final : ZoneAlgorithm {
       //   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;
@@ -529,9 +529,9 @@ class ForwardOpTreeImpl final : ZoneAlgorithm {
     if (SameVal.is_null())
       return ForwardingAction::notApplicable();
 
-    LLVM_DEBUG(dbgs() << "      expected values where " << TargetExpectedVal
+    POLLY_DEBUG(dbgs() << "      expected values where " << TargetExpectedVal
                       << "\n");
-    LLVM_DEBUG(dbgs() << "      candidate elements where " << Candidates
+    POLLY_DEBUG(dbgs() << "      candidate elements where " << Candidates
                       << "\n");
 
     // { ValInst[] }
@@ -569,7 +569,7 @@ class ForwardOpTreeImpl final : ZoneAlgorithm {
 
       // { [TargetDomain[] -> Value[]] -> [DefDomain[] -> Value] }
       LocalTranslator = DefToTarget.reverse().product(ValToVal);
-      LLVM_DEBUG(dbgs() << "      local translator is " << LocalTranslator
+      POLLY_DEBUG(dbgs() << "      local translator is " << LocalTranslator
                         << "\n");
 
       if (LocalTranslator.is_null())
@@ -580,7 +580,7 @@ class ForwardOpTreeImpl final : ZoneAlgorithm {
                        LocalTranslator]() -> bool {
       TargetStmt->prependInstruction(LI);
       MemoryAccess *Access = makeReadArrayAccess(TargetStmt, LI, SameVal);
-      LLVM_DEBUG(dbgs() << "    forwarded known load with new MemoryAccess"
+      POLLY_DEBUG(dbgs() << "    forwarded known load with new MemoryAccess"
                         << Access << "\n");
       (void)Access;
 
@@ -644,7 +644,7 @@ class ForwardOpTreeImpl final : ZoneAlgorithm {
         Access = TargetStmt->ensureValueRead(Inst);
       Access->setNewAccessRelation(SameVal);
 
-      LLVM_DEBUG(dbgs() << "    forwarded known content of " << *Inst
+      POLLY_DEBUG(dbgs() << "    forwarded known content of " << *Inst
                         << " which is " << SameVal << "\n");
       TotalReloads++;
       NumReloads++;
@@ -713,7 +713,7 @@ class ForwardOpTreeImpl final : ZoneAlgorithm {
       // instruction using them.
       TargetStmt->prependInstruction(UseInst);
 
-      LLVM_DEBUG(dbgs() << "    forwarded speculable instruction: " << *UseInst
+      POLLY_DEBUG(dbgs() << "    forwarded speculable instruction: " << *UseInst
                         << "\n");
       NumInstructionsCopied++;
       TotalInstructionsCopied++;
@@ -766,7 +766,7 @@ class ForwardOpTreeImpl final : ZoneAlgorithm {
       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();
@@ -780,7 +780,7 @@ class ForwardOpTreeImpl final : ZoneAlgorithm {
       auto ExecAction = [this, TargetStmt, UseVal]() {
         TargetStmt->ensureValueRead(UseVal);
 
-        LLVM_DEBUG(dbgs() << "    forwarded read-only value " << *UseVal
+        POLLY_DEBUG(dbgs() << "    forwarded read-only value " << *UseVal
                           << "\n");
         NumReadOnlyCopied++;
         TotalReadOnlyCopied++;
@@ -831,7 +831,7 @@ class ForwardOpTreeImpl final : ZoneAlgorithm {
 
       // 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();
     }
 
@@ -946,7 +946,7 @@ class ForwardOpTreeImpl final : ZoneAlgorithm {
   /// 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();
@@ -1037,22 +1037,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 "
+      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 ee7fd6850f6d1a..04409f75184246 100644
--- a/polly/lib/Transform/ManualOptimizer.cpp
+++ b/polly/lib/Transform/ManualOptimizer.cpp
@@ -160,12 +160,12 @@ class SearchTransformVisitor final
       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_DEBUG(dbgs() << "Still accepting transformation due to "
                            "-polly-pragma-ignore-depcheck\n");
       if (ORE) {
         ORE->emit(
@@ -178,7 +178,7 @@ class SearchTransformVisitor final
       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 6ce68e23e99329..51ae5a778e4fa3 100644
--- a/polly/lib/Transform/MatmulOptimizer.cpp
+++ b/polly/lib/Transform/MatmulOptimizer.cpp
@@ -1826,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 07924ff440c32d..55d51982d90e76 100644
--- a/polly/lib/Transform/ScheduleOptimizer.cpp
+++ b/polly/lib/Transform/ScheduleOptimizer.cpp
@@ -731,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;
     }
 
@@ -746,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"));
     }
   }
@@ -756,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;
   }
 
@@ -777,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.
@@ -825,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") {
@@ -874,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);
@@ -909,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 5bdfe4c80b5bac..f0684de825d271 100644
--- a/polly/lib/Transform/ScheduleTreeTransform.cpp
+++ b/polly/lib/Transform/ScheduleTreeTransform.cpp
@@ -600,7 +600,7 @@ class BandCollapseRewriter final
     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";
@@ -645,7 +645,7 @@ class BandCollapseRewriter final
 };
 
 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);
 }
@@ -774,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";
@@ -1229,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 aa4f5afe2e36e6..7bc705c4185ea9 100644
--- a/polly/lib/Transform/ScopInliner.cpp
+++ b/polly/lib/Transform/ScopInliner.cpp
@@ -61,7 +61,7 @@ class ScopInliner final : public CallGraphSCCPass {
     if (!F)
       return false;
     if (F->isDeclaration()) {
-      LLVM_DEBUG(dbgs() << "Skipping " << F->getName()
+      POLLY_DEBUG(dbgs() << "Skipping " << F->getName()
                         << "because it is a declaration.\n");
       return false;
     }
@@ -87,7 +87,7 @@ class ScopInliner final : public CallGraphSCCPass {
 
     bool Changed = false;
     if (HasScopAsTopLevelRegion) {
-      LLVM_DEBUG(dbgs() << "Skipping " << F->getName()
+      POLLY_DEBUG(dbgs() << "Skipping " << F->getName()
                         << " has scop as top level region");
       F->addFnAttr(llvm::Attribute::AlwaysInline);
 
@@ -99,7 +99,7 @@ class ScopInliner final : public CallGraphSCCPass {
       if (!PA.areAllPreserved())
         Changed = true;
     } else {
-      LLVM_DEBUG(dbgs() << F->getName()
+      POLLY_DEBUG(dbgs() << F->getName()
                         << " does NOT have scop as top level region\n");
     }
 
diff --git a/polly/lib/Transform/Simplify.cpp b/polly/lib/Transform/Simplify.cpp
index 52c3abe71fa283..fa92911bbb29eb 100644
--- a/polly/lib/Transform/Simplify.cpp
+++ b/polly/lib/Transform/Simplify.cpp
@@ -238,7 +238,7 @@ void SimplifyImpl::removeEmptyDomainStmts() {
 
   assert(NumStmtsBefore >= S->getSize());
   EmptyDomainsRemoved = NumStmtsBefore - S->getSize();
-  LLVM_DEBUG(dbgs() << "Removed " << EmptyDomainsRemoved << " (of "
+  POLLY_DEBUG(dbgs() << "Removed " << EmptyDomainsRemoved << " (of "
                     << NumStmtsBefore << ") statements with empty domains \n");
   TotalEmptyDomainsRemoved[CallNo] += EmptyDomainsRemoved;
 }
@@ -281,7 +281,7 @@ 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
+        POLLY_DEBUG(dbgs() << "Removing " << MA
                           << " which will be overwritten anyway\n");
 
         Stmt.removeSingleMemoryAccess(MA);
@@ -533,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);
 
@@ -577,7 +577,7 @@ void SimplifyImpl::removeUnnecessaryStmts() {
   S->simplifySCoP(true);
   assert(NumStmtsBefore >= S->getSize());
   StmtsRemoved = NumStmtsBefore - S->getSize();
-  LLVM_DEBUG(dbgs() << "Removed " << StmtsRemoved << " (of " << NumStmtsBefore
+  POLLY_DEBUG(dbgs() << "Removed " << StmtsRemoved << " (of " << NumStmtsBefore
                     << ") statements\n");
   TotalStmtsRemoved[CallNo] += StmtsRemoved;
 }
@@ -596,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);
@@ -629,7 +629,7 @@ void SimplifyImpl::markAndSweep(LoopInfo *LI) {
   for (MemoryAccess *MA : AllMAs) {
     if (UsedMA.count(MA))
       continue;
-    LLVM_DEBUG(dbgs() << "Removing " << MA
+    POLLY_DEBUG(dbgs() << "Removing " << MA
                       << " because its value is not used\n");
     ScopStmt *Stmt = MA->getStatement();
     Stmt->removeSingleMemoryAccess(MA);
@@ -651,7 +651,7 @@ 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());
+        POLLY_DEBUG(dbgs() << "Removing "; Inst->print(dbgs());
                    dbgs() << " because it is not used\n");
         DeadInstructionsRemoved++;
         TotalDeadInstructionsRemoved[CallNo]++;
@@ -709,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 d6cdc16599bb7c..a114a241d87a56 100644
--- a/polly/lib/Transform/ZoneAlgo.cpp
+++ b/polly/lib/Transform/ZoneAlgo.cpp
@@ -343,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());
@@ -363,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";
@@ -374,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";

>From c76ad02f7d4c19743a9efee48edaab889a5b9074 Mon Sep 17 00:00:00 2001
From: Karthika Devi C <quic_kartc at quicinc.com>
Date: Mon, 26 Feb 2024 22:09:39 -0800
Subject: [PATCH 7/7] Replace LLVM_DEBUG with POLLY_DEBUG in multiple polly
 files

---
 polly/lib/Analysis/DependenceInfo.cpp         | 38 ++++----
 polly/lib/Analysis/PolyhedralInfo.cpp         | 14 +--
 polly/lib/Analysis/PruneUnprofitable.cpp      |  4 +-
 polly/lib/Analysis/ScopBuilder.cpp            | 35 +++----
 polly/lib/Analysis/ScopDetection.cpp          | 26 +++---
 polly/lib/Analysis/ScopInfo.cpp               |  2 +-
 polly/lib/CodeGen/CodeGeneration.cpp          |  4 +-
 polly/lib/CodeGen/IslAst.cpp                  |  6 +-
 polly/lib/Support/DumpFunctionPass.cpp        | 10 +-
 polly/lib/Support/DumpModulePass.cpp          |  2 +-
 polly/lib/Support/SCEVValidator.cpp           | 33 +++----
 polly/lib/Transform/DeLICM.cpp                | 92 +++++++++----------
 polly/lib/Transform/FlattenAlgo.cpp           | 36 ++++----
 polly/lib/Transform/FlattenSchedule.cpp       | 16 ++--
 polly/lib/Transform/ForwardOpTree.cpp         | 55 +++++------
 polly/lib/Transform/ManualOptimizer.cpp       |  8 +-
 polly/lib/Transform/MatmulOptimizer.cpp       |  4 +-
 polly/lib/Transform/ScheduleOptimizer.cpp     | 30 +++---
 polly/lib/Transform/ScheduleTreeTransform.cpp | 10 +-
 polly/lib/Transform/ScopInliner.cpp           | 12 +--
 polly/lib/Transform/Simplify.cpp              | 46 +++++-----
 polly/lib/Transform/ZoneAlgo.cpp              |  6 +-
 22 files changed, 247 insertions(+), 242 deletions(-)

diff --git a/polly/lib/Analysis/DependenceInfo.cpp b/polly/lib/Analysis/DependenceInfo.cpp
index fd2becec2bb215..9ee004fbac9e53 100644
--- a/polly/lib/Analysis/DependenceInfo.cpp
+++ b/polly/lib/Analysis/DependenceInfo.cpp
@@ -301,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;
 }
 
@@ -313,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();
 
@@ -361,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;
   {
@@ -505,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";
@@ -554,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";
@@ -604,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";
@@ -616,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";
@@ -632,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 6fc77ee84ce334..8d8e81a9049dfe 100644
--- a/polly/lib/Analysis/PolyhedralInfo.cpp
+++ b/polly/lib/Analysis/PolyhedralInfo.cpp
@@ -78,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);
@@ -126,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 0ca84d7662066a..f8469c03fe55bd 100644
--- a/polly/lib/Analysis/PruneUnprofitable.cpp
+++ b/polly/lib/Analysis/PruneUnprofitable.cpp
@@ -58,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;
@@ -67,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 434d5ede20f9e6..214e4d360d6bbb 100644
--- a/polly/lib/Analysis/ScopBuilder.cpp
+++ b/polly/lib/Analysis/ScopBuilder.cpp
@@ -2545,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.
@@ -2561,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) {
@@ -2572,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;
 }
@@ -3241,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;
 }
 
@@ -3563,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;
   }
@@ -3583,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;
   }
 
@@ -3600,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;
   }
 
@@ -3608,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;
   }
@@ -3627,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;
   }
 
@@ -3639,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;
   }
 
@@ -3663,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 d6c3cf4bc579bb..eab7bd83e6a4e7 100644
--- a/polly/lib/Analysis/ScopDetection.cpp
+++ b/polly/lib/Analysis/ScopDetection.cpp
@@ -407,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");
   }
@@ -705,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;
   }
 
@@ -1487,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());
@@ -1496,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()) {
@@ -1530,7 +1531,7 @@ Region *ScopDetection::expandRegion(Region &R) {
     }
   }
 
-  LLVM_DEBUG({
+  POLLY_DEBUG({
     if (LastValidRegion)
       dbgs() << "\tto " << LastValidRegion->getNameStr() << "\n";
     else
@@ -1751,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;
   }
@@ -1762,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";
     });
@@ -1803,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 a236ba733c4108..fa35fae84aceb2 100644
--- a/polly/lib/Analysis/ScopInfo.cpp
+++ b/polly/lib/Analysis/ScopInfo.cpp
@@ -2043,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/CodeGen/CodeGeneration.cpp b/polly/lib/CodeGen/CodeGeneration.cpp
index 2c5d232023d3e5..c4ca3f2e0f0f0e 100644
--- a/polly/lib/CodeGen/CodeGeneration.cpp
+++ b/polly/lib/CodeGen/CodeGeneration.cpp
@@ -87,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;
@@ -184,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 af8edcaf0b4e22..142a19d5e069ba 100644
--- a/polly/lib/CodeGen/IslAst.cpp
+++ b/polly/lib/CodeGen/IslAst.cpp
@@ -644,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());
   });
@@ -752,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/DumpFunctionPass.cpp b/polly/lib/Support/DumpFunctionPass.cpp
index b4a10ab6849d3c..adf511989fec2f 100644
--- a/polly/lib/Support/DumpFunctionPass.cpp
+++ b/polly/lib/Support/DumpFunctionPass.cpp
@@ -35,8 +35,8 @@ static void runDumpFunction(llvm::Function &F, StringRef Suffix) {
   StringRef ModuleName = M->getName();
   StringRef Stem = sys::path::stem(ModuleName);
   std::string Dumpfile = (Twine(Stem) + "-" + FName + Suffix + ".ll").str();
-  LLVM_DEBUG(dbgs() << "Dumping function '" << FName << "' to '" << Dumpfile
-                    << "'...\n");
+  POLLY_DEBUG(dbgs() << "Dumping function '" << FName << "' to '" << Dumpfile
+                     << "'...\n");
 
   ValueToValueMapTy VMap;
   auto ShouldCloneDefinition = [&F](const GlobalValue *GV) -> bool {
@@ -46,7 +46,7 @@ static void runDumpFunction(llvm::Function &F, StringRef Suffix) {
   Function *NewF = cast<Function>(VMap.lookup(&F));
   assert(NewF && "Expected selected function to be cloned");
 
-  LLVM_DEBUG(dbgs() << "Global DCE...\n");
+  POLLY_DEBUG(dbgs() << "Global DCE...\n");
 
   // Stop F itself from being pruned
   GlobalValue::LinkageTypes OrigLinkage = NewF->getLinkage();
@@ -67,7 +67,7 @@ static void runDumpFunction(llvm::Function &F, StringRef Suffix) {
   // Restore old linkage
   NewF->setLinkage(OrigLinkage);
 
-  LLVM_DEBUG(dbgs() << "Write to file '" << Dumpfile << "'...\n");
+  POLLY_DEBUG(dbgs() << "Write to file '" << Dumpfile << "'...\n");
 
   std::unique_ptr<ToolOutputFile> Out;
   std::error_code EC;
@@ -79,7 +79,7 @@ static void runDumpFunction(llvm::Function &F, StringRef Suffix) {
 
   CM->print(Out->os(), nullptr);
   Out->keep();
-  LLVM_DEBUG(dbgs() << "Dump file " << Dumpfile << " written successfully\n");
+  POLLY_DEBUG(dbgs() << "Dump file " << Dumpfile << " written successfully\n");
 }
 
 class DumpFunctionWrapperPass final : public FunctionPass {
diff --git a/polly/lib/Support/DumpModulePass.cpp b/polly/lib/Support/DumpModulePass.cpp
index c1c27ef6ac757a..11cdf8160e9dd6 100644
--- a/polly/lib/Support/DumpModulePass.cpp
+++ b/polly/lib/Support/DumpModulePass.cpp
@@ -34,7 +34,7 @@ static void runDumpModule(llvm::Module &M, StringRef Filename, bool IsSuffix) {
   } else {
     Dumpfile = Filename.str();
   }
-  LLVM_DEBUG(dbgs() << "Dumping module to " << Dumpfile << '\n');
+  POLLY_DEBUG(dbgs() << "Dumping module to " << Dumpfile << '\n');
 
   std::unique_ptr<ToolOutputFile> Out;
   std::error_code EC;
diff --git a/polly/lib/Support/SCEVValidator.cpp b/polly/lib/Support/SCEVValidator.cpp
index a6cfc418aea07d..5bb82624ed7844 100644
--- a/polly/lib/Support/SCEVValidator.cpp
+++ b/polly/lib/Support/SCEVValidator.cpp
@@ -137,7 +137,7 @@ class SCEVValidator : public SCEVVisitor<SCEVValidator, ValidatorResult> {
 
   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);
   }
 
@@ -204,7 +204,7 @@ class SCEVValidator : public SCEVVisitor<SCEVValidator, ValidatorResult> {
       }
 
       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"
@@ -225,7 +225,7 @@ class SCEVValidator : public SCEVVisitor<SCEVValidator, ValidatorResult> {
 
   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);
     }
 
@@ -240,7 +240,7 @@ class SCEVValidator : public SCEVVisitor<SCEVValidator, ValidatorResult> {
 
     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.");
@@ -254,8 +254,8 @@ class SCEVValidator : public SCEVVisitor<SCEVValidator, ValidatorResult> {
         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);
     }
 
@@ -315,7 +315,7 @@ class SCEVValidator : public SCEVVisitor<SCEVValidator, ValidatorResult> {
       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);
       }
     }
@@ -330,7 +330,7 @@ class SCEVValidator : public SCEVVisitor<SCEVValidator, ValidatorResult> {
       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);
       }
     }
@@ -345,7 +345,7 @@ class SCEVValidator : public SCEVVisitor<SCEVValidator, ValidatorResult> {
       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);
@@ -357,8 +357,8 @@ class SCEVValidator : public SCEVVisitor<SCEVValidator, ValidatorResult> {
 
   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);
     }
 
@@ -394,7 +394,7 @@ class SCEVValidator : public SCEVVisitor<SCEVValidator, ValidatorResult> {
     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);
   }
@@ -435,12 +435,13 @@ class SCEVValidator : public SCEVVisitor<SCEVValidator, ValidatorResult> {
     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);
     }
 
@@ -602,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";
@@ -611,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 781e3852de22a8..8afa63724ade5d 100644
--- a/polly/lib/Transform/DeLICM.cpp
+++ b/polly/lib/Transform/DeLICM.cpp
@@ -548,7 +548,7 @@ class DeLICMImpl final : public ZoneAlgorithm {
   /// @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);
   }
 
@@ -560,7 +560,7 @@ class DeLICMImpl final : public ZoneAlgorithm {
     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;
@@ -577,7 +577,7 @@ class DeLICMImpl final : public ZoneAlgorithm {
         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;
         }
       }
@@ -594,9 +594,9 @@ class DeLICMImpl final : public ZoneAlgorithm {
       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;
         }
       }
@@ -604,7 +604,7 @@ class DeLICMImpl final : public ZoneAlgorithm {
       return true;
     }
 
-    LLVM_DEBUG(dbgs() << "    Reject ExitPHI or other non-value\n");
+    POLLY_DEBUG(dbgs() << "    Reject ExitPHI or other non-value\n");
     return false;
   }
 
@@ -687,12 +687,12 @@ class DeLICMImpl final : public ZoneAlgorithm {
     // { 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;
@@ -705,7 +705,7 @@ class DeLICMImpl final : public ZoneAlgorithm {
     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();
@@ -859,12 +859,12 @@ class DeLICMImpl final : public ZoneAlgorithm {
     // { 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;
@@ -873,7 +873,7 @@ class DeLICMImpl final : public ZoneAlgorithm {
     // { DomainRead[] -> DomainWrite[] }
     auto PerPHIWrites = computePerPHI(SAI);
     if (PerPHIWrites.is_null()) {
-      LLVM_DEBUG(
+      POLLY_DEBUG(
           dbgs() << "    Reject because cannot determine incoming values\n");
       return false;
     }
@@ -895,17 +895,17 @@ class DeLICMImpl final : public ZoneAlgorithm {
     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;
     }
 
@@ -917,7 +917,7 @@ class DeLICMImpl final : public ZoneAlgorithm {
     // { 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);
@@ -1030,7 +1030,7 @@ class DeLICMImpl final : public ZoneAlgorithm {
     // 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;
@@ -1068,8 +1068,8 @@ class DeLICMImpl final : public ZoneAlgorithm {
       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))
@@ -1077,7 +1077,7 @@ class DeLICMImpl final : public ZoneAlgorithm {
 
       auto MASize = DL.getTypeAllocSize(MA->getAccessValue()->getType());
       if (MASize > StoreSize) {
-        LLVM_DEBUG(
+        POLLY_DEBUG(
             dbgs() << "    Reject because storage size is insufficient\n");
         continue;
       }
@@ -1213,7 +1213,7 @@ class DeLICMImpl final : public ZoneAlgorithm {
              "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,
@@ -1224,7 +1224,7 @@ class DeLICMImpl final : public ZoneAlgorithm {
     }
 
     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;
@@ -1246,8 +1246,8 @@ class DeLICMImpl final : public ZoneAlgorithm {
           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 "
@@ -1257,8 +1257,8 @@ class DeLICMImpl final : public ZoneAlgorithm {
         }
 
         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";
@@ -1267,9 +1267,9 @@ class DeLICMImpl final : public ZoneAlgorithm {
         }
 
         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 "
@@ -1279,8 +1279,8 @@ class DeLICMImpl final : public ZoneAlgorithm {
         }
 
         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 "
@@ -1302,9 +1302,9 @@ class DeLICMImpl final : public ZoneAlgorithm {
         // 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 "
@@ -1315,7 +1315,7 @@ class DeLICMImpl final : public ZoneAlgorithm {
 
         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");
@@ -1329,7 +1329,7 @@ class DeLICMImpl final : public ZoneAlgorithm {
 
         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;
       }
@@ -1362,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 20d4ef27e93b1f..27a699e5ea59ae 100644
--- a/polly/lib/Transform/FlattenAlgo.cpp
+++ b/polly/lib/Transform/FlattenAlgo.cpp
@@ -172,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 {};
   }
 
@@ -183,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);
@@ -200,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 {};
     }
 
@@ -237,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;
 }
 
@@ -267,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 {};
   }
 
@@ -298,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) {
@@ -320,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 3f1aa94ef89eaa..f514ef359ba078 100644
--- a/polly/lib/Transform/FlattenSchedule.cpp
+++ b/polly/lib/Transform/FlattenSchedule.cpp
@@ -58,23 +58,23 @@ class FlattenSchedule final : public ScopPass {
     // 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 b398f5f3f9727c..e9be6c9cdcc271 100644
--- a/polly/lib/Transform/ForwardOpTree.cpp
+++ b/polly/lib/Transform/ForwardOpTree.cpp
@@ -172,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;
@@ -369,12 +369,12 @@ class ForwardOpTreeImpl final : ZoneAlgorithm {
       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;
   }
@@ -491,7 +491,7 @@ class ForwardOpTreeImpl final : ZoneAlgorithm {
       //   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;
@@ -529,10 +529,10 @@ class ForwardOpTreeImpl final : ZoneAlgorithm {
     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();
@@ -569,8 +569,8 @@ class ForwardOpTreeImpl final : ZoneAlgorithm {
 
       // { [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();
@@ -580,8 +580,8 @@ class ForwardOpTreeImpl final : ZoneAlgorithm {
                        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())
@@ -644,8 +644,8 @@ class ForwardOpTreeImpl final : ZoneAlgorithm {
         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;
@@ -713,8 +713,8 @@ class ForwardOpTreeImpl final : ZoneAlgorithm {
       // 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;
@@ -766,7 +766,7 @@ class ForwardOpTreeImpl final : ZoneAlgorithm {
       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();
@@ -780,8 +780,8 @@ class ForwardOpTreeImpl final : ZoneAlgorithm {
       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++;
 
@@ -831,7 +831,8 @@ class ForwardOpTreeImpl final : ZoneAlgorithm {
 
       // 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();
     }
 
@@ -946,7 +947,7 @@ class ForwardOpTreeImpl final : ZoneAlgorithm {
   /// 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();
@@ -1037,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 ee7fd6850f6d1a..0e330f207fbc48 100644
--- a/polly/lib/Transform/ManualOptimizer.cpp
+++ b/polly/lib/Transform/ManualOptimizer.cpp
@@ -160,13 +160,13 @@ class SearchTransformVisitor final
       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)
@@ -178,7 +178,7 @@ class SearchTransformVisitor final
       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 6ce68e23e99329..51ae5a778e4fa3 100644
--- a/polly/lib/Transform/MatmulOptimizer.cpp
+++ b/polly/lib/Transform/MatmulOptimizer.cpp
@@ -1826,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 07924ff440c32d..55d51982d90e76 100644
--- a/polly/lib/Transform/ScheduleOptimizer.cpp
+++ b/polly/lib/Transform/ScheduleOptimizer.cpp
@@ -731,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;
     }
 
@@ -746,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"));
     }
   }
@@ -756,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;
   }
 
@@ -777,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.
@@ -825,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") {
@@ -874,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);
@@ -909,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 5bdfe4c80b5bac..f0684de825d271 100644
--- a/polly/lib/Transform/ScheduleTreeTransform.cpp
+++ b/polly/lib/Transform/ScheduleTreeTransform.cpp
@@ -600,7 +600,7 @@ class BandCollapseRewriter final
     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";
@@ -645,7 +645,7 @@ class BandCollapseRewriter final
 };
 
 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);
 }
@@ -774,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";
@@ -1229,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 aa4f5afe2e36e6..b78206c1e40bad 100644
--- a/polly/lib/Transform/ScopInliner.cpp
+++ b/polly/lib/Transform/ScopInliner.cpp
@@ -61,8 +61,8 @@ class ScopInliner final : public CallGraphSCCPass {
     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;
     }
 
@@ -87,8 +87,8 @@ class ScopInliner final : public CallGraphSCCPass {
 
     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;
@@ -99,8 +99,8 @@ class ScopInliner final : public CallGraphSCCPass {
       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 52c3abe71fa283..75e91cd1c031a9 100644
--- a/polly/lib/Transform/Simplify.cpp
+++ b/polly/lib/Transform/Simplify.cpp
@@ -238,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;
 }
 
@@ -281,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++;
@@ -533,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);
 
@@ -577,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;
 }
 
@@ -596,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);
@@ -629,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);
 
@@ -651,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;
@@ -709,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 d6cdc16599bb7c..a114a241d87a56 100644
--- a/polly/lib/Transform/ZoneAlgo.cpp
+++ b/polly/lib/Transform/ZoneAlgo.cpp
@@ -343,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());
@@ -363,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";
@@ -374,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";



More information about the llvm-commits mailing list