LLVM 24.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
25namespace llvm {
26
27class Pass;
29class raw_ostream;
30
31/// If the user specifies the -time-passes argument on an LLVM tool command line
32/// then the value of this boolean will be true, otherwise false.
33/// This is the storage for the -time-passes option.
35/// If TimePassesPerRun is true, there would be one line of report for
36/// each pass invocation.
37/// If TimePassesPerRun is false, there would be only one line of
38/// report for each pass (even there are more than one pass objects).
39/// (For new pass manager only)
40LLVM_ABI extern bool TimePassesPerRun;
41
42/// If -time-passes has been specified, report the timings immediately and then
43/// reset the timers to zero. By default it uses the stream created by
44/// CreateInfoOutputFile().
45LLVM_ABI void reportAndResetTimings(raw_ostream *OutStream = nullptr);
46
47/// Request the timer for this legacy-pass-manager's pass instance.
49
50/// This class implements -time-passes functionality for new pass manager.
51/// It provides the pass-instrumentation callbacks that measure the pass
52/// execution time. They collect timing info into individual timers as
53/// passes are being run.
55 /// Groups of timers for passes and analyses.
56 TimerGroup &PassTG =
60
61 using TimerVector = llvm::SmallVector<std::unique_ptr<Timer>, 4>;
62 /// Map of timers for pass invocations
63 StringMap<TimerVector> TimingData;
64
65 /// Stack of currently active pass timers. Passes can run other
66 /// passes.
67 SmallVector<Timer *, 8> PassActiveTimerStack;
68 /// Stack of currently active analysis timers. Analyses can request other
69 /// analyses.
70 SmallVector<Timer *, 8> AnalysisActiveTimerStack;
71
72 /// Custom output stream to print timing information into.
73 /// By default (== nullptr) we emit time report into the stream created by
74 /// CreateInfoOutputFile().
75 raw_ostream *OutStream = nullptr;
76
77 bool Enabled;
78 bool PerRun;
79
80public:
81 static constexpr StringRef PassGroupName = "pass";
82 static constexpr StringRef AnalysisGroupName = "analysis";
83 static constexpr StringRef PassGroupDesc = "Pass execution timing report";
84 static constexpr StringRef AnalysisGroupDesc =
85 "Analysis execution timing report";
86
88 LLVM_ABI TimePassesHandler(bool Enabled, bool PerRun = false);
89
90 /// Prints out timing information and then resets the timers.
91 LLVM_ABI void print();
92
93 // We intend this to be unique per-compilation, thus no copies.
95 void operator=(const TimePassesHandler &) = delete;
96
98
99 /// Set a custom output stream for subsequent reporting.
100 LLVM_ABI void setOutStream(raw_ostream &OutStream);
101
102private:
103 /// Dumps information for running/triggered timers, useful for debugging
104 LLVM_DUMP_METHOD void dump() const;
105
106 /// Returns the new timer for each new run of the pass.
107 Timer &getPassTimer(StringRef PassID, bool IsPass);
108
109 void startAnalysisTimer(StringRef PassID);
110 void stopAnalysisTimer(StringRef PassID);
111 void startPassTimer(StringRef PassID);
112 void stopPassTimer(StringRef PassID);
113};
114
115} // namespace llvm
116
117#endif
This file defines the StringMap class.
#define LLVM_ABI
Definition Compiler.h:211
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition Compiler.h:702
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:97
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:129
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
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