[llvm] r343104 - [PassTiming] cleaning up legacy PassTimingInfo interface. NFCI.

Fedor Sergeev via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 26 06:01:45 PDT 2018


Author: fedor.sergeev
Date: Wed Sep 26 06:01:43 2018
New Revision: 343104

URL: http://llvm.org/viewvc/llvm-project?rev=343104&view=rev
Log:
[PassTiming] cleaning up legacy PassTimingInfo interface. NFCI.

During D51276 discussion it was decided that legacy PassTimingInfo
interface can not be reused for new pass manager's implementation
of -time-passes.

This is a cleanup in preparation for D51276 to make legacy interface
as concise as possible, moving the PassTimingInfo from the header
into the anonymous legacy namespace in .cpp.

It is rather close to a revert of rL340872 in a sense that it hides
the interface and gets rid of templates. However as compared to
a complete revert it resides in a different translation unit and has
an additional pass-instance counting funcitonality (PassIDCountMap).

Reviewers: philip.pfaffe
Differential Revision: https://reviews.llvm.org/D52356

Modified:
    llvm/trunk/include/llvm/IR/LegacyPassManager.h
    llvm/trunk/include/llvm/IR/PassTimingInfo.h
    llvm/trunk/lib/IR/PassTimingInfo.cpp
    llvm/trunk/lib/LTO/LTOCodeGenerator.cpp
    llvm/trunk/lib/LTO/ThinLTOCodeGenerator.cpp

Modified: llvm/trunk/include/llvm/IR/LegacyPassManager.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/LegacyPassManager.h?rev=343104&r1=343103&r2=343104&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/LegacyPassManager.h (original)
+++ llvm/trunk/include/llvm/IR/LegacyPassManager.h Wed Sep 26 06:01:43 2018
@@ -98,9 +98,6 @@ private:
 // 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

Modified: llvm/trunk/include/llvm/IR/PassTimingInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/PassTimingInfo.h?rev=343104&r1=343103&r2=343104&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/PassTimingInfo.h (original)
+++ llvm/trunk/include/llvm/IR/PassTimingInfo.h Wed Sep 26 06:01:43 2018
@@ -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 <string>
-
 namespace llvm {
 
 class Pass;
-class TimerGroup;
-
-/// 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 <typename PassInfoT> class PassTimingInfo {
-public:
-  using PassInstanceID = void *;
-
-private:
-  StringMap<unsigned> PassIDCountMap; ///< Map that counts instances of passes
-  DenseMap<PassInstanceID, Timer *> 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;
+class Timer;
 
-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.

Modified: llvm/trunk/lib/IR/PassTimingInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/PassTimingInfo.cpp?rev=343104&r1=343103&r2=343104&view=diff
==============================================================================
--- llvm/trunk/lib/IR/PassTimingInfo.cpp (original)
+++ llvm/trunk/lib/IR/PassTimingInfo.cpp Wed Sep 26 06:01:43 2018
@@ -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 @@ using namespace llvm;
 
 namespace llvm {
 
-//===----------------------------------------------------------------------===//
-// TimingInfo implementation
-
 bool TimePassesIsEnabled = false;
+
 static cl::opt<bool, true> 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<unsigned> PassIDCountMap; ///< Map that counts instances of passes
+  DenseMap<PassInstanceID, Timer *> 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<sys::SmartMutex<true>> TimingInfoMutex;
-}
 
-template <typename PassT>
-PassTimingInfo<PassT>::PassTimingInfo()
+PassTimingInfo::PassTimingInfo()
     : TG("pass", "... Pass execution timing report ...") {}
 
-template <typename PassT> PassTimingInfo<PassT>::~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 <typename PassT> void PassTimingInfo<PassT>::init() {
+void PassTimingInfo::init() {
   if (!TimePassesIsEnabled || TheTimeInfo)
     return;
 
@@ -69,13 +109,9 @@ template <typename PassT> void PassTimin
 }
 
 /// Prints out timing information and then resets the timers.
-template <typename PassT> void PassTimingInfo<PassT>::print() {
-  TG.print(*CreateInfoOutputFile());
-}
+void PassTimingInfo::print() { TG.print(*CreateInfoOutputFile()); }
 
-template <typename PassInfoT>
-Timer *PassTimingInfo<PassInfoT>::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 @@ Timer *PassTimingInfo<PassInfoT>::newPas
   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<StringRef>::getPassTimer(StringRef PassID,
-                                               PassInstanceID Pass) {
-  init();
-  sys::SmartScopedLock<true> Lock(*TimingInfoMutex);
-  Timer *&T = TimingData[Pass];
-  if (!T)
-    T = newPassTimer(PassID, PassID);
-  return T;
-}
-
-template <>
-Timer *PassTimingInfo<Pass *>::getPassTimer(Pass *P, PassInstanceID Pass) {
+Timer *PassTimingInfo::getPassTimer(Pass *P, PassInstanceID Pass) {
   if (P->getAsPMDataManager())
     return nullptr;
 
@@ -117,34 +138,22 @@ Timer *PassTimingInfo<Pass *>::getPassTi
   return T;
 }
 
-template <typename PassInfoT>
-PassTimingInfo<PassInfoT> *PassTimingInfo<PassInfoT>::TheTimeInfo;
-
-template class PassTimingInfo<Pass *>;
-template class PassTimingInfo<StringRef>;
+PassTimingInfo *PassTimingInfo::TheTimeInfo;
+} // namespace legacy
+} // namespace
 
 Timer *getPassTimer(Pass *P) {
-  PassTimingInfo<Pass *>::init();
-  if (PassTimingInfo<Pass *>::TheTimeInfo)
-    return PassTimingInfo<Pass *>::TheTimeInfo->getPassTimer(P, P);
-  return nullptr;
-}
-
-Timer *getPassTimer(StringRef PassName) {
-  PassTimingInfo<StringRef>::init();
-  if (PassTimingInfo<StringRef>::TheTimeInfo)
-    return PassTimingInfo<StringRef>::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<StringRef>::TheTimeInfo)
-    PassTimingInfo<StringRef>::TheTimeInfo->print();
-  if (PassTimingInfo<Pass *>::TheTimeInfo)
-    PassTimingInfo<Pass *>::TheTimeInfo->print();
+  if (legacy::PassTimingInfo::TheTimeInfo)
+    legacy::PassTimingInfo::TheTimeInfo->print();
 }
 
 } // namespace llvm

Modified: llvm/trunk/lib/LTO/LTOCodeGenerator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/LTOCodeGenerator.cpp?rev=343104&r1=343103&r2=343104&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/LTOCodeGenerator.cpp (original)
+++ llvm/trunk/lib/LTO/LTOCodeGenerator.cpp Wed Sep 26 06:01:43 2018
@@ -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"

Modified: llvm/trunk/lib/LTO/ThinLTOCodeGenerator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/ThinLTOCodeGenerator.cpp?rev=343104&r1=343103&r2=343104&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/ThinLTOCodeGenerator.cpp (original)
+++ llvm/trunk/lib/LTO/ThinLTOCodeGenerator.cpp Wed Sep 26 06:01:43 2018
@@ -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"




More information about the llvm-commits mailing list