CompilerInstance already contains various objects that are used
throughout the entire run.
Also addresses Daniels review comments in:
http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-
20091123/024508.html
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90073
91177308-0d34-0410-b5e6-
96231b3b80d8
class LLVMContext;
class raw_ostream;
class raw_fd_ostream;
+class Timer;
}
namespace clang {
/// 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;
/// the compiler instance takes ownership of \arg Value.
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
/// {
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 *
#include "llvm/ADT/OwningPtr.h"
#include <string>
-namespace llvm {
-class Timer;
-}
-
namespace clang {
class ASTUnit;
class ASTConsumer;
std::string CurrentFile;
llvm::OwningPtr<ASTUnit> CurrentASTUnit;
CompilerInstance *Instance;
- llvm::Timer *CurrentTimer;
protected:
/// @name Implementation Action Interface
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
/// @{
#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;
llvm::outs()));
}
+void CompilerInstance::createFrontendTimer() {
+ FrontendTimer.reset(new llvm::Timer("Clang front-end timer"));
+}
+
CodeCompleteConsumer *
CompilerInstance::createCodeCompletionConsumer(Preprocessor &PP,
const std::string &Filename,
#include "llvm/Support/raw_ostream.h"
using namespace clang;
-FrontendAction::FrontendAction() : Instance(0), CurrentTimer(0) {}
+FrontendAction::FrontendAction() : Instance(0) {}
FrontendAction::~FrontendAction() {}
return;
}
- llvm::TimeRegion Timer(CurrentTimer);
- ExecuteAction();
+ if (CI.hasFrontendTimer()) {
+ llvm::TimeRegion Timer(CI.getFrontendTimer());
+ ExecuteAction();
+ }
+ else ExecuteAction();
}
void FrontendAction::EndSourceFile() {
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;
<< " 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;
if (!Act)
break;
- Act->setCurrentTimer(ClangFrontendTimer);
if (Act->BeginSourceFile(Clang, InFile, IsAST)) {
Act->Execute();
Act->EndSourceFile();
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