From: Ilya Biryukov Date: Fri, 24 Nov 2017 13:12:38 +0000 (+0000) Subject: Avoid copying the data of in-memory preambles X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e5081fa9ed363e3aafa7bef037bb61bf2472f188;p=clang Avoid copying the data of in-memory preambles Summary: Preambles are large and we should avoid copying them. Reviewers: bkramer, klimek Reviewed By: bkramer Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D40302 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@318945 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Frontend/PrecompiledPreamble.h b/include/clang/Frontend/PrecompiledPreamble.h index 28e25bcdb5..13edea09af 100644 --- a/include/clang/Frontend/PrecompiledPreamble.h +++ b/include/clang/Frontend/PrecompiledPreamble.h @@ -98,6 +98,10 @@ public: /// Changes options inside \p CI to use PCH from this preamble. Also remaps /// main file to \p MainFileBuffer and updates \p VFS to ensure the preamble /// is accessible. + /// For in-memory preambles, PrecompiledPreamble instance continues to own + /// the MemoryBuffer with the Preamble after this method returns. The caller + /// is reponsible for making sure the PrecompiledPreamble instance outlives + /// the compiler run and the AST that will be using the PCH. void AddImplicitPreamble(CompilerInvocation &CI, IntrusiveRefCntPtr &VFS, llvm::MemoryBuffer *MainFileBuffer) const; diff --git a/lib/Frontend/PrecompiledPreamble.cpp b/lib/Frontend/PrecompiledPreamble.cpp index 130b9045c8..c6ee4d0289 100644 --- a/lib/Frontend/PrecompiledPreamble.cpp +++ b/lib/Frontend/PrecompiledPreamble.cpp @@ -699,9 +699,7 @@ void PrecompiledPreamble::setupPreambleStorage( StringRef PCHPath = getInMemoryPreamblePath(); PreprocessorOpts.ImplicitPCHInclude = PCHPath; - // FIMXE(ibiryukov): Preambles can be large. We should allow shared access - // to the preamble data instead of copying it here. - auto Buf = llvm::MemoryBuffer::getMemBufferCopy(Storage.asMemory().Data); + auto Buf = llvm::MemoryBuffer::getMemBuffer(Storage.asMemory().Data); VFS = createVFSOverlayForPreamblePCH(PCHPath, std::move(Buf), VFS); } }