Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/ModulesBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ bool IsModuleFileUpToDate(PathRef ModuleFilePath,
Preprocessor PP(PPOpts, *Diags, LangOpts, SourceMgr, HeaderInfo,
ModuleLoader);

IntrusiveRefCntPtr<ModuleCache> ModCache = createCrossProcessModuleCache();
std::shared_ptr<ModuleCache> ModCache = createCrossProcessModuleCache();
PCHContainerOperations PCHOperations;
CodeGenOptions CodeGenOpts;
ASTReader Reader(PP, *ModCache, /*ASTContext=*/nullptr,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "clang/Serialization/ModuleCache.h"
#include "llvm/ADT/StringMap.h"

#include <atomic>
#include <mutex>
#include <shared_mutex>

Expand All @@ -28,7 +29,7 @@ struct ModuleCacheEntries {
llvm::StringMap<std::unique_ptr<ModuleCacheEntry>> Map;
};

IntrusiveRefCntPtr<ModuleCache>
std::shared_ptr<ModuleCache>
makeInProcessModuleCache(ModuleCacheEntries &Entries);

} // namespace dependencies
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Frontend/ASTUnit.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class ASTUnit {
IntrusiveRefCntPtr<DiagnosticsEngine> Diagnostics;
IntrusiveRefCntPtr<FileManager> FileMgr;
IntrusiveRefCntPtr<SourceManager> SourceMgr;
IntrusiveRefCntPtr<ModuleCache> ModCache;
std::shared_ptr<ModuleCache> ModCache;
std::unique_ptr<HeaderSearch> HeaderInfo;
IntrusiveRefCntPtr<TargetInfo> Target;
std::shared_ptr<Preprocessor> PP;
Expand Down
5 changes: 3 additions & 2 deletions clang/include/clang/Frontend/CompilerInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class CompilerInstance : public ModuleLoader {
IntrusiveRefCntPtr<SourceManager> SourceMgr;

/// The cache of PCM files.
IntrusiveRefCntPtr<ModuleCache> ModCache;
std::shared_ptr<ModuleCache> ModCache;

/// Functor for getting the dependency preprocessor directives of a file.
std::unique_ptr<DependencyDirectivesGetter> GetDependencyDirectives;
Expand Down Expand Up @@ -205,7 +205,7 @@ class CompilerInstance : public ModuleLoader {
std::make_shared<CompilerInvocation>(),
std::shared_ptr<PCHContainerOperations> PCHContainerOps =
std::make_shared<PCHContainerOperations>(),
ModuleCache *ModCache = nullptr);
std::shared_ptr<ModuleCache> ModCache = nullptr);
~CompilerInstance() override;

/// @name High-Level Operations
Expand Down Expand Up @@ -967,6 +967,7 @@ class CompilerInstance : public ModuleLoader {
void setExternalSemaSource(IntrusiveRefCntPtr<ExternalSemaSource> ESS);

ModuleCache &getModuleCache() const { return *ModCache; }
std::shared_ptr<ModuleCache> getModuleCachePtr() const { return ModCache; }
};

} // end namespace clang
Expand Down
5 changes: 2 additions & 3 deletions clang/include/clang/Serialization/ModuleCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#define LLVM_CLANG_SERIALIZATION_MODULECACHE_H

#include "clang/Basic/LLVM.h"
#include "llvm/ADT/IntrusiveRefCntPtr.h"

#include <ctime>

Expand All @@ -23,7 +22,7 @@ class InMemoryModuleCache;

/// The module cache used for compiling modules implicitly. This centralizes the
/// operations the compiler might want to perform on the cache.
class ModuleCache : public RefCountedBase<ModuleCache> {
class ModuleCache {
public:
/// May perform any work that only needs to be performed once for multiple
/// calls \c getLock() with the same module filename.
Expand Down Expand Up @@ -62,7 +61,7 @@ class ModuleCache : public RefCountedBase<ModuleCache> {
/// operated on by multiple processes. This instance must be used across all
/// \c CompilerInstance instances participating in building modules for single
/// translation unit in order to share the same \c InMemoryModuleCache.
IntrusiveRefCntPtr<ModuleCache> createCrossProcessModuleCache();
std::shared_ptr<ModuleCache> createCrossProcessModuleCache();

/// Shared implementation of `ModuleCache::maybePrune()`.
void maybePruneImpl(StringRef Path, time_t PruneInterval, time_t PruneAfter);
Expand Down
5 changes: 2 additions & 3 deletions clang/include/clang/Serialization/ModuleManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "clang/Basic/SourceLocation.h"
#include "clang/Serialization/ModuleFile.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/IntrusiveRefCntPtr.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
Expand Down Expand Up @@ -65,7 +64,7 @@ class ModuleManager {
FileManager &FileMgr;

/// Cache of PCM files.
IntrusiveRefCntPtr<ModuleCache> ModCache;
ModuleCache &ModCache;

/// Knows how to unwrap module containers.
const PCHContainerReader &PCHContainerRdr;
Expand Down Expand Up @@ -306,7 +305,7 @@ class ModuleManager {
/// View the graphviz representation of the module graph.
void viewGraph();

ModuleCache &getModuleCache() const { return *ModCache; }
ModuleCache &getModuleCache() const { return ModCache; }
};

} // namespace serialization
Expand Down
6 changes: 3 additions & 3 deletions clang/lib/DependencyScanning/DependencyScannerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ bool DependencyScanningAction::runInvocation(
createScanCompilerInvocation(*OriginalInvocation, Service);
auto ModCache = makeInProcessModuleCache(Service.getModuleCacheEntries());
ScanInstanceStorage.emplace(std::move(ScanInvocation),
std::move(PCHContainerOps), ModCache.get());
std::move(PCHContainerOps), std::move(ModCache));
CompilerInstance &ScanInstance = *ScanInstanceStorage;

assert(!DiagConsumerFinished && "attempt to reuse finished consumer");
Expand Down Expand Up @@ -741,11 +741,11 @@ bool CompilerInstanceWithContext::initialize(
canonicalizeDefines(OriginalInvocation->getPreprocessorOpts());

// Create the CompilerInstance.
IntrusiveRefCntPtr<ModuleCache> ModCache =
std::shared_ptr<ModuleCache> ModCache =
makeInProcessModuleCache(Worker.Service.getModuleCacheEntries());
CIPtr = std::make_unique<CompilerInstance>(
createScanCompilerInvocation(*OriginalInvocation, Worker.Service),
Worker.PCHContainerOps, ModCache.get());
Worker.PCHContainerOps, std::move(ModCache));
auto &CI = *CIPtr;

initializeScanCompilerInstance(
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/DependencyScanning/InProcessModuleCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class InProcessModuleCache : public ModuleCache {
};
} // namespace

IntrusiveRefCntPtr<ModuleCache>
std::shared_ptr<ModuleCache>
dependencies::makeInProcessModuleCache(ModuleCacheEntries &Entries) {
return llvm::makeIntrusiveRefCnt<InProcessModuleCache>(Entries);
return std::make_shared<InProcessModuleCache>(Entries);
}
3 changes: 2 additions & 1 deletion clang/lib/Frontend/ASTUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1431,6 +1431,7 @@ void ASTUnit::transferASTDataFromCompilerInstance(CompilerInstance &CI) {
if (CI.hasTarget())
Target = CI.getTargetPtr();
Reader = CI.getASTReader();
ModCache = CI.getModuleCachePtr();
HadModuleLoaderFatalFailure = CI.hadModuleLoaderFatalFailure();
if (Invocation != CI.getInvocationPtr()) {
// This happens when Parse creates a copy of \c Invocation to modify.
Expand Down Expand Up @@ -2218,7 +2219,7 @@ bool ASTUnit::serialize(raw_ostream &OS) {

SmallString<128> Buffer;
llvm::BitstreamWriter Stream(Buffer);
IntrusiveRefCntPtr<ModuleCache> ModCache = createCrossProcessModuleCache();
std::shared_ptr<ModuleCache> ModCache = createCrossProcessModuleCache();
ASTWriter Writer(Stream, Buffer, *ModCache, *CodeGenOpts, {});
return serializeUnit(Writer, Buffer, getSema(), OS);
}
Expand Down
9 changes: 5 additions & 4 deletions clang/lib/Frontend/CompilerInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,11 @@ using namespace clang;
CompilerInstance::CompilerInstance(
std::shared_ptr<CompilerInvocation> Invocation,
std::shared_ptr<PCHContainerOperations> PCHContainerOps,
ModuleCache *ModCache)
: ModuleLoader(/*BuildingModule=*/ModCache),
std::shared_ptr<ModuleCache> ModCache)
: ModuleLoader(/*BuildingModule=*/ModCache != nullptr),
Invocation(std::move(Invocation)),
ModCache(ModCache ? ModCache : createCrossProcessModuleCache()),
ModCache(ModCache ? std::move(ModCache)
: createCrossProcessModuleCache()),
ThePCHContainerOperations(std::move(PCHContainerOps)) {
assert(this->Invocation && "Invocation must not be null");
}
Expand Down Expand Up @@ -1169,7 +1170,7 @@ std::unique_ptr<CompilerInstance> CompilerInstance::cloneForModuleCompileImpl(
// CompilerInstance::CompilerInstance is responsible for finalizing the
// buffers to prevent use-after-frees.
auto InstancePtr = std::make_unique<CompilerInstance>(
std::move(Invocation), getPCHContainerOperations(), &getModuleCache());
std::move(Invocation), getPCHContainerOperations(), ModCache);
auto &Instance = *InstancePtr;

auto &Inv = Instance.getInvocation();
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Frontend/Rewrite/FrontendActions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ class RewriteIncludesAction::RewriteImportsListener : public ASTReaderListener {
// Rewrite the contents of the module in a separate compiler instance.
CompilerInstance Instance(
std::make_shared<CompilerInvocation>(CI.getInvocation()),
CI.getPCHContainerOperations(), &CI.getModuleCache());
CI.getPCHContainerOperations(), CI.getModuleCachePtr());
Instance.setVirtualFileSystem(CI.getVirtualFileSystemPtr());
Instance.createDiagnostics(
new ForwardingDiagnosticConsumer(CI.getDiagnosticClient()),
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Serialization/ModuleCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,6 @@ class CrossProcessModuleCache : public ModuleCache {
};
} // namespace

IntrusiveRefCntPtr<ModuleCache> clang::createCrossProcessModuleCache() {
return llvm::makeIntrusiveRefCnt<CrossProcessModuleCache>();
std::shared_ptr<ModuleCache> clang::createCrossProcessModuleCache() {
return std::make_shared<CrossProcessModuleCache>();
}
4 changes: 2 additions & 2 deletions clang/lib/Serialization/ModuleManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ ModuleManager::addModule(StringRef FileName, ModuleKind Type,

if (NewModule->Kind == MK_ImplicitModule)
NewModule->InputFilesValidationTimestamp =
ModCache->getModuleTimestamp(NewModule->FileName);
ModCache.getModuleTimestamp(NewModule->FileName);

// Load the contents of the module
if (std::unique_ptr<llvm::MemoryBuffer> Buffer = lookupBuffer(FileName)) {
Expand Down Expand Up @@ -330,7 +330,7 @@ void ModuleManager::moduleFileAccepted(ModuleFile *MF) {
ModuleManager::ModuleManager(FileManager &FileMgr, ModuleCache &ModCache,
const PCHContainerReader &PCHContainerRdr,
const HeaderSearch &HeaderSearchInfo)
: FileMgr(FileMgr), ModCache(&ModCache), PCHContainerRdr(PCHContainerRdr),
: FileMgr(FileMgr), ModCache(ModCache), PCHContainerRdr(PCHContainerRdr),
HeaderSearchInfo(HeaderSearchInfo) {}

void ModuleManager::visit(llvm::function_ref<bool(ModuleFile &M)> Visitor,
Expand Down
4 changes: 2 additions & 2 deletions clang/unittests/Serialization/ModuleCacheTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ TEST_F(ModuleCacheTest, CachedModuleNewPath) {
ASSERT_TRUE(Invocation2);
CompilerInstance Instance2(std::move(Invocation2),
Instance.getPCHContainerOperations(),
&Instance.getModuleCache());
Instance.getModuleCachePtr());
Instance2.setVirtualFileSystem(CIOpts.VFS);
Instance2.setDiagnostics(Diags);
SyntaxOnlyAction Action2;
Expand Down Expand Up @@ -192,7 +192,7 @@ TEST_F(ModuleCacheTest, CachedModuleNewPathAllowErrors) {
ASSERT_TRUE(Invocation2);
CompilerInstance Instance2(std::move(Invocation2),
Instance.getPCHContainerOperations(),
&Instance.getModuleCache());
Instance.getModuleCachePtr());
Instance2.setVirtualFileSystem(CIOpts.VFS);
Instance2.setDiagnostics(Diags);
SyntaxOnlyAction Action2;
Expand Down
Loading