|
82 | 82 | #include "llvm/Transforms/Instrumentation/SanitizerCoverage.h"
|
83 | 83 | #include "llvm/Transforms/Instrumentation/ThreadSanitizer.h"
|
84 | 84 | #include "llvm/Transforms/ObjCARC.h"
|
| 85 | +#include "llvm/Transforms/Scalar.h" |
85 | 86 |
|
86 | 87 | #include <thread>
|
87 | 88 |
|
@@ -601,10 +602,29 @@ bool swift::compileAndWriteLLVM(llvm::Module *module,
|
601 | 602 | EmitPasses.add(createPrintModulePass(out));
|
602 | 603 | break;
|
603 | 604 | case IRGenOutputKind::LLVMBitcode: {
|
| 605 | + // Emit a module summary by default for Regular LTO except ld64-based ones |
| 606 | + // (which use the legacy LTO API). |
| 607 | + bool EmitRegularLTOSummary = |
| 608 | + targetMachine->getTargetTriple().getVendor() != llvm::Triple::Apple; |
| 609 | + |
| 610 | + if (EmitRegularLTOSummary || opts.LLVMLTOKind == IRGenLLVMLTOKind::Thin) { |
| 611 | + // Rename anon globals to be able to export them in the summary. |
| 612 | + EmitPasses.add(createNameAnonGlobalPass()); |
| 613 | + } |
| 614 | + |
604 | 615 | if (opts.LLVMLTOKind == IRGenLLVMLTOKind::Thin) {
|
605 | 616 | EmitPasses.add(createWriteThinLTOBitcodePass(out));
|
606 | 617 | } else {
|
607 |
| - EmitPasses.add(createBitcodeWriterPass(out)); |
| 618 | + if (EmitRegularLTOSummary) { |
| 619 | + module->addModuleFlag(llvm::Module::Error, "ThinLTO", uint32_t(0)); |
| 620 | + // Assume other sources are compiled with -fsplit-lto-unit (it's enabled |
| 621 | + // by default when -flto is specified on platforms that support regular |
| 622 | + // lto summary.) |
| 623 | + module->addModuleFlag(llvm::Module::Error, "EnableSplitLTOUnit", |
| 624 | + uint32_t(1)); |
| 625 | + } |
| 626 | + EmitPasses.add(createBitcodeWriterPass( |
| 627 | + out, /*ShouldPreserveUseListOrder*/ false, EmitRegularLTOSummary)); |
608 | 628 | }
|
609 | 629 | break;
|
610 | 630 | }
|
|
0 commit comments