LLVM 22.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;
29class PassInstrumentationCallbacks;
30class raw_ostream;
31
32/// If -time-passes has been specified, report the timings immediately and then
33/// reset the timers to zero. By default it uses the stream created by
34/// CreateInfoOutputFile().
35LLVM_ABI void reportAndResetTimings(raw_ostream *OutStream = nullptr);
36
37/// Request the timer for this legacy-pass-manager's pass instance.
38LLVM_ABI Timer *getPassTimer(Pass *);
39
40/// This class implements -time-passes functionality for new pass manager.
41/// It provides the pass-instrumentation callbacks that measure the pass
42/// execution time. They collect timing info into individual timers as
43/// passes are being run.
45 /// Value of this type is capable of uniquely identifying pass invocations.
46 /// It is a pair of string Pass-Identifier (which for now is common
47 /// to all the instance of a given pass) + sequential invocation counter.
48 using PassInvocationID = std::pair<StringRef, unsigned>;
49
50 /// Groups of timers for passes and analyses.
51 TimerGroup &PassTG =
55
57 /// Map of timers for pass invocations
58 StringMap<TimerVector> TimingData;
59
60 /// Stack of currently active pass timers. Passes can run other
61 /// passes.
62 SmallVector<Timer *, 8> PassActiveTimerStack;
63 /// Stack of currently active analysis timers. Analyses can request other
64 /// analyses.
65 SmallVector<Timer *, 8> AnalysisActiveTimerStack;
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 bool PerRun;
74
75public:
76 static constexpr StringRef PassGroupName = "pass";
77 static constexpr StringRef AnalysisGroupName = "analysis";
78 static constexpr StringRef PassGroupDesc = "Pass execution timing report";
79 static constexpr StringRef AnalysisGroupDesc =
80 "Analysis execution timing report";
81
83 LLVM_ABI TimePassesHandler(bool Enabled, bool PerRun = false);
84
85 /// Prints out timing information and then resets the timers.
86 LLVM_ABI void print();
87
88 // We intend this to be unique per-compilation, thus no copies.
90 void operator=(const TimePassesHandler &) = delete;
91
93
94 /// Set a custom output stream for subsequent reporting.
95 LLVM_ABI void setOutStream(raw_ostream &OutStream);
96
97private:
98 /// Dumps information for running/triggered timers, useful for debugging
99 LLVM_DUMP_METHOD void dump() const;
100
101 /// Returns the new timer for each new run of the pass.
102 Timer &getPassTimer(StringRef PassID, bool IsPass);
103
104 void startAnalysisTimer(StringRef PassID);
105 void stopAnalysisTimer(StringRef PassID);
106 void startPassTimer(StringRef PassID);
107 void stopPassTimer(StringRef PassID);
108};
109
110} // namespace llvm
111
112#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:638
PassInstrumentationCallbacks PIC
Shrink Wrap Pass
Definition: ShrinkWrap.cpp:301
This file defines the SmallVector class.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1197
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
This class implements -time-passes functionality for new pass manager.
LLVM_ABI void registerCallbacks(PassInstrumentationCallbacks &PIC)
static constexpr StringRef AnalysisGroupDesc
TimePassesHandler(const TimePassesHandler &)=delete
static constexpr StringRef PassGroupDesc
static constexpr StringRef PassGroupName
LLVM_ABI void print()
Prints out timing information and then resets the timers.
static constexpr StringRef AnalysisGroupName
void operator=(const TimePassesHandler &)=delete
LLVM_ABI void setOutStream(raw_ostream &OutStream)
Set a custom output stream for subsequent reporting.
The TimerGroup class is used to group together related timers into a single report that is printed wh...
Definition: Timer.h:186
This class is used to track the amount of time spent between invocations of its startTimer()/stopTime...
Definition: Timer.h:82
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.
Definition: AddressRanges.h:18
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:258
This class manages callbacks registration, as well as provides a way for PassInstrumentation to pass ...