Skip to content

Commit 24b202f

Browse files
committed
Auto merge of rust-lang#133250 - DianQK:embed-bitcode-pgo, r=nikic
The embedded bitcode should always be prepared for LTO/ThinLTO Fixes rust-lang#115344. Fixes rust-lang#117220. There are currently two methods for generating bitcode that used for LTO. One method involves using `-C linker-plugin-lto` to emit object files as bitcode, which is the typical setting used by cargo. The other method is through `-C embed-bitcode=yes`. When using with `-C embed-bitcode=yes -C lto=no`, we run a complete non-LTO LLVM pipeline to obtain bitcode, then the bitcode is used for LTO. We run the Call Graph Profile Pass twice on the same module. This PR is doing something similar to LLVM's `buildFatLTODefaultPipeline`, obtaining the bitcode for embedding after running `buildThinLTOPreLinkDefaultPipeline`. r? nikic
2 parents b627900 + 9b8701d commit 24b202f

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

src/back/lto.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -632,17 +632,16 @@ pub unsafe fn optimize_thin_module(
632632
Arc::new(SyncContext::new(context))
633633
}
634634
};
635-
let module = ModuleCodegen {
636-
module_llvm: GccContext {
635+
let module = ModuleCodegen::new_regular(
636+
thin_module.name().to_string(),
637+
GccContext {
637638
context,
638639
should_combine_object_files,
639640
// TODO(antoyo): use the correct relocation model here.
640641
relocation_model: RelocModel::Pic,
641642
temp_dir: None,
642643
},
643-
name: thin_module.name().to_string(),
644-
kind: ModuleKind::Regular,
645-
};
644+
);
646645
/*{
647646
let target = &*module.module_llvm.tm;
648647
let llmod = module.module_llvm.llmod();

src/base.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ use std::sync::Arc;
44
use std::time::Instant;
55

66
use gccjit::{CType, Context, FunctionType, GlobalKind};
7+
use rustc_codegen_ssa::ModuleCodegen;
78
use rustc_codegen_ssa::base::maybe_create_entry_wrapper;
89
use rustc_codegen_ssa::mono_item::MonoItemExt;
910
use rustc_codegen_ssa::traits::DebugInfoCodegenMethods;
10-
use rustc_codegen_ssa::{ModuleCodegen, ModuleKind};
1111
use rustc_middle::dep_graph;
1212
use rustc_middle::mir::mono::Linkage;
1313
#[cfg(feature = "master")]
@@ -237,16 +237,15 @@ pub fn compile_codegen_unit(
237237
}
238238
}
239239

240-
ModuleCodegen {
241-
name: cgu_name.to_string(),
242-
module_llvm: GccContext {
240+
ModuleCodegen::new_regular(
241+
cgu_name.to_string(),
242+
GccContext {
243243
context: Arc::new(SyncContext::new(context)),
244244
relocation_model: tcx.sess.relocation_model(),
245245
should_combine_object_files: false,
246246
temp_dir: None,
247247
},
248-
kind: ModuleKind::Regular,
249-
}
248+
)
250249
}
251250

252251
(module, cost)

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ impl WriteBackendMethods for GccCodegenBackend {
393393
unsafe fn optimize(
394394
_cgcx: &CodegenContext<Self>,
395395
_dcx: DiagCtxtHandle<'_>,
396-
module: &ModuleCodegen<Self::Module>,
396+
module: &mut ModuleCodegen<Self::Module>,
397397
config: &ModuleConfig,
398398
) -> Result<(), FatalError> {
399399
module.module_llvm.context.set_optimization_level(to_gcc_opt_level(config.opt_level));

0 commit comments

Comments
 (0)