Skip to content

Commit 8bef5cd

Browse files
committed
Modules: Rename MemoryBufferCache to InMemoryModuleCache
Change MemoryBufferCache to InMemoryModuleCache, moving it from Basic to Serialization. Another patch will start using it to manage module build more explicitly, but this is split out because it's mostly mechanical. Because of the move to Serialization we can no longer abuse the Preprocessor to forward it to the ASTReader. Besides the rename and file move, that means Preprocessor::Preprocessor has one fewer parameter and ASTReader::ASTReader has one more. llvm-svn: 355777
1 parent 506c1ab commit 8bef5cd

33 files changed

+227
-217
lines changed

clang/include/clang/Frontend/ASTUnit.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class FileManager;
7171
class FrontendAction;
7272
class HeaderSearch;
7373
class InputKind;
74-
class MemoryBufferCache;
74+
class InMemoryModuleCache;
7575
class PCHContainerOperations;
7676
class PCHContainerReader;
7777
class Preprocessor;
@@ -107,7 +107,7 @@ class ASTUnit {
107107
IntrusiveRefCntPtr<DiagnosticsEngine> Diagnostics;
108108
IntrusiveRefCntPtr<FileManager> FileMgr;
109109
IntrusiveRefCntPtr<SourceManager> SourceMgr;
110-
IntrusiveRefCntPtr<MemoryBufferCache> PCMCache;
110+
IntrusiveRefCntPtr<InMemoryModuleCache> ModuleCache;
111111
std::unique_ptr<HeaderSearch> HeaderInfo;
112112
IntrusiveRefCntPtr<TargetInfo> Target;
113113
std::shared_ptr<Preprocessor> PP;

clang/include/clang/Frontend/CompilerInstance.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class ExternalASTSource;
4444
class FileEntry;
4545
class FileManager;
4646
class FrontendAction;
47-
class MemoryBufferCache;
47+
class InMemoryModuleCache;
4848
class Module;
4949
class Preprocessor;
5050
class Sema;
@@ -92,7 +92,7 @@ class CompilerInstance : public ModuleLoader {
9292
IntrusiveRefCntPtr<SourceManager> SourceMgr;
9393

9494
/// The cache of PCM files.
95-
IntrusiveRefCntPtr<MemoryBufferCache> PCMCache;
95+
IntrusiveRefCntPtr<InMemoryModuleCache> ModuleCache;
9696

9797
/// The preprocessor.
9898
std::shared_ptr<Preprocessor> PP;
@@ -192,7 +192,7 @@ class CompilerInstance : public ModuleLoader {
192192
explicit CompilerInstance(
193193
std::shared_ptr<PCHContainerOperations> PCHContainerOps =
194194
std::make_shared<PCHContainerOperations>(),
195-
MemoryBufferCache *SharedPCMCache = nullptr);
195+
InMemoryModuleCache *SharedModuleCache = nullptr);
196196
~CompilerInstance() override;
197197

198198
/// @name High-Level Operations
@@ -671,7 +671,8 @@ class CompilerInstance : public ModuleLoader {
671671
/// \return - The new object on success, or null on failure.
672672
static IntrusiveRefCntPtr<ASTReader> createPCHExternalASTSource(
673673
StringRef Path, StringRef Sysroot, bool DisablePCHValidation,
674-
bool AllowPCHWithCompilerErrors, Preprocessor &PP, ASTContext &Context,
674+
bool AllowPCHWithCompilerErrors, Preprocessor &PP,
675+
InMemoryModuleCache &ModuleCache, ASTContext &Context,
675676
const PCHContainerReader &PCHContainerRdr,
676677
ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions,
677678
DependencyFileGenerator *DependencyFile,
@@ -813,7 +814,7 @@ class CompilerInstance : public ModuleLoader {
813814

814815
void setExternalSemaSource(IntrusiveRefCntPtr<ExternalSemaSource> ESS);
815816

816-
MemoryBufferCache &getPCMCache() const { return *PCMCache; }
817+
InMemoryModuleCache &getModuleCache() const { return *ModuleCache; }
817818
};
818819

819820
} // end namespace clang

clang/include/clang/Lex/Preprocessor.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ class FileEntry;
7171
class FileManager;
7272
class HeaderSearch;
7373
class MacroArgs;
74-
class MemoryBufferCache;
7574
class PragmaHandler;
7675
class PragmaNamespace;
7776
class PreprocessingRecord;
@@ -132,7 +131,6 @@ class Preprocessor {
132131
const TargetInfo *AuxTarget = nullptr;
133132
FileManager &FileMgr;
134133
SourceManager &SourceMgr;
135-
MemoryBufferCache &PCMCache;
136134
std::unique_ptr<ScratchBuffer> ScratchBuf;
137135
HeaderSearch &HeaderInfo;
138136
ModuleLoader &TheModuleLoader;
@@ -779,7 +777,6 @@ class Preprocessor {
779777
public:
780778
Preprocessor(std::shared_ptr<PreprocessorOptions> PPOpts,
781779
DiagnosticsEngine &diags, LangOptions &opts, SourceManager &SM,
782-
MemoryBufferCache &PCMCache,
783780
HeaderSearch &Headers, ModuleLoader &TheModuleLoader,
784781
IdentifierInfoLookup *IILookup = nullptr,
785782
bool OwnsHeaderSearch = false,
@@ -819,7 +816,6 @@ class Preprocessor {
819816
const TargetInfo *getAuxTargetInfo() const { return AuxTarget; }
820817
FileManager &getFileManager() const { return FileMgr; }
821818
SourceManager &getSourceManager() const { return SourceMgr; }
822-
MemoryBufferCache &getPCMCache() const { return PCMCache; }
823819
HeaderSearch &getHeaderSearchInfo() const { return HeaderInfo; }
824820

825821
IdentifierTable &getIdentifierTable() { return Identifiers; }

clang/include/clang/Serialization/ASTReader.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class HeaderSearchOptions;
9797
class LangOptions;
9898
class LazyASTUnresolvedSet;
9999
class MacroInfo;
100-
class MemoryBufferCache;
100+
class InMemoryModuleCache;
101101
class NamedDecl;
102102
class NamespaceDecl;
103103
class ObjCCategoryDecl;
@@ -440,9 +440,6 @@ class ASTReader
440440
/// The module manager which manages modules and their dependencies
441441
ModuleManager ModuleMgr;
442442

443-
/// The cache that manages memory buffers for PCM files.
444-
MemoryBufferCache &PCMCache;
445-
446443
/// A dummy identifier resolver used to merge TU-scope declarations in
447444
/// C, for the cases where we don't have a Sema object to provide a real
448445
/// identifier resolver.
@@ -1481,8 +1478,8 @@ class ASTReader
14811478
///
14821479
/// \param ReadTimer If non-null, a timer used to track the time spent
14831480
/// deserializing.
1484-
ASTReader(Preprocessor &PP, ASTContext *Context,
1485-
const PCHContainerReader &PCHContainerRdr,
1481+
ASTReader(Preprocessor &PP, InMemoryModuleCache &ModuleCache,
1482+
ASTContext *Context, const PCHContainerReader &PCHContainerRdr,
14861483
ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions,
14871484
StringRef isysroot = "", bool DisableValidation = false,
14881485
bool AllowASTWithCompilerErrors = false,

clang/include/clang/Serialization/ASTWriter.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ class IdentifierResolver;
7474
class LangOptions;
7575
class MacroDefinitionRecord;
7676
class MacroInfo;
77-
class MemoryBufferCache;
7877
class Module;
78+
class InMemoryModuleCache;
7979
class ModuleFileExtension;
8080
class ModuleFileExtensionWriter;
8181
class NamedDecl;
@@ -132,7 +132,7 @@ class ASTWriter : public ASTDeserializationListener,
132132
const SmallVectorImpl<char> &Buffer;
133133

134134
/// The PCM manager which manages memory buffers for pcm files.
135-
MemoryBufferCache &PCMCache;
135+
InMemoryModuleCache &ModuleCache;
136136

137137
/// The ASTContext we're writing.
138138
ASTContext *Context = nullptr;
@@ -542,7 +542,7 @@ class ASTWriter : public ASTDeserializationListener,
542542
/// Create a new precompiled header writer that outputs to
543543
/// the given bitstream.
544544
ASTWriter(llvm::BitstreamWriter &Stream, SmallVectorImpl<char> &Buffer,
545-
MemoryBufferCache &PCMCache,
545+
InMemoryModuleCache &ModuleCache,
546546
ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions,
547547
bool IncludeTimestamps = true);
548548
~ASTWriter() override;
@@ -981,7 +981,8 @@ class PCHGenerator : public SemaConsumer {
981981
SmallVectorImpl<char> &getPCH() const { return Buffer->Data; }
982982

983983
public:
984-
PCHGenerator(const Preprocessor &PP, StringRef OutputFile, StringRef isysroot,
984+
PCHGenerator(const Preprocessor &PP, InMemoryModuleCache &ModuleCache,
985+
StringRef OutputFile, StringRef isysroot,
985986
std::shared_ptr<PCHBuffer> Buffer,
986987
ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions,
987988
bool AllowASTWithErrors = false, bool IncludeTimestamps = true);

clang/include/clang/Basic/MemoryBufferCache.h renamed to clang/include/clang/Serialization/InMemoryModuleCache.h

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
//===- MemoryBufferCache.h - Cache for loaded memory buffers ----*- C++ -*-===//
1+
//===- InMemoryModuleCache.h - In-memory cache for modules ------*- C++ -*-===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#ifndef LLVM_CLANG_BASIC_MEMORYBUFFERCACHE_H
10-
#define LLVM_CLANG_BASIC_MEMORYBUFFERCACHE_H
9+
#ifndef LLVM_CLANG_SERIALIZATION_INMEMORYMODULECACHE_H
10+
#define LLVM_CLANG_SERIALIZATION_INMEMORYMODULECACHE_H
1111

1212
#include "llvm/ADT/IntrusiveRefCntPtr.h"
13+
#include "llvm/ADT/Optional.h"
1314
#include "llvm/ADT/StringMap.h"
1415
#include <memory>
1516

@@ -19,25 +20,30 @@ class MemoryBuffer;
1920

2021
namespace clang {
2122

22-
/// Manage memory buffers across multiple users.
23+
/// In-memory cache for modules.
2324
///
24-
/// Ensures that multiple users have a consistent view of each buffer. This is
25-
/// used by \a CompilerInstance when building PCMs to ensure that each \a
26-
/// ModuleManager sees the same files.
25+
/// This is a cache for modules for use across a compilation, sharing state
26+
/// between the CompilerInstances in an implicit modules build. It must be
27+
/// shared by each CompilerInstance, ASTReader, ASTWriter, and ModuleManager
28+
/// that are coordinating.
29+
///
30+
/// Critically, it ensures that a single process has a consistent view of each
31+
/// PCM. This is used by \a CompilerInstance when building PCMs to ensure that
32+
/// each \a ModuleManager sees the same files.
2733
///
2834
/// \a finalizeCurrentBuffers() should be called before creating a new user.
29-
/// This locks in the current buffers, ensuring that no buffer that has already
30-
/// been accessed can be purged, preventing use-after-frees.
31-
class MemoryBufferCache : public llvm::RefCountedBase<MemoryBufferCache> {
32-
struct BufferEntry {
35+
/// This locks in the current PCMs, ensuring that no PCM that has already been
36+
/// accessed can be purged, preventing use-after-frees.
37+
class InMemoryModuleCache : public llvm::RefCountedBase<InMemoryModuleCache> {
38+
struct PCM {
3339
std::unique_ptr<llvm::MemoryBuffer> Buffer;
3440

3541
/// Track the timeline of when this was added to the cache.
3642
unsigned Index;
3743
};
3844

3945
/// Cache of buffers.
40-
llvm::StringMap<BufferEntry> Buffers;
46+
llvm::StringMap<PCM> PCMs;
4147

4248
/// Monotonically increasing index.
4349
unsigned NextIndex = 0;
@@ -76,4 +82,4 @@ class MemoryBufferCache : public llvm::RefCountedBase<MemoryBufferCache> {
7682

7783
} // end namespace clang
7884

79-
#endif // LLVM_CLANG_BASIC_MEMORYBUFFERCACHE_H
85+
#endif // LLVM_CLANG_SERIALIZATION_INMEMORYMODULECACHE_H

clang/include/clang/Serialization/Module.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ class ModuleFile {
174174
unsigned Generation;
175175

176176
/// The memory buffer that stores the data associated with
177-
/// this AST file, owned by the PCMCache in the ModuleManager.
177+
/// this AST file, owned by the InMemoryModuleCache.
178178
llvm::MemoryBuffer *Buffer;
179179

180180
/// The size of this file, in bits.

clang/include/clang/Serialization/ModuleManager.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class FileEntry;
3838
class FileManager;
3939
class GlobalModuleIndex;
4040
class HeaderSearch;
41-
class MemoryBufferCache;
41+
class InMemoryModuleCache;
4242
class ModuleMap;
4343
class PCHContainerReader;
4444

@@ -67,7 +67,7 @@ class ModuleManager {
6767
FileManager &FileMgr;
6868

6969
/// Cache of PCM files.
70-
IntrusiveRefCntPtr<MemoryBufferCache> PCMCache;
70+
IntrusiveRefCntPtr<InMemoryModuleCache> ModuleCache;
7171

7272
/// Knows how to unwrap module containers.
7373
const PCHContainerReader &PCHContainerRdr;
@@ -139,7 +139,7 @@ class ModuleManager {
139139
SmallVectorImpl<std::unique_ptr<ModuleFile>>::reverse_iterator>;
140140
using ModuleOffset = std::pair<uint32_t, StringRef>;
141141

142-
explicit ModuleManager(FileManager &FileMgr, MemoryBufferCache &PCMCache,
142+
explicit ModuleManager(FileManager &FileMgr, InMemoryModuleCache &ModuleCache,
143143
const PCHContainerReader &PCHContainerRdr,
144144
const HeaderSearch &HeaderSearchInfo);
145145
~ModuleManager();
@@ -317,7 +317,7 @@ class ModuleManager {
317317
/// View the graphviz representation of the module graph.
318318
void viewGraph();
319319

320-
MemoryBufferCache &getPCMCache() const { return *PCMCache; }
320+
InMemoryModuleCache &getModuleCache() const { return *ModuleCache; }
321321
};
322322

323323
} // namespace serialization

clang/lib/Basic/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ add_clang_library(clangBasic
5050
FixedPoint.cpp
5151
IdentifierTable.cpp
5252
LangOptions.cpp
53-
MemoryBufferCache.cpp
5453
Module.cpp
5554
ObjCRuntime.cpp
5655
OpenMPKinds.cpp

clang/lib/Basic/MemoryBufferCache.cpp

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)