[llvm] [llvm][Support] Enable pass timing in StandardInstrumentations constr… (PR #108983)

Tarun Prabhu via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 17 07:41:06 PDT 2024


https://github.com/tarunprabhu created https://github.com/llvm/llvm-project/pull/108983

…uctor

Add two optional arguments to the llvm::StandardInstrumentations constructor that enables pass timings and pass timings per run. If the optional arguments are not provided, the TimePassesIsEnabled and TimePassesPerRun global variables will be read when constructing the TimePassesHandler object which will preserve the current behavior.

------------------

Notes for reviewers: This was motivated by #107270 which could be simplified if timing of passes could be enabled without having to set `llvm::TimePassesIsEnabled` and `llvm::TimePassesPerRun` directly.

>From 33416d81bf28a5c3a1d16fc37ac83661e0ceabe5 Mon Sep 17 00:00:00 2001
From: Tarun Prabhu <tarun.prabhu at gmail.com>
Date: Tue, 17 Sep 2024 08:30:38 -0600
Subject: [PATCH] [llvm][Support] Enable pass timing in
 StandardInstrumentations constructor

Add two optional arguments to the llvm::StandardInstrumentations constructor
that enables pass timings and pass timings per run. If the optional arguments
are not provided, the TimePassesIsEnabled and TimePassesPerRun global variables
will be read when constructing the TimePassesHandler object which will preserve
the current behavior.
---
 llvm/include/llvm/Passes/StandardInstrumentations.h | 4 +++-
 llvm/lib/Passes/StandardInstrumentations.cpp        | 5 ++++-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/llvm/include/llvm/Passes/StandardInstrumentations.h b/llvm/include/llvm/Passes/StandardInstrumentations.h
index fa9c744294a666..37d918eb30e5c7 100644
--- a/llvm/include/llvm/Passes/StandardInstrumentations.h
+++ b/llvm/include/llvm/Passes/StandardInstrumentations.h
@@ -601,7 +601,9 @@ class StandardInstrumentations {
 public:
   StandardInstrumentations(LLVMContext &Context, bool DebugLogging,
                            bool VerifyEach = false,
-                           PrintPassOptions PrintPassOpts = PrintPassOptions());
+                           PrintPassOptions PrintPassOpts = PrintPassOptions(),
+                           std::optional<bool> TimePasses = std::nullopt,
+                           std::optional<bool> TimePassesPerRun = std::nullopt);
 
   // Register all the standard instrumentation callbacks. If \p FAM is nullptr
   // then PreservedCFGChecker is not enabled.
diff --git a/llvm/lib/Passes/StandardInstrumentations.cpp b/llvm/lib/Passes/StandardInstrumentations.cpp
index 036484c9c1c0c4..44a0a2c03718b9 100644
--- a/llvm/lib/Passes/StandardInstrumentations.cpp
+++ b/llvm/lib/Passes/StandardInstrumentations.cpp
@@ -2442,8 +2442,11 @@ void DotCfgChangeReporter::registerCallbacks(
 
 StandardInstrumentations::StandardInstrumentations(
     LLVMContext &Context, bool DebugLogging, bool VerifyEach,
-    PrintPassOptions PrintPassOpts)
+    PrintPassOptions PrintPassOpts, std::optional<bool> EnableTimePasses,
+    std::optional<bool> EnablePerRunTiming)
     : PrintPass(DebugLogging, PrintPassOpts),
+      TimePasses(EnableTimePasses ? *EnableTimePasses : TimePassesIsEnabled,
+                 EnablePerRunTiming ? *EnablePerRunTiming : TimePassesPerRun),
       OptNone(DebugLogging),
       OptPassGate(Context),
       PrintChangedIR(PrintChanged == ChangePrinter::Verbose),



More information about the llvm-commits mailing list