From 410cbf9d39a2189be400865646fb5c2907c24129 Mon Sep 17 00:00:00 2001 From: Daniel Sanders Date: Mon, 11 Feb 2019 23:02:02 +0000 Subject: [PATCH] [tblgen] Add a timer covering the time spent reading the Instruction defs This patch adds a -time-regions option to tablegen that can enable timers (currently only one) that assess the performance of tablegen itself. This can be useful for identifying scaling problems with tablegen backends. This particular timer has allowed me to ignore time that is not attributed the GISel combiner pass. It's useful by itself but it is particularly useful in combination with https://reviews.llvm.org/D52954 which causes this period of time to be annotated within Xcode Instruments which in turn allows profile samples and recorded allocations attributed to reading instructions to be filtered out. llvm-svn: 353763 --- include/llvm/TableGen/TableGenBackend.h | 2 ++ utils/TableGen/CodeGenTarget.cpp | 4 ++++ utils/TableGen/TableGen.cpp | 11 +++++++++++ 3 files changed, 17 insertions(+) diff --git a/include/llvm/TableGen/TableGenBackend.h b/include/llvm/TableGen/TableGenBackend.h index 08c581519fc..a426e421757 100644 --- a/include/llvm/TableGen/TableGenBackend.h +++ b/include/llvm/TableGen/TableGenBackend.h @@ -22,6 +22,8 @@ class raw_ostream; /// raw_ostream. void emitSourceFileHeader(StringRef Desc, raw_ostream &OS); +extern bool TimeRegions; + } // End llvm namespace #endif diff --git a/utils/TableGen/CodeGenTarget.cpp b/utils/TableGen/CodeGenTarget.cpp index 5dcb5e230cc..5c7be10cebc 100644 --- a/utils/TableGen/CodeGenTarget.cpp +++ b/utils/TableGen/CodeGenTarget.cpp @@ -20,8 +20,10 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Support/CommandLine.h" +#include "llvm/Support/Timer.h" #include "llvm/TableGen/Error.h" #include "llvm/TableGen/Record.h" +#include "llvm/TableGen/TableGenBackend.h" #include using namespace llvm; @@ -326,6 +328,8 @@ CodeGenSchedModels &CodeGenTarget::getSchedModels() const { } void CodeGenTarget::ReadInstructions() const { + NamedRegionTimer T("Read Instructions", "Time spent reading instructions", + "CodeGenTarget", "CodeGenTarget", TimeRegions); std::vector Insts = Records.getAllDerivedDefinitions("Instruction"); if (Insts.size() <= 2) PrintFatalError("No 'Instruction' subclasses defined!"); diff --git a/utils/TableGen/TableGen.cpp b/utils/TableGen/TableGen.cpp index 38f81dc396c..c485ed2feb7 100644 --- a/utils/TableGen/TableGen.cpp +++ b/utils/TableGen/TableGen.cpp @@ -55,6 +55,12 @@ enum ActionType { GenExegesis, }; +namespace llvm { +/// Storage for TimeRegionsOpt as a global so that backends aren't required to +/// include CommandLine.h +bool TimeRegions = false; +} // end namespace llvm + namespace { cl::opt Action(cl::desc("Action to perform:"), @@ -126,6 +132,11 @@ namespace { Class("class", cl::desc("Print Enum list for this class"), cl::value_desc("class name"), cl::cat(PrintEnumsCat)); +cl::opt + TimeRegionsOpt("time-regions", + cl::desc("Time regions of tablegens execution"), + cl::location(TimeRegions)); + bool LLVMTableGenMain(raw_ostream &OS, RecordKeeper &Records) { switch (Action) { case PrintRecords: