|
85 | 85 | #include "llvm/Transforms/Instrumentation/SanitizerCoverage.h"
|
86 | 86 | #include "llvm/Transforms/Instrumentation/ThreadSanitizer.h"
|
87 | 87 | #include "llvm/Transforms/ObjCARC.h"
|
| 88 | +#include "llvm/Transforms/Scalar.h" |
88 | 89 |
|
89 | 90 | #include <thread>
|
90 | 91 |
|
@@ -808,10 +809,29 @@ bool swift::compileAndWriteLLVM(llvm::Module *module,
|
808 | 809 | EmitPasses.add(createPrintModulePass(out));
|
809 | 810 | break;
|
810 | 811 | case IRGenOutputKind::LLVMBitcode: {
|
| 812 | + // Emit a module summary by default for Regular LTO except ld64-based ones |
| 813 | + // (which use the legacy LTO API). |
| 814 | + bool EmitRegularLTOSummary = |
| 815 | + targetMachine->getTargetTriple().getVendor() != llvm::Triple::Apple; |
| 816 | + |
| 817 | + if (EmitRegularLTOSummary || opts.LLVMLTOKind == IRGenLLVMLTOKind::Thin) { |
| 818 | + // Rename anon globals to be able to export them in the summary. |
| 819 | + EmitPasses.add(createNameAnonGlobalPass()); |
| 820 | + } |
| 821 | + |
811 | 822 | if (opts.LLVMLTOKind == IRGenLLVMLTOKind::Thin) {
|
812 | 823 | EmitPasses.add(createWriteThinLTOBitcodePass(out));
|
813 | 824 | } else {
|
814 |
| - EmitPasses.add(createBitcodeWriterPass(out)); |
| 825 | + if (EmitRegularLTOSummary) { |
| 826 | + module->addModuleFlag(llvm::Module::Error, "ThinLTO", uint32_t(0)); |
| 827 | + // Assume other sources are compiled with -fsplit-lto-unit (it's enabled |
| 828 | + // by default when -flto is specified on platforms that support regular |
| 829 | + // lto summary.) |
| 830 | + module->addModuleFlag(llvm::Module::Error, "EnableSplitLTOUnit", |
| 831 | + uint32_t(1)); |
| 832 | + } |
| 833 | + EmitPasses.add(createBitcodeWriterPass( |
| 834 | + out, /*ShouldPreserveUseListOrder*/ false, EmitRegularLTOSummary)); |
815 | 835 | }
|
816 | 836 | break;
|
817 | 837 | }
|
|
0 commit comments