Skip to content

Commit cfe1ece

Browse files
authored
[clang][llvm][fatlto] Avoid cloning modules in FatLTO (#72180)
#70703 pointed out that cloning LLVM modules could lead to miscompiles when using FatLTO. This is due to an existing issue when cloning modules with labels (see #55991 and #47769). Since this can lead to miscompilation, we can avoid cloning the LLVM modules, which was desirable anyway. This patch modifies the EmbedBitcodePass to no longer clone the module or run an input pipeline over it. Further, it make FatLTO always perform UnifiedLTO, so we can still defer the Thin/Full LTO decision to link-time. Lastly, it removes dead/obsolete code related to now defunct options that do not work with the EmbedBitcodePass implementation any longer.
1 parent 51fc854 commit cfe1ece

File tree

14 files changed

+94
-116
lines changed

14 files changed

+94
-116
lines changed

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -996,9 +996,8 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
996996
}
997997

998998
if (CodeGenOpts.FatLTO) {
999-
MPM.addPass(PB.buildFatLTODefaultPipeline(
1000-
Level, PrepareForThinLTO,
1001-
PrepareForThinLTO || shouldEmitRegularLTOSummary()));
999+
assert(CodeGenOpts.UnifiedLTO && "FatLTO requires UnifiedLTO");
1000+
MPM.addPass(PB.buildFatLTODefaultPipeline(Level));
10021001
} else if (PrepareForThinLTO) {
10031002
MPM.addPass(PB.buildThinLTOPreLinkDefaultPipeline(Level));
10041003
} else if (PrepareForLTO) {
@@ -1042,7 +1041,6 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
10421041
MPM.addPass(PrintModulePass(*OS, "", CodeGenOpts.EmitLLVMUseLists,
10431042
/*EmitLTOSummary=*/true));
10441043
}
1045-
10461044
} else {
10471045
// Emit a module summary by default for Regular LTO except for ld64
10481046
// targets
@@ -1073,7 +1071,8 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
10731071
if (!TheModule->getModuleFlag("EnableSplitLTOUnit"))
10741072
TheModule->addModuleFlag(llvm::Module::Error, "EnableSplitLTOUnit",
10751073
uint32_t(CodeGenOpts.EnableSplitLTOUnit));
1076-
if (CodeGenOpts.UnifiedLTO && !TheModule->getModuleFlag("UnifiedLTO"))
1074+
// FatLTO always means UnifiedLTO
1075+
if (!TheModule->getModuleFlag("UnifiedLTO"))
10771076
TheModule->addModuleFlag(llvm::Module::Error, "UnifiedLTO", uint32_t(1));
10781077
}
10791078

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4862,7 +4862,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
48624862
bool UnifiedLTO = false;
48634863
if (IsUsingLTO) {
48644864
UnifiedLTO = Args.hasFlag(options::OPT_funified_lto,
4865-
options::OPT_fno_unified_lto, Triple.isPS());
4865+
options::OPT_fno_unified_lto, Triple.isPS()) ||
4866+
Args.hasFlag(options::OPT_ffat_lto_objects,
4867+
options::OPT_fno_fat_lto_objects, false);
48664868
if (UnifiedLTO)
48674869
CmdArgs.push_back("-funified-lto");
48684870
}

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,6 +1861,20 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args,
18611861
if (Args.hasArg(OPT_funified_lto))
18621862
Opts.PrepareForThinLTO = true;
18631863
}
1864+
if (Arg *A = Args.getLastArg(options::OPT_ffat_lto_objects,
1865+
options::OPT_fno_fat_lto_objects)) {
1866+
if (A->getOption().matches(options::OPT_ffat_lto_objects)) {
1867+
if (Arg *Uni = Args.getLastArg(options::OPT_funified_lto,
1868+
options::OPT_fno_unified_lto)) {
1869+
if (Uni->getOption().matches(options::OPT_fno_unified_lto))
1870+
Diags.Report(diag::err_drv_incompatible_options)
1871+
<< A->getAsString(Args) << "-fno-unified-lto";
1872+
} else
1873+
Diags.Report(diag::err_drv_argument_only_allowed_with)
1874+
<< A->getAsString(Args) << "-funified-lto";
1875+
}
1876+
}
1877+
18641878
if (Arg *A = Args.getLastArg(OPT_fthinlto_index_EQ)) {
18651879
if (IK.getLanguage() != Language::LLVM_IR)
18661880
Diags.Report(diag::err_drv_argument_only_allowed_with)

clang/test/CodeGen/fat-lto-objects.c

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,47 @@
11
// REQUIRES: x86-registered-target
22

3-
// RUN: %clang -cc1 -triple x86_64-unknown-linux-gnu -flto=full -ffat-lto-objects -fsplit-lto-unit -emit-llvm < %s | FileCheck %s --check-prefixes=FULL,SPLIT
4-
// RUN: %clang -cc1 -triple x86_64-unknown-linux-gnu -flto=full -ffat-lto-objects -emit-llvm < %s | FileCheck %s --check-prefixes=FULL,SPLIT
3+
// RUN: not %clang -cc1 -triple x86_64-unknown-linux-gnu -flto=full -ffat-lto-objects -fsplit-lto-unit -emit-llvm < %s 2>&1 | FileCheck %s --check-prefixes=NO-UNIFIED
54

6-
// RUN: %clang -cc1 -triple x86_64-unknown-linux-gnu -flto=thin -fsplit-lto-unit -ffat-lto-objects -emit-llvm < %s | FileCheck %s --check-prefixes=THIN,SPLIT
7-
// RUN: %clang -cc1 -triple x86_64-unknown-linux-gnu -flto=thin -ffat-lto-objects -emit-llvm < %s | FileCheck %s --check-prefixes=THIN,NOSPLIT
5+
// RUN: %clang -cc1 -triple x86_64-unknown-linux-gnu -flto=full -funified-lto -ffat-lto-objects -fsplit-lto-unit -emit-llvm < %s | FileCheck %s --check-prefixes=FULL,SPLIT,UNIFIED
6+
// RUN: %clang -cc1 -triple x86_64-unknown-linux-gnu -flto=full -funified-lto -ffat-lto-objects -emit-llvm < %s | FileCheck %s --check-prefixes=FULL,NOSPLIT,UNIFIED
87

9-
// RUN: %clang -cc1 -triple x86_64-unknown-linux-gnu -flto=full -ffat-lto-objects -fsplit-lto-unit -emit-obj < %s -o %t.full.split.o
8+
// RUN: %clang -cc1 -triple x86_64-unknown-linux-gnu -flto=thin -funified-lto -fsplit-lto-unit -ffat-lto-objects -emit-llvm < %s | FileCheck %s --check-prefixes=THIN,SPLIT,UNIFIED
9+
// RUN: %clang -cc1 -triple x86_64-unknown-linux-gnu -flto=thin -funified-lto -ffat-lto-objects -emit-llvm < %s | FileCheck %s --check-prefixes=THIN,NOSPLIT,UNIFIED
10+
11+
// RUN: %clang -cc1 -triple x86_64-unknown-linux-gnu -flto=full -funified-lto -ffat-lto-objects -fsplit-lto-unit -emit-obj < %s -o %t.full.split.o
1012
// RUN: llvm-readelf -S %t.full.split.o | FileCheck %s --check-prefixes=ELF
1113
// RUN: llvm-objcopy --dump-section=.llvm.lto=%t.full.split.bc %t.full.split.o
12-
// RUN: llvm-dis %t.full.split.bc -o - | FileCheck %s --check-prefixes=FULL,SPLIT,NOUNIFIED
14+
// RUN: llvm-dis %t.full.split.bc -o - | FileCheck %s --check-prefixes=THIN,SPLIT,UNIFIED
1315

14-
// RUN: %clang -cc1 -triple x86_64-unknown-linux-gnu -flto=full -ffat-lto-objects -emit-obj < %s -o %t.full.nosplit.o
16+
// RUN: %clang -cc1 -triple x86_64-unknown-linux-gnu -flto=full -funified-lto -ffat-lto-objects -emit-obj < %s -o %t.full.nosplit.o
1517
// RUN: llvm-readelf -S %t.full.nosplit.o | FileCheck %s --check-prefixes=ELF
1618
// RUN: llvm-objcopy --dump-section=.llvm.lto=%t.full.nosplit.bc %t.full.nosplit.o
17-
// RUN: llvm-dis %t.full.nosplit.bc -o - | FileCheck %s --check-prefixes=FULL,NOSPLIT,NOUNIFIED
19+
// RUN: llvm-dis %t.full.nosplit.bc -o - | FileCheck %s --check-prefixes=THIN,NOSPLIT,UNIFIED
1820

19-
// RUN: %clang -cc1 -triple x86_64-unknown-linux-gnu -flto=thin -fsplit-lto-unit -ffat-lto-objects -emit-obj < %s -o %t.thin.split.o
21+
// RUN: %clang -cc1 -triple x86_64-unknown-linux-gnu -flto=thin -funified-lto -fsplit-lto-unit -ffat-lto-objects -emit-obj < %s -o %t.thin.split.o
2022
// RUN: llvm-readelf -S %t.thin.split.o | FileCheck %s --check-prefixes=ELF
2123
// RUN: llvm-objcopy --dump-section=.llvm.lto=%t.thin.split.bc %t.thin.split.o
22-
// RUN: llvm-dis %t.thin.split.bc -o - | FileCheck %s --check-prefixes=THIN,SPLIT,NOUNIFIED
24+
// RUN: llvm-dis %t.thin.split.bc -o - | FileCheck %s --check-prefixes=THIN,SPLIT,UNIFIED
2325

24-
// RUN: %clang -cc1 -triple x86_64-unknown-linux-gnu -flto=thin -ffat-lto-objects -emit-obj < %s -o %t.thin.nosplit.o
26+
// RUN: %clang -cc1 -triple x86_64-unknown-linux-gnu -flto=thin -funified-lto -ffat-lto-objects -emit-obj < %s -o %t.thin.nosplit.o
2527
// RUN: llvm-readelf -S %t.thin.nosplit.o | FileCheck %s --check-prefixes=ELF
2628
// RUN: llvm-objcopy --dump-section=.llvm.lto=%t.thin.nosplit.bc %t.thin.nosplit.o
27-
// RUN: llvm-dis %t.thin.nosplit.bc -o - | FileCheck %s --check-prefixes=THIN,NOSPLIT,NOUNIFIED
28-
29-
// RUN: %clang -cc1 -triple x86_64-unknown-linux-gnu -flto=thin -funified-lto -ffat-lto-objects -emit-obj < %s -o %t.unified.o
30-
// RUN: llvm-readelf -S %t.unified.o | FileCheck %s --check-prefixes=ELF
31-
// RUN: llvm-objcopy --dump-section=.llvm.lto=%t.unified.bc %t.unified.o
32-
// RUN: llvm-dis %t.unified.bc -o - | FileCheck %s --check-prefixes=THIN,NOSPLIT,UNIFIED
29+
// RUN: llvm-dis %t.thin.nosplit.bc -o - | FileCheck %s --check-prefixes=THIN,NOSPLIT,UNIFIED
3330

34-
// RUN: %clang -cc1 -triple x86_64-unknown-linux-gnu -flto=full -ffat-lto-objects -fsplit-lto-unit -S < %s -o - \
31+
// RUN: %clang -cc1 -triple x86_64-unknown-linux-gnu -flto=full -funified-lto -ffat-lto-objects -fsplit-lto-unit -S < %s -o - \
3532
// RUN: | FileCheck %s --check-prefixes=ASM
3633

37-
/// Check that the ThinLTO metadata is only set false for full LTO.
38-
// FULL: ![[#]] = !{i32 1, !"ThinLTO", i32 0}
39-
// THIN-NOT: ![[#]] = !{i32 1, !"ThinLTO", i32 0}
40-
4134
/// Be sure we enable split LTO units correctly under -ffat-lto-objects.
42-
// SPLIT: ![[#]] = !{i32 1, !"EnableSplitLTOUnit", i32 1}
35+
// SPLIT: ![[#]] = !{i32 1, !"EnableSplitLTOUnit", i32 1}
4336
// NOSPLIT: ![[#]] = !{i32 1, !"EnableSplitLTOUnit", i32 0}
4437

45-
// UNIFIED: ![[#]] = !{i32 1, !"UnifiedLTO", i32 1}
46-
// NOUNIFIED-NOT: ![[#]] = !{i32 1, !"UnifiedLTO", i32 1}
38+
/// Check that the ThinLTO metadata is set true for both full and thin LTO, since FatLTO is based on UnifiedLTO.
39+
// FULL: ![[#]] = !{i32 1, !"ThinLTO", i32 1}
40+
// THIN-NOT: ![[#]] = !{i32 1, !"ThinLTO", i32 0}
41+
42+
/// FatLTO always uses UnifiedLTO. It's an error if they aren't set together
43+
// UNIFIED: ![[#]] = !{i32 1, !"UnifiedLTO", i32 1}
44+
// NO-UNIFIED: error: invalid argument '-ffat-lto-objects' only allowed with '-funified-lto'
4745

4846
// ELF: .llvm.lto
4947

clang/test/Driver/fat-lto-objects.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// RUN: %clang --target=x86_64-unknown-linux-gnu -flto -ffat-lto-objects -### %s -c 2>&1 | FileCheck %s -check-prefix=CHECK-CC
22
// CHECK-CC: -cc1
3+
// CHECK-CC-SAME: -funified-lto
34
// CHECK-CC-SAME: -emit-obj
45
// CHECK-CC-SAME: -ffat-lto-objects
56

@@ -15,6 +16,7 @@
1516
// RUN: %clang --target=x86_64-unknown-linux-gnu -flto -ffat-lto-objects -### %s -S 2>&1 | FileCheck %s -check-prefix=CHECK-CC-S-LTO
1617
// RUN: %clang --target=x86_64-unknown-linux-gnu -flto -ffat-lto-objects -### %s -S -emit-llvm 2>&1 | FileCheck %s -check-prefix=CHECK-CC-S-LTO
1718
// CHECK-CC-S-LTO: -cc1
19+
// CHECK-CC-S-LTO-SAME: -funified-lto
1820
// CHECK-CC-S-LTO-SAME: -emit-llvm
1921
// CHECK-CC-S-LTO-SAME: -ffat-lto-objects
2022

@@ -32,3 +34,13 @@
3234
// RUN: -fuse-ld=lld -fno-lto -ffat-lto-objects -### 2>&1 | FileCheck --check-prefix=NOLTO %s
3335
// LTO: "--fat-lto-objects"
3436
// NOLTO-NOT: "--fat-lto-objects"
37+
38+
/// Make sure that incompatible options emit the correct diagnostics, since -ffat-lto-objects requires -funified-lto
39+
// RUN: %clang -cc1 -triple=x86_64-unknown-linux-gnu -flto -ffat-lto-objects -funified-lto -emit-llvm-only %s 2>&1 | FileCheck %s -check-prefix=UNIFIED --allow-empty
40+
// UNIFIED-NOT: error:
41+
42+
// RUN: not %clang -cc1 -triple=x86_64-unknown-linux-gnu -flto -ffat-lto-objects -emit-llvm-only %s 2>&1 | FileCheck %s -check-prefix=MISSING_UNIFIED
43+
// MISSING_UNIFIED: error: invalid argument '-ffat-lto-objects' only allowed with '-funified-lto'
44+
45+
// RUN: not %clang -cc1 -triple=x86_64-unknown-linux-gnu -flto -fno-unified-lto -ffat-lto-objects -emit-llvm-only %s 2>&1 | FileCheck %s -check-prefix=NO-UNIFIED
46+
// NO-UNIFIED: error: the combination of '-ffat-lto-objects' and '-fno-unified-lto' is incompatible

llvm/docs/FatLTO.rst

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,30 +29,31 @@ Overview
2929
Within LLVM, FatLTO is supported by choosing the ``FatLTODefaultPipeline``.
3030
This pipeline will:
3131

32-
#) Clone the IR module.
33-
#) Run the pre-link (Thin)LTO pipeline using the cloned module.
32+
#) Run the pre-link UnifiedLTO pipeline on the current module.
3433
#) Embed the pre-link bitcode in a special ``.llvm.lto`` section.
35-
#) Optimize the unmodified copy of the module using the normal compilation pipeline.
34+
#) Finish optimizing the module using the post-link ThinLTO pipeline.
3635
#) Emit the object file, including the new ``.llvm.lto`` section.
3736

3837
.. NOTE
3938
40-
At the time of writing, we conservatively run independent pipelines to
41-
generate the bitcode section and the object code, which happen to be
42-
identical to those used outside of FatLTO. This results in compiled
43-
artifacts that are identical to those produced by the default and (Thin)LTO
44-
pipelines. However, this is not a guarantee, and we reserve the right to
45-
change this at any time. Explicitly, users should not rely on the produced
46-
bitcode or object code to mach their non-LTO counterparts precisely. They
47-
will exhibit similar performance characteristics, but may not be bit-for-bit
48-
the same.
39+
Previously, we conservatively ran independent pipelines on separate copies
40+
of the LLVM module to generate the bitcode section and the object code,
41+
which happen to be identical to those used outside of FatLTO. While that
42+
resulted in compiled artifacts that were identical to those produced by the
43+
default and (Thin)LTO pipelines, module cloning led to some cases of
44+
miscompilation, and we have moved away from trying to keep bitcode
45+
generation and optimization completely disjoint.
46+
47+
Bit-for-bit compatibility is not (and never was) a guarantee, and we reserve
48+
the right to change this at any time. Explicitly, users should not rely on
49+
the produced bitcode or object code to match their non-LTO counterparts
50+
precisely. They will exhibit similar performance characteristics, but may
51+
not be bit-for-bit the same.
4952
5053
Internally, the ``.llvm.lto`` section is created by running the
51-
``EmbedBitcodePass`` at the start of the ``PerModuleDefaultPipeline``. This
52-
pass is responsible for cloning and optimizing the module with the appropriate
53-
LTO pipeline and emitting the ``.llvm.lto`` section. Afterwards, the
54-
``PerModuleDefaultPipeline`` runs normally and the compiler can emit the fat
55-
object file.
54+
``EmbedBitcodePass`` after the ``ThinLTOPreLinkDefaultPipeline``. This pass is
55+
responsible for emitting the ``.llvm.lto`` section. Afterwards, the
56+
``ThinLTODefaultPipeline`` runs and the compiler can emit the fat object file.
5657

5758
Limitations
5859
===========

llvm/include/llvm/Passes/PassBuilder.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,7 @@ class PassBuilder {
246246
/// separately to avoid any inconsistencies with an ad-hoc pipeline that tries
247247
/// to approximate the PerModuleDefaultPipeline from the pre-link LTO
248248
/// pipelines.
249-
ModulePassManager buildFatLTODefaultPipeline(OptimizationLevel Level,
250-
bool ThinLTO, bool EmitSummary);
249+
ModulePassManager buildFatLTODefaultPipeline(OptimizationLevel Level);
251250

252251
/// Build a pre-link, ThinLTO-targeting default optimization pipeline to
253252
/// a pass manager.

llvm/include/llvm/Transforms/IPO/EmbedBitcodePass.h

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,13 @@ class Module;
2525
class ModulePass;
2626
class Pass;
2727

28-
struct EmbedBitcodeOptions {
29-
EmbedBitcodeOptions() : EmbedBitcodeOptions(false, false) {}
30-
EmbedBitcodeOptions(bool IsThinLTO, bool EmitLTOSummary)
31-
: IsThinLTO(IsThinLTO), EmitLTOSummary(EmitLTOSummary) {}
32-
bool IsThinLTO;
33-
bool EmitLTOSummary;
34-
};
35-
3628
/// Pass embeds a copy of the module optimized with the provided pass pipeline
3729
/// into a global variable.
3830
class EmbedBitcodePass : public PassInfoMixin<EmbedBitcodePass> {
39-
bool IsThinLTO;
40-
bool EmitLTOSummary;
4131
ModulePassManager MPM;
4232

4333
public:
44-
EmbedBitcodePass(EmbedBitcodeOptions Opts)
45-
: EmbedBitcodePass(Opts.IsThinLTO, Opts.EmitLTOSummary,
46-
ModulePassManager()) {}
47-
EmbedBitcodePass(bool IsThinLTO, bool EmitLTOSummary, ModulePassManager &&MPM)
48-
: IsThinLTO(IsThinLTO), EmitLTOSummary(EmitLTOSummary),
49-
MPM(std::move(MPM)) {}
34+
EmbedBitcodePass() {}
5035

5136
PreservedAnalyses run(Module &M, ModuleAnalysisManager &);
5237

llvm/lib/Passes/PassBuilder.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -759,26 +759,6 @@ Expected<HWAddressSanitizerOptions> parseHWASanPassOptions(StringRef Params) {
759759
return Result;
760760
}
761761

762-
Expected<EmbedBitcodeOptions> parseEmbedBitcodePassOptions(StringRef Params) {
763-
EmbedBitcodeOptions Result;
764-
while (!Params.empty()) {
765-
StringRef ParamName;
766-
std::tie(ParamName, Params) = Params.split(';');
767-
768-
if (ParamName == "thinlto") {
769-
Result.IsThinLTO = true;
770-
} else if (ParamName == "emit-summary") {
771-
Result.EmitLTOSummary = true;
772-
} else {
773-
return make_error<StringError>(
774-
formatv("invalid EmbedBitcode pass parameter '{0}' ", ParamName)
775-
.str(),
776-
inconvertibleErrorCode());
777-
}
778-
}
779-
return Result;
780-
}
781-
782762
Expected<MemorySanitizerOptions> parseMSanPassOptions(StringRef Params) {
783763
MemorySanitizerOptions Result;
784764
while (!Params.empty()) {

llvm/lib/Passes/PassBuilderPipelines.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,14 +1530,22 @@ PassBuilder::buildPerModuleDefaultPipeline(OptimizationLevel Level,
15301530
}
15311531

15321532
ModulePassManager
1533-
PassBuilder::buildFatLTODefaultPipeline(OptimizationLevel Level, bool ThinLTO,
1534-
bool EmitSummary) {
1533+
PassBuilder::buildFatLTODefaultPipeline(OptimizationLevel Level) {
15351534
ModulePassManager MPM;
1536-
MPM.addPass(EmbedBitcodePass(ThinLTO, EmitSummary,
1537-
ThinLTO
1538-
? buildThinLTOPreLinkDefaultPipeline(Level)
1539-
: buildLTOPreLinkDefaultPipeline(Level)));
1540-
MPM.addPass(buildPerModuleDefaultPipeline(Level));
1535+
// FatLTO always uses UnifiedLTO, so use the ThinLTOPreLink pipeline
1536+
MPM.addPass(buildThinLTOPreLinkDefaultPipeline(Level));
1537+
MPM.addPass(EmbedBitcodePass());
1538+
1539+
// Use the ThinLTO post-link pipeline with sample profiling, other
1540+
if (PGOOpt && PGOOpt->Action == PGOOptions::SampleUse)
1541+
MPM.addPass(buildThinLTODefaultPipeline(Level, /*ImportSummary=*/nullptr));
1542+
else {
1543+
// otherwise, just use module optimization
1544+
MPM.addPass(
1545+
buildModuleOptimizationPipeline(Level, ThinOrFullLTOPhase::None));
1546+
// Emit annotation remarks.
1547+
addAnnotationRemarksPass(MPM);
1548+
}
15411549
return MPM;
15421550
}
15431551

llvm/lib/Passes/PassRegistry.def

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ MODULE_PASS("dfsan", DataFlowSanitizerPass())
5858
MODULE_PASS("dot-callgraph", CallGraphDOTPrinterPass())
5959
MODULE_PASS("dxil-upgrade", DXILUpgradePass())
6060
MODULE_PASS("elim-avail-extern", EliminateAvailableExternallyPass())
61+
MODULE_PASS("embed-bitcode", EmbedBitcodePass())
6162
MODULE_PASS("extract-blocks", BlockExtractorPass({}, false))
6263
MODULE_PASS("forceattrs", ForceFunctionAttrsPass())
6364
MODULE_PASS("function-import", FunctionImportPass())
@@ -145,10 +146,6 @@ MODULE_PASS_WITH_PARAMS(
145146
"asan", "AddressSanitizerPass",
146147
[](AddressSanitizerOptions Opts) { return AddressSanitizerPass(Opts); },
147148
parseASanPassOptions, "kernel")
148-
MODULE_PASS_WITH_PARAMS(
149-
"embed-bitcode", "EmbedBitcodePass",
150-
[](EmbedBitcodeOptions Opts) { return EmbedBitcodePass(Opts); },
151-
parseEmbedBitcodePassOptions, "thinlto;emit-summary")
152149
MODULE_PASS_WITH_PARAMS(
153150
"globaldce", "GlobalDCEPass",
154151
[](bool InLTOPostLink) { return GlobalDCEPass(InLTOPostLink); },

llvm/lib/Transforms/IPO/EmbedBitcodePass.cpp

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,15 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "llvm/Transforms/IPO/EmbedBitcodePass.h"
10-
#include "llvm/Bitcode/BitcodeWriter.h"
11-
#include "llvm/Bitcode/BitcodeWriterPass.h"
1210
#include "llvm/IR/PassManager.h"
1311
#include "llvm/Pass.h"
1412
#include "llvm/Support/ErrorHandling.h"
1513
#include "llvm/Support/MemoryBufferRef.h"
1614
#include "llvm/Support/raw_ostream.h"
1715
#include "llvm/TargetParser/Triple.h"
1816
#include "llvm/Transforms/IPO/ThinLTOBitcodeWriter.h"
19-
#include "llvm/Transforms/Utils/Cloning.h"
2017
#include "llvm/Transforms/Utils/ModuleUtils.h"
2118

22-
#include <memory>
2319
#include <string>
2420

2521
using namespace llvm;
@@ -34,19 +30,9 @@ PreservedAnalyses EmbedBitcodePass::run(Module &M, ModuleAnalysisManager &AM) {
3430
report_fatal_error(
3531
"EmbedBitcode pass currently only supports ELF object format",
3632
/*gen_crash_diag=*/false);
37-
38-
std::unique_ptr<Module> NewModule = CloneModule(M);
39-
MPM.run(*NewModule, AM);
40-
4133
std::string Data;
4234
raw_string_ostream OS(Data);
43-
if (IsThinLTO)
44-
ThinLTOBitcodeWriterPass(OS, /*ThinLinkOS=*/nullptr).run(*NewModule, AM);
45-
else
46-
BitcodeWriterPass(OS, /*ShouldPreserveUseListOrder=*/false, EmitLTOSummary)
47-
.run(*NewModule, AM);
48-
35+
ThinLTOBitcodeWriterPass(OS, /*ThinLinkOS=*/nullptr).run(M, AM);
4936
embedBufferInModule(M, MemoryBufferRef(Data, "ModuleData"), ".llvm.lto");
50-
5137
return PreservedAnalyses::all();
5238
}

llvm/test/CodeGen/X86/fat-lto-section.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
;; Ensure that the .llvm.lto section has SHT_EXCLUDE set.
2-
; RUN: opt --mtriple x86_64-unknown-linux-gnu < %s -passes="embed-bitcode<thinlto;emit-summary>" -S \
2+
; RUN: opt --mtriple x86_64-unknown-linux-gnu < %s -passes="embed-bitcode" -S \
33
; RUN: | llc --mtriple x86_64-unknown-linux-gnu -filetype=obj \
44
; RUN: | llvm-readelf - --sections \
55
; RUN: | FileCheck %s --check-prefix=EXCLUDE

llvm/test/Transforms/EmbedBitcode/embed.ll

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
; RUN: opt --mtriple x86_64-unknown-linux-gnu < %s -passes="embed-bitcode" -S | FileCheck %s
2-
; RUN: opt --mtriple x86_64-unknown-linux-gnu < %s -passes="embed-bitcode<thinlto>" -S | FileCheck %s
3-
; RUN: opt --mtriple x86_64-unknown-linux-gnu < %s -passes="embed-bitcode<emit-summary>" -S | FileCheck %s
4-
; RUN: opt --mtriple x86_64-unknown-linux-gnu < %s -passes="embed-bitcode<thinlto;emit-summary>" -S | FileCheck %s
52

63
@a = global i32 1
74

0 commit comments

Comments
 (0)