[Mlir-commits] [mlir] [MLIR] Allow setting call stack limit for SourceMgrDiagnosticHandler (PR #123373)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Fri Jan 17 09:08:35 PST 2025


https://github.com/JoelWee created https://github.com/llvm/llvm-project/pull/123373

Some of our code generates very deep call stacks, and its inconvenient to have the callstack truncated

>From ba22639b69387789d7ceb32effd09f946184b4b2 Mon Sep 17 00:00:00 2001
From: Joel Wee <joelwee at google.com>
Date: Fri, 17 Jan 2025 16:46:39 +0000
Subject: [PATCH] [MLIR] Allow setting call stack limit for
 SourceMgrDiagnosticHandler

---
 mlir/include/mlir/IR/Diagnostics.h | 4 +++-
 mlir/lib/IR/Diagnostics.cpp        | 4 ++++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/mlir/include/mlir/IR/Diagnostics.h b/mlir/include/mlir/IR/Diagnostics.h
index 8429325412dc97..36c433c63b26d1 100644
--- a/mlir/include/mlir/IR/Diagnostics.h
+++ b/mlir/include/mlir/IR/Diagnostics.h
@@ -578,6 +578,9 @@ class SourceMgrDiagnosticHandler : public ScopedDiagnosticHandler {
   void emitDiagnostic(Location loc, Twine message, DiagnosticSeverity kind,
                       bool displaySourceLine = true);
 
+  /// Set the maximum depth that a call stack will be printed. Defaults to 10.
+  void setCallStackLimit(unsigned limit);
+
 protected:
   /// Emit the given diagnostic with the held source manager.
   void emitDiagnostic(Diagnostic &diag);
@@ -605,7 +608,6 @@ class SourceMgrDiagnosticHandler : public ScopedDiagnosticHandler {
   std::optional<Location> findLocToShow(Location loc);
 
   /// The maximum depth that a call stack will be printed.
-  /// TODO: This should be a tunable flag.
   unsigned callStackLimit = 10;
 
   std::unique_ptr<detail::SourceMgrDiagnosticHandlerImpl> impl;
diff --git a/mlir/lib/IR/Diagnostics.cpp b/mlir/lib/IR/Diagnostics.cpp
index 7eb3d5bcd07f19..19b32120f58905 100644
--- a/mlir/lib/IR/Diagnostics.cpp
+++ b/mlir/lib/IR/Diagnostics.cpp
@@ -519,6 +519,10 @@ void SourceMgrDiagnosticHandler::emitDiagnostic(Diagnostic &diag) {
   }
 }
 
+void SourceMgrDiagnosticHandler::setCallStackLimit(unsigned limit) {
+  callStackLimit = limit;
+}
+
 /// Get a memory buffer for the given file, or nullptr if one is not found.
 const llvm::MemoryBuffer *
 SourceMgrDiagnosticHandler::getBufferForFile(StringRef filename) {



More information about the Mlir-commits mailing list