Skip to content

Commit

Permalink
Couple of clif ir printing improvements around abi handling
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorn3 committed Oct 3, 2024
1 parent 0ba0845 commit 47b157d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
5 changes: 5 additions & 0 deletions src/abi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,11 @@ pub(crate) fn codegen_terminator_call<'tcx>(
adjust_call_for_c_variadic(fx, &fn_abi, source_info, func_ref, &mut call_args);
}

if fx.clif_comments.enabled() {
let nop_inst = fx.bcx.ins().nop();
fx.add_comment(nop_inst, format!("abi:{:?}", fn_abi));
}

match func_ref {
CallTarget::Direct(func_ref) => fx.bcx.ins().call(func_ref, &call_args),
CallTarget::Indirect(sig, func_ptr) => {
Expand Down
6 changes: 3 additions & 3 deletions src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@ pub(crate) fn codegen_fn<'tcx>(
let block_map: IndexVec<BasicBlock, Block> =
(0..mir.basic_blocks.len()).map(|_| bcx.create_block()).collect();

let fn_abi = RevealAllLayoutCx(tcx).fn_abi_of_instance(instance, ty::List::empty());

// Make FunctionCx
let target_config = module.target_config();
let pointer_type = target_config.pointer_type();
let clif_comments = crate::pretty_clif::CommentWriter::new(tcx, instance);

let fn_abi = RevealAllLayoutCx(tcx).fn_abi_of_instance(instance, ty::List::empty());
let clif_comments = crate::pretty_clif::CommentWriter::new(tcx, instance, fn_abi);

let func_debug_cx = if let Some(debug_context) = &mut cx.debug_context {
Some(debug_context.define_function(tcx, type_dbg, instance, fn_abi, &symbol_name, mir.span))
Expand Down
13 changes: 7 additions & 6 deletions src/pretty_clif.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ use cranelift_codegen::entity::SecondaryMap;
use cranelift_codegen::ir::Fact;
use cranelift_codegen::ir::entities::AnyEntity;
use cranelift_codegen::write::{FuncWriter, PlainWriter};
use rustc_middle::ty::layout::FnAbiOf;
use rustc_middle::ty::print::with_no_trimmed_paths;
use rustc_session::config::{OutputFilenames, OutputType};
use rustc_target::abi::call::FnAbi;

use crate::prelude::*;

Expand All @@ -76,17 +76,18 @@ pub(crate) struct CommentWriter {
}

impl CommentWriter {
pub(crate) fn new<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> Self {
pub(crate) fn new<'tcx>(
tcx: TyCtxt<'tcx>,
instance: Instance<'tcx>,
fn_abi: &'tcx FnAbi<'tcx, Ty<'tcx>>,
) -> Self {
let enabled = should_write_ir(tcx);
let global_comments = if enabled {
with_no_trimmed_paths!({
vec![
format!("symbol {}", tcx.symbol_name(instance).name),
format!("instance {:?}", instance),
format!(
"abi {:?}",
RevealAllLayoutCx(tcx).fn_abi_of_instance(instance, ty::List::empty())
),
format!("abi {:?}", fn_abi),
String::new(),
]
})
Expand Down

0 comments on commit 47b157d

Please sign in to comment.