From 5c248d89f316fab5569dc79c54b50bd4de7f04a6 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Tue, 15 Dec 2015 09:30:31 +0000 Subject: [libclang] Add a flag to create the precompiled preamble on the first parse. Summary: The current default is to create the preamble on the first reparse, aka second parse. This is useful for clients that do not want to block when opening a file because serializing the preamble takes a bit of time. However, this makes the reparse much more expensive and that may be on the critical path as it's the first interaction a user has with the source code. YouCompleteMe currently optimizes for the first code interaction by parsing the file twice when loaded. That's just unnecessarily slow and this flag helps to avoid that. Reviewers: doug.gregor, klimek Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D15490 llvm-svn: 255635 --- clang/lib/Frontend/ASTUnit.cpp | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) (limited to 'clang/lib/Frontend/ASTUnit.cpp') diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp index 0d5dd536589..e6ba29201f8 100644 --- a/clang/lib/Frontend/ASTUnit.cpp +++ b/clang/lib/Frontend/ASTUnit.cpp @@ -1725,9 +1725,10 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocationAction( std::shared_ptr PCHContainerOps, IntrusiveRefCntPtr Diags, ASTFrontendAction *Action, ASTUnit *Unit, bool Persistent, StringRef ResourceFilesPath, - bool OnlyLocalDecls, bool CaptureDiagnostics, bool PrecompilePreamble, - bool CacheCodeCompletionResults, bool IncludeBriefCommentsInCodeCompletion, - bool UserFilesAreVolatile, std::unique_ptr *ErrAST) { + bool OnlyLocalDecls, bool CaptureDiagnostics, + unsigned PrecompilePreambleAfterNParses, bool CacheCodeCompletionResults, + bool IncludeBriefCommentsInCodeCompletion, bool UserFilesAreVolatile, + std::unique_ptr *ErrAST) { assert(CI && "A CompilerInvocation is required"); std::unique_ptr OwnAST; @@ -1746,8 +1747,8 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocationAction( } AST->OnlyLocalDecls = OnlyLocalDecls; AST->CaptureDiagnostics = CaptureDiagnostics; - if (PrecompilePreamble) - AST->PreambleRebuildCounter = 2; + if (PrecompilePreambleAfterNParses > 0) + AST->PreambleRebuildCounter = PrecompilePreambleAfterNParses; AST->TUKind = Action ? Action->getTranslationUnitKind() : TU_Complete; AST->ShouldCacheCodeCompletionResults = CacheCodeCompletionResults; AST->IncludeBriefCommentsInCodeCompletion @@ -1864,7 +1865,7 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocationAction( bool ASTUnit::LoadFromCompilerInvocation( std::shared_ptr PCHContainerOps, - bool PrecompilePreamble) { + unsigned PrecompilePreambleAfterNParses) { if (!Invocation) return true; @@ -1874,8 +1875,8 @@ bool ASTUnit::LoadFromCompilerInvocation( ProcessWarningOptions(getDiagnostics(), Invocation->getDiagnosticOpts()); std::unique_ptr OverrideMainBuffer; - if (PrecompilePreamble) { - PreambleRebuildCounter = 2; + if (PrecompilePreambleAfterNParses > 0) { + PreambleRebuildCounter = PrecompilePreambleAfterNParses; OverrideMainBuffer = getMainBufferWithPrecompiledPreamble(PCHContainerOps, *Invocation); } @@ -1894,9 +1895,10 @@ std::unique_ptr ASTUnit::LoadFromCompilerInvocation( CompilerInvocation *CI, std::shared_ptr PCHContainerOps, IntrusiveRefCntPtr Diags, FileManager *FileMgr, - bool OnlyLocalDecls, bool CaptureDiagnostics, bool PrecompilePreamble, - TranslationUnitKind TUKind, bool CacheCodeCompletionResults, - bool IncludeBriefCommentsInCodeCompletion, bool UserFilesAreVolatile) { + bool OnlyLocalDecls, bool CaptureDiagnostics, + unsigned PrecompilePreambleAfterNParses, TranslationUnitKind TUKind, + bool CacheCodeCompletionResults, bool IncludeBriefCommentsInCodeCompletion, + bool UserFilesAreVolatile) { // Create the AST unit. std::unique_ptr AST(new ASTUnit(false)); ConfigureDiags(Diags, *AST, CaptureDiagnostics); @@ -1919,7 +1921,8 @@ std::unique_ptr ASTUnit::LoadFromCompilerInvocation( llvm::CrashRecoveryContextReleaseRefCleanup > DiagCleanup(Diags.get()); - if (AST->LoadFromCompilerInvocation(PCHContainerOps, PrecompilePreamble)) + if (AST->LoadFromCompilerInvocation(PCHContainerOps, + PrecompilePreambleAfterNParses)) return nullptr; return AST; } @@ -1930,12 +1933,11 @@ ASTUnit *ASTUnit::LoadFromCommandLine( IntrusiveRefCntPtr Diags, StringRef ResourceFilesPath, bool OnlyLocalDecls, bool CaptureDiagnostics, ArrayRef RemappedFiles, bool RemappedFilesKeepOriginalName, - bool PrecompilePreamble, TranslationUnitKind TUKind, + unsigned PrecompilePreambleAfterNParses, TranslationUnitKind TUKind, bool CacheCodeCompletionResults, bool IncludeBriefCommentsInCodeCompletion, bool AllowPCHWithCompilerErrors, bool SkipFunctionBodies, bool UserFilesAreVolatile, bool ForSerialization, - llvm::Optional ModuleFormat, - std::unique_ptr *ErrAST) { + llvm::Optional ModuleFormat, std::unique_ptr *ErrAST) { assert(Diags.get() && "no DiagnosticsEngine was provided"); SmallVector StoredDiagnostics; @@ -2002,7 +2004,8 @@ ASTUnit *ASTUnit::LoadFromCommandLine( llvm::CrashRecoveryContextCleanupRegistrar ASTUnitCleanup(AST.get()); - if (AST->LoadFromCompilerInvocation(PCHContainerOps, PrecompilePreamble)) { + if (AST->LoadFromCompilerInvocation(PCHContainerOps, + PrecompilePreambleAfterNParses)) { // Some error occurred, if caller wants to examine diagnostics, pass it the // ASTUnit. if (ErrAST) { -- cgit v1.2.3