[clang] 0276621 - [clang][serialization] Reduce `ASTWriter::WriteControlBlock()` scope
Jan Svoboda via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 6 12:41:09 PST 2024
Author: Jan Svoboda
Date: 2024-11-06T12:36:46-08:00
New Revision: 0276621f8f5ae489fbe9343cb4cca07579a244a4
URL: https://github.com/llvm/llvm-project/commit/0276621f8f5ae489fbe9343cb4cca07579a244a4
DIFF: https://github.com/llvm/llvm-project/commit/0276621f8f5ae489fbe9343cb4cca07579a244a4.diff
LOG: [clang][serialization] Reduce `ASTWriter::WriteControlBlock()` scope
Added:
Modified:
clang/include/clang/Serialization/ASTWriter.h
clang/lib/Serialization/ASTWriter.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Serialization/ASTWriter.h b/clang/include/clang/Serialization/ASTWriter.h
index 918a9a635185b2..83684443ca948e 100644
--- a/clang/include/clang/Serialization/ASTWriter.h
+++ b/clang/include/clang/Serialization/ASTWriter.h
@@ -548,8 +548,7 @@ class ASTWriter : public ASTDeserializationListener,
void WriteSubStmt(Stmt *S);
void WriteBlockInfoBlock();
- void WriteControlBlock(Preprocessor &PP, ASTContext &Context,
- StringRef isysroot);
+ void WriteControlBlock(Preprocessor &PP, StringRef isysroot);
/// Write out the signature and diagnostic options, and return the signature.
void writeUnhashedControlBlock(Preprocessor &PP, ASTContext &Context);
diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp
index 0c244e73b30895..13ee9904b29fd3 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -1403,10 +1403,12 @@ void ASTWriter::writeUnhashedControlBlock(Preprocessor &PP,
}
/// Write the control block.
-void ASTWriter::WriteControlBlock(Preprocessor &PP, ASTContext &Context,
- StringRef isysroot) {
+void ASTWriter::WriteControlBlock(Preprocessor &PP, StringRef isysroot) {
using namespace llvm;
+ SourceManager &SourceMgr = PP.getSourceManager();
+ FileManager &FileMgr = PP.getFileManager();
+
Stream.EnterSubblock(CONTROL_BLOCK_ID, 5);
RecordData Record;
@@ -1454,14 +1456,12 @@ void ASTWriter::WriteControlBlock(Preprocessor &PP, ASTContext &Context,
SmallString<128> BaseDir;
if (PP.getHeaderSearchInfo().getHeaderSearchOpts().ModuleFileHomeIsCwd) {
// Use the current working directory as the base path for all inputs.
- auto CWD =
- Context.getSourceManager().getFileManager().getOptionalDirectoryRef(
- ".");
+ auto CWD = FileMgr.getOptionalDirectoryRef(".");
BaseDir.assign(CWD->getName());
} else {
BaseDir.assign(WritingModule->Directory->getName());
}
- cleanPathForOutput(Context.getSourceManager().getFileManager(), BaseDir);
+ cleanPathForOutput(FileMgr, BaseDir);
// If the home of the module is the current working directory, then we
// want to pick up the cwd of the build process loading the module, not
@@ -1554,7 +1554,7 @@ void ASTWriter::WriteControlBlock(Preprocessor &PP, ASTContext &Context,
// Language options.
Record.clear();
- const LangOptions &LangOpts = Context.getLangOpts();
+ const LangOptions &LangOpts = PP.getLangOpts();
#define LANGOPT(Name, Bits, Default, Description) \
Record.push_back(LangOpts.Name);
#define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
@@ -1591,7 +1591,7 @@ void ASTWriter::WriteControlBlock(Preprocessor &PP, ASTContext &Context,
// Target options.
Record.clear();
- const TargetInfo &Target = Context.getTargetInfo();
+ const TargetInfo &Target = PP.getTargetInfo();
const TargetOptions &TargetOpts = Target.getTargetOpts();
AddString(TargetOpts.Triple, Record);
AddString(TargetOpts.CPU, Record);
@@ -1609,8 +1609,7 @@ void ASTWriter::WriteControlBlock(Preprocessor &PP, ASTContext &Context,
// File system options.
Record.clear();
- const FileSystemOptions &FSOpts =
- Context.getSourceManager().getFileManager().getFileSystemOpts();
+ const FileSystemOptions &FSOpts = FileMgr.getFileSystemOpts();
AddString(FSOpts.WorkingDir, Record);
Stream.EmitRecord(FILE_SYSTEM_OPTIONS, Record);
@@ -1675,8 +1674,8 @@ void ASTWriter::WriteControlBlock(Preprocessor &PP, ASTContext &Context,
Stream.ExitBlock();
// Original file name and file ID
- SourceManager &SM = Context.getSourceManager();
- if (auto MainFile = SM.getFileEntryRefForID(SM.getMainFileID())) {
+ if (auto MainFile =
+ SourceMgr.getFileEntryRefForID(SourceMgr.getMainFileID())) {
auto FileAbbrev = std::make_shared<BitCodeAbbrev>();
FileAbbrev->Add(BitCodeAbbrevOp(ORIGINAL_FILE));
FileAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // File ID
@@ -1685,16 +1684,15 @@ void ASTWriter::WriteControlBlock(Preprocessor &PP, ASTContext &Context,
Record.clear();
Record.push_back(ORIGINAL_FILE);
- AddFileID(SM.getMainFileID(), Record);
+ AddFileID(SourceMgr.getMainFileID(), Record);
EmitRecordWithPath(FileAbbrevCode, Record, MainFile->getName());
}
Record.clear();
- AddFileID(SM.getMainFileID(), Record);
+ AddFileID(SourceMgr.getMainFileID(), Record);
Stream.EmitRecord(ORIGINAL_FILE_ID, Record);
- WriteInputFiles(Context.SourceMgr,
- PP.getHeaderSearchInfo().getHeaderSearchOpts());
+ WriteInputFiles(SourceMgr, PP.getHeaderSearchInfo().getHeaderSearchOpts());
Stream.ExitBlock();
}
@@ -5432,7 +5430,7 @@ ASTFileSignature ASTWriter::WriteASTCore(Sema &SemaRef, StringRef isysroot,
PrepareWritingSpecialDecls(SemaRef);
// Write the control block
- WriteControlBlock(PP, Context, isysroot);
+ WriteControlBlock(PP, isysroot);
// Write the remaining AST contents.
Stream.FlushToWord();
More information about the cfe-commits
mailing list