aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/LTO/LTOBackend.cpp
diff options
context:
space:
mode:
authorTobias Stadler <mail@stadler-tobias.de>2025-09-22 16:41:39 +0100
committerGitHub <noreply@github.com>2025-09-22 16:41:39 +0100
commitdfbd76bda01e804a66c3750193f5e766e4e4cf62 (patch)
tree4ac4d54878c4e6198ec6cc478562be650eba3f50 /llvm/lib/LTO/LTOBackend.cpp
parenteede47656b0cc9c3cff8e1959a6f3d55402f3283 (diff)
downloadllvm-dfbd76bda01e804a66c3750193f5e766e4e4cf62.zip
llvm-dfbd76bda01e804a66c3750193f5e766e4e4cf62.tar.gz
llvm-dfbd76bda01e804a66c3750193f5e766e4e4cf62.tar.bz2
[Remarks] Restructure bitstream remarks to be fully standalone (#156715)
Currently there are two serialization modes for bitstream Remarks: standalone and separate. The separate mode splits remark metadata (e.g. the string table) from actual remark data. The metadata is written into the object file by the AsmPrinter, while the remark data is stored in a separate remarks file. This means we can't use bitstream remarks with tools like opt that don't generate an object file. Also, it is confusing to post-process bitstream remarks files, because only the standalone files can be read by llvm-remarkutil. We always need to use dsymutil to convert the separate files to standalone files, which only works for MachO. It is not possible for clang/opt to directly emit bitstream remark files in standalone mode, because the string table can only be serialized after all remarks were emitted. Therefore, this change completely removes the separate serialization mode. Instead, the remark string table is now always written to the end of the remarks file. This requires us to tell the serializer when to finalize remark serialization. This automatically happens when the serializer goes out of scope. However, often the remark file goes out of scope before the serializer is destroyed. To diagnose this, I have added an assert to alert users that they need to explicitly call finalizeLLVMOptimizationRemarks. This change paves the way for further improvements to the remark infrastructure, including more tooling (e.g. #159784), size optimizations for bitstream remarks, and more. Pull Request: https://github.com/llvm/llvm-project/pull/156715
Diffstat (limited to 'llvm/lib/LTO/LTOBackend.cpp')
-rw-r--r--llvm/lib/LTO/LTOBackend.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/llvm/lib/LTO/LTOBackend.cpp b/llvm/lib/LTO/LTOBackend.cpp
index ce42fc5..c126e8e 100644
--- a/llvm/lib/LTO/LTOBackend.cpp
+++ b/llvm/lib/LTO/LTOBackend.cpp
@@ -540,12 +540,12 @@ static Expected<const Target *> initAndLookupTarget(const Config &C,
return T;
}
-Error lto::finalizeOptimizationRemarks(
- std::unique_ptr<ToolOutputFile> DiagOutputFile) {
+Error lto::finalizeOptimizationRemarks(LLVMRemarkFileHandle DiagOutputFile) {
// Make sure we flush the diagnostic remarks file in case the linker doesn't
// call the global destructors before exiting.
if (!DiagOutputFile)
return Error::success();
+ DiagOutputFile.finalize();
DiagOutputFile->keep();
DiagOutputFile->os().flush();
return Error::success();
@@ -640,7 +640,7 @@ Error lto::thinBackend(const Config &Conf, unsigned Task, AddStreamFn AddStream,
auto OptimizeAndCodegen =
[&](Module &Mod, TargetMachine *TM,
- std::unique_ptr<ToolOutputFile> DiagnosticOutputFile) {
+ LLVMRemarkFileHandle DiagnosticOutputFile) {
// Perform optimization and code generation for ThinLTO.
if (!opt(Conf, TM, Task, Mod, /*IsThinLTO=*/true,
/*ExportSummary=*/nullptr, /*ImportSummary=*/&CombinedIndex,