Skip to content

Conversation

shaurya0
Copy link

This change allows for selecting the output format of the DefaultTimingManager through an API which was previously only accessible when running e.g. mlir-opt --mlir-timing --mlir-output-format=<value> at the command line. The use case is to be able to enable MLIR pass timing in situations when setting CL options is not viable. The DefaultTimingManager already allows for setting the DisplayMode in a similar manner.

Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot llvmbot added mlir:core MLIR Core Infrastructure mlir labels Aug 16, 2024
@llvmbot
Copy link
Member

llvmbot commented Aug 16, 2024

@llvm/pr-subscribers-mlir-core

@llvm/pr-subscribers-mlir

Author: Shaurya Sharma (shaurya0)

Changes

This change allows for selecting the output format of the DefaultTimingManager through an API which was previously only accessible when running e.g. mlir-opt --mlir-timing --mlir-output-format=&lt;value&gt; at the command line. The use case is to be able to enable MLIR pass timing in situations when setting CL options is not viable. The DefaultTimingManager already allows for setting the DisplayMode in a similar manner.


Full diff: https://github.com/llvm/llvm-project/pull/104548.diff

2 Files Affected:

  • (modified) mlir/include/mlir/Support/Timing.h (+3)
  • (modified) mlir/lib/Support/Timing.cpp (+8)
diff --git a/mlir/include/mlir/Support/Timing.h b/mlir/include/mlir/Support/Timing.h
index a8a4bfd1c6cf16..133456e8499c6f 100644
--- a/mlir/include/mlir/Support/Timing.h
+++ b/mlir/include/mlir/Support/Timing.h
@@ -430,6 +430,9 @@ class DefaultTimingManager : public TimingManager {
   /// Change the stream where the output will be printed to.
   void setOutput(std::unique_ptr<OutputStrategy> output);
 
+  /// Change the output format.
+  void setOutputFormat(OutputFormat format);
+
   /// Print and clear the timing results. Only call this when there are no more
   /// references to nested timers around, as printing post-processes and clears
   /// the timers.
diff --git a/mlir/lib/Support/Timing.cpp b/mlir/lib/Support/Timing.cpp
index ac16eb7d224c9a..9cde0ef6503e15 100644
--- a/mlir/lib/Support/Timing.cpp
+++ b/mlir/lib/Support/Timing.cpp
@@ -527,6 +527,14 @@ void DefaultTimingManager::setOutput(std::unique_ptr<OutputStrategy> output) {
   out = std::move(output);
 }
 
+/// Change the output format.
+void DefaultTimingManager::setOutputFormat(OutputFormat outputFormat) {
+  if (outputFormat == OutputFormat::Text)
+    setOutput(std::make_unique<OutputTextStrategy>(llvm::errs()));
+  else if (outputFormat == OutputFormat::Json)
+    setOutput(std::make_unique<OutputJsonStrategy>(llvm::errs()));
+}
+
 /// Print and clear the timing results.
 void DefaultTimingManager::print() {
   if (impl->enabled) {

@shaurya0 shaurya0 marked this pull request as draft August 16, 2024 06:47
@shaurya0 shaurya0 closed this Aug 16, 2024
@shaurya0 shaurya0 deleted the shaurya/mlir_timing_outputformat branch August 16, 2024 06:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mlir:core MLIR Core Infrastructure mlir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants