diff options
Diffstat (limited to 'include/clang')
-rw-r--r-- | include/clang/Frontend/ASTUnit.h | 4 | ||||
-rw-r--r-- | include/clang/Frontend/CompilerInstance.h | 11 | ||||
-rw-r--r-- | include/clang/Lex/Preprocessor.h | 4 | ||||
-rw-r--r-- | include/clang/Serialization/ASTReader.h | 9 | ||||
-rw-r--r-- | include/clang/Serialization/ASTWriter.h | 9 | ||||
-rw-r--r-- | include/clang/Serialization/InMemoryModuleCache.h (renamed from include/clang/Basic/MemoryBufferCache.h) | 32 | ||||
-rw-r--r-- | include/clang/Serialization/Module.h | 2 | ||||
-rw-r--r-- | include/clang/Serialization/ModuleManager.h | 8 |
8 files changed, 40 insertions, 39 deletions
diff --git a/include/clang/Frontend/ASTUnit.h b/include/clang/Frontend/ASTUnit.h index cef638e271..750f6c8577 100644 --- a/include/clang/Frontend/ASTUnit.h +++ b/include/clang/Frontend/ASTUnit.h @@ -71,7 +71,7 @@ class FileManager; class FrontendAction; class HeaderSearch; class InputKind; -class MemoryBufferCache; +class InMemoryModuleCache; class PCHContainerOperations; class PCHContainerReader; class Preprocessor; @@ -107,7 +107,7 @@ private: IntrusiveRefCntPtr<DiagnosticsEngine> Diagnostics; IntrusiveRefCntPtr<FileManager> FileMgr; IntrusiveRefCntPtr<SourceManager> SourceMgr; - IntrusiveRefCntPtr<MemoryBufferCache> PCMCache; + IntrusiveRefCntPtr<InMemoryModuleCache> ModuleCache; std::unique_ptr<HeaderSearch> HeaderInfo; IntrusiveRefCntPtr<TargetInfo> Target; std::shared_ptr<Preprocessor> PP; diff --git a/include/clang/Frontend/CompilerInstance.h b/include/clang/Frontend/CompilerInstance.h index 002cc61eb4..2fc61574e3 100644 --- a/include/clang/Frontend/CompilerInstance.h +++ b/include/clang/Frontend/CompilerInstance.h @@ -44,7 +44,7 @@ class ExternalASTSource; class FileEntry; class FileManager; class FrontendAction; -class MemoryBufferCache; +class InMemoryModuleCache; class Module; class Preprocessor; class Sema; @@ -92,7 +92,7 @@ class CompilerInstance : public ModuleLoader { IntrusiveRefCntPtr<SourceManager> SourceMgr; /// The cache of PCM files. - IntrusiveRefCntPtr<MemoryBufferCache> PCMCache; + IntrusiveRefCntPtr<InMemoryModuleCache> ModuleCache; /// The preprocessor. std::shared_ptr<Preprocessor> PP; @@ -192,7 +192,7 @@ public: explicit CompilerInstance( std::shared_ptr<PCHContainerOperations> PCHContainerOps = std::make_shared<PCHContainerOperations>(), - MemoryBufferCache *SharedPCMCache = nullptr); + InMemoryModuleCache *SharedModuleCache = nullptr); ~CompilerInstance() override; /// @name High-Level Operations @@ -671,7 +671,8 @@ public: /// \return - The new object on success, or null on failure. static IntrusiveRefCntPtr<ASTReader> createPCHExternalASTSource( StringRef Path, StringRef Sysroot, bool DisablePCHValidation, - bool AllowPCHWithCompilerErrors, Preprocessor &PP, ASTContext &Context, + bool AllowPCHWithCompilerErrors, Preprocessor &PP, + InMemoryModuleCache &ModuleCache, ASTContext &Context, const PCHContainerReader &PCHContainerRdr, ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions, DependencyFileGenerator *DependencyFile, @@ -813,7 +814,7 @@ public: void setExternalSemaSource(IntrusiveRefCntPtr<ExternalSemaSource> ESS); - MemoryBufferCache &getPCMCache() const { return *PCMCache; } + InMemoryModuleCache &getModuleCache() const { return *ModuleCache; } }; } // end namespace clang diff --git a/include/clang/Lex/Preprocessor.h b/include/clang/Lex/Preprocessor.h index 29d4250490..0292a33d60 100644 --- a/include/clang/Lex/Preprocessor.h +++ b/include/clang/Lex/Preprocessor.h @@ -71,7 +71,6 @@ class FileEntry; class FileManager; class HeaderSearch; class MacroArgs; -class MemoryBufferCache; class PragmaHandler; class PragmaNamespace; class PreprocessingRecord; @@ -132,7 +131,6 @@ class Preprocessor { const TargetInfo *AuxTarget = nullptr; FileManager &FileMgr; SourceManager &SourceMgr; - MemoryBufferCache &PCMCache; std::unique_ptr<ScratchBuffer> ScratchBuf; HeaderSearch &HeaderInfo; ModuleLoader &TheModuleLoader; @@ -779,7 +777,6 @@ private: public: Preprocessor(std::shared_ptr<PreprocessorOptions> PPOpts, DiagnosticsEngine &diags, LangOptions &opts, SourceManager &SM, - MemoryBufferCache &PCMCache, HeaderSearch &Headers, ModuleLoader &TheModuleLoader, IdentifierInfoLookup *IILookup = nullptr, bool OwnsHeaderSearch = false, @@ -819,7 +816,6 @@ public: const TargetInfo *getAuxTargetInfo() const { return AuxTarget; } FileManager &getFileManager() const { return FileMgr; } SourceManager &getSourceManager() const { return SourceMgr; } - MemoryBufferCache &getPCMCache() const { return PCMCache; } HeaderSearch &getHeaderSearchInfo() const { return HeaderInfo; } IdentifierTable &getIdentifierTable() { return Identifiers; } diff --git a/include/clang/Serialization/ASTReader.h b/include/clang/Serialization/ASTReader.h index 5b92b13722..58a3b6594c 100644 --- a/include/clang/Serialization/ASTReader.h +++ b/include/clang/Serialization/ASTReader.h @@ -97,7 +97,7 @@ class HeaderSearchOptions; class LangOptions; class LazyASTUnresolvedSet; class MacroInfo; -class MemoryBufferCache; +class InMemoryModuleCache; class NamedDecl; class NamespaceDecl; class ObjCCategoryDecl; @@ -440,9 +440,6 @@ private: /// The module manager which manages modules and their dependencies ModuleManager ModuleMgr; - /// The cache that manages memory buffers for PCM files. - MemoryBufferCache &PCMCache; - /// A dummy identifier resolver used to merge TU-scope declarations in /// C, for the cases where we don't have a Sema object to provide a real /// identifier resolver. @@ -1481,8 +1478,8 @@ public: /// /// \param ReadTimer If non-null, a timer used to track the time spent /// deserializing. - ASTReader(Preprocessor &PP, ASTContext *Context, - const PCHContainerReader &PCHContainerRdr, + ASTReader(Preprocessor &PP, InMemoryModuleCache &ModuleCache, + ASTContext *Context, const PCHContainerReader &PCHContainerRdr, ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions, StringRef isysroot = "", bool DisableValidation = false, bool AllowASTWithCompilerErrors = false, diff --git a/include/clang/Serialization/ASTWriter.h b/include/clang/Serialization/ASTWriter.h index ed512ef8f5..b0f7222470 100644 --- a/include/clang/Serialization/ASTWriter.h +++ b/include/clang/Serialization/ASTWriter.h @@ -74,8 +74,8 @@ class IdentifierResolver; class LangOptions; class MacroDefinitionRecord; class MacroInfo; -class MemoryBufferCache; class Module; +class InMemoryModuleCache; class ModuleFileExtension; class ModuleFileExtensionWriter; class NamedDecl; @@ -132,7 +132,7 @@ private: const SmallVectorImpl<char> &Buffer; /// The PCM manager which manages memory buffers for pcm files. - MemoryBufferCache &PCMCache; + InMemoryModuleCache &ModuleCache; /// The ASTContext we're writing. ASTContext *Context = nullptr; @@ -542,7 +542,7 @@ public: /// Create a new precompiled header writer that outputs to /// the given bitstream. ASTWriter(llvm::BitstreamWriter &Stream, SmallVectorImpl<char> &Buffer, - MemoryBufferCache &PCMCache, + InMemoryModuleCache &ModuleCache, ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions, bool IncludeTimestamps = true); ~ASTWriter() override; @@ -981,7 +981,8 @@ protected: SmallVectorImpl<char> &getPCH() const { return Buffer->Data; } public: - PCHGenerator(const Preprocessor &PP, StringRef OutputFile, StringRef isysroot, + PCHGenerator(const Preprocessor &PP, InMemoryModuleCache &ModuleCache, + StringRef OutputFile, StringRef isysroot, std::shared_ptr<PCHBuffer> Buffer, ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions, bool AllowASTWithErrors = false, bool IncludeTimestamps = true); diff --git a/include/clang/Basic/MemoryBufferCache.h b/include/clang/Serialization/InMemoryModuleCache.h index 9a2b62e0d9..aea4a8d60b 100644 --- a/include/clang/Basic/MemoryBufferCache.h +++ b/include/clang/Serialization/InMemoryModuleCache.h @@ -1,4 +1,4 @@ -//===- MemoryBufferCache.h - Cache for loaded memory buffers ----*- C++ -*-===// +//===- InMemoryModuleCache.h - In-memory cache for modules ------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,10 +6,11 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_CLANG_BASIC_MEMORYBUFFERCACHE_H -#define LLVM_CLANG_BASIC_MEMORYBUFFERCACHE_H +#ifndef LLVM_CLANG_SERIALIZATION_INMEMORYMODULECACHE_H +#define LLVM_CLANG_SERIALIZATION_INMEMORYMODULECACHE_H #include "llvm/ADT/IntrusiveRefCntPtr.h" +#include "llvm/ADT/Optional.h" #include "llvm/ADT/StringMap.h" #include <memory> @@ -19,17 +20,22 @@ class MemoryBuffer; namespace clang { -/// Manage memory buffers across multiple users. +/// In-memory cache for modules. /// -/// Ensures that multiple users have a consistent view of each buffer. This is -/// used by \a CompilerInstance when building PCMs to ensure that each \a -/// ModuleManager sees the same files. +/// This is a cache for modules for use across a compilation, sharing state +/// between the CompilerInstances in an implicit modules build. It must be +/// shared by each CompilerInstance, ASTReader, ASTWriter, and ModuleManager +/// that are coordinating. +/// +/// Critically, it ensures that a single process has a consistent view of each +/// PCM. This is used by \a CompilerInstance when building PCMs to ensure that +/// each \a ModuleManager sees the same files. /// /// \a finalizeCurrentBuffers() should be called before creating a new user. -/// This locks in the current buffers, ensuring that no buffer that has already -/// been accessed can be purged, preventing use-after-frees. -class MemoryBufferCache : public llvm::RefCountedBase<MemoryBufferCache> { - struct BufferEntry { +/// This locks in the current PCMs, ensuring that no PCM that has already been +/// accessed can be purged, preventing use-after-frees. +class InMemoryModuleCache : public llvm::RefCountedBase<InMemoryModuleCache> { + struct PCM { std::unique_ptr<llvm::MemoryBuffer> Buffer; /// Track the timeline of when this was added to the cache. @@ -37,7 +43,7 @@ class MemoryBufferCache : public llvm::RefCountedBase<MemoryBufferCache> { }; /// Cache of buffers. - llvm::StringMap<BufferEntry> Buffers; + llvm::StringMap<PCM> PCMs; /// Monotonically increasing index. unsigned NextIndex = 0; @@ -76,4 +82,4 @@ public: } // end namespace clang -#endif // LLVM_CLANG_BASIC_MEMORYBUFFERCACHE_H +#endif // LLVM_CLANG_SERIALIZATION_INMEMORYMODULECACHE_H diff --git a/include/clang/Serialization/Module.h b/include/clang/Serialization/Module.h index 45f82d4764..ebaaeea29a 100644 --- a/include/clang/Serialization/Module.h +++ b/include/clang/Serialization/Module.h @@ -174,7 +174,7 @@ public: unsigned Generation; /// The memory buffer that stores the data associated with - /// this AST file, owned by the PCMCache in the ModuleManager. + /// this AST file, owned by the InMemoryModuleCache. llvm::MemoryBuffer *Buffer; /// The size of this file, in bits. diff --git a/include/clang/Serialization/ModuleManager.h b/include/clang/Serialization/ModuleManager.h index 7bd7dc290a..5b3b22be75 100644 --- a/include/clang/Serialization/ModuleManager.h +++ b/include/clang/Serialization/ModuleManager.h @@ -38,7 +38,7 @@ class FileEntry; class FileManager; class GlobalModuleIndex; class HeaderSearch; -class MemoryBufferCache; +class InMemoryModuleCache; class ModuleMap; class PCHContainerReader; @@ -67,7 +67,7 @@ class ModuleManager { FileManager &FileMgr; /// Cache of PCM files. - IntrusiveRefCntPtr<MemoryBufferCache> PCMCache; + IntrusiveRefCntPtr<InMemoryModuleCache> ModuleCache; /// Knows how to unwrap module containers. const PCHContainerReader &PCHContainerRdr; @@ -139,7 +139,7 @@ public: SmallVectorImpl<std::unique_ptr<ModuleFile>>::reverse_iterator>; using ModuleOffset = std::pair<uint32_t, StringRef>; - explicit ModuleManager(FileManager &FileMgr, MemoryBufferCache &PCMCache, + explicit ModuleManager(FileManager &FileMgr, InMemoryModuleCache &ModuleCache, const PCHContainerReader &PCHContainerRdr, const HeaderSearch &HeaderSearchInfo); ~ModuleManager(); @@ -317,7 +317,7 @@ public: /// View the graphviz representation of the module graph. void viewGraph(); - MemoryBufferCache &getPCMCache() const { return *PCMCache; } + InMemoryModuleCache &getModuleCache() const { return *ModuleCache; } }; } // namespace serialization |