LLVM  10.0.0svn
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/StringMap.h"
21 #include "llvm/ADT/StringRef.h"
22 #include "llvm/Support/Timer.h"
23 #include "llvm/Support/TypeName.h"
24 #include <memory>
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 /// If the user specifies the -time-passes argument on an LLVM tool command line
40 /// then the value of this boolean will be true, otherwise false.
41 /// This is the storage for the -time-passes option.
42 extern bool TimePassesIsEnabled;
43 
44 /// This class implements -time-passes functionality for new pass manager.
45 /// It provides the pass-instrumentation callbacks that measure the pass
46 /// execution time. They collect timing info into individual timers as
47 /// passes are being run. At the end of its life-time it prints the resulting
48 /// timing report.
50  /// Value of this type is capable of uniquely identifying pass invocations.
51  /// It is a pair of string Pass-Identifier (which for now is common
52  /// to all the instance of a given pass) + sequential invocation counter.
53  using PassInvocationID = std::pair<StringRef, unsigned>;
54 
55  /// A group of all pass-timing timers.
56  TimerGroup TG;
57 
58  /// Map of timers for pass invocations
60 
61  /// Map that counts invocations of passes, for use in UniqPassID construction.
62  StringMap<unsigned> PassIDCountMap;
63 
64  /// Stack of currently active timers.
65  SmallVector<Timer *, 8> TimerStack;
66 
67  /// Custom output stream to print timing information into.
68  /// By default (== nullptr) we emit time report into the stream created by
69  /// CreateInfoOutputFile().
70  raw_ostream *OutStream = nullptr;
71 
72  bool Enabled;
73 
74 public:
75  TimePassesHandler(bool Enabled = TimePassesIsEnabled);
76 
77  /// Destructor handles the print action if it has not been handled before.
79 
80  /// Prints out timing information and then resets the timers.
81  void print();
82 
83  // We intend this to be unique per-compilation, thus no copies.
84  TimePassesHandler(const TimePassesHandler &) = delete;
85  void operator=(const TimePassesHandler &) = delete;
86 
88 
89  /// Set a custom output stream for subsequent reporting.
90  void setOutStream(raw_ostream &OutStream);
91 
92 private:
93  /// Dumps information for running/triggered timers, useful for debugging
94  LLVM_DUMP_METHOD void dump() const;
95 
96  /// Returns the new timer for each new run of the pass.
97  Timer &getPassTimer(StringRef PassID);
98 
99  /// Returns the incremented counter for the next invocation of \p PassID.
100  unsigned nextPassID(StringRef PassID) { return ++PassIDCountMap[PassID]; }
101 
102  void startTimer(StringRef PassID);
103  void stopTimer(StringRef PassID);
104 
105  // Implementation of pass instrumentation callbacks.
106  bool runBeforePass(StringRef PassID);
107  void runAfterPass(StringRef PassID);
108 };
109 
110 } // namespace llvm
111 
112 #endif
~TimePassesHandler()
Destructor handles the print action if it has not been handled before.
void registerCallbacks(PassInstrumentationCallbacks &PIC)
This class represents lattice values for constants.
Definition: AllocatorList.h:23
void operator=(const TimePassesHandler &)=delete
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
Definition: Compiler.h:476
void setOutStream(raw_ostream &OutStream)
Set a custom output stream for subsequent reporting.
void print()
Prints out timing information and then resets the timers.
Timer * getPassTimer(Pass *)
Request the timer for this legacy-pass-manager&#39;s pass instance.
TimePassesHandler(bool Enabled=TimePassesIsEnabled)
This class is used to track the amount of time spent between invocations of its startTimer()/stopTime...
Definition: Timer.h:76
void reportAndResetTimings(raw_ostream *OutStream=nullptr)
If -time-passes has been specified, report the timings immediately and then reset the timers to zero...
print lazy value Lazy Value Info Printer Pass
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:837
The TimerGroup class is used to group together related timers into a single report that is printed wh...
Definition: Timer.h:170
This class implements -time-passes functionality for new pass manager.
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
This class manages callbacks registration, as well as provides a way for PassInstrumentation to pass ...
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
bool TimePassesIsEnabled
If the user specifies the -time-passes argument on an LLVM tool command line then the value of this b...
Definition: Pass.h:356