LLVM  17.0.0git
PassTimingInfo.h
Go to the documentation of this file.
1 //===- PassTimingInfo.h - pass execution timing -----------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 /// \file
9 ///
10 /// This header defines classes/functions to handle pass execution timing
11 /// information with interfaces for both pass managers.
12 ///
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_IR_PASSTIMINGINFO_H
16 #define LLVM_IR_PASSTIMINGINFO_H
17 
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/ADT/StringMap.h"
20 #include "llvm/ADT/StringRef.h"
21 #include "llvm/Support/Timer.h"
22 #include <memory>
23 #include <utility>
24 
25 namespace llvm {
26 
27 class Pass;
28 class PassInstrumentationCallbacks;
29 class raw_ostream;
30 
31 /// If -time-passes has been specified, report the timings immediately and then
32 /// reset the timers to zero. By default it uses the stream created by
33 /// CreateInfoOutputFile().
34 void reportAndResetTimings(raw_ostream *OutStream = nullptr);
35 
36 /// Request the timer for this legacy-pass-manager's pass instance.
37 Timer *getPassTimer(Pass *);
38 
39 /// This class implements -time-passes functionality for new pass manager.
40 /// It provides the pass-instrumentation callbacks that measure the pass
41 /// execution time. They collect timing info into individual timers as
42 /// passes are being run. At the end of its life-time it prints the resulting
43 /// timing report.
45  /// Value of this type is capable of uniquely identifying pass invocations.
46  /// It is a pair of string Pass-Identifier (which for now is common
47  /// to all the instance of a given pass) + sequential invocation counter.
48  using PassInvocationID = std::pair<StringRef, unsigned>;
49 
50  /// Groups of timers for passes and analyses.
51  TimerGroup PassTG;
52  TimerGroup AnalysisTG;
53 
55  /// Map of timers for pass invocations
56  StringMap<TimerVector> TimingData;
57 
58  /// Currently active pass timer.
59  Timer *ActivePassTimer = nullptr;
60  /// Stack of currently active analysis timers. Analyses can request other
61  /// analyses.
62  SmallVector<Timer *, 8> AnalysisActiveTimerStack;
63 
64  /// Custom output stream to print timing information into.
65  /// By default (== nullptr) we emit time report into the stream created by
66  /// CreateInfoOutputFile().
67  raw_ostream *OutStream = nullptr;
68 
69  bool Enabled;
70  bool PerRun;
71 
72 public:
74  TimePassesHandler(bool Enabled, bool PerRun = false);
75 
76  /// Destructor handles the print action if it has not been handled before.
78 
79  /// Prints out timing information and then resets the timers.
80  void print();
81 
82  // We intend this to be unique per-compilation, thus no copies.
83  TimePassesHandler(const TimePassesHandler &) = delete;
84  void operator=(const TimePassesHandler &) = delete;
85 
87 
88  /// Set a custom output stream for subsequent reporting.
89  void setOutStream(raw_ostream &OutStream);
90 
91 private:
92  /// Dumps information for running/triggered timers, useful for debugging
93  LLVM_DUMP_METHOD void dump() const;
94 
95  /// Returns the new timer for each new run of the pass.
96  Timer &getPassTimer(StringRef PassID, bool IsPass);
97 
98  void startAnalysisTimer(StringRef PassID);
99  void stopAnalysisTimer(StringRef PassID);
100  void startPassTimer(StringRef PassID);
101  void stopPassTimer(StringRef PassID);
102 };
103 
104 } // namespace llvm
105 
106 #endif
LLVM_DUMP_METHOD
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition: Compiler.h:492
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::reportAndResetTimings
void reportAndResetTimings(raw_ostream *OutStream=nullptr)
If -time-passes has been specified, report the timings immediately and then reset the timers to zero.
Definition: PassTimingInfo.cpp:161
Pass
print lazy value Lazy Value Info Printer Pass
Definition: LazyValueInfo.cpp:2066
StringRef.h
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1199
llvm::TimePassesHandler::operator=
void operator=(const TimePassesHandler &)=delete
llvm::Timer
This class is used to track the amount of time spent between invocations of its startTimer()/stopTime...
Definition: Timer.h:81
PIC
PassInstrumentationCallbacks PIC
Definition: PassBuilderBindings.cpp:55
llvm::TimePassesHandler::TimePassesHandler
TimePassesHandler()
Definition: PassTimingInfo.cpp:200
llvm::TimePassesHandler::print
void print()
Prints out timing information and then resets the timers.
Definition: PassTimingInfo.cpp:207
llvm::TimePassesHandler::~TimePassesHandler
~TimePassesHandler()
Destructor handles the print action if it has not been handled before.
Definition: PassTimingInfo.h:77
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
llvm::StringMap
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition: StringMap.h:110
llvm::TimePassesHandler::setOutStream
void setOutStream(raw_ostream &OutStream)
Set a custom output stream for subsequent reporting.
Definition: PassTimingInfo.cpp:203
Timer.h
llvm::getPassTimer
Timer * getPassTimer(Pass *)
Request the timer for this legacy-pass-manager's pass instance.
Definition: PassTimingInfo.cpp:152
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
llvm::TimePassesHandler::registerCallbacks
void registerCallbacks(PassInstrumentationCallbacks &PIC)
Definition: PassTimingInfo.cpp:299
llvm::TimerGroup
The TimerGroup class is used to group together related timers into a single report that is printed wh...
Definition: Timer.h:175
SmallVector.h
llvm::PassInstrumentationCallbacks
This class manages callbacks registration, as well as provides a way for PassInstrumentation to pass ...
Definition: PassInstrumentation.h:66
llvm::TimePassesHandler
This class implements -time-passes functionality for new pass manager.
Definition: PassTimingInfo.h:44
StringMap.h