Skip to content

Commit 4080116

Browse files
Use CASID to encode splitDwarfFilename
1 parent 1154244 commit 4080116

38 files changed

+763
-154
lines changed

clang/include/clang/Basic/ASTSourceDescriptor.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,23 @@ class ASTSourceDescriptor {
3030
StringRef Path;
3131
StringRef ASTFile;
3232
ASTFileSignature Signature;
33+
StringRef CASID;
3334
Module *ClangModule = nullptr;
3435

3536
public:
3637
ASTSourceDescriptor() = default;
3738
ASTSourceDescriptor(StringRef Name, StringRef Path, StringRef ASTFile,
38-
ASTFileSignature Signature)
39+
ASTFileSignature Signature, StringRef CASID)
3940
: PCHModuleName(std::move(Name)), Path(std::move(Path)),
40-
ASTFile(std::move(ASTFile)), Signature(Signature) {}
41+
ASTFile(std::move(ASTFile)), Signature(Signature), CASID(CASID) {}
4142
ASTSourceDescriptor(Module &M);
4243

4344
std::string getModuleName() const;
4445
StringRef getPath() const { return Path; }
4546
StringRef getASTFile() const { return ASTFile; }
4647
ASTFileSignature getSignature() const { return Signature; }
4748
Module *getModuleOrNull() const { return ClangModule; }
49+
StringRef getCASID() const { return CASID; }
4850
};
4951

5052
} // namespace clang

clang/include/clang/Basic/DiagnosticCASKinds.td

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ def err_cas_depscan_daemon_connection: Error<
2323
def err_cas_depscan_failed: Error<
2424
"CAS-based dependency scan failed: %0">, DefaultFatal;
2525
def err_cas_store: Error<"failed to store to CAS: %0">, DefaultFatal;
26-
def err_cas_unloadable_module : Error<
27-
"module file '%0' not found: unloadable module cache key %1: %2">, DefaultFatal;
26+
def err_cas_unloadable_module
27+
: Error<"module file '%0' not found: unloadable %select{casid|module cache "
28+
"key}1 %2: %3">,
29+
DefaultFatal;
2830
def err_cas_missing_module : Error<
2931
"module file '%0' not found: missing module cache key %1: %2">, DefaultFatal;
3032
def err_cas_missing_root_id : Error<

clang/include/clang/Basic/Module.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,9 @@ class alignas(8) Module {
274274
/// The \c ActionCache key for this module, if any.
275275
std::optional<std::string> ModuleCacheKey;
276276

277+
/// The \c CASID for the loaded module, otherwise empty.
278+
std::string CASID;
279+
277280
/// The top-level headers associated with this module.
278281
llvm::SmallSetVector<FileEntryRef, 2> TopHeaders;
279282

@@ -773,6 +776,13 @@ class alignas(8) Module {
773776
getTopLevelModule()->ModuleCacheKey = std::move(Key);
774777
}
775778

779+
StringRef getCASID() const { return getTopLevelModule()->CASID; }
780+
781+
void setCASID(std::string ID) {
782+
assert(getCASID().empty() || getCASID() == ID);
783+
getTopLevelModule()->CASID = std::move(ID);
784+
}
785+
776786
/// Retrieve the umbrella directory as written.
777787
std::optional<DirectoryName> getUmbrellaDirAsWritten() const {
778788
if (const auto *Dir = std::get_if<DirectoryEntryRef>(&Umbrella))

clang/include/clang/Frontend/CompilerInstance.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,8 +1001,8 @@ class CompilerInstance : public ModuleLoader {
10011001
/// "-fmodule-file-cache-key", or an imported pcm file. Used in diagnostics.
10021002
///
10031003
/// \returns true on failure.
1004-
bool addCachedModuleFile(StringRef Path, StringRef CacheKey,
1005-
StringRef Provider);
1004+
bool addCachedModuleFile(StringRef Path, StringRef CASID, StringRef Provider,
1005+
bool IsKey);
10061006

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

clang/include/clang/Serialization/ASTReader.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,14 @@ class ASTReaderListener {
286286
return false;
287287
}
288288

289+
/// Called for each module CASID.
290+
///
291+
/// \returns true to indicate the key cannot be loaded.
292+
virtual bool readModuleCASID(StringRef ModuleName, StringRef Filename,
293+
StringRef CASID) {
294+
return false;
295+
}
296+
289297
/// Indicates that a particular module file extension has been read.
290298
virtual void readModuleFileExtension(
291299
const ModuleFileExtensionMetadata &Metadata) {}
@@ -342,6 +350,8 @@ class ChainedASTReaderListener : public ASTReaderListener {
342350
bool readIncludeTreeID(StringRef ID, bool Complain) override;
343351
bool readModuleCacheKey(StringRef ModuleName, StringRef Filename,
344352
StringRef CacheKey) override;
353+
bool readModuleCASID(StringRef ModuleName, StringRef Filename,
354+
StringRef CASID) override;
345355
void readModuleFileExtension(
346356
const ModuleFileExtensionMetadata &Metadata) override;
347357
};

clang/include/clang/Serialization/InMemoryModuleCache.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ class InMemoryModuleCache : public llvm::RefCountedBase<InMemoryModuleCache> {
3030
struct PCM {
3131
std::unique_ptr<llvm::MemoryBuffer> Buffer;
3232

33+
std::string CASID;
34+
3335
/// Track whether this PCM is known to be good (either built or
3436
/// successfully imported by a CompilerInstance/ASTReader using this
3537
/// cache).
@@ -38,6 +40,9 @@ class InMemoryModuleCache : public llvm::RefCountedBase<InMemoryModuleCache> {
3840
PCM() = default;
3941
PCM(std::unique_ptr<llvm::MemoryBuffer> Buffer)
4042
: Buffer(std::move(Buffer)) {}
43+
44+
PCM(std::unique_ptr<llvm::MemoryBuffer> Buffer, llvm::StringRef CASID)
45+
: Buffer(std::move(Buffer)), CASID(CASID.str()) {}
4146
};
4247

4348
/// Cache of buffers.
@@ -64,7 +69,8 @@ class InMemoryModuleCache : public llvm::RefCountedBase<InMemoryModuleCache> {
6469
/// \post state is Tentative
6570
/// \return a reference to the buffer as a convenience.
6671
llvm::MemoryBuffer &addPCM(llvm::StringRef Filename,
67-
std::unique_ptr<llvm::MemoryBuffer> Buffer);
72+
std::unique_ptr<llvm::MemoryBuffer> Buffer,
73+
llvm::StringRef CASID = "");
6874

6975
/// Store a just-built PCM under the Filename.
7076
///
@@ -90,6 +96,9 @@ class InMemoryModuleCache : public llvm::RefCountedBase<InMemoryModuleCache> {
9096
/// Get a pointer to the pCM if it exists; else nullptr.
9197
llvm::MemoryBuffer *lookupPCM(llvm::StringRef Filename) const;
9298

99+
/// Get the PCM if it exits; else nullptr.
100+
const PCM *lookup(llvm::StringRef Filename) const;
101+
93102
/// Check whether the PCM is final and has been shown to work.
94103
///
95104
/// \return true iff state is Final.

clang/include/clang/Serialization/ModuleFile.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ class ModuleFile {
147147
/// The \c ActionCache key for this module, or empty.
148148
std::string ModuleCacheKey;
149149

150+
/// The \c CASID for the module, or empty.
151+
std::string CASID;
152+
150153
/// The CAS filesystem root ID for implicit modules built with the dependency
151154
/// scanner, or empty.
152155
std::string CASFileSystemRootID;

clang/lib/Basic/ASTSourceDescriptor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ ASTSourceDescriptor::ASTSourceDescriptor(Module &M)
2121
Path = M.Directory->getName();
2222
if (auto File = M.getASTFile())
2323
ASTFile = File->getName();
24+
CASID = M.getCASID();
2425
}
2526

2627
std::string ASTSourceDescriptor::getModuleName() const {

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3348,6 +3348,11 @@ llvm::DIModule *CGDebugInfo::getOrCreateModuleRef(ASTSourceDescriptor Mod,
33483348
PCM = Mod.getPath();
33493349
}
33503350
llvm::sys::path::append(PCM, Mod.getASTFile());
3351+
3352+
// FIXME: Prefer CASID if exists.
3353+
if (!Mod.getCASID().empty())
3354+
PCM = Mod.getCASID();
3355+
33513356
DIB.createCompileUnit(
33523357
TheCU->getSourceLanguage(),
33533358
// TODO: Support "Source" from external AST providers?

clang/lib/CodeGen/ObjectFilePCHContainerWriter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ class PCHContainerGenerator : public ASTConsumer {
191191
// Prepare CGDebugInfo to emit debug info for a clang module.
192192
auto *DI = Builder->getModuleDebugInfo();
193193
StringRef ModuleName = llvm::sys::path::filename(MainFileName);
194-
DI->setPCHDescriptor(
195-
{ModuleName, "", OutputFileName, ASTFileSignature::createDISentinel()});
194+
DI->setPCHDescriptor({ModuleName, "", OutputFileName,
195+
ASTFileSignature::createDISentinel(), /*CASID=*/""});
196196
DI->setModuleMap(MMap);
197197
}
198198

0 commit comments

Comments
 (0)