LLVM 23.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
19#include "llvm/ADT/StringMap.h"
20#include "llvm/ADT/StringRef.h"
22#include "llvm/Support/Timer.h"
23#include <memory>
24#include <utility>
25
26namespace llvm {
27
28class Pass;
30class raw_ostream;
31
32/// If the user specifies the -time-passes argument on an LLVM tool command line
33/// then the value of this boolean will be true, otherwise false.
34/// This is the storage for the -time-passes option.
36/// If TimePassesPerRun is true, there would be one line of report for
37/// each pass invocation.
38/// If TimePassesPerRun is false, there would be only one line of
39/// report for each pass (even there are more than one pass objects).
40/// (For new pass manager only)
41LLVM_ABI extern bool TimePassesPerRun;
42
43/// If -time-passes has been specified, report the timings immediately and then
44/// reset the timers to zero. By default it uses the stream created by
45/// CreateInfoOutputFile().
46LLVM_ABI void reportAndResetTimings(raw_ostream *OutStream = nullptr);
47
48/// Request the timer for this legacy-pass-manager's pass instance.
50
51/// This class implements -time-passes functionality for new pass manager.
52/// It provides the pass-instrumentation callbacks that measure the pass
53/// execution time. They collect timing info into individual timers as
54/// passes are being run.
56 /// Value of this type is capable of uniquely identifying pass invocations.
57 /// It is a pair of string Pass-Identifier (which for now is common
58 /// to all the instance of a given pass) + sequential invocation counter.
59 using PassInvocationID = std::pair<StringRef, unsigned>;
60
61 /// Groups of timers for passes and analyses.
62 TimerGroup &PassTG =
66
67 using TimerVector = llvm::SmallVector<std::unique_ptr<Timer>, 4>;
68 /// Map of timers for pass invocations
69 StringMap<TimerVector> TimingData;
70
71 /// Stack of currently active pass timers. Passes can run other
72 /// passes.
73 SmallVector<Timer *, 8> PassActiveTimerStack;
74 /// Stack of currently active analysis timers. Analyses can request other
75 /// analyses.
76 SmallVector<Timer *, 8> AnalysisActiveTimerStack;
77
78 /// Custom output stream to print timing information into.
79 /// By default (== nullptr) we emit time report into the stream created by
80 /// CreateInfoOutputFile().
81 raw_ostream *OutStream = nullptr;
82
83 bool Enabled;
84 bool PerRun;
85
86public:
87 static constexpr StringRef PassGroupName = "pass";
88 static constexpr StringRef AnalysisGroupName = "analysis";
89 static constexpr StringRef PassGroupDesc = "Pass execution timing report";
90 static constexpr StringRef AnalysisGroupDesc =
91 "Analysis execution timing report";
92
94 LLVM_ABI TimePassesHandler(bool Enabled, bool PerRun = false);
95
96 /// Prints out timing information and then resets the timers.
97 LLVM_ABI void print();
98
99 // We intend this to be unique per-compilation, thus no copies.
101 void operator=(const TimePassesHandler &) = delete;
102
104
105 /// Set a custom output stream for subsequent reporting.
106 LLVM_ABI void setOutStream(raw_ostream &OutStream);
107
108private:
109 /// Dumps information for running/triggered timers, useful for debugging
110 LLVM_DUMP_METHOD void dump() const;
111
112 /// Returns the new timer for each new run of the pass.
113 Timer &getPassTimer(StringRef PassID, bool IsPass);
114
115 void startAnalysisTimer(StringRef PassID);
116 void stopAnalysisTimer(StringRef PassID);
117 void startPassTimer(StringRef PassID);
118 void stopPassTimer(StringRef PassID);
119};
120
121} // namespace llvm
122
123#endif
This file defines the StringMap class.
#define LLVM_ABI
Definition Compiler.h:213
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition Compiler.h:661
PassInstrumentationCallbacks PIC
This file defines the SmallVector class.
This class manages callbacks registration, as well as provides a way for PassInstrumentation to pass ...
Pass interface - Implemented by all 'passes'.
Definition Pass.h:99
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition StringMap.h:133
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
LLVM_ABI void print()
Prints out timing information and then resets the timers.
static constexpr StringRef AnalysisGroupDesc
TimePassesHandler(const TimePassesHandler &)=delete
LLVM_ABI void setOutStream(raw_ostream &OutStream)
Set a custom output stream for subsequent reporting.
LLVM_ABI void registerCallbacks(PassInstrumentationCallbacks &PIC)
static constexpr StringRef PassGroupDesc
static constexpr StringRef PassGroupName
static constexpr StringRef AnalysisGroupName
void operator=(const TimePassesHandler &)=delete
The TimerGroup class is used to group together related timers into a single report that is printed wh...
Definition Timer.h:191
This class is used to track the amount of time spent between invocations of its startTimer()/stopTime...
Definition Timer.h:87
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI bool TimePassesIsEnabled
If the user specifies the -time-passes argument on an LLVM tool command line then the value of this b...
LLVM_ABI bool TimePassesPerRun
If TimePassesPerRun is true, there would be one line of report for each pass invocation.
LLVM_ABI void reportAndResetTimings(raw_ostream *OutStream=nullptr)
If -time-passes has been specified, report the timings immediately and then reset the timers to zero.
LLVM_ABI Timer * getPassTimer(Pass *)
Request the timer for this legacy-pass-manager's pass instance.
static LLVM_ABI TimerGroup & getNamedTimerGroup(StringRef GroupName, StringRef GroupDescription)
Definition Timer.cpp:260