From 91b8b8010a55ca2969f379e6a110420afbbac12e Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Tue, 10 Mar 2009 20:41:52 +0000 Subject: [PATCH] Add a timer to the DwarfWriter pass that measures the total time it takes to emit exception and debug Dwarf info. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@66571 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/DwarfWriter.h | 6 +- lib/CodeGen/AsmPrinter/DwarfWriter.cpp | 118 +++++++++++++++++++++++-- 2 files changed, 115 insertions(+), 9 deletions(-) diff --git a/include/llvm/CodeGen/DwarfWriter.h b/include/llvm/CodeGen/DwarfWriter.h index a5597322fcb..97cf80bbffd 100644 --- a/include/llvm/CodeGen/DwarfWriter.h +++ b/include/llvm/CodeGen/DwarfWriter.h @@ -33,6 +33,7 @@ class Value; class Module; class GlobalVariable; class TargetAsmInfo; +class Timer; class raw_ostream; //===----------------------------------------------------------------------===// @@ -49,12 +50,15 @@ private: /// DwarfException *DE; + /// DwarfTimer - Timer for the Dwarf writer. + /// + Timer *DwarfTimer; public: static char ID; // Pass identification, replacement for typeid DwarfWriter(); virtual ~DwarfWriter(); - + //===--------------------------------------------------------------------===// // Main entry points. // diff --git a/lib/CodeGen/AsmPrinter/DwarfWriter.cpp b/lib/CodeGen/AsmPrinter/DwarfWriter.cpp index c5b24eff452..ec4f465ed71 100644 --- a/lib/CodeGen/AsmPrinter/DwarfWriter.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfWriter.cpp @@ -25,6 +25,7 @@ #include "llvm/Support/CommandLine.h" #include "llvm/Support/DataTypes.h" #include "llvm/Support/Mangler.h" +#include "llvm/Support/Timer.h" #include "llvm/Support/raw_ostream.h" #include "llvm/System/Path.h" #include "llvm/Target/TargetAsmInfo.h" @@ -47,6 +48,16 @@ static RegisterPass X("dwarfwriter", "DWARF Information Writer"); char DwarfWriter::ID = 0; +namespace { + +static TimerGroup *DwarfTimerGroup = 0; +static TimerGroup *getDwarfTimerGroup() { + if (DwarfTimerGroup) return DwarfTimerGroup; + return DwarfTimerGroup = new TimerGroup("Dwarf Exception and Debugging"); +} + +} // end anonymous namespace + namespace llvm { //===----------------------------------------------------------------------===// @@ -4365,12 +4376,17 @@ void DIE::dump() { /// DwarfWriter Implementation /// -DwarfWriter::DwarfWriter() : ImmutablePass(&ID), DD(NULL), DE(NULL) { +DwarfWriter::DwarfWriter() + : ImmutablePass(&ID), DD(0), DE(0), DwarfTimer(0) { + if (TimePassesIsEnabled) + DwarfTimer = new Timer("Dwarf Writer", *getDwarfTimerGroup()); } DwarfWriter::~DwarfWriter() { delete DE; delete DD; + delete DwarfTimer; + delete DwarfTimerGroup; DwarfTimerGroup = 0; } /// BeginModule - Emit all Dwarf sections that should come prior to the @@ -4379,42 +4395,74 @@ void DwarfWriter::BeginModule(Module *M, MachineModuleInfo *MMI, raw_ostream &OS, AsmPrinter *A, const TargetAsmInfo *T) { + if (TimePassesIsEnabled) + DwarfTimer->startTimer(); + DE = new DwarfException(OS, A, T); DD = new DwarfDebug(OS, A, T); DE->BeginModule(M); DD->BeginModule(M); DD->SetDebugInfo(MMI); DE->SetModuleInfo(MMI); + + if (TimePassesIsEnabled) + DwarfTimer->stopTimer(); } /// EndModule - Emit all Dwarf sections that should come after the content. /// void DwarfWriter::EndModule() { + if (TimePassesIsEnabled) + DwarfTimer->startTimer(); + DE->EndModule(); DD->EndModule(); + + if (TimePassesIsEnabled) + DwarfTimer->stopTimer(); } /// BeginFunction - Gather pre-function debug information. Assumes being /// emitted immediately after the function entry point. void DwarfWriter::BeginFunction(MachineFunction *MF) { + if (TimePassesIsEnabled) + DwarfTimer->startTimer(); + DE->BeginFunction(MF); DD->BeginFunction(MF); + + if (TimePassesIsEnabled) + DwarfTimer->stopTimer(); } /// EndFunction - Gather and emit post-function debug information. /// void DwarfWriter::EndFunction(MachineFunction *MF) { + if (TimePassesIsEnabled) + DwarfTimer->startTimer(); + DD->EndFunction(MF); DE->EndFunction(); if (MachineModuleInfo *MMI = DD->getMMI() ? DD->getMMI() : DE->getMMI()) // Clear function debug information. MMI->EndFunction(); + + if (TimePassesIsEnabled) + DwarfTimer->stopTimer(); } /// ValidDebugInfo - Return true if V represents valid debug info value. bool DwarfWriter::ValidDebugInfo(Value *V) { - return DD && DD->ValidDebugInfo(V); + if (TimePassesIsEnabled) + DwarfTimer->startTimer(); + + bool Res = DD && DD->ValidDebugInfo(V); + + if (TimePassesIsEnabled) + DwarfTimer->stopTimer(); + + return Res; } /// RecordSourceLine - Records location information and associates it with a @@ -4422,7 +4470,15 @@ bool DwarfWriter::ValidDebugInfo(Value *V) { /// correspondence to the source line list. unsigned DwarfWriter::RecordSourceLine(unsigned Line, unsigned Col, unsigned Src) { - return DD->RecordSourceLine(Line, Col, Src); + if (TimePassesIsEnabled) + DwarfTimer->startTimer(); + + unsigned Res = DD->RecordSourceLine(Line, Col, Src); + + if (TimePassesIsEnabled) + DwarfTimer->stopTimer(); + + return Res; } /// getOrCreateSourceID - Look up the source id with the given directory and @@ -4431,32 +4487,78 @@ unsigned DwarfWriter::RecordSourceLine(unsigned Line, unsigned Col, /// as well. unsigned DwarfWriter::getOrCreateSourceID(const std::string &DirName, const std::string &FileName) { - return DD->getOrCreateSourceID(DirName, FileName); + if (TimePassesIsEnabled) + DwarfTimer->startTimer(); + + unsigned Res = DD->getOrCreateSourceID(DirName, FileName); + + if (TimePassesIsEnabled) + DwarfTimer->stopTimer(); + + return Res; } /// RecordRegionStart - Indicate the start of a region. unsigned DwarfWriter::RecordRegionStart(GlobalVariable *V) { - return DD->RecordRegionStart(V); + if (TimePassesIsEnabled) + DwarfTimer->startTimer(); + + unsigned Res = DD->RecordRegionStart(V); + + if (TimePassesIsEnabled) + DwarfTimer->stopTimer(); + + return Res; } /// RecordRegionEnd - Indicate the end of a region. unsigned DwarfWriter::RecordRegionEnd(GlobalVariable *V) { - return DD->RecordRegionEnd(V); + if (TimePassesIsEnabled) + DwarfTimer->startTimer(); + + unsigned Res = DD->RecordRegionEnd(V); + + if (TimePassesIsEnabled) + DwarfTimer->stopTimer(); + + return Res; } /// getRecordSourceLineCount - Count source lines. unsigned DwarfWriter::getRecordSourceLineCount() { - return DD->getRecordSourceLineCount(); + if (TimePassesIsEnabled) + DwarfTimer->startTimer(); + + unsigned Res = DD->getRecordSourceLineCount(); + + if (TimePassesIsEnabled) + DwarfTimer->stopTimer(); + + return Res; } /// RecordVariable - Indicate the declaration of a local variable. /// void DwarfWriter::RecordVariable(GlobalVariable *GV, unsigned FrameIndex) { + if (TimePassesIsEnabled) + DwarfTimer->startTimer(); + DD->RecordVariable(GV, FrameIndex); + + if (TimePassesIsEnabled) + DwarfTimer->stopTimer(); } /// ShouldEmitDwarfDebug - Returns true if Dwarf debugging declarations should /// be emitted. bool DwarfWriter::ShouldEmitDwarfDebug() const { - return DD->ShouldEmitDwarfDebug(); + if (TimePassesIsEnabled) + DwarfTimer->startTimer(); + + bool Res = DD->ShouldEmitDwarfDebug(); + + if (TimePassesIsEnabled) + DwarfTimer->stopTimer(); + + return Res; }