LLVM  14.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/Any.h"
19 #include "llvm/ADT/DenseMap.h"
20 #include "llvm/ADT/SmallVector.h"
21 #include "llvm/ADT/StringMap.h"
22 #include "llvm/ADT/StringRef.h"
23 #include "llvm/Support/Timer.h"
24 #include <memory>
25 #include <utility>
26 
27 namespace llvm {
28 
29 class Pass;
30 class PassInstrumentationCallbacks;
31 class raw_ostream;
32 
33 /// If -time-passes has been specified, report the timings immediately and then
34 /// reset the timers to zero. By default it uses the stream created by
35 /// CreateInfoOutputFile().
36 void reportAndResetTimings(raw_ostream *OutStream = nullptr);
37 
38 /// Request the timer for this legacy-pass-manager's pass instance.
39 Timer *getPassTimer(Pass *);
40 
41 /// This class implements -time-passes functionality for new pass manager.
42 /// It provides the pass-instrumentation callbacks that measure the pass
43 /// execution time. They collect timing info into individual timers as
44 /// passes are being run. At the end of its life-time it prints the resulting
45 /// timing report.
47  /// Value of this type is capable of uniquely identifying pass invocations.
48  /// It is a pair of string Pass-Identifier (which for now is common
49  /// to all the instance of a given pass) + sequential invocation counter.
50  using PassInvocationID = std::pair<StringRef, unsigned>;
51 
52  /// A group of all pass-timing timers.
53  TimerGroup TG;
54 
56  /// Map of timers for pass invocations
57  StringMap<TimerVector> TimingData;
58 
59  /// Stack of currently active timers.
60  SmallVector<Timer *, 8> TimerStack;
61 
62  /// Custom output stream to print timing information into.
63  /// By default (== nullptr) we emit time report into the stream created by
64  /// CreateInfoOutputFile().
65  raw_ostream *OutStream = nullptr;
66 
67  bool Enabled;
68  bool PerRun;
69 
70 public:
72  TimePassesHandler(bool Enabled, bool PerRun = false);
73 
74  /// Destructor handles the print action if it has not been handled before.
76 
77  /// Prints out timing information and then resets the timers.
78  void print();
79 
80  // We intend this to be unique per-compilation, thus no copies.
81  TimePassesHandler(const TimePassesHandler &) = delete;
82  void operator=(const TimePassesHandler &) = delete;
83 
85 
86  /// Set a custom output stream for subsequent reporting.
87  void setOutStream(raw_ostream &OutStream);
88 
89 private:
90  /// Dumps information for running/triggered timers, useful for debugging
91  LLVM_DUMP_METHOD void dump() const;
92 
93  /// Returns the new timer for each new run of the pass.
94  Timer &getPassTimer(StringRef PassID);
95 
96  void startTimer(StringRef PassID);
97  void stopTimer(StringRef PassID);
98 
99  // Implementation of pass instrumentation callbacks.
100  void runBeforePass(StringRef PassID);
101  void runAfterPass(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:506
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
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:162
Pass
print lazy value Lazy Value Info Printer Pass
Definition: LazyValueInfo.cpp:1965
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:1168
llvm::TimePassesHandler::operator=
void operator=(const TimePassesHandler &)=delete
DenseMap.h
llvm::Timer
This class is used to track the amount of time spent between invocations of its startTimer()/stopTime...
Definition: Timer.h:82
PIC
PassInstrumentationCallbacks PIC
Definition: PassBuilderBindings.cpp:55
llvm::TimePassesHandler::TimePassesHandler
TimePassesHandler()
Definition: PassTimingInfo.cpp:199
llvm::TimePassesHandler::print
void print()
Prints out timing information and then resets the timers.
Definition: PassTimingInfo.cpp:206
llvm::TimePassesHandler::~TimePassesHandler
~TimePassesHandler()
Destructor handles the print action if it has not been handled before.
Definition: PassTimingInfo.h:75
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
StringMap.h
llvm::StringMap
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition: StringMap.h:108
llvm::TimePassesHandler::setOutStream
void setOutStream(raw_ostream &OutStream)
Set a custom output stream for subsequent reporting.
Definition: PassTimingInfo.cpp:202
Timer.h
llvm::getPassTimer
Timer * getPassTimer(Pass *)
Request the timer for this legacy-pass-manager's pass instance.
Definition: PassTimingInfo.cpp:153
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::TimePassesHandler::registerCallbacks
void registerCallbacks(PassInstrumentationCallbacks &PIC)
Definition: PassTimingInfo.cpp:273
llvm::TimerGroup
The TimerGroup class is used to group together related timers into a single report that is printed wh...
Definition: Timer.h:176
Any.h
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:46