1
Fork 0

Merge commit '35d9c6bf25' into sync_cg_clif-2022-02-23

This commit is contained in:
bjorn3 2022-02-23 11:49:34 +01:00
commit f596dce542
24 changed files with 843 additions and 809 deletions

View file

@ -1,13 +1,15 @@
//! Codegen of a single function
use cranelift_codegen::binemit::{NullStackMapSink, NullTrapSink};
use rustc_ast::InlineAsmOptions;
use rustc_index::vec::IndexVec;
use rustc_middle::ty::adjustment::PointerCast;
use rustc_middle::ty::layout::FnAbiOf;
use indexmap::IndexSet;
use crate::constant::ConstantCx;
use crate::prelude::*;
use crate::pretty_clif::CommentWriter;
pub(crate) fn codegen_fn<'tcx>(
cx: &mut crate::CodegenCx<'tcx>,
@ -99,27 +101,54 @@ pub(crate) fn codegen_fn<'tcx>(
// Recover all necessary data from fx, before accessing func will prevent future access to it.
let instance = fx.instance;
let mut clif_comments = fx.clif_comments;
let clif_comments = fx.clif_comments;
let source_info_set = fx.source_info_set;
let local_map = fx.local_map;
fx.constants_cx.finalize(fx.tcx, &mut *fx.module);
// Store function in context
let context = &mut cx.cached_context;
context.func = func;
crate::pretty_clif::write_clif_file(
tcx,
"unopt",
module.isa(),
instance,
&context,
&func,
&clif_comments,
);
// Verify function
verify_func(tcx, &clif_comments, &context.func);
verify_func(tcx, &clif_comments, &func);
compile_fn(
cx,
module,
instance,
symbol_name.name,
func_id,
func,
clif_comments,
source_info_set,
local_map,
);
}
fn compile_fn<'tcx>(
cx: &mut crate::CodegenCx<'tcx>,
module: &mut dyn Module,
instance: Instance<'tcx>,
symbol_name: &str,
func_id: FuncId,
func: Function,
mut clif_comments: CommentWriter,
source_info_set: IndexSet<SourceInfo>,
local_map: IndexVec<mir::Local, CPlace<'tcx>>,
) {
let tcx = cx.tcx;
// Store function in context
let context = &mut cx.cached_context;
context.clear();
context.func = func;
// If the return block is not reachable, then the SSA builder may have inserted an `iconst.i128`
// instruction, which doesn't have an encoding.
@ -145,9 +174,7 @@ pub(crate) fn codegen_fn<'tcx>(
// Define function
tcx.sess.time("define function", || {
context.want_disasm = crate::pretty_clif::should_write_ir(tcx);
module
.define_function(func_id, context, &mut NullTrapSink {}, &mut NullStackMapSink {})
.unwrap()
module.define_function(func_id, context).unwrap()
});
// Write optimized function to file for debugging
@ -156,7 +183,7 @@ pub(crate) fn codegen_fn<'tcx>(
"opt",
module.isa(),
instance,
&context,
&context.func,
&clif_comments,
);
@ -177,7 +204,7 @@ pub(crate) fn codegen_fn<'tcx>(
debug_context.define_function(
instance,
func_id,
symbol_name.name,
symbol_name,
isa,
context,
&source_info_set,
@ -186,9 +213,6 @@ pub(crate) fn codegen_fn<'tcx>(
}
unwind_context.add_function(func_id, &context, isa);
});
// Clear context to make it usable for the next function
context.clear();
}
pub(crate) fn verify_func(