-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[IRGen] Emit mod summary for full LTO to enable hermetic seal with lld #42366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,6 +82,7 @@ | |
#include "llvm/Transforms/Instrumentation/SanitizerCoverage.h" | ||
#include "llvm/Transforms/Instrumentation/ThreadSanitizer.h" | ||
#include "llvm/Transforms/ObjCARC.h" | ||
#include "llvm/Transforms/Scalar.h" | ||
|
||
#include <thread> | ||
|
||
|
@@ -601,10 +602,29 @@ bool swift::compileAndWriteLLVM(llvm::Module *module, | |
EmitPasses.add(createPrintModulePass(out)); | ||
break; | ||
case IRGenOutputKind::LLVMBitcode: { | ||
// Emit a module summary by default for Regular LTO except ld64-based ones | ||
// (which use the legacy LTO API). | ||
bool EmitRegularLTOSummary = | ||
targetMachine->getTargetTriple().getVendor() != llvm::Triple::Apple; | ||
|
||
if (EmitRegularLTOSummary || opts.LLVMLTOKind == IRGenLLVMLTOKind::Thin) { | ||
// Rename anon globals to be able to export them in the summary. | ||
EmitPasses.add(createNameAnonGlobalPass()); | ||
} | ||
|
||
if (opts.LLVMLTOKind == IRGenLLVMLTOKind::Thin) { | ||
EmitPasses.add(createWriteThinLTOBitcodePass(out)); | ||
} else { | ||
EmitPasses.add(createBitcodeWriterPass(out)); | ||
if (EmitRegularLTOSummary) { | ||
module->addModuleFlag(llvm::Module::Error, "ThinLTO", uint32_t(0)); | ||
// Assume other sources are compiled with -fsplit-lto-unit (it's enabled | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we avoid this assumption? Why do we need this assumption in the first place? Perhaps we should serialize and reference this from the Swift module? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Other sources mean not only Swiftc-oriented LTO summary but also including Clang-oriented summary. So we can't propagate that information through swiftmodule. |
||
// by default when -flto is specified on platforms that support regular | ||
// lto summary.) | ||
module->addModuleFlag(llvm::Module::Error, "EnableSplitLTOUnit", | ||
uint32_t(1)); | ||
} | ||
EmitPasses.add(createBitcodeWriterPass( | ||
out, /*ShouldPreserveUseListOrder*/ false, EmitRegularLTOSummary)); | ||
} | ||
break; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the vendor check rather than
!targetMachine->getTargetTriple().isOSDarwin()
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kubamracek Which form do we prefer here?
!= Apple
orisOSDarwin
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I followed what clang does.
https://github.com/llvm/llvm-project/blob/a5040860412f3e61151e427af1cff6ff0aebb775/clang/lib/CodeGen/BackendUtil.cpp#L164-L172