Skip to content

Commit bd10966

Browse files
committed
Merge remote-tracking branch 'origin/main' into rebranch
2 parents 66925a3 + 9c4972f commit bd10966

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

lib/IRGen/IRGen.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
#include "llvm/Transforms/Instrumentation/SanitizerCoverage.h"
8686
#include "llvm/Transforms/Instrumentation/ThreadSanitizer.h"
8787
#include "llvm/Transforms/ObjCARC.h"
88+
#include "llvm/Transforms/Scalar.h"
8889

8990
#include <thread>
9091

@@ -804,10 +805,29 @@ bool swift::compileAndWriteLLVM(llvm::Module *module,
804805
EmitPasses.add(createPrintModulePass(out));
805806
break;
806807
case IRGenOutputKind::LLVMBitcode: {
808+
// Emit a module summary by default for Regular LTO except ld64-based ones
809+
// (which use the legacy LTO API).
810+
bool EmitRegularLTOSummary =
811+
targetMachine->getTargetTriple().getVendor() != llvm::Triple::Apple;
812+
813+
if (EmitRegularLTOSummary || opts.LLVMLTOKind == IRGenLLVMLTOKind::Thin) {
814+
// Rename anon globals to be able to export them in the summary.
815+
EmitPasses.add(createNameAnonGlobalPass());
816+
}
817+
807818
if (opts.LLVMLTOKind == IRGenLLVMLTOKind::Thin) {
808819
EmitPasses.add(createWriteThinLTOBitcodePass(out));
809820
} else {
810-
EmitPasses.add(createBitcodeWriterPass(out));
821+
if (EmitRegularLTOSummary) {
822+
module->addModuleFlag(llvm::Module::Error, "ThinLTO", uint32_t(0));
823+
// Assume other sources are compiled with -fsplit-lto-unit (it's enabled
824+
// by default when -flto is specified on platforms that support regular
825+
// lto summary.)
826+
module->addModuleFlag(llvm::Module::Error, "EnableSplitLTOUnit",
827+
uint32_t(1));
828+
}
829+
EmitPasses.add(createBitcodeWriterPass(
830+
out, /*ShouldPreserveUseListOrder*/ false, EmitRegularLTOSummary));
811831
}
812832
break;
813833
}

0 commit comments

Comments
 (0)