Misc target related improvements

This commit is contained in:
bjorn3 2021-07-03 14:28:53 +02:00
parent 55e0779708
commit 6a31385363
5 changed files with 27 additions and 12 deletions

View File

@ -109,7 +109,14 @@ pub(crate) fn codegen_fn<'tcx>(
let context = &mut cx.cached_context;
context.func = func;
crate::pretty_clif::write_clif_file(tcx, "unopt", None, instance, &context, &clif_comments);
crate::pretty_clif::write_clif_file(
tcx,
"unopt",
module.isa(),
instance,
&context,
&clif_comments,
);
// Verify function
verify_func(tcx, &clif_comments, &context.func);
@ -126,7 +133,13 @@ pub(crate) fn codegen_fn<'tcx>(
// Perform rust specific optimizations
tcx.sess.time("optimize clif ir", || {
crate::optimize::optimize_function(tcx, instance, context, &mut clif_comments);
crate::optimize::optimize_function(
tcx,
module.isa(),
instance,
context,
&mut clif_comments,
);
});
// Define function
@ -141,7 +154,7 @@ pub(crate) fn codegen_fn<'tcx>(
crate::pretty_clif::write_clif_file(
tcx,
"opt",
Some(module.isa()),
module.isa(),
instance,
&context,
&clif_comments,

View File

@ -290,13 +290,15 @@ pub(crate) fn run_aot(
None
};
// FIXME handle `-Ctarget-cpu=native`
let target_cpu = tcx.sess.opts.cg.target_cpu.as_ref().unwrap_or(&tcx.sess.target.cpu).to_owned();
Box::new((
CodegenResults {
modules,
allocator_module,
metadata_module,
metadata,
linker_info: LinkerInfo::new(tcx, crate::target_triple(tcx.sess).to_string()),
linker_info: LinkerInfo::new(tcx, target_cpu),
crate_info: CrateInfo::new(tcx),
},
work_products,

View File

@ -159,7 +159,7 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! {
AbiParam::new(jit_module.target_config().pointer_type()),
],
returns: vec![AbiParam::new(jit_module.target_config().pointer_type() /*isize*/)],
call_conv: CallConv::triple_default(&crate::target_triple(tcx.sess)),
call_conv: jit_module.target_config().default_call_conv,
};
let start_func_id = jit_module.declare_function("main", Linkage::Import, &start_sig).unwrap();
let finalized_start: *const u8 = jit_module.get_finalized_function(start_func_id);

View File

@ -1,17 +1,20 @@
//! Various optimizations specific to cg_clif
use cranelift_codegen::isa::TargetIsa;
use crate::prelude::*;
pub(crate) mod peephole;
pub(crate) fn optimize_function<'tcx>(
tcx: TyCtxt<'tcx>,
isa: &dyn TargetIsa,
instance: Instance<'tcx>,
ctx: &mut Context,
clif_comments: &mut crate::pretty_clif::CommentWriter,
) {
// FIXME classify optimizations over opt levels once we have more
crate::pretty_clif::write_clif_file(tcx, "preopt", None, instance, &ctx, &*clif_comments);
crate::pretty_clif::write_clif_file(tcx, "preopt", isa, instance, &ctx, &*clif_comments);
crate::base::verify_func(tcx, &*clif_comments, &ctx.func);
}

View File

@ -233,7 +233,7 @@ pub(crate) fn write_ir_file(
pub(crate) fn write_clif_file<'tcx>(
tcx: TyCtxt<'tcx>,
postfix: &str,
isa: Option<&dyn cranelift_codegen::isa::TargetIsa>,
isa: &dyn cranelift_codegen::isa::TargetIsa,
instance: Instance<'tcx>,
context: &cranelift_codegen::Context,
mut clif_comments: &CommentWriter,
@ -242,22 +242,19 @@ pub(crate) fn write_clif_file<'tcx>(
tcx,
|| format!("{}.{}.clif", tcx.symbol_name(instance).name, postfix),
|file| {
let value_ranges = isa
.map(|isa| context.build_value_labels_ranges(isa).expect("value location ranges"));
let mut clif = String::new();
cranelift_codegen::write::decorate_function(
&mut clif_comments,
&mut clif,
&context.func,
&DisplayFunctionAnnotations { isa, value_ranges: value_ranges.as_ref() },
&DisplayFunctionAnnotations { isa: Some(isa), value_ranges: None },
)
.unwrap();
writeln!(file, "test compile")?;
writeln!(file, "set is_pic")?;
writeln!(file, "set enable_simd")?;
writeln!(file, "target {} haswell", crate::target_triple(tcx.sess))?;
writeln!(file, "target {} nehalem", crate::target_triple(tcx.sess))?;
writeln!(file)?;
file.write_all(clif.as_bytes())?;
Ok(())