Also emit vcode when emitting clif ir while using new style backends
This commit is contained in:
parent
cd21269ae0
commit
44b331047d
10
src/base.rs
10
src/base.rs
@ -118,6 +118,8 @@ pub(crate) fn codegen_fn<'tcx>(
|
|||||||
context.eliminate_unreachable_code(cx.module.isa()).unwrap();
|
context.eliminate_unreachable_code(cx.module.isa()).unwrap();
|
||||||
context.dce(cx.module.isa()).unwrap();
|
context.dce(cx.module.isa()).unwrap();
|
||||||
|
|
||||||
|
context.want_disasm = crate::pretty_clif::should_write_ir(tcx);
|
||||||
|
|
||||||
// Define function
|
// Define function
|
||||||
let module = &mut cx.module;
|
let module = &mut cx.module;
|
||||||
tcx.sess.time("define function", || {
|
tcx.sess.time("define function", || {
|
||||||
@ -140,6 +142,14 @@ pub(crate) fn codegen_fn<'tcx>(
|
|||||||
&clif_comments,
|
&clif_comments,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if let Some(mach_compile_result) = &context.mach_compile_result {
|
||||||
|
if let Some(disasm) = &mach_compile_result.disasm {
|
||||||
|
crate::pretty_clif::write_ir_file(tcx, &format!("{}.vcode", tcx.symbol_name(instance).name), |file| {
|
||||||
|
file.write_all(disasm.as_bytes())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Define debuginfo for function
|
// Define debuginfo for function
|
||||||
let isa = cx.module.isa();
|
let isa = cx.module.isa();
|
||||||
let debug_context = &mut cx.debug_context;
|
let debug_context = &mut cx.debug_context;
|
||||||
|
@ -53,6 +53,7 @@
|
|||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
use std::io::Write;
|
||||||
|
|
||||||
use cranelift_codegen::{
|
use cranelift_codegen::{
|
||||||
entity::SecondaryMap,
|
entity::SecondaryMap,
|
||||||
@ -200,31 +201,23 @@ impl<M: Module> FunctionCx<'_, '_, M> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn write_clif_file<'tcx>(
|
pub(crate) fn should_write_ir(tcx: TyCtxt<'_>) -> bool {
|
||||||
tcx: TyCtxt<'tcx>,
|
cfg!(debug_assertions)
|
||||||
postfix: &str,
|
|| tcx
|
||||||
isa: Option<&dyn cranelift_codegen::isa::TargetIsa>,
|
|
||||||
instance: Instance<'tcx>,
|
|
||||||
context: &cranelift_codegen::Context,
|
|
||||||
mut clif_comments: &CommentWriter,
|
|
||||||
) {
|
|
||||||
use std::io::Write;
|
|
||||||
|
|
||||||
if !cfg!(debug_assertions)
|
|
||||||
&& !tcx
|
|
||||||
.sess
|
.sess
|
||||||
.opts
|
.opts
|
||||||
.output_types
|
.output_types
|
||||||
.contains_key(&OutputType::LlvmAssembly)
|
.contains_key(&OutputType::LlvmAssembly)
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let value_ranges = isa.map(|isa| {
|
pub(crate) fn write_ir_file<'tcx>(
|
||||||
context
|
tcx: TyCtxt<'tcx>,
|
||||||
.build_value_labels_ranges(isa)
|
name: &str,
|
||||||
.expect("value location ranges")
|
write: impl FnOnce(&mut dyn Write) -> std::io::Result<()>,
|
||||||
});
|
) {
|
||||||
|
if !should_write_ir(tcx) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let clif_output_dir = tcx.output_filenames(LOCAL_CRATE).with_extension("clif");
|
let clif_output_dir = tcx.output_filenames(LOCAL_CRATE).with_extension("clif");
|
||||||
|
|
||||||
@ -234,11 +227,35 @@ pub(crate) fn write_clif_file<'tcx>(
|
|||||||
res @ Err(_) => res.unwrap(),
|
res @ Err(_) => res.unwrap(),
|
||||||
}
|
}
|
||||||
|
|
||||||
let clif_file_name = clif_output_dir.join(format!(
|
let clif_file_name = clif_output_dir.join(name);
|
||||||
|
|
||||||
|
let res: std::io::Result<()> = try {
|
||||||
|
let mut file = std::fs::File::create(clif_file_name)?;
|
||||||
|
write(&mut file)?;
|
||||||
|
};
|
||||||
|
if let Err(err) = res {
|
||||||
|
tcx.sess.warn(&format!("error writing ir file: {}", err));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn write_clif_file<'tcx>(
|
||||||
|
tcx: TyCtxt<'tcx>,
|
||||||
|
postfix: &str,
|
||||||
|
isa: Option<&dyn cranelift_codegen::isa::TargetIsa>,
|
||||||
|
instance: Instance<'tcx>,
|
||||||
|
context: &cranelift_codegen::Context,
|
||||||
|
mut clif_comments: &CommentWriter,
|
||||||
|
) {
|
||||||
|
write_ir_file(tcx, &format!(
|
||||||
"{}.{}.clif",
|
"{}.{}.clif",
|
||||||
tcx.symbol_name(instance).name,
|
tcx.symbol_name(instance).name,
|
||||||
postfix
|
postfix
|
||||||
));
|
), |file| {
|
||||||
|
let value_ranges = isa.map(|isa| {
|
||||||
|
context
|
||||||
|
.build_value_labels_ranges(isa)
|
||||||
|
.expect("value location ranges")
|
||||||
|
});
|
||||||
|
|
||||||
let mut clif = String::new();
|
let mut clif = String::new();
|
||||||
cranelift_codegen::write::decorate_function(
|
cranelift_codegen::write::decorate_function(
|
||||||
@ -254,19 +271,14 @@ pub(crate) fn write_clif_file<'tcx>(
|
|||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let res: std::io::Result<()> = try {
|
|
||||||
let mut file = std::fs::File::create(clif_file_name)?;
|
|
||||||
let target_triple = crate::target_triple(tcx.sess);
|
|
||||||
writeln!(file, "test compile")?;
|
writeln!(file, "test compile")?;
|
||||||
writeln!(file, "set is_pic")?;
|
writeln!(file, "set is_pic")?;
|
||||||
writeln!(file, "set enable_simd")?;
|
writeln!(file, "set enable_simd")?;
|
||||||
writeln!(file, "target {} haswell", target_triple)?;
|
writeln!(file, "target {} haswell", crate::target_triple(tcx.sess))?;
|
||||||
writeln!(file)?;
|
writeln!(file)?;
|
||||||
file.write_all(clif.as_bytes())?;
|
file.write_all(clif.as_bytes())?;
|
||||||
};
|
Ok(())
|
||||||
if let Err(err) = res {
|
});
|
||||||
tcx.sess.warn(&format!("err writing clif file: {}", err));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<M: Module> fmt::Debug for FunctionCx<'_, '_, M> {
|
impl<M: Module> fmt::Debug for FunctionCx<'_, '_, M> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user