diff options
-rw-r--r-- | include/clang/Frontend/CompilerInstance.h | 18 | ||||
-rw-r--r-- | include/clang/Frontend/FrontendAction.h | 17 | ||||
-rw-r--r-- | lib/Frontend/CompilerInstance.cpp | 5 | ||||
-rw-r--r-- | lib/Frontend/FrontendAction.cpp | 9 | ||||
-rw-r--r-- | tools/clang-cc/clang-cc.cpp | 10 |
5 files changed, 30 insertions, 29 deletions
diff --git a/include/clang/Frontend/CompilerInstance.h b/include/clang/Frontend/CompilerInstance.h index ed28050877..d7e7d991f3 100644 --- a/include/clang/Frontend/CompilerInstance.h +++ b/include/clang/Frontend/CompilerInstance.h @@ -21,6 +21,7 @@ namespace llvm { class LLVMContext; class raw_ostream; class raw_fd_ostream; +class Timer; } namespace clang { @@ -89,6 +90,9 @@ class CompilerInstance { /// The code completion consumer. llvm::OwningPtr<CodeCompleteConsumer> CompletionConsumer; + /// The frontend timer + llvm::OwningPtr<llvm::Timer> FrontendTimer; + /// The list of active output files. std::list< std::pair<std::string, llvm::raw_ostream*> > OutputFiles; @@ -367,6 +371,17 @@ public: void setCodeCompletionConsumer(CodeCompleteConsumer *Value); /// } + /// @name Frontend timer + /// { + + bool hasFrontendTimer() const { return FrontendTimer != 0; } + + llvm::Timer &getFrontendTimer() const { + assert(FrontendTimer && "Compiler instance has no frontend timer!"); + return *FrontendTimer; + } + + /// } /// @name Output Files /// { @@ -462,6 +477,9 @@ public: bool UseDebugPrinter, bool ShowMacros, llvm::raw_ostream &OS); + /// Create the frontend timer and replace any existing one with it. + void createFrontendTimer(); + /// Create the default output file (from the invocation's options) and add it /// to the list of tracked output files. llvm::raw_fd_ostream * diff --git a/include/clang/Frontend/FrontendAction.h b/include/clang/Frontend/FrontendAction.h index 469ea535f6..3042767af8 100644 --- a/include/clang/Frontend/FrontendAction.h +++ b/include/clang/Frontend/FrontendAction.h @@ -14,10 +14,6 @@ #include "llvm/ADT/OwningPtr.h" #include <string> -namespace llvm { -class Timer; -} - namespace clang { class ASTUnit; class ASTConsumer; @@ -29,7 +25,6 @@ class FrontendAction { std::string CurrentFile; llvm::OwningPtr<ASTUnit> CurrentASTUnit; CompilerInstance *Instance; - llvm::Timer *CurrentTimer; protected: /// @name Implementation Action Interface @@ -112,18 +107,6 @@ public: void setCurrentFile(llvm::StringRef Value, ASTUnit *AST = 0); /// @} - /// @name Timing Utilities - /// @{ - - llvm::Timer *getCurrentTimer() const { - return CurrentTimer; - } - - void setCurrentTimer(llvm::Timer *Value) { - CurrentTimer = Value; - } - - /// @} /// @name Supported Modes /// @{ diff --git a/lib/Frontend/CompilerInstance.cpp b/lib/Frontend/CompilerInstance.cpp index 872b7713f3..1cb5993fae 100644 --- a/lib/Frontend/CompilerInstance.cpp +++ b/lib/Frontend/CompilerInstance.cpp @@ -27,6 +27,7 @@ #include "llvm/LLVMContext.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/raw_ostream.h" +#include "llvm/Support/Timer.h" #include "llvm/System/Path.h" using namespace clang; @@ -257,6 +258,10 @@ void CompilerInstance::createCodeCompletionConsumer() { llvm::outs())); } +void CompilerInstance::createFrontendTimer() { + FrontendTimer.reset(new llvm::Timer("Clang front-end timer")); +} + CodeCompleteConsumer * CompilerInstance::createCodeCompletionConsumer(Preprocessor &PP, const std::string &Filename, diff --git a/lib/Frontend/FrontendAction.cpp b/lib/Frontend/FrontendAction.cpp index ff63a0dab5..91c946c9cf 100644 --- a/lib/Frontend/FrontendAction.cpp +++ b/lib/Frontend/FrontendAction.cpp @@ -21,7 +21,7 @@ #include "llvm/Support/raw_ostream.h" using namespace clang; -FrontendAction::FrontendAction() : Instance(0), CurrentTimer(0) {} +FrontendAction::FrontendAction() : Instance(0) {} FrontendAction::~FrontendAction() {} @@ -144,8 +144,11 @@ void FrontendAction::Execute() { return; } - llvm::TimeRegion Timer(CurrentTimer); - ExecuteAction(); + if (CI.hasFrontendTimer()) { + llvm::TimeRegion Timer(CI.getFrontendTimer()); + ExecuteAction(); + } + else ExecuteAction(); } void FrontendAction::EndSourceFile() { diff --git a/tools/clang-cc/clang-cc.cpp b/tools/clang-cc/clang-cc.cpp index 3dfe51190d..a5996c6fc5 100644 --- a/tools/clang-cc/clang-cc.cpp +++ b/tools/clang-cc/clang-cc.cpp @@ -74,11 +74,6 @@ static void LLVMErrorHandler(void *UserData, const std::string &Message) { exit(1); } -/// ClangFrontendTimer - The front-end activities should charge time to it with -/// TimeRegion. The -ftime-report option controls whether this will do -/// anything. -llvm::Timer *ClangFrontendTimer = 0; - static FrontendAction *CreateFrontendAction(CompilerInstance &CI) { using namespace clang::frontend; @@ -244,7 +239,7 @@ int main(int argc, char **argv) { << " hosted on " << llvm::sys::getHostTriple() << "\n"; if (Clang.getFrontendOpts().ShowTimers) - ClangFrontendTimer = new llvm::Timer("Clang front-end time"); + Clang.createFrontendTimer(); for (unsigned i = 0, e = Clang.getFrontendOpts().Inputs.size(); i != e; ++i) { const std::string &InFile = Clang.getFrontendOpts().Inputs[i].second; @@ -272,7 +267,6 @@ int main(int argc, char **argv) { if (!Act) break; - Act->setCurrentTimer(ClangFrontendTimer); if (Act->BeginSourceFile(Clang, InFile, IsAST)) { Act->Execute(); Act->EndSourceFile(); @@ -289,8 +283,6 @@ int main(int argc, char **argv) { fprintf(stderr, "\n"); } - delete ClangFrontendTimer; - // Return the appropriate status when verifying diagnostics. // // FIXME: If we could make getNumErrors() do the right thing, we wouldn't need |