LLVM 19.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"
21#include "llvm/Support/Timer.h"
22#include <memory>
23#include <utility>
24
25namespace llvm {
26
27class Pass;
28class PassInstrumentationCallbacks;
29class 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().
34void reportAndResetTimings(raw_ostream *OutStream = nullptr);
35
36/// Request the timer for this legacy-pass-manager's pass instance.
37Timer *getPassTimer(Pass *);
38
39/// This class implements -time-passes functionality for new pass manager.
40/// It provides the pass-instrumentation callbacks that measure the pass
41/// execution time. They collect timing info into individual timers as
42/// passes are being run. At the end of its life-time it prints the resulting
43/// timing report.
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;
52 TimerGroup AnalysisTG;
53
55 /// Map of timers for pass invocations
56 StringMap<TimerVector> TimingData;
57
58 /// Stack of currently active pass timers. Passes can run other
59 /// passes.
60 SmallVector<Timer *, 8> PassActiveTimerStack;
61 /// Stack of currently active analysis timers. Analyses can request other
62 /// analyses.
63 SmallVector<Timer *, 8> AnalysisActiveTimerStack;
64
65 /// Custom output stream to print timing information into.
66 /// By default (== nullptr) we emit time report into the stream created by
67 /// CreateInfoOutputFile().
68 raw_ostream *OutStream = nullptr;
69
70 bool Enabled;
71 bool PerRun;
72
73public:
75 TimePassesHandler(bool Enabled, bool PerRun = false);
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.
85 void operator=(const TimePassesHandler &) = delete;
86
88
89 /// Set a custom output stream for subsequent reporting.
90 void setOutStream(raw_ostream &OutStream);
91
92private:
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, bool IsPass);
98
99 void startAnalysisTimer(StringRef PassID);
100 void stopAnalysisTimer(StringRef PassID);
101 void startPassTimer(StringRef PassID);
102 void stopPassTimer(StringRef PassID);
103};
104
105} // namespace llvm
106
107#endif
aarch64 AArch64 CCMP Pass
This file defines the StringMap class.
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition: Compiler.h:529
PassInstrumentationCallbacks PIC
This file defines the SmallVector class.
This class manages callbacks registration, as well as provides a way for PassInstrumentation to pass ...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1209
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition: StringMap.h:128
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
This class implements -time-passes functionality for new pass manager.
void registerCallbacks(PassInstrumentationCallbacks &PIC)
TimePassesHandler(const TimePassesHandler &)=delete
void print()
Prints out timing information and then resets the timers.
~TimePassesHandler()
Destructor handles the print action if it has not been handled before.
void operator=(const TimePassesHandler &)=delete
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:173
This class is used to track the amount of time spent between invocations of its startTimer()/stopTime...
Definition: Timer.h:79
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
void reportAndResetTimings(raw_ostream *OutStream=nullptr)
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's pass instance.