Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions compiler/rustc_codegen_gcc/src/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ struct LtoData {
}

fn prepare_lto(
cgcx: &CodegenContext<GccCodegenBackend>,
cgcx: &CodegenContext,
each_linked_rlib_for_lto: &[PathBuf],
dcx: DiagCtxtHandle<'_>,
) -> LtoData {
Expand Down Expand Up @@ -111,7 +111,7 @@ fn save_as_file(obj: &[u8], path: &Path) -> Result<(), LtoBitcodeFromRlib> {
/// Performs fat LTO by merging all modules into a single one and returning it
/// for further optimization.
pub(crate) fn run_fat(
cgcx: &CodegenContext<GccCodegenBackend>,
cgcx: &CodegenContext,
shared_emitter: &SharedEmitter,
each_linked_rlib_for_lto: &[PathBuf],
modules: Vec<FatLtoInput<GccCodegenBackend>>,
Expand All @@ -132,7 +132,7 @@ pub(crate) fn run_fat(
}

fn fat_lto(
cgcx: &CodegenContext<GccCodegenBackend>,
cgcx: &CodegenContext,
_dcx: DiagCtxtHandle<'_>,
modules: Vec<FatLtoInput<GccCodegenBackend>>,
mut serialized_modules: Vec<(SerializedModule<ModuleBuffer>, CString)>,
Expand Down Expand Up @@ -283,7 +283,7 @@ impl ModuleBufferMethods for ModuleBuffer {
/// lists, one of the modules that need optimization and another for modules that
/// can simply be copied over from the incr. comp. cache.
pub(crate) fn run_thin(
cgcx: &CodegenContext<GccCodegenBackend>,
cgcx: &CodegenContext,
dcx: DiagCtxtHandle<'_>,
each_linked_rlib_for_lto: &[PathBuf],
modules: Vec<(String, ThinBuffer)>,
Expand Down Expand Up @@ -345,7 +345,7 @@ pub(crate) fn prepare_thin(module: ModuleCodegen<GccContext>) -> (String, ThinBu
/// all of the `LtoModuleCodegen` units returned below and destroyed once
/// they all go out of scope.
fn thin_lto(
cgcx: &CodegenContext<GccCodegenBackend>,
cgcx: &CodegenContext,
_dcx: DiagCtxtHandle<'_>,
modules: Vec<(String, ThinBuffer)>,
serialized_modules: Vec<(SerializedModule<ModuleBuffer>, CString)>,
Expand Down Expand Up @@ -520,11 +520,9 @@ fn thin_lto(

pub fn optimize_thin_module(
thin_module: ThinModule<GccCodegenBackend>,
_cgcx: &CodegenContext<GccCodegenBackend>,
_cgcx: &CodegenContext,
) -> ModuleCodegen<GccContext> {
//let module_name = &thin_module.shared.module_names[thin_module.idx];
/*let tm_factory_config = TargetMachineFactoryConfig::new(cgcx, module_name.to_str().unwrap());
let tm = (cgcx.tm_factory)(tm_factory_config).map_err(|e| write::llvm_err(&dcx, e))?;*/

// Right now the implementation we've got only works over serialized
// modules, so we create a fresh new LLVM context and parse the module
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_gcc/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ use rustc_target::spec::SplitDebuginfo;

use crate::base::add_pic_option;
use crate::errors::CopyBitcode;
use crate::{GccCodegenBackend, GccContext, LtoMode};
use crate::{GccContext, LtoMode};

pub(crate) fn codegen(
cgcx: &CodegenContext<GccCodegenBackend>,
cgcx: &CodegenContext,
shared_emitter: &SharedEmitter,
module: ModuleCodegen<GccContext>,
config: &ModuleConfig,
Expand Down Expand Up @@ -227,7 +227,7 @@ pub(crate) fn codegen(
}

pub(crate) fn save_temp_bitcode(
cgcx: &CodegenContext<GccCodegenBackend>,
cgcx: &CodegenContext,
_module: &ModuleCodegen<GccContext>,
_name: &str,
) {
Expand Down
15 changes: 8 additions & 7 deletions compiler/rustc_codegen_gcc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ impl ExtraBackendMethods for GccCodegenBackend {
_features: &[String],
) -> TargetMachineFactoryFn<Self> {
// TODO(antoyo): set opt level.
Arc::new(|_| Ok(()))
Arc::new(|_, _| ())
}
}

Expand Down Expand Up @@ -421,14 +421,14 @@ unsafe impl Sync for SyncContext {}
impl WriteBackendMethods for GccCodegenBackend {
type Module = GccContext;
type TargetMachine = ();
type TargetMachineError = ();
type ModuleBuffer = ModuleBuffer;
type ThinData = ThinData;
type ThinBuffer = ThinBuffer;

fn run_and_optimize_fat_lto(
cgcx: &CodegenContext<Self>,
cgcx: &CodegenContext,
shared_emitter: &SharedEmitter,
_tm_factory: TargetMachineFactoryFn<Self>,
// FIXME(bjorn3): Limit LTO exports to these symbols
_exported_symbols_for_lto: &[String],
each_linked_rlib_for_lto: &[PathBuf],
Expand All @@ -438,7 +438,7 @@ impl WriteBackendMethods for GccCodegenBackend {
}

fn run_thin_lto(
cgcx: &CodegenContext<Self>,
cgcx: &CodegenContext,
dcx: DiagCtxtHandle<'_>,
// FIXME(bjorn3): Limit LTO exports to these symbols
_exported_symbols_for_lto: &[String],
Expand All @@ -458,7 +458,7 @@ impl WriteBackendMethods for GccCodegenBackend {
}

fn optimize(
_cgcx: &CodegenContext<Self>,
_cgcx: &CodegenContext,
_shared_emitter: &SharedEmitter,
module: &mut ModuleCodegen<Self::Module>,
config: &ModuleConfig,
Expand All @@ -467,15 +467,16 @@ impl WriteBackendMethods for GccCodegenBackend {
}

fn optimize_thin(
cgcx: &CodegenContext<Self>,
cgcx: &CodegenContext,
_shared_emitter: &SharedEmitter,
_tm_factory: TargetMachineFactoryFn<Self>,
thin: ThinModule<Self>,
) -> ModuleCodegen<Self::Module> {
back::lto::optimize_thin_module(thin, cgcx)
}

fn codegen(
cgcx: &CodegenContext<Self>,
cgcx: &CodegenContext,
shared_emitter: &SharedEmitter,
module: ModuleCodegen<Self::Module>,
config: &ModuleConfig,
Expand Down
37 changes: 25 additions & 12 deletions compiler/rustc_codegen_llvm/src/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ use std::{io, iter, slice};
use object::read::archive::ArchiveFile;
use object::{Object, ObjectSection};
use rustc_codegen_ssa::back::lto::{SerializedModule, ThinModule, ThinShared};
use rustc_codegen_ssa::back::write::{CodegenContext, FatLtoInput, SharedEmitter};
use rustc_codegen_ssa::back::write::{
CodegenContext, FatLtoInput, SharedEmitter, TargetMachineFactoryFn,
};
use rustc_codegen_ssa::traits::*;
use rustc_codegen_ssa::{ModuleCodegen, ModuleKind, looks_like_rust_object_file};
use rustc_data_structures::fx::FxHashMap;
Expand All @@ -33,7 +35,7 @@ use crate::{LlvmCodegenBackend, ModuleLlvm};
const THIN_LTO_KEYS_INCR_COMP_FILE_NAME: &str = "thin-lto-past-keys.bin";

fn prepare_lto(
cgcx: &CodegenContext<LlvmCodegenBackend>,
cgcx: &CodegenContext,
exported_symbols_for_lto: &[String],
each_linked_rlib_for_lto: &[PathBuf],
dcx: DiagCtxtHandle<'_>,
Expand Down Expand Up @@ -123,7 +125,7 @@ fn prepare_lto(

fn get_bitcode_slice_from_object_data<'a>(
obj: &'a [u8],
cgcx: &CodegenContext<LlvmCodegenBackend>,
cgcx: &CodegenContext,
) -> Result<&'a [u8], LtoBitcodeFromRlib> {
// We're about to assume the data here is an object file with sections, but if it's raw LLVM IR
// that won't work. Fortunately, if that's what we have we can just return the object directly,
Expand All @@ -149,8 +151,9 @@ fn get_bitcode_slice_from_object_data<'a>(
/// Performs fat LTO by merging all modules into a single one and returning it
/// for further optimization.
pub(crate) fn run_fat(
cgcx: &CodegenContext<LlvmCodegenBackend>,
cgcx: &CodegenContext,
shared_emitter: &SharedEmitter,
tm_factory: TargetMachineFactoryFn<LlvmCodegenBackend>,
exported_symbols_for_lto: &[String],
each_linked_rlib_for_lto: &[PathBuf],
modules: Vec<FatLtoInput<LlvmCodegenBackend>>,
Expand All @@ -161,14 +164,22 @@ pub(crate) fn run_fat(
prepare_lto(cgcx, exported_symbols_for_lto, each_linked_rlib_for_lto, dcx);
let symbols_below_threshold =
symbols_below_threshold.iter().map(|c| c.as_ptr()).collect::<Vec<_>>();
fat_lto(cgcx, dcx, shared_emitter, modules, upstream_modules, &symbols_below_threshold)
fat_lto(
cgcx,
dcx,
shared_emitter,
tm_factory,
modules,
upstream_modules,
&symbols_below_threshold,
)
}

/// Performs thin LTO by performing necessary global analysis and returning two
/// lists, one of the modules that need optimization and another for modules that
/// can simply be copied over from the incr. comp. cache.
pub(crate) fn run_thin(
cgcx: &CodegenContext<LlvmCodegenBackend>,
cgcx: &CodegenContext,
dcx: DiagCtxtHandle<'_>,
exported_symbols_for_lto: &[String],
each_linked_rlib_for_lto: &[PathBuf],
Expand All @@ -195,9 +206,10 @@ pub(crate) fn prepare_thin(module: ModuleCodegen<ModuleLlvm>) -> (String, ThinBu
}

fn fat_lto(
cgcx: &CodegenContext<LlvmCodegenBackend>,
cgcx: &CodegenContext,
dcx: DiagCtxtHandle<'_>,
shared_emitter: &SharedEmitter,
tm_factory: TargetMachineFactoryFn<LlvmCodegenBackend>,
modules: Vec<FatLtoInput<LlvmCodegenBackend>>,
mut serialized_modules: Vec<(SerializedModule<ModuleBuffer>, CString)>,
symbols_below_threshold: &[*const libc::c_char],
Expand Down Expand Up @@ -252,7 +264,7 @@ fn fat_lto(
assert!(!serialized_modules.is_empty(), "must have at least one serialized module");
let (buffer, name) = serialized_modules.remove(0);
info!("no in-memory regular modules to choose from, parsing {:?}", name);
let llvm_module = ModuleLlvm::parse(cgcx, &name, buffer.data(), dcx);
let llvm_module = ModuleLlvm::parse(cgcx, tm_factory, &name, buffer.data(), dcx);
ModuleCodegen::new_regular(name.into_string().unwrap(), llvm_module)
}
};
Expand Down Expand Up @@ -381,7 +393,7 @@ impl Drop for Linker<'_> {
/// all of the `LtoModuleCodegen` units returned below and destroyed once
/// they all go out of scope.
fn thin_lto(
cgcx: &CodegenContext<LlvmCodegenBackend>,
cgcx: &CodegenContext,
dcx: DiagCtxtHandle<'_>,
modules: Vec<(String, ThinBuffer)>,
serialized_modules: Vec<(SerializedModule<ModuleBuffer>, CString)>,
Expand Down Expand Up @@ -585,7 +597,7 @@ pub(crate) fn enable_autodiff_settings(ad: &[config::AutoDiff]) {
}

pub(crate) fn run_pass_manager(
cgcx: &CodegenContext<LlvmCodegenBackend>,
cgcx: &CodegenContext,
dcx: DiagCtxtHandle<'_>,
module: &mut ModuleCodegen<ModuleLlvm>,
thin: bool,
Expand Down Expand Up @@ -726,8 +738,9 @@ impl Drop for ThinBuffer {
}

pub(crate) fn optimize_thin_module(
cgcx: &CodegenContext<LlvmCodegenBackend>,
cgcx: &CodegenContext,
shared_emitter: &SharedEmitter,
tm_factory: TargetMachineFactoryFn<LlvmCodegenBackend>,
thin_module: ThinModule<LlvmCodegenBackend>,
) -> ModuleCodegen<ModuleLlvm> {
let dcx = DiagCtxt::new(Box::new(shared_emitter.clone()));
Expand All @@ -740,7 +753,7 @@ pub(crate) fn optimize_thin_module(
// into that context. One day, however, we may do this for upstream
// crates but for locally codegened modules we may be able to reuse
// that LLVM Context and Module.
let module_llvm = ModuleLlvm::parse(cgcx, module_name, thin_module.data(), dcx);
let module_llvm = ModuleLlvm::parse(cgcx, tm_factory, module_name, thin_module.data(), dcx);
let mut module = ModuleCodegen::new_regular(thin_module.name(), module_llvm);
// Given that the newly created module lacks a thinlto buffer for embedding, we need to re-add it here.
if cgcx.module_config.embed_bitcode() {
Expand Down
Loading
Loading