davide created this revision. davide added reviewers: rafael, vsk. davide added a subscriber: cfe-commits.
See http://reviews.llvm.org/D20735 for more context. Implementing this clang-side is not as terrible as I originally thought. Maybe needs a test case, but I wasn't able to reduce one easily (yet). http://reviews.llvm.org/D20748 Files: clang/lib/CodeGen/CodeGenAction.cpp Index: clang/lib/CodeGen/CodeGenAction.cpp =================================================================== --- clang/lib/CodeGen/CodeGenAction.cpp +++ clang/lib/CodeGen/CodeGenAction.cpp @@ -50,6 +50,7 @@ ASTContext *Context; Timer LLVMIRGeneration; + unsigned LLVMIRGenerationRefCount; std::unique_ptr<CodeGenerator> Gen; @@ -73,6 +74,7 @@ : Diags(Diags), Action(Action), CodeGenOpts(CodeGenOpts), TargetOpts(TargetOpts), LangOpts(LangOpts), AsmOutStream(OS), Context(nullptr), LLVMIRGeneration("LLVM IR Generation Time"), + LLVMIRGenerationRefCount(0), Gen(CreateLLVMCodeGen(Diags, InFile, HeaderSearchOpts, PPOpts, CodeGenOpts, C, CoverageInfo)) { llvm::TimePassesIsEnabled = TimePasses; @@ -112,13 +114,20 @@ Context->getSourceManager(), "LLVM IR generation of declaration"); - if (llvm::TimePassesIsEnabled) - LLVMIRGeneration.startTimer(); + // Recurse. + if (llvm::TimePassesIsEnabled) { + LLVMIRGenerationRefCount += 1; + if (LLVMIRGenerationRefCount == 1) + LLVMIRGeneration.startTimer(); + } Gen->HandleTopLevelDecl(D); - if (llvm::TimePassesIsEnabled) - LLVMIRGeneration.stopTimer(); + if (llvm::TimePassesIsEnabled) { + LLVMIRGenerationRefCount -= 1; + if (LLVMIRGenerationRefCount == 0) + LLVMIRGeneration.stopTimer(); + } return true; } @@ -139,13 +148,19 @@ void HandleTranslationUnit(ASTContext &C) override { { PrettyStackTraceString CrashInfo("Per-file LLVM IR generation"); - if (llvm::TimePassesIsEnabled) - LLVMIRGeneration.startTimer(); + if (llvm::TimePassesIsEnabled) { + LLVMIRGenerationRefCount += 1; + if (LLVMIRGenerationRefCount == 1) + LLVMIRGeneration.startTimer(); + } Gen->HandleTranslationUnit(C); - if (llvm::TimePassesIsEnabled) - LLVMIRGeneration.stopTimer(); + if (llvm::TimePassesIsEnabled) { + LLVMIRGenerationRefCount -= 1; + if (LLVMIRGenerationRefCount == 0) + LLVMIRGeneration.stopTimer(); + } } // Silently ignore if we weren't initialized for some reason.
Index: clang/lib/CodeGen/CodeGenAction.cpp =================================================================== --- clang/lib/CodeGen/CodeGenAction.cpp +++ clang/lib/CodeGen/CodeGenAction.cpp @@ -50,6 +50,7 @@ ASTContext *Context; Timer LLVMIRGeneration; + unsigned LLVMIRGenerationRefCount; std::unique_ptr<CodeGenerator> Gen; @@ -73,6 +74,7 @@ : Diags(Diags), Action(Action), CodeGenOpts(CodeGenOpts), TargetOpts(TargetOpts), LangOpts(LangOpts), AsmOutStream(OS), Context(nullptr), LLVMIRGeneration("LLVM IR Generation Time"), + LLVMIRGenerationRefCount(0), Gen(CreateLLVMCodeGen(Diags, InFile, HeaderSearchOpts, PPOpts, CodeGenOpts, C, CoverageInfo)) { llvm::TimePassesIsEnabled = TimePasses; @@ -112,13 +114,20 @@ Context->getSourceManager(), "LLVM IR generation of declaration"); - if (llvm::TimePassesIsEnabled) - LLVMIRGeneration.startTimer(); + // Recurse. + if (llvm::TimePassesIsEnabled) { + LLVMIRGenerationRefCount += 1; + if (LLVMIRGenerationRefCount == 1) + LLVMIRGeneration.startTimer(); + } Gen->HandleTopLevelDecl(D); - if (llvm::TimePassesIsEnabled) - LLVMIRGeneration.stopTimer(); + if (llvm::TimePassesIsEnabled) { + LLVMIRGenerationRefCount -= 1; + if (LLVMIRGenerationRefCount == 0) + LLVMIRGeneration.stopTimer(); + } return true; } @@ -139,13 +148,19 @@ void HandleTranslationUnit(ASTContext &C) override { { PrettyStackTraceString CrashInfo("Per-file LLVM IR generation"); - if (llvm::TimePassesIsEnabled) - LLVMIRGeneration.startTimer(); + if (llvm::TimePassesIsEnabled) { + LLVMIRGenerationRefCount += 1; + if (LLVMIRGenerationRefCount == 1) + LLVMIRGeneration.startTimer(); + } Gen->HandleTranslationUnit(C); - if (llvm::TimePassesIsEnabled) - LLVMIRGeneration.stopTimer(); + if (llvm::TimePassesIsEnabled) { + LLVMIRGenerationRefCount -= 1; + if (LLVMIRGenerationRefCount == 0) + LLVMIRGeneration.stopTimer(); + } } // Silently ignore if we weren't initialized for some reason.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits