2018-08-28 23:06:51 +02:00
|
|
|
//===- PassTimingInfo.h - pass execution timing -----------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2018-08-28 23:06:51 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// \file
|
|
|
|
///
|
|
|
|
/// This header defines classes/functions to handle pass execution timing
|
2018-10-06 00:32:01 +02:00
|
|
|
/// information with interfaces for both pass managers.
|
2018-08-28 23:06:51 +02:00
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_IR_PASSTIMINGINFO_H
|
|
|
|
#define LLVM_IR_PASSTIMINGINFO_H
|
|
|
|
|
2018-10-06 00:32:01 +02:00
|
|
|
#include "llvm/ADT/Any.h"
|
|
|
|
#include "llvm/ADT/DenseMap.h"
|
|
|
|
#include "llvm/ADT/StringMap.h"
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
#include "llvm/Support/Timer.h"
|
|
|
|
#include "llvm/Support/TypeName.h"
|
|
|
|
#include <memory>
|
2018-08-28 23:06:51 +02:00
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
class Pass;
|
2018-10-06 00:32:01 +02:00
|
|
|
class PassInstrumentationCallbacks;
|
2019-03-15 23:15:23 +01:00
|
|
|
class raw_ostream;
|
2018-09-04 08:12:28 +02:00
|
|
|
|
2018-09-26 15:01:43 +02:00
|
|
|
/// If -time-passes has been specified, report the timings immediately and then
|
2019-03-23 00:11:08 +01:00
|
|
|
/// reset the timers to zero. By default it uses the stream created by
|
|
|
|
/// CreateInfoOutputFile().
|
|
|
|
void reportAndResetTimings(raw_ostream *OutStream = nullptr);
|
2018-08-28 23:06:51 +02:00
|
|
|
|
2018-09-26 15:01:43 +02:00
|
|
|
/// Request the timer for this legacy-pass-manager's pass instance.
|
2018-08-28 23:06:51 +02:00
|
|
|
Timer *getPassTimer(Pass *);
|
|
|
|
|
|
|
|
/// If the user specifies the -time-passes argument on an LLVM tool command line
|
|
|
|
/// then the value of this boolean will be true, otherwise false.
|
|
|
|
/// This is the storage for the -time-passes option.
|
|
|
|
extern bool TimePassesIsEnabled;
|
|
|
|
|
2018-10-06 00:32:01 +02:00
|
|
|
/// This class implements -time-passes functionality for new pass manager.
|
|
|
|
/// It provides the pass-instrumentation callbacks that measure the pass
|
|
|
|
/// execution time. They collect timing info into individual timers as
|
|
|
|
/// passes are being run. At the end of its life-time it prints the resulting
|
|
|
|
/// timing report.
|
|
|
|
class TimePassesHandler {
|
|
|
|
/// Value of this type is capable of uniquely identifying pass invocations.
|
|
|
|
/// It is a pair of string Pass-Identifier (which for now is common
|
|
|
|
/// to all the instance of a given pass) + sequential invocation counter.
|
|
|
|
using PassInvocationID = std::pair<StringRef, unsigned>;
|
|
|
|
|
|
|
|
/// A group of all pass-timing timers.
|
|
|
|
TimerGroup TG;
|
|
|
|
|
|
|
|
/// Map of timers for pass invocations
|
|
|
|
DenseMap<PassInvocationID, std::unique_ptr<Timer>> TimingData;
|
|
|
|
|
|
|
|
/// Map that counts invocations of passes, for use in UniqPassID construction.
|
|
|
|
StringMap<unsigned> PassIDCountMap;
|
|
|
|
|
2018-10-06 13:09:15 +02:00
|
|
|
/// Stack of currently active timers.
|
|
|
|
SmallVector<Timer *, 8> TimerStack;
|
2018-10-06 00:32:01 +02:00
|
|
|
|
2019-03-15 23:15:23 +01:00
|
|
|
/// Custom output stream to print timing information into.
|
2019-03-23 00:11:08 +01:00
|
|
|
/// By default (== nullptr) we emit time report into the stream created by
|
|
|
|
/// CreateInfoOutputFile().
|
2019-03-15 23:15:23 +01:00
|
|
|
raw_ostream *OutStream = nullptr;
|
|
|
|
|
2018-10-06 00:32:01 +02:00
|
|
|
bool Enabled;
|
|
|
|
|
|
|
|
public:
|
|
|
|
TimePassesHandler(bool Enabled = TimePassesIsEnabled);
|
|
|
|
|
|
|
|
/// Destructor handles the print action if it has not been handled before.
|
2019-03-15 23:15:23 +01:00
|
|
|
~TimePassesHandler() { print(); }
|
2018-10-06 00:32:01 +02:00
|
|
|
|
|
|
|
/// Prints out timing information and then resets the timers.
|
|
|
|
void print();
|
|
|
|
|
|
|
|
// We intend this to be unique per-compilation, thus no copies.
|
|
|
|
TimePassesHandler(const TimePassesHandler &) = delete;
|
|
|
|
void operator=(const TimePassesHandler &) = delete;
|
|
|
|
|
|
|
|
void registerCallbacks(PassInstrumentationCallbacks &PIC);
|
|
|
|
|
2019-03-15 23:15:23 +01:00
|
|
|
/// Set a custom output stream for subsequent reporting.
|
|
|
|
void setOutStream(raw_ostream &OutStream);
|
|
|
|
|
2018-10-06 00:32:01 +02:00
|
|
|
private:
|
|
|
|
/// Dumps information for running/triggered timers, useful for debugging
|
|
|
|
LLVM_DUMP_METHOD void dump() const;
|
|
|
|
|
|
|
|
/// Returns the new timer for each new run of the pass.
|
|
|
|
Timer &getPassTimer(StringRef PassID);
|
|
|
|
|
|
|
|
/// Returns the incremented counter for the next invocation of \p PassID.
|
|
|
|
unsigned nextPassID(StringRef PassID) { return ++PassIDCountMap[PassID]; }
|
|
|
|
|
|
|
|
void startTimer(StringRef PassID);
|
|
|
|
void stopTimer(StringRef PassID);
|
|
|
|
|
|
|
|
// Implementation of pass instrumentation callbacks.
|
2018-12-11 20:05:35 +01:00
|
|
|
bool runBeforePass(StringRef PassID);
|
|
|
|
void runAfterPass(StringRef PassID);
|
2018-10-06 00:32:01 +02:00
|
|
|
};
|
|
|
|
|
2018-08-28 23:06:51 +02:00
|
|
|
} // namespace llvm
|
|
|
|
|
|
|
|
#endif
|