[Mlir-commits] [mlir] [mlir] Expose output strategies of TimingManager (PR #166548)
Andrei Golubev
llvmlistbot at llvm.org
Wed Nov 5 04:56:24 PST 2025
https://github.com/andrey-golubev created https://github.com/llvm/llvm-project/pull/166548
After the original API change to DefaultTimingManager::setOutput() (see 362aa434cc31ccca96749a6db8cd97f5b7d71206), users are forced to provide their own implementation of OutputStrategy. However, default MLIR implementations are usually sufficient. Expose Text and Json strategies via factory-like method to avoid the problem in downstream projects.
>From 045216b704f53aa8feb48d2db8c2b575107b6e45 Mon Sep 17 00:00:00 2001
From: "Golubev, Andrey" <andrey.golubev at intel.com>
Date: Wed, 5 Nov 2025 12:55:33 +0000
Subject: [PATCH] [mlir] Expose output strategies of TimingManager
After the original API change to DefaultTimingManager::setOutput() (see
362aa434cc31ccca96749a6db8cd97f5b7d71206), users are forced to provide
their own implementation of OutputStrategy. However, default MLIR
implementations are usually sufficient. Expose Text and Json
strategies via factory-like method to avoid the problem in downstream projects.
---
mlir/include/mlir/Support/Timing.h | 7 +++++++
mlir/lib/Support/Timing.cpp | 19 +++++++++++++------
2 files changed, 20 insertions(+), 6 deletions(-)
diff --git a/mlir/include/mlir/Support/Timing.h b/mlir/include/mlir/Support/Timing.h
index 3d61a0a7a85c9..bbb57644b1596 100644
--- a/mlir/include/mlir/Support/Timing.h
+++ b/mlir/include/mlir/Support/Timing.h
@@ -473,6 +473,13 @@ void registerDefaultTimingManagerCLOptions();
/// 'registerDefaultTimingManagerOptions' to a `DefaultTimingManager`.
void applyDefaultTimingManagerCLOptions(DefaultTimingManager &tm);
+/// Return a default output strategy for the specified format. This function can
+/// be used in combination with DefaultTimingManager::setOutput() to use
+/// MLIR-provided output format.
+std::unique_ptr<OutputStrategy>
+createDefaultOutputStrategy(DefaultTimingManager::OutputFormat fmt,
+ raw_ostream &os);
+
} // namespace mlir
#endif // MLIR_SUPPORT_TIMING_H
diff --git a/mlir/lib/Support/Timing.cpp b/mlir/lib/Support/Timing.cpp
index 2e92d9c1e7835..42f993edd5a3e 100644
--- a/mlir/lib/Support/Timing.cpp
+++ b/mlir/lib/Support/Timing.cpp
@@ -619,11 +619,18 @@ void mlir::applyDefaultTimingManagerCLOptions(DefaultTimingManager &tm) {
return;
tm.setEnabled(options->timing);
tm.setDisplayMode(options->displayMode);
+ tm.setOutput(
+ createDefaultOutputStrategy(options->outputFormat, llvm::errs()));
+}
- std::unique_ptr<OutputStrategy> printer;
- if (options->outputFormat == OutputFormat::Text)
- printer = std::make_unique<OutputTextStrategy>(llvm::errs());
- else if (options->outputFormat == OutputFormat::Json)
- printer = std::make_unique<OutputJsonStrategy>(llvm::errs());
- tm.setOutput(std::move(printer));
+std::unique_ptr<OutputStrategy>
+mlir::createDefaultOutputStrategy(DefaultTimingManager::OutputFormat fmt,
+ raw_ostream &os) {
+ switch (fmt) {
+ case OutputFormat::Text:
+ return std::make_unique<OutputTextStrategy>(os);
+ case OutputFormat::Json:
+ return std::make_unique<OutputJsonStrategy>(os);
+ }
+ llvm_unreachable("Invalid output format");
}
More information about the Mlir-commits
mailing list