LLVM  8.0.1
PassTimingInfo.h
Go to the documentation of this file.
1 //===- PassTimingInfo.h - pass execution timing -----------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 /// \file
10 ///
11 /// This header defines classes/functions to handle pass execution timing
12 /// information with interfaces for both pass managers.
13 ///
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef LLVM_IR_PASSTIMINGINFO_H
17 #define LLVM_IR_PASSTIMINGINFO_H
18 
19 #include "llvm/ADT/Any.h"
20 #include "llvm/ADT/DenseMap.h"
21 #include "llvm/ADT/StringMap.h"
22 #include "llvm/ADT/StringRef.h"
23 #include "llvm/Support/Timer.h"
24 #include "llvm/Support/TypeName.h"
25 #include <memory>
26 namespace llvm {
27 
28 class Pass;
29 class PassInstrumentationCallbacks;
30 
31 /// If -time-passes has been specified, report the timings immediately and then
32 /// reset the timers to zero.
34 
35 /// Request the timer for this legacy-pass-manager's pass instance.
36 Timer *getPassTimer(Pass *);
37 
38 /// If the user specifies the -time-passes argument on an LLVM tool command line
39 /// then the value of this boolean will be true, otherwise false.
40 /// This is the storage for the -time-passes option.
41 extern bool TimePassesIsEnabled;
42 
43 /// This class implements -time-passes functionality for new pass manager.
44 /// It provides the pass-instrumentation callbacks that measure the pass
45 /// execution time. They collect timing info into individual timers as
46 /// passes are being run. At the end of its life-time it prints the resulting
47 /// timing report.
49  /// Value of this type is capable of uniquely identifying pass invocations.
50  /// It is a pair of string Pass-Identifier (which for now is common
51  /// to all the instance of a given pass) + sequential invocation counter.
52  using PassInvocationID = std::pair<StringRef, unsigned>;
53 
54  /// A group of all pass-timing timers.
55  TimerGroup TG;
56 
57  /// Map of timers for pass invocations
59 
60  /// Map that counts invocations of passes, for use in UniqPassID construction.
61  StringMap<unsigned> PassIDCountMap;
62 
63  /// Stack of currently active timers.
64  SmallVector<Timer *, 8> TimerStack;
65 
66  bool Enabled;
67 
68 public:
69  TimePassesHandler(bool Enabled = TimePassesIsEnabled);
70 
71  /// Destructor handles the print action if it has not been handled before.
73  // First destroying the timers from TimingData, which deploys all their
74  // collected data into the TG time group member, which later prints itself
75  // when being destroyed.
76  TimingData.clear();
77  }
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 private:
89  /// Dumps information for running/triggered timers, useful for debugging
90  LLVM_DUMP_METHOD void dump() const;
91 
92  /// Returns the new timer for each new run of the pass.
93  Timer &getPassTimer(StringRef PassID);
94 
95  /// Returns the incremented counter for the next invocation of \p PassID.
96  unsigned nextPassID(StringRef PassID) { return ++PassIDCountMap[PassID]; }
97 
98  void startTimer(StringRef PassID);
99  void stopTimer(StringRef PassID);
100 
101  // Implementation of pass instrumentation callbacks.
102  bool runBeforePass(StringRef PassID);
103  void runAfterPass(StringRef PassID);
104 };
105 
106 } // namespace llvm
107 
108 #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:24
void operator=(const TimePassesHandler &)=delete
void print()
Prints out timing information and then resets the timers.
void reportAndResetTimings()
If -time-passes has been specified, report the timings immediately and then reset the timers to zero...
Timer * getPassTimer(Pass *)
Request the timer for this legacy-pass-manager&#39;s pass instance.
#define LLVM_DUMP_METHOD
Definition: Compiler.h:74
TimePassesHandler(bool Enabled=TimePassesIsEnabled)
This class is used to track the amount of time spent between invocations of its startTimer()/stopTime...
Definition: Timer.h:77
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:847
The TimerGroup class is used to group together related timers into a single report that is printed wh...
Definition: Timer.h:171
This class implements -time-passes functionality for new pass manager.
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:49
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:357