[llvm] [OFFLOAD] Implement excluding filters for debugging (PR #180538)

Alex Duran via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 9 07:23:59 PST 2026


https://github.com/adurang updated https://github.com/llvm/llvm-project/pull/180538

>From c2d0ae75977d961466a733d97692cc7a5fd3b876 Mon Sep 17 00:00:00 2001
From: Alex Duran <alejandro.duran at intel.com>
Date: Mon, 9 Feb 2026 10:56:13 +0100
Subject: [PATCH 1/4] [OFFLOAD] Add exclude debug filters

---
 offload/include/Shared/Debug.h | 36 +++++++++++++++++++++++++---------
 1 file changed, 27 insertions(+), 9 deletions(-)

diff --git a/offload/include/Shared/Debug.h b/offload/include/Shared/Debug.h
index 0f98a445c73ea..3f5c44de7511c 100644
--- a/offload/include/Shared/Debug.h
+++ b/offload/include/Shared/Debug.h
@@ -271,6 +271,7 @@ struct DebugFilter {
 struct DebugSettings {
   bool Enabled = false;
   uint32_t DefaultLevel = 1;
+  llvm::SmallVector<StringRef> ExcludeFilters;
   llvm::SmallVector<DebugFilter> Filters;
 };
 
@@ -309,13 +310,12 @@ struct DebugSettings {
 
     Settings.Enabled = true;
 
-    if (EnvRef.starts_with_insensitive("all")) {
-      auto Spec = parseDebugFilter(EnvRef);
-      if (Spec.Type.equals_insensitive("all")) {
-        Settings.DefaultLevel = Spec.Level;
-        return;
-      }
-    }
+    // Messages with Type/Components added to the exclude list are not 
+    // not printed when debug is enabled unless they are explicitly 
+    // requested by the user.
+    // Eventuall this should be configured from the upper layers but 
+    // for now we can hardcode some excluded types here like:
+    // Settings.ExcludeFilters.push_back(Type); 
 
     if (!EnvRef.getAsInteger(10, Settings.DefaultLevel))
       return;
@@ -325,7 +325,18 @@ struct DebugSettings {
     for (auto &FilterSpec : llvm::split(EnvRef, ',')) {
       if (FilterSpec.empty())
         continue;
-      Settings.Filters.push_back(parseDebugFilter(FilterSpec));
+      DebugFilter Filter = parseDebugFilter(FilterSpec);
+
+      // Remove from ExcludeFilters if present
+      Settings.ExcludeFilters.erase(
+            std::remove_if(Settings.ExcludeFilters.begin(),
+                           Settings.ExcludeFilters.end(),
+                           [&](StringRef OutType) {
+                             return OutType.equals_insensitive(Filter.Type);
+                           }),
+            Settings.ExcludeFilters.end());
+
+      Settings.Filters.push_back(Filter);
     }
   });
 
@@ -340,6 +351,12 @@ shouldPrintDebug(const char *Component, const char *Type, uint32_t &Level) {
   if (!Settings.Enabled)
     return false;
 
+  for (const auto &Filter : Settings.ExcludeFilters) {
+    if (Filter.equals_insensitive(Type) ||
+        Filter.equals_insensitive(Component))
+      return false;
+  }
+
   if (Settings.Filters.empty()) {
     if (Level <= Settings.DefaultLevel) {
       Level = Settings.DefaultLevel;
@@ -351,7 +368,8 @@ shouldPrintDebug(const char *Component, const char *Type, uint32_t &Level) {
   for (const auto &DT : Settings.Filters) {
     if (DT.Level < Level)
       continue;
-    if (DT.Type.equals_insensitive(Type) ||
+    if (DT.Type.equals_insensitive("all") ||
+        DT.Type.equals_insensitive(Type) ||
         DT.Type.equals_insensitive(Component)) {
       Level = DT.Level;
       return true;

>From 1817317ab53f314951a40e3cd76153854873e1f6 Mon Sep 17 00:00:00 2001
From: Alex Duran <alejandro.duran at intel.com>
Date: Mon, 9 Feb 2026 11:03:15 +0100
Subject: [PATCH 2/4] rename other filter field

---
 offload/include/Shared/Debug.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/offload/include/Shared/Debug.h b/offload/include/Shared/Debug.h
index 3f5c44de7511c..cb158b2db0709 100644
--- a/offload/include/Shared/Debug.h
+++ b/offload/include/Shared/Debug.h
@@ -272,7 +272,7 @@ struct DebugSettings {
   bool Enabled = false;
   uint32_t DefaultLevel = 1;
   llvm::SmallVector<StringRef> ExcludeFilters;
-  llvm::SmallVector<DebugFilter> Filters;
+  llvm::SmallVector<DebugFilter> IncludeFilters;
 };
 
 [[maybe_unused]] static DebugFilter parseDebugFilter(StringRef Filter) {
@@ -336,7 +336,7 @@ struct DebugSettings {
                            }),
             Settings.ExcludeFilters.end());
 
-      Settings.Filters.push_back(Filter);
+      Settings.IncludeFilters.push_back(Filter);
     }
   });
 
@@ -357,7 +357,7 @@ shouldPrintDebug(const char *Component, const char *Type, uint32_t &Level) {
       return false;
   }
 
-  if (Settings.Filters.empty()) {
+  if (Settings.IncludeFilters.empty()) {
     if (Level <= Settings.DefaultLevel) {
       Level = Settings.DefaultLevel;
       return true;
@@ -365,7 +365,7 @@ shouldPrintDebug(const char *Component, const char *Type, uint32_t &Level) {
     return false;
   }
 
-  for (const auto &DT : Settings.Filters) {
+  for (const auto &DT : Settings.IncludeFilters) {
     if (DT.Level < Level)
       continue;
     if (DT.Type.equals_insensitive("all") ||

>From 2b9a7d3783ad6c20733d57f17eff3c30fdb75328 Mon Sep 17 00:00:00 2001
From: Alex Duran <alejandro.duran at intel.com>
Date: Mon, 9 Feb 2026 11:07:59 +0100
Subject: [PATCH 3/4] add comments

---
 offload/include/Shared/Debug.h | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/offload/include/Shared/Debug.h b/offload/include/Shared/Debug.h
index cb158b2db0709..31b46129540d4 100644
--- a/offload/include/Shared/Debug.h
+++ b/offload/include/Shared/Debug.h
@@ -271,7 +271,11 @@ struct DebugFilter {
 struct DebugSettings {
   bool Enabled = false;
   uint32_t DefaultLevel = 1;
+  // Types/Components in this list are not printed when debug is enabled 
+  // unless they are explicitly requested by the user in IncludeFilters.
   llvm::SmallVector<StringRef> ExcludeFilters;
+  // Types/Components in this list are printed when debug is enabled if 
+  // the debug level is equal or higher than the specified level.
   llvm::SmallVector<DebugFilter> IncludeFilters;
 };
 
@@ -310,10 +314,10 @@ struct DebugSettings {
 
     Settings.Enabled = true;
 
-    // Messages with Type/Components added to the exclude list are not 
+    // Messages with Type/Components added to the exclude list are not
     // not printed when debug is enabled unless they are explicitly 
     // requested by the user.
-    // Eventuall this should be configured from the upper layers but 
+    // Eventuall this should be configured from the upper layers but
     // for now we can hardcode some excluded types here like:
     // Settings.ExcludeFilters.push_back(Type); 
 

>From 5a9a65d1eda35a32513556231751f9ee60a5054e Mon Sep 17 00:00:00 2001
From: Alex Duran <alejandro.duran at intel.com>
Date: Mon, 9 Feb 2026 16:23:43 +0100
Subject: [PATCH 4/4] format

---
 offload/include/Shared/Debug.h | 26 ++++++++++++--------------
 1 file changed, 12 insertions(+), 14 deletions(-)

diff --git a/offload/include/Shared/Debug.h b/offload/include/Shared/Debug.h
index 31b46129540d4..723761b2f65ed 100644
--- a/offload/include/Shared/Debug.h
+++ b/offload/include/Shared/Debug.h
@@ -271,10 +271,10 @@ struct DebugFilter {
 struct DebugSettings {
   bool Enabled = false;
   uint32_t DefaultLevel = 1;
-  // Types/Components in this list are not printed when debug is enabled 
+  // Types/Components in this list are not printed when debug is enabled
   // unless they are explicitly requested by the user in IncludeFilters.
   llvm::SmallVector<StringRef> ExcludeFilters;
-  // Types/Components in this list are printed when debug is enabled if 
+  // Types/Components in this list are printed when debug is enabled if
   // the debug level is equal or higher than the specified level.
   llvm::SmallVector<DebugFilter> IncludeFilters;
 };
@@ -315,11 +315,11 @@ struct DebugSettings {
     Settings.Enabled = true;
 
     // Messages with Type/Components added to the exclude list are not
-    // not printed when debug is enabled unless they are explicitly 
+    // not printed when debug is enabled unless they are explicitly
     // requested by the user.
     // Eventuall this should be configured from the upper layers but
     // for now we can hardcode some excluded types here like:
-    // Settings.ExcludeFilters.push_back(Type); 
+    // Settings.ExcludeFilters.push_back(Type);
 
     if (!EnvRef.getAsInteger(10, Settings.DefaultLevel))
       return;
@@ -333,12 +333,12 @@ struct DebugSettings {
 
       // Remove from ExcludeFilters if present
       Settings.ExcludeFilters.erase(
-            std::remove_if(Settings.ExcludeFilters.begin(),
-                           Settings.ExcludeFilters.end(),
-                           [&](StringRef OutType) {
-                             return OutType.equals_insensitive(Filter.Type);
-                           }),
-            Settings.ExcludeFilters.end());
+          std::remove_if(Settings.ExcludeFilters.begin(),
+                         Settings.ExcludeFilters.end(),
+                         [&](StringRef OutType) {
+                           return OutType.equals_insensitive(Filter.Type);
+                         }),
+          Settings.ExcludeFilters.end());
 
       Settings.IncludeFilters.push_back(Filter);
     }
@@ -356,8 +356,7 @@ shouldPrintDebug(const char *Component, const char *Type, uint32_t &Level) {
     return false;
 
   for (const auto &Filter : Settings.ExcludeFilters) {
-    if (Filter.equals_insensitive(Type) ||
-        Filter.equals_insensitive(Component))
+    if (Filter.equals_insensitive(Type) || Filter.equals_insensitive(Component))
       return false;
   }
 
@@ -372,8 +371,7 @@ shouldPrintDebug(const char *Component, const char *Type, uint32_t &Level) {
   for (const auto &DT : Settings.IncludeFilters) {
     if (DT.Level < Level)
       continue;
-    if (DT.Type.equals_insensitive("all") ||
-        DT.Type.equals_insensitive(Type) ||
+    if (DT.Type.equals_insensitive("all") || DT.Type.equals_insensitive(Type) ||
         DT.Type.equals_insensitive(Component)) {
       Level = DT.Level;
       return true;



More information about the llvm-commits mailing list