Index: llvm/trunk/include/llvm/IR/LegacyPassManager.h =================================================================== --- llvm/trunk/include/llvm/IR/LegacyPassManager.h +++ llvm/trunk/include/llvm/IR/LegacyPassManager.h @@ -98,9 +98,6 @@ // Create wrappers for C Binding types (see CBindingWrapping.h). DEFINE_STDCXX_CONVERSION_FUNCTIONS(legacy::PassManagerBase, LLVMPassManagerRef) -/// If -time-passes has been specified, report the timings immediately and then -/// reset the timers to zero. -void reportAndResetTimings(); } // End llvm namespace #endif Index: llvm/trunk/include/llvm/IR/PassTimingInfo.h =================================================================== --- llvm/trunk/include/llvm/IR/PassTimingInfo.h +++ llvm/trunk/include/llvm/IR/PassTimingInfo.h @@ -16,57 +16,17 @@ #ifndef LLVM_IR_PASSTIMINGINFO_H #define LLVM_IR_PASSTIMINGINFO_H -#include "llvm/ADT/DenseMap.h" -#include "llvm/ADT/StringMap.h" -#include "llvm/ADT/StringRef.h" -#include "llvm/Support/Timer.h" -#include - namespace llvm { class Pass; -class TimerGroup; +class Timer; -/// Provides a generic interface for collecting pass timing information. -/// Legacy pass managers should specialize with \p PassInfo*. -/// New pass managers should specialize with \p StringRef. -template class PassTimingInfo { -public: - using PassInstanceID = void *; - -private: - StringMap PassIDCountMap; ///< Map that counts instances of passes - DenseMap TimingData; ///< timers for pass instances - TimerGroup TG; - -public: - /// Default constructor for yet-inactive timeinfo. - /// Use \p init() to activate it. - PassTimingInfo(); - - /// Print out timing information and release timers. - ~PassTimingInfo(); - - /// Initializes the static \p TheTimeInfo member to a non-null value when - /// -time-passes is enabled. Leaves it null otherwise. - /// - /// This method may be called multiple times. - static void init(); - - /// Prints out timing information and then resets the timers. - void print(); - - /// Returns the timer for the specified pass if it exists. - Timer *getPassTimer(PassInfoT, PassInstanceID); - - static PassTimingInfo *TheTimeInfo; - -private: - Timer *newPassTimer(StringRef PassID, StringRef PassDesc); -}; +/// If -time-passes has been specified, report the timings immediately and then +/// reset the timers to zero. +void reportAndResetTimings(); +/// Request the timer for this legacy-pass-manager's pass instance. Timer *getPassTimer(Pass *); -Timer *getPassTimer(StringRef); /// 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. Index: llvm/trunk/lib/IR/PassTimingInfo.cpp =================================================================== --- llvm/trunk/lib/IR/PassTimingInfo.cpp +++ llvm/trunk/lib/IR/PassTimingInfo.cpp @@ -10,7 +10,7 @@ // This file implements the LLVM Pass Timing infrastructure for both // new and legacy pass managers. // -// TimingInfo Class - This class is used to calculate information about the +// PassTimingInfo Class - This class is used to calculate information about the // amount of time each pass takes to execute. This only happens when // -time-passes is enabled on the command line. // @@ -34,30 +34,70 @@ namespace llvm { -//===----------------------------------------------------------------------===// -// TimingInfo implementation - bool TimePassesIsEnabled = false; + static cl::opt EnableTiming( "time-passes", cl::location(TimePassesIsEnabled), cl::Hidden, cl::desc("Time each pass, printing elapsed time for each on exit")); namespace { +namespace legacy { + +//===----------------------------------------------------------------------===// +// TimingInfo implementation + +/// Provides an interface for collecting pass timing information. +/// +/// It was intended to be generic but now we decided to split +/// interfaces completely. This is now exclusively for legacy-pass-manager use. +class PassTimingInfo { +public: + using PassInstanceID = void *; + +private: + StringMap PassIDCountMap; ///< Map that counts instances of passes + DenseMap TimingData; ///< timers for pass instances + TimerGroup TG; + +public: + /// Default constructor for yet-inactive timeinfo. + /// Use \p init() to activate it. + PassTimingInfo(); + + /// Print out timing information and release timers. + ~PassTimingInfo(); + + /// Initializes the static \p TheTimeInfo member to a non-null value when + /// -time-passes is enabled. Leaves it null otherwise. + /// + /// This method may be called multiple times. + static void init(); + + /// Prints out timing information and then resets the timers. + void print(); + + /// Returns the timer for the specified pass if it exists. + Timer *getPassTimer(Pass *, PassInstanceID); + + static PassTimingInfo *TheTimeInfo; + +private: + Timer *newPassTimer(StringRef PassID, StringRef PassDesc); +}; + static ManagedStatic> TimingInfoMutex; -} -template -PassTimingInfo::PassTimingInfo() +PassTimingInfo::PassTimingInfo() : TG("pass", "... Pass execution timing report ...") {} -template PassTimingInfo::~PassTimingInfo() { +PassTimingInfo::~PassTimingInfo() { // Deleting the timers accumulates their info into the TG member. // Then TG member is (implicitly) deleted, actually printing the report. for (auto &I : TimingData) delete I.getSecond(); } -template void PassTimingInfo::init() { +void PassTimingInfo::init() { if (!TimePassesIsEnabled || TheTimeInfo) return; @@ -69,13 +109,9 @@ } /// Prints out timing information and then resets the timers. -template void PassTimingInfo::print() { - TG.print(*CreateInfoOutputFile()); -} +void PassTimingInfo::print() { TG.print(*CreateInfoOutputFile()); } -template -Timer *PassTimingInfo::newPassTimer(StringRef PassID, - StringRef PassDesc) { +Timer *PassTimingInfo::newPassTimer(StringRef PassID, StringRef PassDesc) { unsigned &num = PassIDCountMap[PassID]; num++; // Appending description with a pass-instance number for all but the first one @@ -84,22 +120,7 @@ return new Timer(PassID, PassDescNumbered, TG); } -/// Returns the timer for the specified pass instance \p Pass. -/// Instances of the same pass type (uniquely identified by \p PassID) are -/// numbered by the order of appearance. -template <> -Timer *PassTimingInfo::getPassTimer(StringRef PassID, - PassInstanceID Pass) { - init(); - sys::SmartScopedLock Lock(*TimingInfoMutex); - Timer *&T = TimingData[Pass]; - if (!T) - T = newPassTimer(PassID, PassID); - return T; -} - -template <> -Timer *PassTimingInfo::getPassTimer(Pass *P, PassInstanceID Pass) { +Timer *PassTimingInfo::getPassTimer(Pass *P, PassInstanceID Pass) { if (P->getAsPMDataManager()) return nullptr; @@ -117,34 +138,22 @@ return T; } -template -PassTimingInfo *PassTimingInfo::TheTimeInfo; - -template class PassTimingInfo; -template class PassTimingInfo; +PassTimingInfo *PassTimingInfo::TheTimeInfo; +} // namespace legacy +} // namespace Timer *getPassTimer(Pass *P) { - PassTimingInfo::init(); - if (PassTimingInfo::TheTimeInfo) - return PassTimingInfo::TheTimeInfo->getPassTimer(P, P); - return nullptr; -} - -Timer *getPassTimer(StringRef PassName) { - PassTimingInfo::init(); - if (PassTimingInfo::TheTimeInfo) - return PassTimingInfo::TheTimeInfo->getPassTimer(PassName, - nullptr); + legacy::PassTimingInfo::init(); + if (legacy::PassTimingInfo::TheTimeInfo) + return legacy::PassTimingInfo::TheTimeInfo->getPassTimer(P, P); return nullptr; } /// If timing is enabled, report the times collected up to now and then reset /// them. void reportAndResetTimings() { - if (PassTimingInfo::TheTimeInfo) - PassTimingInfo::TheTimeInfo->print(); - if (PassTimingInfo::TheTimeInfo) - PassTimingInfo::TheTimeInfo->print(); + if (legacy::PassTimingInfo::TheTimeInfo) + legacy::PassTimingInfo::TheTimeInfo->print(); } } // namespace llvm Index: llvm/trunk/lib/LTO/LTOCodeGenerator.cpp =================================================================== --- llvm/trunk/lib/LTO/LTOCodeGenerator.cpp +++ llvm/trunk/lib/LTO/LTOCodeGenerator.cpp @@ -33,6 +33,7 @@ #include "llvm/IR/LegacyPassManager.h" #include "llvm/IR/Mangler.h" #include "llvm/IR/Module.h" +#include "llvm/IR/PassTimingInfo.h" #include "llvm/IR/Verifier.h" #include "llvm/InitializePasses.h" #include "llvm/LTO/LTO.h" Index: llvm/trunk/lib/LTO/ThinLTOCodeGenerator.cpp =================================================================== --- llvm/trunk/lib/LTO/ThinLTOCodeGenerator.cpp +++ llvm/trunk/lib/LTO/ThinLTOCodeGenerator.cpp @@ -29,6 +29,7 @@ #include "llvm/IR/LLVMContext.h" #include "llvm/IR/LegacyPassManager.h" #include "llvm/IR/Mangler.h" +#include "llvm/IR/PassTimingInfo.h" #include "llvm/IR/Verifier.h" #include "llvm/IRReader/IRReader.h" #include "llvm/LTO/LTO.h"