dblaikie created this revision. dblaikie added reviewers: rnk, llunak, hans. Herald added a project: clang. Herald added a subscriber: cfe-commits.
I was trying to pick this up a bit when reviewing D48426 <https://reviews.llvm.org/D48426> (& perhaps D69778 <https://reviews.llvm.org/D69778>) - in any case, looks like D48426 <https://reviews.llvm.org/D48426> added a module level flag that might not be needed. The D48426 <https://reviews.llvm.org/D48426> implementation worked by setting a module level flag, then code generating contents from the PCH a special case in ASTContext::DeclMustBeEmitted would be used to delay emitting the definition of these functions if they came from a Module with this flag. This strategy is similar to the one initially implemented for modular codegen that was removed in D29901 <https://reviews.llvm.org/D29901> in favor of the modular decls list and a bit on each decl to specify whether it's homed to a module. One major difference between PCH object support and modular code generation, other than the specific list of decls that are homed, is the compilation model: MSVC PCH modules are built into the object file for some other source file (when compiling that source file /Yc is specified to say "this compilation is where the PCH is homed"), whereas modular code generation invokes a separate compilation for the PCH alone. So the current modular code generation test of to decide if a decl should be emitted "is the module where this decl is serialized the current main file" has to be extended (as Lubos did in D69778 <https://reviews.llvm.org/D69778>) to also test the command line flag -building-pch-with-obj. Otherwise the whole thing is basically streamlined down to the modular code generation path. This even offers one extra material improvement compared to the existing divergent implementation: Homed functions are not emitted into object files that use the pch. Instead at -O0 they are not emitted into the IR at all, and at -O1 they are emitted using available_externally (existing functionality implemented for modular code generation). The pch-codegen test has been updated to reflect this new behavior. [If possible: I'd love it if we could not have the extra MSVC-style way of accessing dllexport-pch-homing, and just do it the modular codegen way, but I understand that it might be a limitation of existing build systems. @hans / @thakis: Do either of you know if it'd be practical to move to something more similar to .pcm handling, where the pch itself is passed to the compilation, rather than homed as a side effect of compiling some other source file?] Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D83652 Files: clang/include/clang/AST/ExternalASTSource.h clang/include/clang/Sema/MultiplexExternalSemaSource.h clang/include/clang/Serialization/ASTReader.h clang/include/clang/Serialization/ModuleFile.h clang/lib/Sema/MultiplexExternalSemaSource.cpp clang/lib/Serialization/ASTReader.cpp clang/lib/Serialization/ASTWriter.cpp
Index: clang/lib/Serialization/ASTWriter.cpp =================================================================== --- clang/lib/Serialization/ASTWriter.cpp +++ clang/lib/Serialization/ASTWriter.cpp @@ -1119,7 +1119,6 @@ MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang min. MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Relocatable MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Timestamps - MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // PCHHasObjectFile MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Errors MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // SVN branch/tag unsigned MetadataAbbrevCode = Stream.EmitAbbrev(std::move(MetadataAbbrev)); @@ -1134,7 +1133,6 @@ CLANG_VERSION_MINOR, !isysroot.empty(), IncludeTimestamps, - false, ASTHasCompilerErrors}; Stream.EmitRecordWithBlob(MetadataAbbrevCode, Record, getClangFullRepositoryVersion()); Index: clang/lib/Serialization/ASTReader.cpp =================================================================== --- clang/lib/Serialization/ASTReader.cpp +++ clang/lib/Serialization/ASTReader.cpp @@ -2747,7 +2747,7 @@ return VersionMismatch; } - bool hasErrors = Record[7]; + bool hasErrors = Record[6]; if (hasErrors && !DisableValidation && !AllowASTWithCompilerErrors) { Diag(diag::err_pch_with_compiler_errors); return HadErrors; @@ -2765,8 +2765,6 @@ F.HasTimestamps = Record[5]; - F.PCHHasObjectFile = Record[6]; - const std::string &CurBranch = getClangFullRepositoryVersion(); StringRef ASTBranch = Blob; if (StringRef(CurBranch) != ASTBranch && !DisableValidation) { @@ -8590,11 +8588,6 @@ return getSubmodule(ID); } -bool ASTReader::DeclIsFromPCHWithObjectFile(const Decl *D) { - ModuleFile *MF = getOwningModuleFile(D); - return MF && MF->PCHHasObjectFile; -} - ModuleFile *ASTReader::getLocalModuleFile(ModuleFile &F, unsigned ID) { if (ID & 1) { // It's a module, look it up by submodule ID. Index: clang/lib/Sema/MultiplexExternalSemaSource.cpp =================================================================== --- clang/lib/Sema/MultiplexExternalSemaSource.cpp +++ clang/lib/Sema/MultiplexExternalSemaSource.cpp @@ -172,13 +172,6 @@ return nullptr; } -bool MultiplexExternalSemaSource::DeclIsFromPCHWithObjectFile(const Decl *D) { - for (auto *S : Sources) - if (S->DeclIsFromPCHWithObjectFile(D)) - return true; - return false; -} - bool MultiplexExternalSemaSource::layoutRecordType(const RecordDecl *Record, uint64_t &Size, uint64_t &Alignment, Index: clang/include/clang/Serialization/ModuleFile.h =================================================================== --- clang/include/clang/Serialization/ModuleFile.h +++ clang/include/clang/Serialization/ModuleFile.h @@ -155,9 +155,6 @@ /// Whether timestamps are included in this module file. bool HasTimestamps = false; - /// Whether the PCH has a corresponding object file. - bool PCHHasObjectFile = false; - /// Whether the top-level module has been read from the AST file. bool DidReadTopLevelSubmodule = false; Index: clang/include/clang/Serialization/ASTReader.h =================================================================== --- clang/include/clang/Serialization/ASTReader.h +++ clang/include/clang/Serialization/ASTReader.h @@ -2085,8 +2085,6 @@ /// Note: overrides method in ExternalASTSource Module *getModule(unsigned ID) override; - bool DeclIsFromPCHWithObjectFile(const Decl *D) override; - /// Retrieve the module file with a given local ID within the specified /// ModuleFile. ModuleFile *getLocalModuleFile(ModuleFile &M, unsigned ID); Index: clang/include/clang/Sema/MultiplexExternalSemaSource.h =================================================================== --- clang/include/clang/Sema/MultiplexExternalSemaSource.h +++ clang/include/clang/Sema/MultiplexExternalSemaSource.h @@ -153,8 +153,6 @@ /// Retrieve the module that corresponds to the given module ID. Module *getModule(unsigned ID) override; - bool DeclIsFromPCHWithObjectFile(const Decl *D) override; - /// Perform layout on the given record. /// /// This routine allows the external AST source to provide an specific Index: clang/include/clang/AST/ExternalASTSource.h =================================================================== --- clang/include/clang/AST/ExternalASTSource.h +++ clang/include/clang/AST/ExternalASTSource.h @@ -161,10 +161,6 @@ /// Retrieve the module that corresponds to the given module ID. virtual Module *getModule(unsigned ID) { return nullptr; } - /// Determine whether D comes from a PCH which was built with a corresponding - /// object file. - virtual bool DeclIsFromPCHWithObjectFile(const Decl *D) { return false; } - /// Return a descriptor for the corresponding module, if one exists. virtual llvm::Optional<ASTSourceDescriptor> getSourceDescriptor(unsigned ID);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits