FunctionCx: Rename codegen_cx -> cx
This commit is contained in:
parent
4cb2a2b793
commit
7b534d653d
20 changed files with 255 additions and 255 deletions
|
@ -226,9 +226,9 @@ pub(crate) fn import_function<'tcx>(
|
||||||
impl<'tcx, B: Backend + 'static> FunctionCx<'_, 'tcx, B> {
|
impl<'tcx, B: Backend + 'static> FunctionCx<'_, 'tcx, B> {
|
||||||
/// Instance must be monomorphized
|
/// Instance must be monomorphized
|
||||||
pub(crate) fn get_function_ref(&mut self, inst: Instance<'tcx>) -> FuncRef {
|
pub(crate) fn get_function_ref(&mut self, inst: Instance<'tcx>) -> FuncRef {
|
||||||
let func_id = import_function(self.codegen_cx.tcx, &mut self.codegen_cx.module, inst);
|
let func_id = import_function(self.cx.tcx, &mut self.cx.module, inst);
|
||||||
let func_ref = self
|
let func_ref = self
|
||||||
.codegen_cx.module
|
.cx.module
|
||||||
.declare_func_in_func(func_id, &mut self.bcx.func);
|
.declare_func_in_func(func_id, &mut self.bcx.func);
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
|
@ -250,11 +250,11 @@ impl<'tcx, B: Backend + 'static> FunctionCx<'_, 'tcx, B> {
|
||||||
call_conv: CallConv::triple_default(self.triple()),
|
call_conv: CallConv::triple_default(self.triple()),
|
||||||
};
|
};
|
||||||
let func_id = self
|
let func_id = self
|
||||||
.codegen_cx.module
|
.cx.module
|
||||||
.declare_function(&name, Linkage::Import, &sig)
|
.declare_function(&name, Linkage::Import, &sig)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let func_ref = self
|
let func_ref = self
|
||||||
.codegen_cx.module
|
.cx.module
|
||||||
.declare_func_in_func(func_id, &mut self.bcx.func);
|
.declare_func_in_func(func_id, &mut self.bcx.func);
|
||||||
let call_inst = self.bcx.ins().call(func_ref, args);
|
let call_inst = self.bcx.ins().call(func_ref, args);
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
|
@ -374,9 +374,9 @@ pub(crate) fn codegen_fn_prelude<'tcx>(
|
||||||
.collect::<Vec<(Local, ArgKind<'tcx>, Ty<'tcx>)>>();
|
.collect::<Vec<(Local, ArgKind<'tcx>, Ty<'tcx>)>>();
|
||||||
|
|
||||||
assert!(fx.caller_location.is_none());
|
assert!(fx.caller_location.is_none());
|
||||||
if fx.instance.def.requires_caller_location(fx.codegen_cx.tcx) {
|
if fx.instance.def.requires_caller_location(fx.cx.tcx) {
|
||||||
// Store caller location for `#[track_caller]`.
|
// Store caller location for `#[track_caller]`.
|
||||||
fx.caller_location = Some(cvalue_for_param(fx, start_block, None, None, fx.codegen_cx.tcx.caller_location_ty()).unwrap());
|
fx.caller_location = Some(cvalue_for_param(fx, start_block, None, None, fx.cx.tcx.caller_location_ty()).unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
fx.bcx.switch_to_block(start_block);
|
fx.bcx.switch_to_block(start_block);
|
||||||
|
@ -398,7 +398,7 @@ pub(crate) fn codegen_fn_prelude<'tcx>(
|
||||||
let local_decl = &fx.mir.local_decls[local];
|
let local_decl = &fx.mir.local_decls[local];
|
||||||
// v this ! is important
|
// v this ! is important
|
||||||
let internally_mutable = !val.layout().ty.is_freeze(
|
let internally_mutable = !val.layout().ty.is_freeze(
|
||||||
fx.codegen_cx.tcx.at(local_decl.source_info.span),
|
fx.cx.tcx.at(local_decl.source_info.span),
|
||||||
ParamEnv::reveal_all(),
|
ParamEnv::reveal_all(),
|
||||||
);
|
);
|
||||||
if local_decl.mutability == mir::Mutability::Not && !internally_mutable {
|
if local_decl.mutability == mir::Mutability::Not && !internally_mutable {
|
||||||
|
@ -465,24 +465,24 @@ pub(crate) fn codegen_terminator_call<'tcx>(
|
||||||
args: &[Operand<'tcx>],
|
args: &[Operand<'tcx>],
|
||||||
destination: Option<(Place<'tcx>, BasicBlock)>,
|
destination: Option<(Place<'tcx>, BasicBlock)>,
|
||||||
) {
|
) {
|
||||||
let fn_ty = fx.monomorphize(&func.ty(fx.mir, fx.codegen_cx.tcx));
|
let fn_ty = fx.monomorphize(&func.ty(fx.mir, fx.cx.tcx));
|
||||||
let fn_sig = fx
|
let fn_sig = fx
|
||||||
.codegen_cx.tcx
|
.cx.tcx
|
||||||
.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), &fn_ty.fn_sig(fx.codegen_cx.tcx));
|
.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), &fn_ty.fn_sig(fx.cx.tcx));
|
||||||
|
|
||||||
let destination = destination.map(|(place, bb)| (trans_place(fx, place), bb));
|
let destination = destination.map(|(place, bb)| (trans_place(fx, place), bb));
|
||||||
|
|
||||||
// Handle special calls like instrinsics and empty drop glue.
|
// Handle special calls like instrinsics and empty drop glue.
|
||||||
let instance = if let ty::FnDef(def_id, substs) = fn_ty.kind {
|
let instance = if let ty::FnDef(def_id, substs) = fn_ty.kind {
|
||||||
let instance = ty::Instance::resolve(fx.codegen_cx.tcx, ty::ParamEnv::reveal_all(), def_id, substs)
|
let instance = ty::Instance::resolve(fx.cx.tcx, ty::ParamEnv::reveal_all(), def_id, substs)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.polymorphize(fx.codegen_cx.tcx);
|
.polymorphize(fx.cx.tcx);
|
||||||
|
|
||||||
if fx.codegen_cx.tcx.symbol_name(instance).name.starts_with("llvm.") {
|
if fx.cx.tcx.symbol_name(instance).name.starts_with("llvm.") {
|
||||||
crate::intrinsics::codegen_llvm_intrinsic_call(
|
crate::intrinsics::codegen_llvm_intrinsic_call(
|
||||||
fx,
|
fx,
|
||||||
&fx.codegen_cx.tcx.symbol_name(instance).name,
|
&fx.cx.tcx.symbol_name(instance).name,
|
||||||
substs,
|
substs,
|
||||||
args,
|
args,
|
||||||
destination,
|
destination,
|
||||||
|
@ -510,7 +510,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
|
||||||
|
|
||||||
let is_cold =
|
let is_cold =
|
||||||
instance.map(|inst|
|
instance.map(|inst|
|
||||||
fx.codegen_cx.tcx.codegen_fn_attrs(inst.def_id())
|
fx.cx.tcx.codegen_fn_attrs(inst.def_id())
|
||||||
.flags.contains(CodegenFnAttrFlags::COLD))
|
.flags.contains(CodegenFnAttrFlags::COLD))
|
||||||
.unwrap_or(false);
|
.unwrap_or(false);
|
||||||
if is_cold {
|
if is_cold {
|
||||||
|
@ -558,7 +558,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
|
||||||
nop_inst,
|
nop_inst,
|
||||||
format!(
|
format!(
|
||||||
"virtual call; self arg pass mode: {:?}",
|
"virtual call; self arg pass mode: {:?}",
|
||||||
get_pass_mode(fx.codegen_cx.tcx, args[0].layout())
|
get_pass_mode(fx.cx.tcx, args[0].layout())
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -608,7 +608,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
|
||||||
)
|
)
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
if instance.map(|inst| inst.def.requires_caller_location(fx.codegen_cx.tcx)).unwrap_or(false) {
|
if instance.map(|inst| inst.def.requires_caller_location(fx.cx.tcx)).unwrap_or(false) {
|
||||||
// Pass the caller location for `#[track_caller]`.
|
// Pass the caller location for `#[track_caller]`.
|
||||||
let caller_location = fx.get_caller_location(span);
|
let caller_location = fx.get_caller_location(span);
|
||||||
call_args.extend(adjust_arg_for_abi(fx, caller_location).into_iter());
|
call_args.extend(adjust_arg_for_abi(fx, caller_location).into_iter());
|
||||||
|
@ -616,7 +616,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
|
||||||
|
|
||||||
let call_inst = if let Some(func_ref) = func_ref {
|
let call_inst = if let Some(func_ref) = func_ref {
|
||||||
let sig = clif_sig_from_fn_sig(
|
let sig = clif_sig_from_fn_sig(
|
||||||
fx.codegen_cx.tcx,
|
fx.cx.tcx,
|
||||||
fx.triple(),
|
fx.triple(),
|
||||||
fn_sig,
|
fn_sig,
|
||||||
span,
|
span,
|
||||||
|
@ -637,7 +637,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
|
||||||
// FIXME find a cleaner way to support varargs
|
// FIXME find a cleaner way to support varargs
|
||||||
if fn_sig.c_variadic {
|
if fn_sig.c_variadic {
|
||||||
if fn_sig.abi != Abi::C {
|
if fn_sig.abi != Abi::C {
|
||||||
fx.codegen_cx.tcx.sess.span_fatal(span, &format!("Variadic call for non-C abi {:?}", fn_sig.abi));
|
fx.cx.tcx.sess.span_fatal(span, &format!("Variadic call for non-C abi {:?}", fn_sig.abi));
|
||||||
}
|
}
|
||||||
let sig_ref = fx.bcx.func.dfg.call_signature(call_inst).unwrap();
|
let sig_ref = fx.bcx.func.dfg.call_signature(call_inst).unwrap();
|
||||||
let abi_params = call_args
|
let abi_params = call_args
|
||||||
|
@ -646,7 +646,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
|
||||||
let ty = fx.bcx.func.dfg.value_type(arg);
|
let ty = fx.bcx.func.dfg.value_type(arg);
|
||||||
if !ty.is_int() {
|
if !ty.is_int() {
|
||||||
// FIXME set %al to upperbound on float args once floats are supported
|
// FIXME set %al to upperbound on float args once floats are supported
|
||||||
fx.codegen_cx.tcx.sess.span_fatal(span, &format!("Non int ty {:?} for variadic call", ty));
|
fx.cx.tcx.sess.span_fatal(span, &format!("Non int ty {:?} for variadic call", ty));
|
||||||
}
|
}
|
||||||
AbiParam::new(ty)
|
AbiParam::new(ty)
|
||||||
})
|
})
|
||||||
|
@ -668,17 +668,17 @@ pub(crate) fn codegen_drop<'tcx>(
|
||||||
drop_place: CPlace<'tcx>,
|
drop_place: CPlace<'tcx>,
|
||||||
) {
|
) {
|
||||||
let ty = drop_place.layout().ty;
|
let ty = drop_place.layout().ty;
|
||||||
let drop_fn = Instance::resolve_drop_in_place(fx.codegen_cx.tcx, ty).polymorphize(fx.codegen_cx.tcx);
|
let drop_fn = Instance::resolve_drop_in_place(fx.cx.tcx, ty).polymorphize(fx.cx.tcx);
|
||||||
|
|
||||||
if let ty::InstanceDef::DropGlue(_, None) = drop_fn.def {
|
if let ty::InstanceDef::DropGlue(_, None) = drop_fn.def {
|
||||||
// we don't actually need to drop anything
|
// we don't actually need to drop anything
|
||||||
} else {
|
} else {
|
||||||
let drop_fn_ty = drop_fn.ty(fx.codegen_cx.tcx, ParamEnv::reveal_all());
|
let drop_fn_ty = drop_fn.ty(fx.cx.tcx, ParamEnv::reveal_all());
|
||||||
let fn_sig = fx.codegen_cx.tcx.normalize_erasing_late_bound_regions(
|
let fn_sig = fx.cx.tcx.normalize_erasing_late_bound_regions(
|
||||||
ParamEnv::reveal_all(),
|
ParamEnv::reveal_all(),
|
||||||
&drop_fn_ty.fn_sig(fx.codegen_cx.tcx),
|
&drop_fn_ty.fn_sig(fx.cx.tcx),
|
||||||
);
|
);
|
||||||
assert_eq!(fn_sig.output(), fx.codegen_cx.tcx.mk_unit());
|
assert_eq!(fn_sig.output(), fx.cx.tcx.mk_unit());
|
||||||
|
|
||||||
match ty.kind {
|
match ty.kind {
|
||||||
ty::Dynamic(..) => {
|
ty::Dynamic(..) => {
|
||||||
|
@ -687,7 +687,7 @@ pub(crate) fn codegen_drop<'tcx>(
|
||||||
let drop_fn = crate::vtable::drop_fn_of_obj(fx, vtable.unwrap());
|
let drop_fn = crate::vtable::drop_fn_of_obj(fx, vtable.unwrap());
|
||||||
|
|
||||||
let sig = clif_sig_from_fn_sig(
|
let sig = clif_sig_from_fn_sig(
|
||||||
fx.codegen_cx.tcx,
|
fx.cx.tcx,
|
||||||
fx.triple(),
|
fx.triple(),
|
||||||
fn_sig,
|
fn_sig,
|
||||||
span,
|
span,
|
||||||
|
@ -702,7 +702,7 @@ pub(crate) fn codegen_drop<'tcx>(
|
||||||
|
|
||||||
let arg_place = CPlace::new_stack_slot(
|
let arg_place = CPlace::new_stack_slot(
|
||||||
fx,
|
fx,
|
||||||
fx.layout_of(fx.codegen_cx.tcx.mk_ref(
|
fx.layout_of(fx.cx.tcx.mk_ref(
|
||||||
&ty::RegionKind::ReErased,
|
&ty::RegionKind::ReErased,
|
||||||
TypeAndMut {
|
TypeAndMut {
|
||||||
ty,
|
ty,
|
||||||
|
@ -716,7 +716,7 @@ pub(crate) fn codegen_drop<'tcx>(
|
||||||
|
|
||||||
let mut call_args: Vec<Value> = arg_value.into_iter().collect::<Vec<_>>();
|
let mut call_args: Vec<Value> = arg_value.into_iter().collect::<Vec<_>>();
|
||||||
|
|
||||||
if drop_fn.def.requires_caller_location(fx.codegen_cx.tcx) {
|
if drop_fn.def.requires_caller_location(fx.cx.tcx) {
|
||||||
// Pass the caller location for `#[track_caller]`.
|
// Pass the caller location for `#[track_caller]`.
|
||||||
let caller_location = fx.get_caller_location(span);
|
let caller_location = fx.get_caller_location(span);
|
||||||
call_args.extend(adjust_arg_for_abi(fx, caller_location).into_iter());
|
call_args.extend(adjust_arg_for_abi(fx, caller_location).into_iter());
|
||||||
|
|
|
@ -118,7 +118,7 @@ pub(super) fn adjust_arg_for_abi<'tcx>(
|
||||||
fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
|
fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
|
||||||
arg: CValue<'tcx>,
|
arg: CValue<'tcx>,
|
||||||
) -> EmptySinglePair<Value> {
|
) -> EmptySinglePair<Value> {
|
||||||
match get_pass_mode(fx.codegen_cx.tcx, arg.layout()) {
|
match get_pass_mode(fx.cx.tcx, arg.layout()) {
|
||||||
PassMode::NoPass => Empty,
|
PassMode::NoPass => Empty,
|
||||||
PassMode::ByVal(_) => Single(arg.load_scalar(fx)),
|
PassMode::ByVal(_) => Single(arg.load_scalar(fx)),
|
||||||
PassMode::ByValPair(_, _) => {
|
PassMode::ByValPair(_, _) => {
|
||||||
|
@ -144,13 +144,13 @@ pub(super) fn cvalue_for_param<'tcx>(
|
||||||
arg_ty: Ty<'tcx>,
|
arg_ty: Ty<'tcx>,
|
||||||
) -> Option<CValue<'tcx>> {
|
) -> Option<CValue<'tcx>> {
|
||||||
let layout = fx.layout_of(arg_ty);
|
let layout = fx.layout_of(arg_ty);
|
||||||
let pass_mode = get_pass_mode(fx.codegen_cx.tcx, layout);
|
let pass_mode = get_pass_mode(fx.cx.tcx, layout);
|
||||||
|
|
||||||
if let PassMode::NoPass = pass_mode {
|
if let PassMode::NoPass = pass_mode {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let clif_types = pass_mode.get_param_ty(fx.codegen_cx.tcx);
|
let clif_types = pass_mode.get_param_ty(fx.cx.tcx);
|
||||||
let block_params = clif_types.map(|t| fx.bcx.append_block_param(start_block, t));
|
let block_params = clif_types.map(|t| fx.bcx.append_block_param(start_block, t));
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
|
|
|
@ -19,7 +19,7 @@ pub(super) fn codegen_return_param(
|
||||||
start_block: Block,
|
start_block: Block,
|
||||||
) {
|
) {
|
||||||
let ret_layout = return_layout(fx);
|
let ret_layout = return_layout(fx);
|
||||||
let ret_pass_mode = get_pass_mode(fx.codegen_cx.tcx, ret_layout);
|
let ret_pass_mode = get_pass_mode(fx.cx.tcx, ret_layout);
|
||||||
let ret_param = match ret_pass_mode {
|
let ret_param = match ret_pass_mode {
|
||||||
PassMode::NoPass => {
|
PassMode::NoPass => {
|
||||||
fx.local_map
|
fx.local_map
|
||||||
|
@ -66,7 +66,7 @@ pub(super) fn codegen_with_call_return_arg<'tcx, B: Backend, T>(
|
||||||
) -> (Inst, T) {
|
) -> (Inst, T) {
|
||||||
let ret_layout = fx.layout_of(fn_sig.output());
|
let ret_layout = fx.layout_of(fn_sig.output());
|
||||||
|
|
||||||
let output_pass_mode = get_pass_mode(fx.codegen_cx.tcx, ret_layout);
|
let output_pass_mode = get_pass_mode(fx.cx.tcx, ret_layout);
|
||||||
let return_ptr = match output_pass_mode {
|
let return_ptr = match output_pass_mode {
|
||||||
PassMode::NoPass => None,
|
PassMode::NoPass => None,
|
||||||
PassMode::ByRef { size: Some(_)} => match ret_place {
|
PassMode::ByRef { size: Some(_)} => match ret_place {
|
||||||
|
@ -102,7 +102,7 @@ pub(super) fn codegen_with_call_return_arg<'tcx, B: Backend, T>(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn codegen_return(fx: &mut FunctionCx<'_, '_, impl Backend>) {
|
pub(crate) fn codegen_return(fx: &mut FunctionCx<'_, '_, impl Backend>) {
|
||||||
match get_pass_mode(fx.codegen_cx.tcx, return_layout(fx)) {
|
match get_pass_mode(fx.cx.tcx, return_layout(fx)) {
|
||||||
PassMode::NoPass | PassMode::ByRef { size: Some(_) } => {
|
PassMode::NoPass | PassMode::ByRef { size: Some(_) } => {
|
||||||
fx.bcx.ins().return_(&[]);
|
fx.bcx.ins().return_(&[]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,8 +35,8 @@ pub(crate) fn analyze(fx: &FunctionCx<'_, '_, impl Backend>) -> IndexVec<Local,
|
||||||
match &bb.terminator().kind {
|
match &bb.terminator().kind {
|
||||||
TerminatorKind::Call { destination, .. } => {
|
TerminatorKind::Call { destination, .. } => {
|
||||||
if let Some((dest_place, _dest_bb)) = destination {
|
if let Some((dest_place, _dest_bb)) = destination {
|
||||||
let dest_layout = fx.layout_of(fx.monomorphize(&dest_place.ty(&fx.mir.local_decls, fx.codegen_cx.tcx).ty));
|
let dest_layout = fx.layout_of(fx.monomorphize(&dest_place.ty(&fx.mir.local_decls, fx.cx.tcx).ty));
|
||||||
if !crate::abi::can_return_to_ssa_var(fx.codegen_cx.tcx, dest_layout) {
|
if !crate::abi::can_return_to_ssa_var(fx.cx.tcx, dest_layout) {
|
||||||
not_ssa(&mut flag_map, dest_place.local)
|
not_ssa(&mut flag_map, dest_place.local)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,7 +81,7 @@ pub(crate) fn init_global_lock_constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn lock_global_lock(fx: &mut FunctionCx<'_, '_, impl Backend>) {
|
pub(crate) fn lock_global_lock(fx: &mut FunctionCx<'_, '_, impl Backend>) {
|
||||||
let atomic_mutex = fx.codegen_cx.module.declare_data(
|
let atomic_mutex = fx.cx.module.declare_data(
|
||||||
"__cg_clif_global_atomic_mutex",
|
"__cg_clif_global_atomic_mutex",
|
||||||
Linkage::Import,
|
Linkage::Import,
|
||||||
true,
|
true,
|
||||||
|
@ -89,24 +89,24 @@ pub(crate) fn lock_global_lock(fx: &mut FunctionCx<'_, '_, impl Backend>) {
|
||||||
None,
|
None,
|
||||||
).unwrap();
|
).unwrap();
|
||||||
|
|
||||||
let pthread_mutex_lock = fx.codegen_cx.module.declare_function("pthread_mutex_lock", Linkage::Import, &cranelift_codegen::ir::Signature {
|
let pthread_mutex_lock = fx.cx.module.declare_function("pthread_mutex_lock", Linkage::Import, &cranelift_codegen::ir::Signature {
|
||||||
call_conv: fx.codegen_cx.module.target_config().default_call_conv,
|
call_conv: fx.cx.module.target_config().default_call_conv,
|
||||||
params: vec![
|
params: vec![
|
||||||
AbiParam::new(fx.codegen_cx.module.target_config().pointer_type() /* *mut pthread_mutex_t */),
|
AbiParam::new(fx.cx.module.target_config().pointer_type() /* *mut pthread_mutex_t */),
|
||||||
],
|
],
|
||||||
returns: vec![AbiParam::new(types::I32 /* c_int */)],
|
returns: vec![AbiParam::new(types::I32 /* c_int */)],
|
||||||
}).unwrap();
|
}).unwrap();
|
||||||
|
|
||||||
let pthread_mutex_lock = fx.codegen_cx.module.declare_func_in_func(pthread_mutex_lock, fx.bcx.func);
|
let pthread_mutex_lock = fx.cx.module.declare_func_in_func(pthread_mutex_lock, fx.bcx.func);
|
||||||
|
|
||||||
let atomic_mutex = fx.codegen_cx.module.declare_data_in_func(atomic_mutex, fx.bcx.func);
|
let atomic_mutex = fx.cx.module.declare_data_in_func(atomic_mutex, fx.bcx.func);
|
||||||
let atomic_mutex = fx.bcx.ins().global_value(fx.codegen_cx.module.target_config().pointer_type(), atomic_mutex);
|
let atomic_mutex = fx.bcx.ins().global_value(fx.cx.module.target_config().pointer_type(), atomic_mutex);
|
||||||
|
|
||||||
fx.bcx.ins().call(pthread_mutex_lock, &[atomic_mutex]);
|
fx.bcx.ins().call(pthread_mutex_lock, &[atomic_mutex]);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn unlock_global_lock(fx: &mut FunctionCx<'_, '_, impl Backend>) {
|
pub(crate) fn unlock_global_lock(fx: &mut FunctionCx<'_, '_, impl Backend>) {
|
||||||
let atomic_mutex = fx.codegen_cx.module.declare_data(
|
let atomic_mutex = fx.cx.module.declare_data(
|
||||||
"__cg_clif_global_atomic_mutex",
|
"__cg_clif_global_atomic_mutex",
|
||||||
Linkage::Import,
|
Linkage::Import,
|
||||||
true,
|
true,
|
||||||
|
@ -114,18 +114,18 @@ pub(crate) fn unlock_global_lock(fx: &mut FunctionCx<'_, '_, impl Backend>) {
|
||||||
None,
|
None,
|
||||||
).unwrap();
|
).unwrap();
|
||||||
|
|
||||||
let pthread_mutex_unlock = fx.codegen_cx.module.declare_function("pthread_mutex_unlock", Linkage::Import, &cranelift_codegen::ir::Signature {
|
let pthread_mutex_unlock = fx.cx.module.declare_function("pthread_mutex_unlock", Linkage::Import, &cranelift_codegen::ir::Signature {
|
||||||
call_conv: fx.codegen_cx.module.target_config().default_call_conv,
|
call_conv: fx.cx.module.target_config().default_call_conv,
|
||||||
params: vec![
|
params: vec![
|
||||||
AbiParam::new(fx.codegen_cx.module.target_config().pointer_type() /* *mut pthread_mutex_t */),
|
AbiParam::new(fx.cx.module.target_config().pointer_type() /* *mut pthread_mutex_t */),
|
||||||
],
|
],
|
||||||
returns: vec![AbiParam::new(types::I32 /* c_int */)],
|
returns: vec![AbiParam::new(types::I32 /* c_int */)],
|
||||||
}).unwrap();
|
}).unwrap();
|
||||||
|
|
||||||
let pthread_mutex_unlock = fx.codegen_cx.module.declare_func_in_func(pthread_mutex_unlock, fx.bcx.func);
|
let pthread_mutex_unlock = fx.cx.module.declare_func_in_func(pthread_mutex_unlock, fx.bcx.func);
|
||||||
|
|
||||||
let atomic_mutex = fx.codegen_cx.module.declare_data_in_func(atomic_mutex, fx.bcx.func);
|
let atomic_mutex = fx.cx.module.declare_data_in_func(atomic_mutex, fx.bcx.func);
|
||||||
let atomic_mutex = fx.bcx.ins().global_value(fx.codegen_cx.module.target_config().pointer_type(), atomic_mutex);
|
let atomic_mutex = fx.bcx.ins().global_value(fx.cx.module.target_config().pointer_type(), atomic_mutex);
|
||||||
|
|
||||||
fx.bcx.ins().call(pthread_mutex_unlock, &[atomic_mutex]);
|
fx.bcx.ins().call(pthread_mutex_unlock, &[atomic_mutex]);
|
||||||
}
|
}
|
||||||
|
|
70
src/base.rs
70
src/base.rs
|
@ -34,7 +34,7 @@ pub(crate) fn trans_fn<'tcx, B: Backend + 'static>(
|
||||||
let clif_comments = crate::pretty_clif::CommentWriter::new(tcx, instance);
|
let clif_comments = crate::pretty_clif::CommentWriter::new(tcx, instance);
|
||||||
|
|
||||||
let mut fx = FunctionCx {
|
let mut fx = FunctionCx {
|
||||||
codegen_cx: cx,
|
cx,
|
||||||
pointer_type,
|
pointer_type,
|
||||||
|
|
||||||
instance,
|
instance,
|
||||||
|
@ -220,7 +220,7 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, impl Backend>) {
|
||||||
target,
|
target,
|
||||||
cleanup: _,
|
cleanup: _,
|
||||||
} => {
|
} => {
|
||||||
if !fx.codegen_cx.tcx.sess.overflow_checks() {
|
if !fx.cx.tcx.sess.overflow_checks() {
|
||||||
if let mir::AssertKind::OverflowNeg(_) = *msg {
|
if let mir::AssertKind::OverflowNeg(_) = *msg {
|
||||||
let target = fx.get_block(*target);
|
let target = fx.get_block(*target);
|
||||||
fx.bcx.ins().jump(target, &[]);
|
fx.bcx.ins().jump(target, &[]);
|
||||||
|
@ -261,12 +261,12 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, impl Backend>) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let def_id = fx.codegen_cx.tcx.lang_items().require(lang_item).unwrap_or_else(|s| {
|
let def_id = fx.cx.tcx.lang_items().require(lang_item).unwrap_or_else(|s| {
|
||||||
fx.codegen_cx.tcx.sess.span_fatal(bb_data.terminator().source_info.span, &s)
|
fx.cx.tcx.sess.span_fatal(bb_data.terminator().source_info.span, &s)
|
||||||
});
|
});
|
||||||
|
|
||||||
let instance = Instance::mono(fx.codegen_cx.tcx, def_id).polymorphize(fx.codegen_cx.tcx);
|
let instance = Instance::mono(fx.cx.tcx, def_id).polymorphize(fx.cx.tcx);
|
||||||
let symbol_name = fx.codegen_cx.tcx.symbol_name(instance).name;
|
let symbol_name = fx.cx.tcx.symbol_name(instance).name;
|
||||||
|
|
||||||
fx.lib_call(&*symbol_name, vec![fx.pointer_type, fx.pointer_type, fx.pointer_type], vec![], &args);
|
fx.lib_call(&*symbol_name, vec![fx.pointer_type, fx.pointer_type, fx.pointer_type], vec![], &args);
|
||||||
|
|
||||||
|
@ -296,7 +296,7 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, impl Backend>) {
|
||||||
cleanup: _,
|
cleanup: _,
|
||||||
from_hir_call: _,
|
from_hir_call: _,
|
||||||
} => {
|
} => {
|
||||||
fx.codegen_cx.tcx.sess.time("codegen call", || crate::abi::codegen_terminator_call(
|
fx.cx.tcx.sess.time("codegen call", || crate::abi::codegen_terminator_call(
|
||||||
fx,
|
fx,
|
||||||
*fn_span,
|
*fn_span,
|
||||||
block,
|
block,
|
||||||
|
@ -415,7 +415,7 @@ fn trans_stmt<'tcx>(
|
||||||
let lhs = trans_operand(fx, lhs);
|
let lhs = trans_operand(fx, lhs);
|
||||||
let rhs = trans_operand(fx, rhs);
|
let rhs = trans_operand(fx, rhs);
|
||||||
|
|
||||||
let res = if !fx.codegen_cx.tcx.sess.overflow_checks() {
|
let res = if !fx.cx.tcx.sess.overflow_checks() {
|
||||||
let val =
|
let val =
|
||||||
crate::num::trans_int_binop(fx, *bin_op, lhs, rhs).load_scalar(fx);
|
crate::num::trans_int_binop(fx, *bin_op, lhs, rhs).load_scalar(fx);
|
||||||
let is_overflow = fx.bcx.ins().iconst(types::I8, 0);
|
let is_overflow = fx.bcx.ins().iconst(types::I8, 0);
|
||||||
|
@ -461,14 +461,14 @@ fn trans_stmt<'tcx>(
|
||||||
lval.write_cvalue(fx, res);
|
lval.write_cvalue(fx, res);
|
||||||
}
|
}
|
||||||
Rvalue::Cast(CastKind::Pointer(PointerCast::ReifyFnPointer), operand, to_ty) => {
|
Rvalue::Cast(CastKind::Pointer(PointerCast::ReifyFnPointer), operand, to_ty) => {
|
||||||
let from_ty = fx.monomorphize(&operand.ty(&fx.mir.local_decls, fx.codegen_cx.tcx));
|
let from_ty = fx.monomorphize(&operand.ty(&fx.mir.local_decls, fx.cx.tcx));
|
||||||
let to_layout = fx.layout_of(fx.monomorphize(to_ty));
|
let to_layout = fx.layout_of(fx.monomorphize(to_ty));
|
||||||
match from_ty.kind {
|
match from_ty.kind {
|
||||||
ty::FnDef(def_id, substs) => {
|
ty::FnDef(def_id, substs) => {
|
||||||
let func_ref = fx.get_function_ref(
|
let func_ref = fx.get_function_ref(
|
||||||
Instance::resolve_for_fn_ptr(fx.codegen_cx.tcx, ParamEnv::reveal_all(), def_id, substs)
|
Instance::resolve_for_fn_ptr(fx.cx.tcx, ParamEnv::reveal_all(), def_id, substs)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.polymorphize(fx.codegen_cx.tcx),
|
.polymorphize(fx.cx.tcx),
|
||||||
);
|
);
|
||||||
let func_addr = fx.bcx.ins().func_addr(fx.pointer_type, func_ref);
|
let func_addr = fx.bcx.ins().func_addr(fx.pointer_type, func_ref);
|
||||||
lval.write_cvalue(fx, CValue::by_val(func_addr, to_layout));
|
lval.write_cvalue(fx, CValue::by_val(func_addr, to_layout));
|
||||||
|
@ -497,7 +497,7 @@ fn trans_stmt<'tcx>(
|
||||||
|ty::TypeAndMut {
|
|ty::TypeAndMut {
|
||||||
ty: pointee_ty,
|
ty: pointee_ty,
|
||||||
mutbl: _,
|
mutbl: _,
|
||||||
}| has_ptr_meta(fx.codegen_cx.tcx, pointee_ty),
|
}| has_ptr_meta(fx.cx.tcx, pointee_ty),
|
||||||
)
|
)
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
}
|
}
|
||||||
|
@ -523,7 +523,7 @@ fn trans_stmt<'tcx>(
|
||||||
|
|
||||||
match &operand.layout().variants {
|
match &operand.layout().variants {
|
||||||
Variants::Single { index } => {
|
Variants::Single { index } => {
|
||||||
let discr = operand.layout().ty.discriminant_for_variant(fx.codegen_cx.tcx, *index).unwrap();
|
let discr = operand.layout().ty.discriminant_for_variant(fx.cx.tcx, *index).unwrap();
|
||||||
let discr = if discr.ty.is_signed() {
|
let discr = if discr.ty.is_signed() {
|
||||||
rustc_middle::mir::interpret::sign_extend(discr.val, fx.layout_of(discr.ty).size)
|
rustc_middle::mir::interpret::sign_extend(discr.val, fx.layout_of(discr.ty).size)
|
||||||
} else {
|
} else {
|
||||||
|
@ -575,11 +575,11 @@ fn trans_stmt<'tcx>(
|
||||||
match operand.layout().ty.kind {
|
match operand.layout().ty.kind {
|
||||||
ty::Closure(def_id, substs) => {
|
ty::Closure(def_id, substs) => {
|
||||||
let instance = Instance::resolve_closure(
|
let instance = Instance::resolve_closure(
|
||||||
fx.codegen_cx.tcx,
|
fx.cx.tcx,
|
||||||
def_id,
|
def_id,
|
||||||
substs,
|
substs,
|
||||||
ty::ClosureKind::FnOnce,
|
ty::ClosureKind::FnOnce,
|
||||||
).polymorphize(fx.codegen_cx.tcx);
|
).polymorphize(fx.cx.tcx);
|
||||||
let func_ref = fx.get_function_ref(instance);
|
let func_ref = fx.get_function_ref(instance);
|
||||||
let func_addr = fx.bcx.ins().func_addr(fx.pointer_type, func_ref);
|
let func_addr = fx.bcx.ins().func_addr(fx.pointer_type, func_ref);
|
||||||
lval.write_cvalue(fx, CValue::by_val(func_addr, lval.layout()));
|
lval.write_cvalue(fx, CValue::by_val(func_addr, lval.layout()));
|
||||||
|
@ -602,9 +602,9 @@ fn trans_stmt<'tcx>(
|
||||||
let operand = trans_operand(fx, operand);
|
let operand = trans_operand(fx, operand);
|
||||||
let times = fx
|
let times = fx
|
||||||
.monomorphize(times)
|
.monomorphize(times)
|
||||||
.eval(fx.codegen_cx.tcx, ParamEnv::reveal_all())
|
.eval(fx.cx.tcx, ParamEnv::reveal_all())
|
||||||
.val
|
.val
|
||||||
.try_to_bits(fx.codegen_cx.tcx.data_layout.pointer_size)
|
.try_to_bits(fx.cx.tcx.data_layout.pointer_size)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
for i in 0..times {
|
for i in 0..times {
|
||||||
let index = fx.bcx.ins().iconst(fx.pointer_type, i as i64);
|
let index = fx.bcx.ins().iconst(fx.pointer_type, i as i64);
|
||||||
|
@ -614,14 +614,14 @@ fn trans_stmt<'tcx>(
|
||||||
}
|
}
|
||||||
Rvalue::Len(place) => {
|
Rvalue::Len(place) => {
|
||||||
let place = trans_place(fx, *place);
|
let place = trans_place(fx, *place);
|
||||||
let usize_layout = fx.layout_of(fx.codegen_cx.tcx.types.usize);
|
let usize_layout = fx.layout_of(fx.cx.tcx.types.usize);
|
||||||
let len = codegen_array_len(fx, place);
|
let len = codegen_array_len(fx, place);
|
||||||
lval.write_cvalue(fx, CValue::by_val(len, usize_layout));
|
lval.write_cvalue(fx, CValue::by_val(len, usize_layout));
|
||||||
}
|
}
|
||||||
Rvalue::NullaryOp(NullOp::Box, content_ty) => {
|
Rvalue::NullaryOp(NullOp::Box, content_ty) => {
|
||||||
use rustc_hir::lang_items::ExchangeMallocFnLangItem;
|
use rustc_hir::lang_items::ExchangeMallocFnLangItem;
|
||||||
|
|
||||||
let usize_type = fx.clif_type(fx.codegen_cx.tcx.types.usize).unwrap();
|
let usize_type = fx.clif_type(fx.cx.tcx.types.usize).unwrap();
|
||||||
let content_ty = fx.monomorphize(content_ty);
|
let content_ty = fx.monomorphize(content_ty);
|
||||||
let layout = fx.layout_of(content_ty);
|
let layout = fx.layout_of(content_ty);
|
||||||
let llsize = fx.bcx.ins().iconst(usize_type, layout.size.bytes() as i64);
|
let llsize = fx.bcx.ins().iconst(usize_type, layout.size.bytes() as i64);
|
||||||
|
@ -629,18 +629,18 @@ fn trans_stmt<'tcx>(
|
||||||
.bcx
|
.bcx
|
||||||
.ins()
|
.ins()
|
||||||
.iconst(usize_type, layout.align.abi.bytes() as i64);
|
.iconst(usize_type, layout.align.abi.bytes() as i64);
|
||||||
let box_layout = fx.layout_of(fx.codegen_cx.tcx.mk_box(content_ty));
|
let box_layout = fx.layout_of(fx.cx.tcx.mk_box(content_ty));
|
||||||
|
|
||||||
// Allocate space:
|
// Allocate space:
|
||||||
let def_id = match fx.codegen_cx.tcx.lang_items().require(ExchangeMallocFnLangItem) {
|
let def_id = match fx.cx.tcx.lang_items().require(ExchangeMallocFnLangItem) {
|
||||||
Ok(id) => id,
|
Ok(id) => id,
|
||||||
Err(s) => {
|
Err(s) => {
|
||||||
fx.codegen_cx.tcx
|
fx.cx.tcx
|
||||||
.sess
|
.sess
|
||||||
.fatal(&format!("allocation of `{}` {}", box_layout.ty, s));
|
.fatal(&format!("allocation of `{}` {}", box_layout.ty, s));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let instance = ty::Instance::mono(fx.codegen_cx.tcx, def_id).polymorphize(fx.codegen_cx.tcx);
|
let instance = ty::Instance::mono(fx.cx.tcx, def_id).polymorphize(fx.cx.tcx);
|
||||||
let func_ref = fx.get_function_ref(instance);
|
let func_ref = fx.get_function_ref(instance);
|
||||||
let call = fx.bcx.ins().call(func_ref, &[llsize, llalign]);
|
let call = fx.bcx.ins().call(func_ref, &[llsize, llalign]);
|
||||||
let ptr = fx.bcx.inst_results(call)[0];
|
let ptr = fx.bcx.inst_results(call)[0];
|
||||||
|
@ -650,9 +650,9 @@ fn trans_stmt<'tcx>(
|
||||||
assert!(lval
|
assert!(lval
|
||||||
.layout()
|
.layout()
|
||||||
.ty
|
.ty
|
||||||
.is_sized(fx.codegen_cx.tcx.at(stmt.source_info.span), ParamEnv::reveal_all()));
|
.is_sized(fx.cx.tcx.at(stmt.source_info.span), ParamEnv::reveal_all()));
|
||||||
let ty_size = fx.layout_of(fx.monomorphize(ty)).size.bytes();
|
let ty_size = fx.layout_of(fx.monomorphize(ty)).size.bytes();
|
||||||
let val = CValue::const_val(fx, fx.layout_of(fx.codegen_cx.tcx.types.usize), ty_size.into());
|
let val = CValue::const_val(fx, fx.layout_of(fx.cx.tcx.types.usize), ty_size.into());
|
||||||
lval.write_cvalue(fx, val);
|
lval.write_cvalue(fx, val);
|
||||||
}
|
}
|
||||||
Rvalue::Aggregate(kind, operands) => match **kind {
|
Rvalue::Aggregate(kind, operands) => match **kind {
|
||||||
|
@ -717,10 +717,10 @@ fn trans_stmt<'tcx>(
|
||||||
let (eax, ebx, ecx, edx) = crate::intrinsics::codegen_cpuid_call(fx, leaf, subleaf);
|
let (eax, ebx, ecx, edx) = crate::intrinsics::codegen_cpuid_call(fx, leaf, subleaf);
|
||||||
|
|
||||||
assert_eq!(outputs.len(), 4);
|
assert_eq!(outputs.len(), 4);
|
||||||
trans_place(fx, outputs[0]).write_cvalue(fx, CValue::by_val(eax, fx.layout_of(fx.codegen_cx.tcx.types.u32)));
|
trans_place(fx, outputs[0]).write_cvalue(fx, CValue::by_val(eax, fx.layout_of(fx.cx.tcx.types.u32)));
|
||||||
trans_place(fx, outputs[1]).write_cvalue(fx, CValue::by_val(ebx, fx.layout_of(fx.codegen_cx.tcx.types.u32)));
|
trans_place(fx, outputs[1]).write_cvalue(fx, CValue::by_val(ebx, fx.layout_of(fx.cx.tcx.types.u32)));
|
||||||
trans_place(fx, outputs[2]).write_cvalue(fx, CValue::by_val(ecx, fx.layout_of(fx.codegen_cx.tcx.types.u32)));
|
trans_place(fx, outputs[2]).write_cvalue(fx, CValue::by_val(ecx, fx.layout_of(fx.cx.tcx.types.u32)));
|
||||||
trans_place(fx, outputs[3]).write_cvalue(fx, CValue::by_val(edx, fx.layout_of(fx.codegen_cx.tcx.types.u32)));
|
trans_place(fx, outputs[3]).write_cvalue(fx, CValue::by_val(edx, fx.layout_of(fx.cx.tcx.types.u32)));
|
||||||
}
|
}
|
||||||
"xgetbv" => {
|
"xgetbv" => {
|
||||||
assert_eq!(input_names, &[Symbol::intern("{ecx}")]);
|
assert_eq!(input_names, &[Symbol::intern("{ecx}")]);
|
||||||
|
@ -740,17 +740,17 @@ fn trans_stmt<'tcx>(
|
||||||
crate::trap::trap_unimplemented(fx, "_xgetbv arch intrinsic is not supported");
|
crate::trap::trap_unimplemented(fx, "_xgetbv arch intrinsic is not supported");
|
||||||
}
|
}
|
||||||
// ___chkstk, ___chkstk_ms and __alloca are only used on Windows
|
// ___chkstk, ___chkstk_ms and __alloca are only used on Windows
|
||||||
_ if fx.codegen_cx.tcx.symbol_name(fx.instance).name.starts_with("___chkstk") => {
|
_ if fx.cx.tcx.symbol_name(fx.instance).name.starts_with("___chkstk") => {
|
||||||
crate::trap::trap_unimplemented(fx, "Stack probes are not supported");
|
crate::trap::trap_unimplemented(fx, "Stack probes are not supported");
|
||||||
}
|
}
|
||||||
_ if fx.codegen_cx.tcx.symbol_name(fx.instance).name == "__alloca" => {
|
_ if fx.cx.tcx.symbol_name(fx.instance).name == "__alloca" => {
|
||||||
crate::trap::trap_unimplemented(fx, "Alloca is not supported");
|
crate::trap::trap_unimplemented(fx, "Alloca is not supported");
|
||||||
}
|
}
|
||||||
// Used in sys::windows::abort_internal
|
// Used in sys::windows::abort_internal
|
||||||
"int $$0x29" => {
|
"int $$0x29" => {
|
||||||
crate::trap::trap_unimplemented(fx, "Windows abort");
|
crate::trap::trap_unimplemented(fx, "Windows abort");
|
||||||
}
|
}
|
||||||
_ => fx.codegen_cx.tcx.sess.span_fatal(stmt.source_info.span, "Inline assembly is not supported"),
|
_ => fx.cx.tcx.sess.span_fatal(stmt.source_info.span, "Inline assembly is not supported"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -763,8 +763,8 @@ fn codegen_array_len<'tcx>(
|
||||||
match place.layout().ty.kind {
|
match place.layout().ty.kind {
|
||||||
ty::Array(_elem_ty, len) => {
|
ty::Array(_elem_ty, len) => {
|
||||||
let len = fx.monomorphize(&len)
|
let len = fx.monomorphize(&len)
|
||||||
.eval(fx.codegen_cx.tcx, ParamEnv::reveal_all())
|
.eval(fx.cx.tcx, ParamEnv::reveal_all())
|
||||||
.eval_usize(fx.codegen_cx.tcx, ParamEnv::reveal_all()) as i64;
|
.eval_usize(fx.cx.tcx, ParamEnv::reveal_all()) as i64;
|
||||||
fx.bcx.ins().iconst(fx.pointer_type, len)
|
fx.bcx.ins().iconst(fx.pointer_type, len)
|
||||||
}
|
}
|
||||||
ty::Slice(_elem_ty) => place
|
ty::Slice(_elem_ty) => place
|
||||||
|
@ -817,7 +817,7 @@ pub(crate) fn trans_place<'tcx>(
|
||||||
let ptr = cplace.to_ptr();
|
let ptr = cplace.to_ptr();
|
||||||
cplace = CPlace::for_ptr(
|
cplace = CPlace::for_ptr(
|
||||||
ptr.offset_i64(fx, elem_layout.size.bytes() as i64 * i64::from(from)),
|
ptr.offset_i64(fx, elem_layout.size.bytes() as i64 * i64::from(from)),
|
||||||
fx.layout_of(fx.codegen_cx.tcx.mk_array(elem_ty, u64::from(to) - u64::from(from))),
|
fx.layout_of(fx.cx.tcx.mk_array(elem_ty, u64::from(to) - u64::from(from))),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
ty::Slice(elem_ty) => {
|
ty::Slice(elem_ty) => {
|
||||||
|
|
16
src/cast.rs
16
src/cast.rs
|
@ -86,14 +86,14 @@ pub(crate) fn clif_int_or_float_cast(
|
||||||
);
|
);
|
||||||
|
|
||||||
let from_rust_ty = if from_signed {
|
let from_rust_ty = if from_signed {
|
||||||
fx.codegen_cx.tcx.types.i128
|
fx.cx.tcx.types.i128
|
||||||
} else {
|
} else {
|
||||||
fx.codegen_cx.tcx.types.u128
|
fx.cx.tcx.types.u128
|
||||||
};
|
};
|
||||||
|
|
||||||
let to_rust_ty = match to_ty {
|
let to_rust_ty = match to_ty {
|
||||||
types::F32 => fx.codegen_cx.tcx.types.f32,
|
types::F32 => fx.cx.tcx.types.f32,
|
||||||
types::F64 => fx.codegen_cx.tcx.types.f64,
|
types::F64 => fx.cx.tcx.types.f64,
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -131,15 +131,15 @@ pub(crate) fn clif_int_or_float_cast(
|
||||||
);
|
);
|
||||||
|
|
||||||
let from_rust_ty = match from_ty {
|
let from_rust_ty = match from_ty {
|
||||||
types::F32 => fx.codegen_cx.tcx.types.f32,
|
types::F32 => fx.cx.tcx.types.f32,
|
||||||
types::F64 => fx.codegen_cx.tcx.types.f64,
|
types::F64 => fx.cx.tcx.types.f64,
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let to_rust_ty = if to_signed {
|
let to_rust_ty = if to_signed {
|
||||||
fx.codegen_cx.tcx.types.i128
|
fx.cx.tcx.types.i128
|
||||||
} else {
|
} else {
|
||||||
fx.codegen_cx.tcx.types.u128
|
fx.cx.tcx.types.u128
|
||||||
};
|
};
|
||||||
|
|
||||||
return fx
|
return fx
|
||||||
|
|
|
@ -9,7 +9,7 @@ pub(crate) fn maybe_codegen<'tcx>(
|
||||||
lhs: CValue<'tcx>,
|
lhs: CValue<'tcx>,
|
||||||
rhs: CValue<'tcx>,
|
rhs: CValue<'tcx>,
|
||||||
) -> Option<CValue<'tcx>> {
|
) -> Option<CValue<'tcx>> {
|
||||||
if lhs.layout().ty != fx.codegen_cx.tcx.types.u128 && lhs.layout().ty != fx.codegen_cx.tcx.types.i128 {
|
if lhs.layout().ty != fx.cx.tcx.types.u128 && lhs.layout().ty != fx.cx.tcx.types.i128 {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ pub(crate) fn maybe_codegen<'tcx>(
|
||||||
}
|
}
|
||||||
BinOp::Add | BinOp::Sub if !checked => return None,
|
BinOp::Add | BinOp::Sub if !checked => return None,
|
||||||
BinOp::Add => {
|
BinOp::Add => {
|
||||||
let out_ty = fx.codegen_cx.tcx.mk_tup([lhs.layout().ty, fx.codegen_cx.tcx.types.bool].iter());
|
let out_ty = fx.cx.tcx.mk_tup([lhs.layout().ty, fx.cx.tcx.types.bool].iter());
|
||||||
return Some(if is_signed {
|
return Some(if is_signed {
|
||||||
fx.easy_call("__rust_i128_addo", &[lhs, rhs], out_ty)
|
fx.easy_call("__rust_i128_addo", &[lhs, rhs], out_ty)
|
||||||
} else {
|
} else {
|
||||||
|
@ -33,7 +33,7 @@ pub(crate) fn maybe_codegen<'tcx>(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
BinOp::Sub => {
|
BinOp::Sub => {
|
||||||
let out_ty = fx.codegen_cx.tcx.mk_tup([lhs.layout().ty, fx.codegen_cx.tcx.types.bool].iter());
|
let out_ty = fx.cx.tcx.mk_tup([lhs.layout().ty, fx.cx.tcx.types.bool].iter());
|
||||||
return Some(if is_signed {
|
return Some(if is_signed {
|
||||||
fx.easy_call("__rust_i128_subo", &[lhs, rhs], out_ty)
|
fx.easy_call("__rust_i128_subo", &[lhs, rhs], out_ty)
|
||||||
} else {
|
} else {
|
||||||
|
@ -43,7 +43,7 @@ pub(crate) fn maybe_codegen<'tcx>(
|
||||||
BinOp::Offset => unreachable!("offset should only be used on pointers, not 128bit ints"),
|
BinOp::Offset => unreachable!("offset should only be used on pointers, not 128bit ints"),
|
||||||
BinOp::Mul => {
|
BinOp::Mul => {
|
||||||
let res = if checked {
|
let res = if checked {
|
||||||
let out_ty = fx.codegen_cx.tcx.mk_tup([lhs.layout().ty, fx.codegen_cx.tcx.types.bool].iter());
|
let out_ty = fx.cx.tcx.mk_tup([lhs.layout().ty, fx.cx.tcx.types.bool].iter());
|
||||||
if is_signed {
|
if is_signed {
|
||||||
fx.easy_call("__rust_i128_mulo", &[lhs, rhs], out_ty)
|
fx.easy_call("__rust_i128_mulo", &[lhs, rhs], out_ty)
|
||||||
} else {
|
} else {
|
||||||
|
@ -51,9 +51,9 @@ pub(crate) fn maybe_codegen<'tcx>(
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let val_ty = if is_signed {
|
let val_ty = if is_signed {
|
||||||
fx.codegen_cx.tcx.types.i128
|
fx.cx.tcx.types.i128
|
||||||
} else {
|
} else {
|
||||||
fx.codegen_cx.tcx.types.u128
|
fx.cx.tcx.types.u128
|
||||||
};
|
};
|
||||||
fx.easy_call("__multi3", &[lhs, rhs], val_ty)
|
fx.easy_call("__multi3", &[lhs, rhs], val_ty)
|
||||||
};
|
};
|
||||||
|
@ -62,17 +62,17 @@ pub(crate) fn maybe_codegen<'tcx>(
|
||||||
BinOp::Div => {
|
BinOp::Div => {
|
||||||
assert!(!checked);
|
assert!(!checked);
|
||||||
if is_signed {
|
if is_signed {
|
||||||
Some(fx.easy_call("__divti3", &[lhs, rhs], fx.codegen_cx.tcx.types.i128))
|
Some(fx.easy_call("__divti3", &[lhs, rhs], fx.cx.tcx.types.i128))
|
||||||
} else {
|
} else {
|
||||||
Some(fx.easy_call("__udivti3", &[lhs, rhs], fx.codegen_cx.tcx.types.u128))
|
Some(fx.easy_call("__udivti3", &[lhs, rhs], fx.cx.tcx.types.u128))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BinOp::Rem => {
|
BinOp::Rem => {
|
||||||
assert!(!checked);
|
assert!(!checked);
|
||||||
if is_signed {
|
if is_signed {
|
||||||
Some(fx.easy_call("__modti3", &[lhs, rhs], fx.codegen_cx.tcx.types.i128))
|
Some(fx.easy_call("__modti3", &[lhs, rhs], fx.cx.tcx.types.i128))
|
||||||
} else {
|
} else {
|
||||||
Some(fx.easy_call("__umodti3", &[lhs, rhs], fx.codegen_cx.tcx.types.u128))
|
Some(fx.easy_call("__umodti3", &[lhs, rhs], fx.cx.tcx.types.u128))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BinOp::Lt | BinOp::Le | BinOp::Eq | BinOp::Ge | BinOp::Gt | BinOp::Ne => {
|
BinOp::Lt | BinOp::Le | BinOp::Eq | BinOp::Ge | BinOp::Gt | BinOp::Ne => {
|
||||||
|
@ -104,7 +104,7 @@ pub(crate) fn maybe_codegen<'tcx>(
|
||||||
let val = match (bin_op, is_signed) {
|
let val = match (bin_op, is_signed) {
|
||||||
(BinOp::Shr, false) => {
|
(BinOp::Shr, false) => {
|
||||||
let val = fx.bcx.ins().iconcat(lhs_msb, all_zeros);
|
let val = fx.bcx.ins().iconcat(lhs_msb, all_zeros);
|
||||||
Some(CValue::by_val(val, fx.layout_of(fx.codegen_cx.tcx.types.u128)))
|
Some(CValue::by_val(val, fx.layout_of(fx.cx.tcx.types.u128)))
|
||||||
}
|
}
|
||||||
(BinOp::Shr, true) => {
|
(BinOp::Shr, true) => {
|
||||||
let sign = fx.bcx.ins().icmp_imm(IntCC::SignedLessThan, lhs_msb, 0);
|
let sign = fx.bcx.ins().icmp_imm(IntCC::SignedLessThan, lhs_msb, 0);
|
||||||
|
@ -112,13 +112,13 @@ pub(crate) fn maybe_codegen<'tcx>(
|
||||||
let all_sign_bits = fx.bcx.ins().select(sign, all_zeros, all_ones);
|
let all_sign_bits = fx.bcx.ins().select(sign, all_zeros, all_ones);
|
||||||
|
|
||||||
let val = fx.bcx.ins().iconcat(lhs_msb, all_sign_bits);
|
let val = fx.bcx.ins().iconcat(lhs_msb, all_sign_bits);
|
||||||
Some(CValue::by_val(val, fx.layout_of(fx.codegen_cx.tcx.types.i128)))
|
Some(CValue::by_val(val, fx.layout_of(fx.cx.tcx.types.i128)))
|
||||||
}
|
}
|
||||||
(BinOp::Shl, _) => {
|
(BinOp::Shl, _) => {
|
||||||
let val_ty = if is_signed {
|
let val_ty = if is_signed {
|
||||||
fx.codegen_cx.tcx.types.i128
|
fx.cx.tcx.types.i128
|
||||||
} else {
|
} else {
|
||||||
fx.codegen_cx.tcx.types.u128
|
fx.cx.tcx.types.u128
|
||||||
};
|
};
|
||||||
let val = fx.bcx.ins().iconcat(all_zeros, lhs_lsb);
|
let val = fx.bcx.ins().iconcat(all_zeros, lhs_lsb);
|
||||||
Some(CValue::by_val(val, fx.layout_of(val_ty)))
|
Some(CValue::by_val(val, fx.layout_of(val_ty)))
|
||||||
|
@ -127,7 +127,7 @@ pub(crate) fn maybe_codegen<'tcx>(
|
||||||
};
|
};
|
||||||
if let Some(val) = val {
|
if let Some(val) = val {
|
||||||
if let Some(is_overflow) = is_overflow {
|
if let Some(is_overflow) = is_overflow {
|
||||||
let out_ty = fx.codegen_cx.tcx.mk_tup([lhs.layout().ty, fx.codegen_cx.tcx.types.bool].iter());
|
let out_ty = fx.cx.tcx.mk_tup([lhs.layout().ty, fx.cx.tcx.types.bool].iter());
|
||||||
let val = val.load_scalar(fx);
|
let val = val.load_scalar(fx);
|
||||||
return Some(CValue::by_val_pair(val, is_overflow, fx.layout_of(out_ty)));
|
return Some(CValue::by_val_pair(val, is_overflow, fx.layout_of(out_ty)));
|
||||||
} else {
|
} else {
|
||||||
|
@ -137,24 +137,24 @@ pub(crate) fn maybe_codegen<'tcx>(
|
||||||
}
|
}
|
||||||
|
|
||||||
let truncated_rhs = clif_intcast(fx, rhs_val, types::I32, false);
|
let truncated_rhs = clif_intcast(fx, rhs_val, types::I32, false);
|
||||||
let truncated_rhs = CValue::by_val(truncated_rhs, fx.layout_of(fx.codegen_cx.tcx.types.u32));
|
let truncated_rhs = CValue::by_val(truncated_rhs, fx.layout_of(fx.cx.tcx.types.u32));
|
||||||
let val = match (bin_op, is_signed) {
|
let val = match (bin_op, is_signed) {
|
||||||
(BinOp::Shl, false) => {
|
(BinOp::Shl, false) => {
|
||||||
fx.easy_call("__ashlti3", &[lhs, truncated_rhs], fx.codegen_cx.tcx.types.u128)
|
fx.easy_call("__ashlti3", &[lhs, truncated_rhs], fx.cx.tcx.types.u128)
|
||||||
}
|
}
|
||||||
(BinOp::Shl, true) => {
|
(BinOp::Shl, true) => {
|
||||||
fx.easy_call("__ashlti3", &[lhs, truncated_rhs], fx.codegen_cx.tcx.types.i128)
|
fx.easy_call("__ashlti3", &[lhs, truncated_rhs], fx.cx.tcx.types.i128)
|
||||||
}
|
}
|
||||||
(BinOp::Shr, false) => {
|
(BinOp::Shr, false) => {
|
||||||
fx.easy_call("__lshrti3", &[lhs, truncated_rhs], fx.codegen_cx.tcx.types.u128)
|
fx.easy_call("__lshrti3", &[lhs, truncated_rhs], fx.cx.tcx.types.u128)
|
||||||
}
|
}
|
||||||
(BinOp::Shr, true) => {
|
(BinOp::Shr, true) => {
|
||||||
fx.easy_call("__ashrti3", &[lhs, truncated_rhs], fx.codegen_cx.tcx.types.i128)
|
fx.easy_call("__ashrti3", &[lhs, truncated_rhs], fx.cx.tcx.types.i128)
|
||||||
}
|
}
|
||||||
(_, _) => unreachable!(),
|
(_, _) => unreachable!(),
|
||||||
};
|
};
|
||||||
if let Some(is_overflow) = is_overflow {
|
if let Some(is_overflow) = is_overflow {
|
||||||
let out_ty = fx.codegen_cx.tcx.mk_tup([lhs.layout().ty, fx.codegen_cx.tcx.types.bool].iter());
|
let out_ty = fx.cx.tcx.mk_tup([lhs.layout().ty, fx.cx.tcx.types.bool].iter());
|
||||||
let val = val.load_scalar(fx);
|
let val = val.load_scalar(fx);
|
||||||
Some(CValue::by_val_pair(val, is_overflow, fx.layout_of(out_ty)))
|
Some(CValue::by_val_pair(val, is_overflow, fx.layout_of(out_ty)))
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -265,7 +265,7 @@ pub(crate) fn type_sign(ty: Ty<'_>) -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) struct FunctionCx<'clif, 'tcx, B: Backend + 'static> {
|
pub(crate) struct FunctionCx<'clif, 'tcx, B: Backend + 'static> {
|
||||||
pub(crate) codegen_cx: &'clif mut crate::CodegenCx<'tcx, B>,
|
pub(crate) cx: &'clif mut crate::CodegenCx<'tcx, B>,
|
||||||
pub(crate) pointer_type: Type, // Cached from module
|
pub(crate) pointer_type: Type, // Cached from module
|
||||||
|
|
||||||
pub(crate) instance: Instance<'tcx>,
|
pub(crate) instance: Instance<'tcx>,
|
||||||
|
@ -296,11 +296,11 @@ impl<'tcx, B: Backend> LayoutOf for FunctionCx<'_, 'tcx, B> {
|
||||||
|
|
||||||
fn layout_of(&self, ty: Ty<'tcx>) -> TyAndLayout<'tcx> {
|
fn layout_of(&self, ty: Ty<'tcx>) -> TyAndLayout<'tcx> {
|
||||||
assert!(!ty.still_further_specializable());
|
assert!(!ty.still_further_specializable());
|
||||||
self.codegen_cx.tcx
|
self.cx.tcx
|
||||||
.layout_of(ParamEnv::reveal_all().and(&ty))
|
.layout_of(ParamEnv::reveal_all().and(&ty))
|
||||||
.unwrap_or_else(|e| {
|
.unwrap_or_else(|e| {
|
||||||
if let layout::LayoutError::SizeOverflow(_) = e {
|
if let layout::LayoutError::SizeOverflow(_) = e {
|
||||||
self.codegen_cx.tcx.sess.fatal(&e.to_string())
|
self.cx.tcx.sess.fatal(&e.to_string())
|
||||||
} else {
|
} else {
|
||||||
bug!("failed to get layout for `{}`: {}", ty, e)
|
bug!("failed to get layout for `{}`: {}", ty, e)
|
||||||
}
|
}
|
||||||
|
@ -310,13 +310,13 @@ impl<'tcx, B: Backend> LayoutOf for FunctionCx<'_, 'tcx, B> {
|
||||||
|
|
||||||
impl<'tcx, B: Backend + 'static> layout::HasTyCtxt<'tcx> for FunctionCx<'_, 'tcx, B> {
|
impl<'tcx, B: Backend + 'static> layout::HasTyCtxt<'tcx> for FunctionCx<'_, 'tcx, B> {
|
||||||
fn tcx<'b>(&'b self) -> TyCtxt<'tcx> {
|
fn tcx<'b>(&'b self) -> TyCtxt<'tcx> {
|
||||||
self.codegen_cx.tcx
|
self.cx.tcx
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx, B: Backend + 'static> rustc_target::abi::HasDataLayout for FunctionCx<'_, 'tcx, B> {
|
impl<'tcx, B: Backend + 'static> rustc_target::abi::HasDataLayout for FunctionCx<'_, 'tcx, B> {
|
||||||
fn data_layout(&self) -> &rustc_target::abi::TargetDataLayout {
|
fn data_layout(&self) -> &rustc_target::abi::TargetDataLayout {
|
||||||
&self.codegen_cx.tcx.data_layout
|
&self.cx.tcx.data_layout
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -328,7 +328,7 @@ impl<'tcx, B: Backend + 'static> layout::HasParamEnv<'tcx> for FunctionCx<'_, 't
|
||||||
|
|
||||||
impl<'tcx, B: Backend + 'static> HasTargetSpec for FunctionCx<'_, 'tcx, B> {
|
impl<'tcx, B: Backend + 'static> HasTargetSpec for FunctionCx<'_, 'tcx, B> {
|
||||||
fn target_spec(&self) -> &Target {
|
fn target_spec(&self) -> &Target {
|
||||||
&self.codegen_cx.tcx.sess.target.target
|
&self.cx.tcx.sess.target.target
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -338,22 +338,22 @@ impl<'tcx, B: Backend + 'static> FunctionCx<'_, 'tcx, B> {
|
||||||
T: TypeFoldable<'tcx> + Copy,
|
T: TypeFoldable<'tcx> + Copy,
|
||||||
{
|
{
|
||||||
if let Some(substs) = self.instance.substs_for_mir_body() {
|
if let Some(substs) = self.instance.substs_for_mir_body() {
|
||||||
self.codegen_cx.tcx.subst_and_normalize_erasing_regions(
|
self.cx.tcx.subst_and_normalize_erasing_regions(
|
||||||
substs,
|
substs,
|
||||||
ty::ParamEnv::reveal_all(),
|
ty::ParamEnv::reveal_all(),
|
||||||
value,
|
value,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
self.codegen_cx.tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), *value)
|
self.cx.tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), *value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn clif_type(&self, ty: Ty<'tcx>) -> Option<Type> {
|
pub(crate) fn clif_type(&self, ty: Ty<'tcx>) -> Option<Type> {
|
||||||
clif_type_from_ty(self.codegen_cx.tcx, ty)
|
clif_type_from_ty(self.cx.tcx, ty)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn clif_pair_type(&self, ty: Ty<'tcx>) -> Option<(Type, Type)> {
|
pub(crate) fn clif_pair_type(&self, ty: Ty<'tcx>) -> Option<(Type, Type)> {
|
||||||
clif_pair_type_from_ty(self.codegen_cx.tcx, ty)
|
clif_pair_type_from_ty(self.cx.tcx, ty)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn get_block(&self, bb: BasicBlock) -> Block {
|
pub(crate) fn get_block(&self, bb: BasicBlock) -> Block {
|
||||||
|
@ -378,8 +378,8 @@ impl<'tcx, B: Backend + 'static> FunctionCx<'_, 'tcx, B> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span);
|
let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span);
|
||||||
let caller = self.codegen_cx.tcx.sess.source_map().lookup_char_pos(topmost.lo());
|
let caller = self.cx.tcx.sess.source_map().lookup_char_pos(topmost.lo());
|
||||||
let const_loc = self.codegen_cx.tcx.const_caller_location((
|
let const_loc = self.cx.tcx.const_caller_location((
|
||||||
rustc_span::symbol::Symbol::intern(&caller.file.name.to_string()),
|
rustc_span::symbol::Symbol::intern(&caller.file.name.to_string()),
|
||||||
caller.line as u32,
|
caller.line as u32,
|
||||||
caller.col_display as u32 + 1,
|
caller.col_display as u32 + 1,
|
||||||
|
@ -387,12 +387,12 @@ impl<'tcx, B: Backend + 'static> FunctionCx<'_, 'tcx, B> {
|
||||||
crate::constant::trans_const_value(
|
crate::constant::trans_const_value(
|
||||||
self,
|
self,
|
||||||
const_loc,
|
const_loc,
|
||||||
self.codegen_cx.tcx.caller_location_ty(),
|
self.cx.tcx.caller_location_ty(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn triple(&self) -> &target_lexicon::Triple {
|
pub(crate) fn triple(&self) -> &target_lexicon::Triple {
|
||||||
self.codegen_cx.module.isa().triple()
|
self.cx.module.isa().triple()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn anonymous_str(&mut self, prefix: &str, msg: &str) -> Value {
|
pub(crate) fn anonymous_str(&mut self, prefix: &str, msg: &str) -> Value {
|
||||||
|
@ -405,7 +405,7 @@ impl<'tcx, B: Backend + 'static> FunctionCx<'_, 'tcx, B> {
|
||||||
let mut data_ctx = DataContext::new();
|
let mut data_ctx = DataContext::new();
|
||||||
data_ctx.define(msg.as_bytes().to_vec().into_boxed_slice());
|
data_ctx.define(msg.as_bytes().to_vec().into_boxed_slice());
|
||||||
let msg_id = self
|
let msg_id = self
|
||||||
.codegen_cx.module
|
.cx.module
|
||||||
.declare_data(
|
.declare_data(
|
||||||
&format!("__{}_{:08x}", prefix, msg_hash),
|
&format!("__{}_{:08x}", prefix, msg_hash),
|
||||||
Linkage::Local,
|
Linkage::Local,
|
||||||
|
@ -416,9 +416,9 @@ impl<'tcx, B: Backend + 'static> FunctionCx<'_, 'tcx, B> {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// Ignore DuplicateDefinition error, as the data will be the same
|
// Ignore DuplicateDefinition error, as the data will be the same
|
||||||
let _ = self.codegen_cx.module.define_data(msg_id, &data_ctx);
|
let _ = self.cx.module.define_data(msg_id, &data_ctx);
|
||||||
|
|
||||||
let local_msg_id = self.codegen_cx.module.declare_data_in_func(msg_id, self.bcx.func);
|
let local_msg_id = self.cx.module.declare_data_in_func(msg_id, self.bcx.func);
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
{
|
{
|
||||||
self.add_comment(local_msg_id, msg);
|
self.add_comment(local_msg_id, msg);
|
||||||
|
|
|
@ -41,10 +41,10 @@ pub(crate) fn check_constants(fx: &mut FunctionCx<'_, '_, impl Backend>) {
|
||||||
match const_.val {
|
match const_.val {
|
||||||
ConstKind::Value(_) => {}
|
ConstKind::Value(_) => {}
|
||||||
ConstKind::Unevaluated(def, ref substs, promoted) => {
|
ConstKind::Unevaluated(def, ref substs, promoted) => {
|
||||||
if let Err(err) = fx.codegen_cx.tcx.const_eval_resolve(ParamEnv::reveal_all(), def, substs, promoted, None) {
|
if let Err(err) = fx.cx.tcx.const_eval_resolve(ParamEnv::reveal_all(), def, substs, promoted, None) {
|
||||||
match err {
|
match err {
|
||||||
ErrorHandled::Reported(ErrorReported) | ErrorHandled::Linted => {
|
ErrorHandled::Reported(ErrorReported) | ErrorHandled::Linted => {
|
||||||
fx.codegen_cx.tcx.sess.span_err(constant.span, "erroneous constant encountered");
|
fx.cx.tcx.sess.span_err(constant.span, "erroneous constant encountered");
|
||||||
}
|
}
|
||||||
ErrorHandled::TooGeneric => {
|
ErrorHandled::TooGeneric => {
|
||||||
span_bug!(constant.span, "codgen encountered polymorphic constant: {:?}", err);
|
span_bug!(constant.span, "codgen encountered polymorphic constant: {:?}", err);
|
||||||
|
@ -67,8 +67,8 @@ pub(crate) fn codegen_tls_ref<'tcx>(
|
||||||
def_id: DefId,
|
def_id: DefId,
|
||||||
layout: TyAndLayout<'tcx>,
|
layout: TyAndLayout<'tcx>,
|
||||||
) -> CValue<'tcx> {
|
) -> CValue<'tcx> {
|
||||||
let data_id = data_id_for_static(fx.codegen_cx.tcx, &mut fx.codegen_cx.module, def_id, false);
|
let data_id = data_id_for_static(fx.cx.tcx, &mut fx.cx.module, def_id, false);
|
||||||
let local_data_id = fx.codegen_cx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
|
let local_data_id = fx.cx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
fx.add_comment(local_data_id, format!("tls {:?}", def_id));
|
fx.add_comment(local_data_id, format!("tls {:?}", def_id));
|
||||||
let tls_ptr = fx.bcx.ins().tls_value(fx.pointer_type, local_data_id);
|
let tls_ptr = fx.bcx.ins().tls_value(fx.pointer_type, local_data_id);
|
||||||
|
@ -80,8 +80,8 @@ fn codegen_static_ref<'tcx>(
|
||||||
def_id: DefId,
|
def_id: DefId,
|
||||||
layout: TyAndLayout<'tcx>,
|
layout: TyAndLayout<'tcx>,
|
||||||
) -> CPlace<'tcx> {
|
) -> CPlace<'tcx> {
|
||||||
let data_id = data_id_for_static(fx.codegen_cx.tcx, &mut fx.codegen_cx.module, def_id, false);
|
let data_id = data_id_for_static(fx.cx.tcx, &mut fx.cx.module, def_id, false);
|
||||||
let local_data_id = fx.codegen_cx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
|
let local_data_id = fx.cx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
fx.add_comment(local_data_id, format!("{:?}", def_id));
|
fx.add_comment(local_data_id, format!("{:?}", def_id));
|
||||||
let global_ptr = fx.bcx.ins().global_value(fx.pointer_type, local_data_id);
|
let global_ptr = fx.bcx.ins().global_value(fx.pointer_type, local_data_id);
|
||||||
|
@ -97,7 +97,7 @@ pub(crate) fn trans_constant<'tcx>(
|
||||||
let const_ = fx.monomorphize(&constant.literal);
|
let const_ = fx.monomorphize(&constant.literal);
|
||||||
let const_val = match const_.val {
|
let const_val = match const_.val {
|
||||||
ConstKind::Value(const_val) => const_val,
|
ConstKind::Value(const_val) => const_val,
|
||||||
ConstKind::Unevaluated(def, ref substs, promoted) if fx.codegen_cx.tcx.is_static(def.did) => {
|
ConstKind::Unevaluated(def, ref substs, promoted) if fx.cx.tcx.is_static(def.did) => {
|
||||||
assert!(substs.is_empty());
|
assert!(substs.is_empty());
|
||||||
assert!(promoted.is_none());
|
assert!(promoted.is_none());
|
||||||
|
|
||||||
|
@ -108,11 +108,11 @@ pub(crate) fn trans_constant<'tcx>(
|
||||||
).to_cvalue(fx);
|
).to_cvalue(fx);
|
||||||
}
|
}
|
||||||
ConstKind::Unevaluated(def, ref substs, promoted) => {
|
ConstKind::Unevaluated(def, ref substs, promoted) => {
|
||||||
match fx.codegen_cx.tcx.const_eval_resolve(ParamEnv::reveal_all(), def, substs, promoted, None) {
|
match fx.cx.tcx.const_eval_resolve(ParamEnv::reveal_all(), def, substs, promoted, None) {
|
||||||
Ok(const_val) => const_val,
|
Ok(const_val) => const_val,
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
if promoted.is_none() {
|
if promoted.is_none() {
|
||||||
fx.codegen_cx.tcx.sess.span_err(constant.span, "erroneous constant encountered");
|
fx.cx.tcx.sess.span_err(constant.span, "erroneous constant encountered");
|
||||||
}
|
}
|
||||||
return crate::trap::trap_unreachable_ret_value(
|
return crate::trap::trap_unreachable_ret_value(
|
||||||
fx,
|
fx,
|
||||||
|
@ -154,7 +154,7 @@ pub(crate) fn trans_const_value<'tcx>(
|
||||||
);
|
);
|
||||||
let ptr = Pointer::new(AllocId(!0), Size::ZERO); // The alloc id is never used
|
let ptr = Pointer::new(AllocId(!0), Size::ZERO); // The alloc id is never used
|
||||||
alloc.write_scalar(fx, ptr, x.into(), size).unwrap();
|
alloc.write_scalar(fx, ptr, x.into(), size).unwrap();
|
||||||
let alloc = fx.codegen_cx.tcx.intern_const_alloc(alloc);
|
let alloc = fx.cx.tcx.intern_const_alloc(alloc);
|
||||||
return CValue::by_ref(pointer_for_allocation(fx, alloc), layout);
|
return CValue::by_ref(pointer_for_allocation(fx, alloc), layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,25 +164,25 @@ pub(crate) fn trans_const_value<'tcx>(
|
||||||
return CValue::const_val(fx, layout, data);
|
return CValue::const_val(fx, layout, data);
|
||||||
}
|
}
|
||||||
Scalar::Ptr(ptr) => {
|
Scalar::Ptr(ptr) => {
|
||||||
let alloc_kind = fx.codegen_cx.tcx.get_global_alloc(ptr.alloc_id);
|
let alloc_kind = fx.cx.tcx.get_global_alloc(ptr.alloc_id);
|
||||||
let base_addr = match alloc_kind {
|
let base_addr = match alloc_kind {
|
||||||
Some(GlobalAlloc::Memory(alloc)) => {
|
Some(GlobalAlloc::Memory(alloc)) => {
|
||||||
fx.codegen_cx.constants_cx.todo.push(TodoItem::Alloc(ptr.alloc_id));
|
fx.cx.constants_cx.todo.push(TodoItem::Alloc(ptr.alloc_id));
|
||||||
let data_id = data_id_for_alloc_id(&mut fx.codegen_cx.module, ptr.alloc_id, alloc.align, alloc.mutability);
|
let data_id = data_id_for_alloc_id(&mut fx.cx.module, ptr.alloc_id, alloc.align, alloc.mutability);
|
||||||
let local_data_id = fx.codegen_cx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
|
let local_data_id = fx.cx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
fx.add_comment(local_data_id, format!("{:?}", ptr.alloc_id));
|
fx.add_comment(local_data_id, format!("{:?}", ptr.alloc_id));
|
||||||
fx.bcx.ins().global_value(fx.pointer_type, local_data_id)
|
fx.bcx.ins().global_value(fx.pointer_type, local_data_id)
|
||||||
}
|
}
|
||||||
Some(GlobalAlloc::Function(instance)) => {
|
Some(GlobalAlloc::Function(instance)) => {
|
||||||
let func_id = crate::abi::import_function(fx.codegen_cx.tcx, &mut fx.codegen_cx.module, instance);
|
let func_id = crate::abi::import_function(fx.cx.tcx, &mut fx.cx.module, instance);
|
||||||
let local_func_id = fx.codegen_cx.module.declare_func_in_func(func_id, &mut fx.bcx.func);
|
let local_func_id = fx.cx.module.declare_func_in_func(func_id, &mut fx.bcx.func);
|
||||||
fx.bcx.ins().func_addr(fx.pointer_type, local_func_id)
|
fx.bcx.ins().func_addr(fx.pointer_type, local_func_id)
|
||||||
}
|
}
|
||||||
Some(GlobalAlloc::Static(def_id)) => {
|
Some(GlobalAlloc::Static(def_id)) => {
|
||||||
assert!(fx.codegen_cx.tcx.is_static(def_id));
|
assert!(fx.cx.tcx.is_static(def_id));
|
||||||
let data_id = data_id_for_static(fx.codegen_cx.tcx, &mut fx.codegen_cx.module, def_id, false);
|
let data_id = data_id_for_static(fx.cx.tcx, &mut fx.cx.module, def_id, false);
|
||||||
let local_data_id = fx.codegen_cx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
|
let local_data_id = fx.cx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
fx.add_comment(local_data_id, format!("{:?}", def_id));
|
fx.add_comment(local_data_id, format!("{:?}", def_id));
|
||||||
fx.bcx.ins().global_value(fx.pointer_type, local_data_id)
|
fx.bcx.ins().global_value(fx.pointer_type, local_data_id)
|
||||||
|
@ -215,11 +215,11 @@ fn pointer_for_allocation<'tcx>(
|
||||||
fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
|
fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
|
||||||
alloc: &'tcx Allocation,
|
alloc: &'tcx Allocation,
|
||||||
) -> crate::pointer::Pointer {
|
) -> crate::pointer::Pointer {
|
||||||
let alloc_id = fx.codegen_cx.tcx.create_memory_alloc(alloc);
|
let alloc_id = fx.cx.tcx.create_memory_alloc(alloc);
|
||||||
fx.codegen_cx.constants_cx.todo.push(TodoItem::Alloc(alloc_id));
|
fx.cx.constants_cx.todo.push(TodoItem::Alloc(alloc_id));
|
||||||
let data_id = data_id_for_alloc_id(&mut fx.codegen_cx.module, alloc_id, alloc.align, alloc.mutability);
|
let data_id = data_id_for_alloc_id(&mut fx.cx.module, alloc_id, alloc.align, alloc.mutability);
|
||||||
|
|
||||||
let local_data_id = fx.codegen_cx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
|
let local_data_id = fx.cx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
fx.add_comment(local_data_id, format!("{:?}", alloc_id));
|
fx.add_comment(local_data_id, format!("{:?}", alloc_id));
|
||||||
let global_ptr = fx.bcx.ins().global_value(fx.pointer_type, local_data_id);
|
let global_ptr = fx.bcx.ins().global_value(fx.pointer_type, local_data_id);
|
||||||
|
@ -419,7 +419,7 @@ pub(crate) fn mir_operand_get_const_val<'tcx>(
|
||||||
match operand {
|
match operand {
|
||||||
Operand::Copy(_) | Operand::Move(_) => None,
|
Operand::Copy(_) | Operand::Move(_) => None,
|
||||||
Operand::Constant(const_) => {
|
Operand::Constant(const_) => {
|
||||||
Some(fx.monomorphize(&const_.literal).eval(fx.codegen_cx.tcx, ParamEnv::reveal_all()))
|
Some(fx.monomorphize(&const_.literal).eval(fx.cx.tcx, ParamEnv::reveal_all()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ pub(crate) fn codegen_set_discriminant<'tcx>(
|
||||||
let ptr = place.place_field(fx, mir::Field::new(tag_field));
|
let ptr = place.place_field(fx, mir::Field::new(tag_field));
|
||||||
let to = layout
|
let to = layout
|
||||||
.ty
|
.ty
|
||||||
.discriminant_for_variant(fx.codegen_cx.tcx, variant_index)
|
.discriminant_for_variant(fx.cx.tcx, variant_index)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.val;
|
.val;
|
||||||
let discr = CValue::const_val(fx, ptr.layout(), to);
|
let discr = CValue::const_val(fx, ptr.layout(), to);
|
||||||
|
@ -73,7 +73,7 @@ pub(crate) fn codegen_get_discriminant<'tcx>(
|
||||||
Variants::Single { index } => {
|
Variants::Single { index } => {
|
||||||
let discr_val = layout
|
let discr_val = layout
|
||||||
.ty
|
.ty
|
||||||
.discriminant_for_variant(fx.codegen_cx.tcx, *index)
|
.discriminant_for_variant(fx.cx.tcx, *index)
|
||||||
.map_or(u128::from(index.as_u32()), |discr| discr.val);
|
.map_or(u128::from(index.as_u32()), |discr| discr.val);
|
||||||
return CValue::const_val(fx, dest_layout, discr_val);
|
return CValue::const_val(fx, dest_layout, discr_val);
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,10 +70,10 @@ pub(crate) fn codegen_inline_asm<'tcx>(
|
||||||
|
|
||||||
let inline_asm_index = fx.inline_asm_index;
|
let inline_asm_index = fx.inline_asm_index;
|
||||||
fx.inline_asm_index += 1;
|
fx.inline_asm_index += 1;
|
||||||
let asm_name = format!("{}__inline_asm_{}", fx.codegen_cx.tcx.symbol_name(fx.instance).name, inline_asm_index);
|
let asm_name = format!("{}__inline_asm_{}", fx.cx.tcx.symbol_name(fx.instance).name, inline_asm_index);
|
||||||
|
|
||||||
let generated_asm = generate_asm_wrapper(&asm_name, InlineAsmArch::X86_64, options, template, clobbered_regs, &inputs, &outputs);
|
let generated_asm = generate_asm_wrapper(&asm_name, InlineAsmArch::X86_64, options, template, clobbered_regs, &inputs, &outputs);
|
||||||
fx.codegen_cx.global_asm.push_str(&generated_asm);
|
fx.cx.global_asm.push_str(&generated_asm);
|
||||||
|
|
||||||
call_inline_asm(fx, &asm_name, slot_size, inputs, outputs);
|
call_inline_asm(fx, &asm_name, slot_size, inputs, outputs);
|
||||||
}
|
}
|
||||||
|
@ -169,12 +169,12 @@ fn call_inline_asm<'tcx>(
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
fx.add_comment(stack_slot, "inline asm scratch slot");
|
fx.add_comment(stack_slot, "inline asm scratch slot");
|
||||||
|
|
||||||
let inline_asm_func = fx.codegen_cx.module.declare_function(asm_name, Linkage::Import, &Signature {
|
let inline_asm_func = fx.cx.module.declare_function(asm_name, Linkage::Import, &Signature {
|
||||||
call_conv: CallConv::SystemV,
|
call_conv: CallConv::SystemV,
|
||||||
params: vec![AbiParam::new(fx.pointer_type)],
|
params: vec![AbiParam::new(fx.pointer_type)],
|
||||||
returns: vec![],
|
returns: vec![],
|
||||||
}).unwrap();
|
}).unwrap();
|
||||||
let inline_asm_func = fx.codegen_cx.module.declare_func_in_func(inline_asm_func, &mut fx.bcx.func);
|
let inline_asm_func = fx.cx.module.declare_func_in_func(inline_asm_func, &mut fx.bcx.func);
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
fx.add_comment(inline_asm_func, asm_name);
|
fx.add_comment(inline_asm_func, asm_name);
|
||||||
|
|
||||||
|
|
|
@ -30,13 +30,13 @@ pub(crate) fn codegen_llvm_intrinsic_call<'tcx>(
|
||||||
intrinsic_match! {
|
intrinsic_match! {
|
||||||
fx, intrinsic, substs, args,
|
fx, intrinsic, substs, args,
|
||||||
_ => {
|
_ => {
|
||||||
fx.codegen_cx.tcx.sess.warn(&format!("unsupported llvm intrinsic {}; replacing with trap", intrinsic));
|
fx.cx.tcx.sess.warn(&format!("unsupported llvm intrinsic {}; replacing with trap", intrinsic));
|
||||||
crate::trap::trap_unimplemented(fx, intrinsic);
|
crate::trap::trap_unimplemented(fx, intrinsic);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Used by `_mm_movemask_epi8` and `_mm256_movemask_epi8`
|
// Used by `_mm_movemask_epi8` and `_mm256_movemask_epi8`
|
||||||
llvm.x86.sse2.pmovmskb.128 | llvm.x86.avx2.pmovmskb | llvm.x86.sse2.movmsk.pd, (c a) {
|
llvm.x86.sse2.pmovmskb.128 | llvm.x86.avx2.pmovmskb | llvm.x86.sse2.movmsk.pd, (c a) {
|
||||||
let (lane_layout, lane_count) = lane_type_and_count(fx.codegen_cx.tcx, a.layout());
|
let (lane_layout, lane_count) = lane_type_and_count(fx.cx.tcx, a.layout());
|
||||||
let lane_ty = fx.clif_type(lane_layout.ty).unwrap();
|
let lane_ty = fx.clif_type(lane_layout.ty).unwrap();
|
||||||
assert!(lane_count <= 32);
|
assert!(lane_count <= 32);
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ pub(crate) fn codegen_llvm_intrinsic_call<'tcx>(
|
||||||
res = fx.bcx.ins().bor(res, a_lane_sign);
|
res = fx.bcx.ins().bor(res, a_lane_sign);
|
||||||
}
|
}
|
||||||
|
|
||||||
let res = CValue::by_val(res, fx.layout_of(fx.codegen_cx.tcx.types.i32));
|
let res = CValue::by_val(res, fx.layout_of(fx.cx.tcx.types.i32));
|
||||||
ret.write_cvalue(fx, res);
|
ret.write_cvalue(fx, res);
|
||||||
};
|
};
|
||||||
llvm.x86.sse2.cmp.ps | llvm.x86.sse2.cmp.pd, (c x, c y, o kind) {
|
llvm.x86.sse2.cmp.ps | llvm.x86.sse2.cmp.pd, (c x, c y, o kind) {
|
||||||
|
|
|
@ -88,7 +88,7 @@ macro call_intrinsic_match {
|
||||||
let ($($arg,)*) = (
|
let ($($arg,)*) = (
|
||||||
$(trans_operand($fx, $arg),)*
|
$(trans_operand($fx, $arg),)*
|
||||||
);
|
);
|
||||||
let res = $fx.easy_call(stringify!($func), &[$($arg),*], $fx.codegen_cx.tcx.types.$ty);
|
let res = $fx.easy_call(stringify!($func), &[$($arg),*], $fx.cx.tcx.types.$ty);
|
||||||
$ret.write_cvalue($fx, res);
|
$ret.write_cvalue($fx, res);
|
||||||
|
|
||||||
if let Some((_, dest)) = $destination {
|
if let Some((_, dest)) = $destination {
|
||||||
|
@ -144,7 +144,7 @@ macro validate_atomic_type($fx:ident, $intrinsic:ident, $span:ident, $ty:expr) {
|
||||||
match $ty.kind {
|
match $ty.kind {
|
||||||
ty::Uint(_) | ty::Int(_) => {}
|
ty::Uint(_) | ty::Int(_) => {}
|
||||||
_ => {
|
_ => {
|
||||||
$fx.codegen_cx.tcx.sess.span_err($span, &format!("`{}` intrinsic: expected basic integer type, found `{:?}`", $intrinsic, $ty));
|
$fx.cx.tcx.sess.span_err($span, &format!("`{}` intrinsic: expected basic integer type, found `{:?}`", $intrinsic, $ty));
|
||||||
// Prevent verifier error
|
// Prevent verifier error
|
||||||
crate::trap::trap_unreachable($fx, "compilation should not have succeeded");
|
crate::trap::trap_unreachable($fx, "compilation should not have succeeded");
|
||||||
return;
|
return;
|
||||||
|
@ -154,7 +154,7 @@ macro validate_atomic_type($fx:ident, $intrinsic:ident, $span:ident, $ty:expr) {
|
||||||
|
|
||||||
macro validate_simd_type($fx:ident, $intrinsic:ident, $span:ident, $ty:expr) {
|
macro validate_simd_type($fx:ident, $intrinsic:ident, $span:ident, $ty:expr) {
|
||||||
if !$ty.is_simd() {
|
if !$ty.is_simd() {
|
||||||
$fx.codegen_cx.tcx.sess.span_err($span, &format!("invalid monomorphization of `{}` intrinsic: expected SIMD input type, found non-SIMD `{}`", $intrinsic, $ty));
|
$fx.cx.tcx.sess.span_err($span, &format!("invalid monomorphization of `{}` intrinsic: expected SIMD input type, found non-SIMD `{}`", $intrinsic, $ty));
|
||||||
// Prevent verifier error
|
// Prevent verifier error
|
||||||
crate::trap::trap_unreachable($fx, "compilation should not have succeeded");
|
crate::trap::trap_unreachable($fx, "compilation should not have succeeded");
|
||||||
return;
|
return;
|
||||||
|
@ -203,8 +203,8 @@ fn simd_for_each_lane<'tcx, B: Backend>(
|
||||||
) {
|
) {
|
||||||
let layout = val.layout();
|
let layout = val.layout();
|
||||||
|
|
||||||
let (lane_layout, lane_count) = lane_type_and_count(fx.codegen_cx.tcx, layout);
|
let (lane_layout, lane_count) = lane_type_and_count(fx.cx.tcx, layout);
|
||||||
let (ret_lane_layout, ret_lane_count) = lane_type_and_count(fx.codegen_cx.tcx, ret.layout());
|
let (ret_lane_layout, ret_lane_count) = lane_type_and_count(fx.cx.tcx, ret.layout());
|
||||||
assert_eq!(lane_count, ret_lane_count);
|
assert_eq!(lane_count, ret_lane_count);
|
||||||
|
|
||||||
for lane_idx in 0..lane_count {
|
for lane_idx in 0..lane_count {
|
||||||
|
@ -233,8 +233,8 @@ fn simd_pair_for_each_lane<'tcx, B: Backend>(
|
||||||
assert_eq!(x.layout(), y.layout());
|
assert_eq!(x.layout(), y.layout());
|
||||||
let layout = x.layout();
|
let layout = x.layout();
|
||||||
|
|
||||||
let (lane_layout, lane_count) = lane_type_and_count(fx.codegen_cx.tcx, layout);
|
let (lane_layout, lane_count) = lane_type_and_count(fx.cx.tcx, layout);
|
||||||
let (ret_lane_layout, ret_lane_count) = lane_type_and_count(fx.codegen_cx.tcx, ret.layout());
|
let (ret_lane_layout, ret_lane_count) = lane_type_and_count(fx.cx.tcx, ret.layout());
|
||||||
assert_eq!(lane_count, ret_lane_count);
|
assert_eq!(lane_count, ret_lane_count);
|
||||||
|
|
||||||
for lane in 0..lane_count {
|
for lane in 0..lane_count {
|
||||||
|
@ -273,7 +273,7 @@ fn bool_to_zero_or_max_uint<'tcx>(
|
||||||
|
|
||||||
macro simd_cmp {
|
macro simd_cmp {
|
||||||
($fx:expr, $cc:ident($x:ident, $y:ident) -> $ret:ident) => {
|
($fx:expr, $cc:ident($x:ident, $y:ident) -> $ret:ident) => {
|
||||||
let vector_ty = clif_vector_type($fx.codegen_cx.tcx, $x.layout());
|
let vector_ty = clif_vector_type($fx.cx.tcx, $x.layout());
|
||||||
|
|
||||||
if let Some(vector_ty) = vector_ty {
|
if let Some(vector_ty) = vector_ty {
|
||||||
let x = $x.load_scalar($fx);
|
let x = $x.load_scalar($fx);
|
||||||
|
@ -390,7 +390,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
|
||||||
let def_id = instance.def_id();
|
let def_id = instance.def_id();
|
||||||
let substs = instance.substs;
|
let substs = instance.substs;
|
||||||
|
|
||||||
let intrinsic = fx.codegen_cx.tcx.item_name(def_id).as_str();
|
let intrinsic = fx.cx.tcx.item_name(def_id).as_str();
|
||||||
let intrinsic = &intrinsic[..];
|
let intrinsic = &intrinsic[..];
|
||||||
|
|
||||||
let ret = match destination {
|
let ret = match destination {
|
||||||
|
@ -423,7 +423,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let usize_layout = fx.layout_of(fx.codegen_cx.tcx.types.usize);
|
let usize_layout = fx.layout_of(fx.cx.tcx.types.usize);
|
||||||
|
|
||||||
call_intrinsic_match! {
|
call_intrinsic_match! {
|
||||||
fx, intrinsic, substs, ret, destination, args,
|
fx, intrinsic, substs, ret, destination, args,
|
||||||
|
@ -473,7 +473,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
|
||||||
intrinsic_match! {
|
intrinsic_match! {
|
||||||
fx, intrinsic, substs, args,
|
fx, intrinsic, substs, args,
|
||||||
_ => {
|
_ => {
|
||||||
fx.codegen_cx.tcx.sess.span_fatal(span, &format!("unsupported intrinsic {}", intrinsic));
|
fx.cx.tcx.sess.span_fatal(span, &format!("unsupported intrinsic {}", intrinsic));
|
||||||
};
|
};
|
||||||
|
|
||||||
assume, (c _a) {};
|
assume, (c _a) {};
|
||||||
|
@ -494,10 +494,10 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
|
||||||
|
|
||||||
if intrinsic.contains("nonoverlapping") {
|
if intrinsic.contains("nonoverlapping") {
|
||||||
// FIXME emit_small_memcpy
|
// FIXME emit_small_memcpy
|
||||||
fx.bcx.call_memcpy(fx.codegen_cx.module.target_config(), dst, src, byte_amount);
|
fx.bcx.call_memcpy(fx.cx.module.target_config(), dst, src, byte_amount);
|
||||||
} else {
|
} else {
|
||||||
// FIXME emit_small_memmove
|
// FIXME emit_small_memmove
|
||||||
fx.bcx.call_memmove(fx.codegen_cx.module.target_config(), dst, src, byte_amount);
|
fx.bcx.call_memmove(fx.cx.module.target_config(), dst, src, byte_amount);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// NOTE: the volatile variants have src and dst swapped
|
// NOTE: the volatile variants have src and dst swapped
|
||||||
|
@ -513,10 +513,10 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
|
||||||
// FIXME make the copy actually volatile when using emit_small_mem{cpy,move}
|
// FIXME make the copy actually volatile when using emit_small_mem{cpy,move}
|
||||||
if intrinsic.contains("nonoverlapping") {
|
if intrinsic.contains("nonoverlapping") {
|
||||||
// FIXME emit_small_memcpy
|
// FIXME emit_small_memcpy
|
||||||
fx.bcx.call_memcpy(fx.codegen_cx.module.target_config(), dst, src, byte_amount);
|
fx.bcx.call_memcpy(fx.cx.module.target_config(), dst, src, byte_amount);
|
||||||
} else {
|
} else {
|
||||||
// FIXME emit_small_memmove
|
// FIXME emit_small_memmove
|
||||||
fx.bcx.call_memmove(fx.codegen_cx.module.target_config(), dst, src, byte_amount);
|
fx.bcx.call_memmove(fx.cx.module.target_config(), dst, src, byte_amount);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
discriminant_value, (c ptr) {
|
discriminant_value, (c ptr) {
|
||||||
|
@ -680,11 +680,11 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
|
||||||
let dst_ptr = dst.load_scalar(fx);
|
let dst_ptr = dst.load_scalar(fx);
|
||||||
// FIXME make the memset actually volatile when switching to emit_small_memset
|
// FIXME make the memset actually volatile when switching to emit_small_memset
|
||||||
// FIXME use emit_small_memset
|
// FIXME use emit_small_memset
|
||||||
fx.bcx.call_memset(fx.codegen_cx.module.target_config(), dst_ptr, val, count);
|
fx.bcx.call_memset(fx.cx.module.target_config(), dst_ptr, val, count);
|
||||||
};
|
};
|
||||||
ctlz | ctlz_nonzero, <T> (v arg) {
|
ctlz | ctlz_nonzero, <T> (v arg) {
|
||||||
// FIXME trap on `ctlz_nonzero` with zero arg.
|
// FIXME trap on `ctlz_nonzero` with zero arg.
|
||||||
let res = if T == fx.codegen_cx.tcx.types.u128 || T == fx.codegen_cx.tcx.types.i128 {
|
let res = if T == fx.cx.tcx.types.u128 || T == fx.cx.tcx.types.i128 {
|
||||||
// FIXME verify this algorithm is correct
|
// FIXME verify this algorithm is correct
|
||||||
let (lsb, msb) = fx.bcx.ins().isplit(arg);
|
let (lsb, msb) = fx.bcx.ins().isplit(arg);
|
||||||
let lsb_lz = fx.bcx.ins().clz(lsb);
|
let lsb_lz = fx.bcx.ins().clz(lsb);
|
||||||
|
@ -701,7 +701,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
|
||||||
};
|
};
|
||||||
cttz | cttz_nonzero, <T> (v arg) {
|
cttz | cttz_nonzero, <T> (v arg) {
|
||||||
// FIXME trap on `cttz_nonzero` with zero arg.
|
// FIXME trap on `cttz_nonzero` with zero arg.
|
||||||
let res = if T == fx.codegen_cx.tcx.types.u128 || T == fx.codegen_cx.tcx.types.i128 {
|
let res = if T == fx.cx.tcx.types.u128 || T == fx.cx.tcx.types.i128 {
|
||||||
// FIXME verify this algorithm is correct
|
// FIXME verify this algorithm is correct
|
||||||
let (lsb, msb) = fx.bcx.ins().isplit(arg);
|
let (lsb, msb) = fx.bcx.ins().isplit(arg);
|
||||||
let lsb_tz = fx.bcx.ins().ctz(lsb);
|
let lsb_tz = fx.bcx.ins().ctz(lsb);
|
||||||
|
@ -842,7 +842,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
|
||||||
|
|
||||||
size_of | pref_align_of | min_align_of | needs_drop | type_id | type_name | variant_count, () {
|
size_of | pref_align_of | min_align_of | needs_drop | type_id | type_name | variant_count, () {
|
||||||
let const_val =
|
let const_val =
|
||||||
fx.codegen_cx.tcx.const_eval_instance(ParamEnv::reveal_all(), instance, None).unwrap();
|
fx.cx.tcx.const_eval_instance(ParamEnv::reveal_all(), instance, None).unwrap();
|
||||||
let val = crate::constant::trans_const_value(
|
let val = crate::constant::trans_const_value(
|
||||||
fx,
|
fx,
|
||||||
const_val,
|
const_val,
|
||||||
|
@ -852,7 +852,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
|
||||||
};
|
};
|
||||||
|
|
||||||
ptr_offset_from, <T> (v ptr, v base) {
|
ptr_offset_from, <T> (v ptr, v base) {
|
||||||
let isize_layout = fx.layout_of(fx.codegen_cx.tcx.types.isize);
|
let isize_layout = fx.layout_of(fx.cx.tcx.types.isize);
|
||||||
|
|
||||||
let pointee_size: u64 = fx.layout_of(T).size.bytes();
|
let pointee_size: u64 = fx.layout_of(T).size.bytes();
|
||||||
let diff = fx.bcx.ins().isub(ptr, base);
|
let diff = fx.bcx.ins().isub(ptr, base);
|
||||||
|
@ -1011,22 +1011,22 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
|
||||||
|
|
||||||
minnumf32, (v a, v b) {
|
minnumf32, (v a, v b) {
|
||||||
let val = fx.bcx.ins().fmin(a, b);
|
let val = fx.bcx.ins().fmin(a, b);
|
||||||
let val = CValue::by_val(val, fx.layout_of(fx.codegen_cx.tcx.types.f32));
|
let val = CValue::by_val(val, fx.layout_of(fx.cx.tcx.types.f32));
|
||||||
ret.write_cvalue(fx, val);
|
ret.write_cvalue(fx, val);
|
||||||
};
|
};
|
||||||
minnumf64, (v a, v b) {
|
minnumf64, (v a, v b) {
|
||||||
let val = fx.bcx.ins().fmin(a, b);
|
let val = fx.bcx.ins().fmin(a, b);
|
||||||
let val = CValue::by_val(val, fx.layout_of(fx.codegen_cx.tcx.types.f64));
|
let val = CValue::by_val(val, fx.layout_of(fx.cx.tcx.types.f64));
|
||||||
ret.write_cvalue(fx, val);
|
ret.write_cvalue(fx, val);
|
||||||
};
|
};
|
||||||
maxnumf32, (v a, v b) {
|
maxnumf32, (v a, v b) {
|
||||||
let val = fx.bcx.ins().fmax(a, b);
|
let val = fx.bcx.ins().fmax(a, b);
|
||||||
let val = CValue::by_val(val, fx.layout_of(fx.codegen_cx.tcx.types.f32));
|
let val = CValue::by_val(val, fx.layout_of(fx.cx.tcx.types.f32));
|
||||||
ret.write_cvalue(fx, val);
|
ret.write_cvalue(fx, val);
|
||||||
};
|
};
|
||||||
maxnumf64, (v a, v b) {
|
maxnumf64, (v a, v b) {
|
||||||
let val = fx.bcx.ins().fmax(a, b);
|
let val = fx.bcx.ins().fmax(a, b);
|
||||||
let val = CValue::by_val(val, fx.layout_of(fx.codegen_cx.tcx.types.f64));
|
let val = CValue::by_val(val, fx.layout_of(fx.cx.tcx.types.f64));
|
||||||
ret.write_cvalue(fx, val);
|
ret.write_cvalue(fx, val);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -11,13 +11,13 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
|
||||||
let def_id = instance.def_id();
|
let def_id = instance.def_id();
|
||||||
let substs = instance.substs;
|
let substs = instance.substs;
|
||||||
|
|
||||||
let intrinsic = fx.codegen_cx.tcx.item_name(def_id).as_str();
|
let intrinsic = fx.cx.tcx.item_name(def_id).as_str();
|
||||||
let intrinsic = &intrinsic[..];
|
let intrinsic = &intrinsic[..];
|
||||||
|
|
||||||
intrinsic_match! {
|
intrinsic_match! {
|
||||||
fx, intrinsic, substs, args,
|
fx, intrinsic, substs, args,
|
||||||
_ => {
|
_ => {
|
||||||
fx.codegen_cx.tcx.sess.span_fatal(span, &format!("Unknown SIMD intrinsic {}", intrinsic));
|
fx.cx.tcx.sess.span_fatal(span, &format!("Unknown SIMD intrinsic {}", intrinsic));
|
||||||
};
|
};
|
||||||
|
|
||||||
simd_cast, (c a) {
|
simd_cast, (c a) {
|
||||||
|
@ -68,8 +68,8 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
|
||||||
assert_eq!(x.layout(), y.layout());
|
assert_eq!(x.layout(), y.layout());
|
||||||
let layout = x.layout();
|
let layout = x.layout();
|
||||||
|
|
||||||
let (lane_type, lane_count) = lane_type_and_count(fx.codegen_cx.tcx, layout);
|
let (lane_type, lane_count) = lane_type_and_count(fx.cx.tcx, layout);
|
||||||
let (ret_lane_type, ret_lane_count) = lane_type_and_count(fx.codegen_cx.tcx, ret.layout());
|
let (ret_lane_type, ret_lane_count) = lane_type_and_count(fx.cx.tcx, ret.layout());
|
||||||
|
|
||||||
assert_eq!(lane_type, ret_lane_type);
|
assert_eq!(lane_type, ret_lane_type);
|
||||||
assert_eq!(n, ret_lane_count);
|
assert_eq!(n, ret_lane_count);
|
||||||
|
@ -92,7 +92,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
|
||||||
(0..ret_lane_count).map(|i| {
|
(0..ret_lane_count).map(|i| {
|
||||||
let i = usize::try_from(i).unwrap();
|
let i = usize::try_from(i).unwrap();
|
||||||
let idx = rustc_middle::mir::interpret::read_target_uint(
|
let idx = rustc_middle::mir::interpret::read_target_uint(
|
||||||
fx.codegen_cx.tcx.data_layout.endian,
|
fx.cx.tcx.data_layout.endian,
|
||||||
&idx_bytes[4*i.. 4*i + 4],
|
&idx_bytes[4*i.. 4*i + 4],
|
||||||
).expect("read_target_uint");
|
).expect("read_target_uint");
|
||||||
u16::try_from(idx).expect("try_from u32")
|
u16::try_from(idx).expect("try_from u32")
|
||||||
|
@ -119,7 +119,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
|
||||||
let idx_const = if let Some(idx_const) = crate::constant::mir_operand_get_const_val(fx, idx) {
|
let idx_const = if let Some(idx_const) = crate::constant::mir_operand_get_const_val(fx, idx) {
|
||||||
idx_const
|
idx_const
|
||||||
} else {
|
} else {
|
||||||
fx.codegen_cx.tcx.sess.span_warn(
|
fx.cx.tcx.sess.span_warn(
|
||||||
fx.mir.span,
|
fx.mir.span,
|
||||||
"`#[rustc_arg_required_const(..)]` is not yet supported. Calling this function will panic.",
|
"`#[rustc_arg_required_const(..)]` is not yet supported. Calling this function will panic.",
|
||||||
);
|
);
|
||||||
|
@ -128,9 +128,9 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
|
||||||
};
|
};
|
||||||
|
|
||||||
let idx = idx_const.val.try_to_bits(Size::from_bytes(4 /* u32*/)).expect(&format!("kind not scalar: {:?}", idx_const));
|
let idx = idx_const.val.try_to_bits(Size::from_bytes(4 /* u32*/)).expect(&format!("kind not scalar: {:?}", idx_const));
|
||||||
let (_lane_type, lane_count) = lane_type_and_count(fx.codegen_cx.tcx, base.layout());
|
let (_lane_type, lane_count) = lane_type_and_count(fx.cx.tcx, base.layout());
|
||||||
if idx >= lane_count.into() {
|
if idx >= lane_count.into() {
|
||||||
fx.codegen_cx.tcx.sess.span_fatal(fx.mir.span, &format!("[simd_insert] idx {} >= lane_count {}", idx, lane_count));
|
fx.cx.tcx.sess.span_fatal(fx.mir.span, &format!("[simd_insert] idx {} >= lane_count {}", idx, lane_count));
|
||||||
}
|
}
|
||||||
|
|
||||||
ret.write_cvalue(fx, base);
|
ret.write_cvalue(fx, base);
|
||||||
|
@ -143,7 +143,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
|
||||||
let idx_const = if let Some(idx_const) = crate::constant::mir_operand_get_const_val(fx, idx) {
|
let idx_const = if let Some(idx_const) = crate::constant::mir_operand_get_const_val(fx, idx) {
|
||||||
idx_const
|
idx_const
|
||||||
} else {
|
} else {
|
||||||
fx.codegen_cx.tcx.sess.span_warn(
|
fx.cx.tcx.sess.span_warn(
|
||||||
fx.mir.span,
|
fx.mir.span,
|
||||||
"`#[rustc_arg_required_const(..)]` is not yet supported. Calling this function will panic.",
|
"`#[rustc_arg_required_const(..)]` is not yet supported. Calling this function will panic.",
|
||||||
);
|
);
|
||||||
|
@ -153,9 +153,9 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
|
||||||
};
|
};
|
||||||
|
|
||||||
let idx = idx_const.val.try_to_bits(Size::from_bytes(4 /* u32*/)).expect(&format!("kind not scalar: {:?}", idx_const));
|
let idx = idx_const.val.try_to_bits(Size::from_bytes(4 /* u32*/)).expect(&format!("kind not scalar: {:?}", idx_const));
|
||||||
let (_lane_type, lane_count) = lane_type_and_count(fx.codegen_cx.tcx, v.layout());
|
let (_lane_type, lane_count) = lane_type_and_count(fx.cx.tcx, v.layout());
|
||||||
if idx >= lane_count.into() {
|
if idx >= lane_count.into() {
|
||||||
fx.codegen_cx.tcx.sess.span_fatal(fx.mir.span, &format!("[simd_extract] idx {} >= lane_count {}", idx, lane_count));
|
fx.cx.tcx.sess.span_fatal(fx.mir.span, &format!("[simd_extract] idx {} >= lane_count {}", idx, lane_count));
|
||||||
}
|
}
|
||||||
|
|
||||||
let ret_lane = v.value_field(fx, mir::Field::new(idx.try_into().unwrap()));
|
let ret_lane = v.value_field(fx, mir::Field::new(idx.try_into().unwrap()));
|
||||||
|
@ -205,8 +205,8 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
|
||||||
assert_eq!(a.layout(), c.layout());
|
assert_eq!(a.layout(), c.layout());
|
||||||
let layout = a.layout();
|
let layout = a.layout();
|
||||||
|
|
||||||
let (_lane_layout, lane_count) = lane_type_and_count(fx.codegen_cx.tcx, layout);
|
let (_lane_layout, lane_count) = lane_type_and_count(fx.cx.tcx, layout);
|
||||||
let (ret_lane_layout, ret_lane_count) = lane_type_and_count(fx.codegen_cx.tcx, ret.layout());
|
let (ret_lane_layout, ret_lane_count) = lane_type_and_count(fx.cx.tcx, ret.layout());
|
||||||
assert_eq!(lane_count, ret_lane_count);
|
assert_eq!(lane_count, ret_lane_count);
|
||||||
|
|
||||||
for lane in 0..lane_count {
|
for lane in 0..lane_count {
|
||||||
|
|
16
src/num.rs
16
src/num.rs
|
@ -48,7 +48,7 @@ fn codegen_compare_bin_op<'tcx>(
|
||||||
let intcc = crate::num::bin_op_to_intcc(bin_op, signed).unwrap();
|
let intcc = crate::num::bin_op_to_intcc(bin_op, signed).unwrap();
|
||||||
let val = fx.bcx.ins().icmp(intcc, lhs, rhs);
|
let val = fx.bcx.ins().icmp(intcc, lhs, rhs);
|
||||||
let val = fx.bcx.ins().bint(types::I8, val);
|
let val = fx.bcx.ins().bint(types::I8, val);
|
||||||
CValue::by_val(val, fx.layout_of(fx.codegen_cx.tcx.types.bool))
|
CValue::by_val(val, fx.layout_of(fx.cx.tcx.types.bool))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn codegen_binop<'tcx>(
|
pub(crate) fn codegen_binop<'tcx>(
|
||||||
|
@ -66,8 +66,8 @@ pub(crate) fn codegen_binop<'tcx>(
|
||||||
let rhs = in_rhs.load_scalar(fx);
|
let rhs = in_rhs.load_scalar(fx);
|
||||||
|
|
||||||
let (lhs, rhs) = if (bin_op == BinOp::Eq || bin_op == BinOp::Ne)
|
let (lhs, rhs) = if (bin_op == BinOp::Eq || bin_op == BinOp::Ne)
|
||||||
&& (in_lhs.layout().ty.kind == fx.codegen_cx.tcx.types.i8.kind
|
&& (in_lhs.layout().ty.kind == fx.cx.tcx.types.i8.kind
|
||||||
|| in_lhs.layout().ty.kind == fx.codegen_cx.tcx.types.i16.kind)
|
|| in_lhs.layout().ty.kind == fx.cx.tcx.types.i16.kind)
|
||||||
{
|
{
|
||||||
// FIXME(CraneStation/cranelift#896) icmp_imm.i8/i16 with eq/ne for signed ints is implemented wrong.
|
// FIXME(CraneStation/cranelift#896) icmp_imm.i8/i16 with eq/ne for signed ints is implemented wrong.
|
||||||
(
|
(
|
||||||
|
@ -118,7 +118,7 @@ pub(crate) fn trans_bool_binop<'tcx>(
|
||||||
_ => unreachable!("{:?}({:?}, {:?})", bin_op, in_lhs, in_rhs),
|
_ => unreachable!("{:?}({:?}, {:?})", bin_op, in_lhs, in_rhs),
|
||||||
};
|
};
|
||||||
|
|
||||||
CValue::by_val(res, fx.layout_of(fx.codegen_cx.tcx.types.bool))
|
CValue::by_val(res, fx.layout_of(fx.cx.tcx.types.bool))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn trans_int_binop<'tcx>(
|
pub(crate) fn trans_int_binop<'tcx>(
|
||||||
|
@ -323,7 +323,7 @@ pub(crate) fn trans_checked_int_binop<'tcx>(
|
||||||
// FIXME directly write to result place instead
|
// FIXME directly write to result place instead
|
||||||
let out_place = CPlace::new_stack_slot(
|
let out_place = CPlace::new_stack_slot(
|
||||||
fx,
|
fx,
|
||||||
fx.layout_of(fx.codegen_cx.tcx.mk_tup([in_lhs.layout().ty, fx.codegen_cx.tcx.types.bool].iter())),
|
fx.layout_of(fx.cx.tcx.mk_tup([in_lhs.layout().ty, fx.cx.tcx.types.bool].iter())),
|
||||||
);
|
);
|
||||||
let out_layout = out_place.layout();
|
let out_layout = out_place.layout();
|
||||||
out_place.write_cvalue(fx, CValue::by_val_pair(res, has_overflow, out_layout));
|
out_place.write_cvalue(fx, CValue::by_val_pair(res, has_overflow, out_layout));
|
||||||
|
@ -368,7 +368,7 @@ pub(crate) fn trans_float_binop<'tcx>(
|
||||||
};
|
};
|
||||||
let val = fx.bcx.ins().fcmp(fltcc, lhs, rhs);
|
let val = fx.bcx.ins().fcmp(fltcc, lhs, rhs);
|
||||||
let val = fx.bcx.ins().bint(types::I8, val);
|
let val = fx.bcx.ins().bint(types::I8, val);
|
||||||
return CValue::by_val(val, fx.layout_of(fx.codegen_cx.tcx.types.bool));
|
return CValue::by_val(val, fx.layout_of(fx.cx.tcx.types.bool));
|
||||||
}
|
}
|
||||||
_ => unreachable!("{:?}({:?}, {:?})", bin_op, in_lhs, in_rhs),
|
_ => unreachable!("{:?}({:?}, {:?})", bin_op, in_lhs, in_rhs),
|
||||||
};
|
};
|
||||||
|
@ -383,7 +383,7 @@ pub(crate) fn trans_ptr_binop<'tcx>(
|
||||||
in_rhs: CValue<'tcx>,
|
in_rhs: CValue<'tcx>,
|
||||||
) -> CValue<'tcx> {
|
) -> CValue<'tcx> {
|
||||||
let is_thin_ptr = in_lhs.layout().ty.builtin_deref(true).map(|TypeAndMut { ty, mutbl: _}| {
|
let is_thin_ptr = in_lhs.layout().ty.builtin_deref(true).map(|TypeAndMut { ty, mutbl: _}| {
|
||||||
!has_ptr_meta(fx.codegen_cx.tcx, ty)
|
!has_ptr_meta(fx.cx.tcx, ty)
|
||||||
}).unwrap_or(true);
|
}).unwrap_or(true);
|
||||||
|
|
||||||
if is_thin_ptr {
|
if is_thin_ptr {
|
||||||
|
@ -440,7 +440,7 @@ pub(crate) fn trans_ptr_binop<'tcx>(
|
||||||
|
|
||||||
CValue::by_val(
|
CValue::by_val(
|
||||||
fx.bcx.ins().bint(types::I8, res),
|
fx.bcx.ins().bint(types::I8, res),
|
||||||
fx.layout_of(fx.codegen_cx.tcx.types.bool),
|
fx.layout_of(fx.cx.tcx.types.bool),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,24 +2,24 @@ use crate::prelude::*;
|
||||||
|
|
||||||
fn codegen_print(fx: &mut FunctionCx<'_, '_, impl cranelift_module::Backend>, msg: &str) {
|
fn codegen_print(fx: &mut FunctionCx<'_, '_, impl cranelift_module::Backend>, msg: &str) {
|
||||||
let puts = fx
|
let puts = fx
|
||||||
.codegen_cx.module
|
.cx.module
|
||||||
.declare_function(
|
.declare_function(
|
||||||
"puts",
|
"puts",
|
||||||
Linkage::Import,
|
Linkage::Import,
|
||||||
&Signature {
|
&Signature {
|
||||||
call_conv: CallConv::triple_default(fx.triple()),
|
call_conv: CallConv::triple_default(fx.triple()),
|
||||||
params: vec![AbiParam::new(pointer_ty(fx.codegen_cx.tcx))],
|
params: vec![AbiParam::new(pointer_ty(fx.cx.tcx))],
|
||||||
returns: vec![AbiParam::new(types::I32)],
|
returns: vec![AbiParam::new(types::I32)],
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let puts = fx.codegen_cx.module.declare_func_in_func(puts, &mut fx.bcx.func);
|
let puts = fx.cx.module.declare_func_in_func(puts, &mut fx.bcx.func);
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
{
|
{
|
||||||
fx.add_comment(puts, "puts");
|
fx.add_comment(puts, "puts");
|
||||||
}
|
}
|
||||||
|
|
||||||
let symbol_name = fx.codegen_cx.tcx.symbol_name(fx.instance);
|
let symbol_name = fx.cx.tcx.symbol_name(fx.instance);
|
||||||
let real_msg = format!("trap at {:?} ({}): {}\0", fx.instance, symbol_name, msg);
|
let real_msg = format!("trap at {:?} ({}): {}\0", fx.instance, symbol_name, msg);
|
||||||
let msg_ptr = fx.anonymous_str("trap", &real_msg);
|
let msg_ptr = fx.anonymous_str("trap", &real_msg);
|
||||||
fx.bcx.ins().call(puts, &[msg_ptr]);
|
fx.bcx.ins().call(puts, &[msg_ptr]);
|
||||||
|
|
|
@ -15,12 +15,12 @@ pub(crate) fn unsized_info<'tcx>(
|
||||||
old_info: Option<Value>,
|
old_info: Option<Value>,
|
||||||
) -> Value {
|
) -> Value {
|
||||||
let (source, target) =
|
let (source, target) =
|
||||||
fx.codegen_cx.tcx
|
fx.cx.tcx
|
||||||
.struct_lockstep_tails_erasing_lifetimes(source, target, ParamEnv::reveal_all());
|
.struct_lockstep_tails_erasing_lifetimes(source, target, ParamEnv::reveal_all());
|
||||||
match (&source.kind, &target.kind) {
|
match (&source.kind, &target.kind) {
|
||||||
(&ty::Array(_, len), &ty::Slice(_)) => fx.bcx.ins().iconst(
|
(&ty::Array(_, len), &ty::Slice(_)) => fx.bcx.ins().iconst(
|
||||||
fx.pointer_type,
|
fx.pointer_type,
|
||||||
len.eval_usize(fx.codegen_cx.tcx, ParamEnv::reveal_all()) as i64,
|
len.eval_usize(fx.cx.tcx, ParamEnv::reveal_all()) as i64,
|
||||||
),
|
),
|
||||||
(&ty::Dynamic(..), &ty::Dynamic(..)) => {
|
(&ty::Dynamic(..), &ty::Dynamic(..)) => {
|
||||||
// For now, upcasts are limited to changes in marker
|
// For now, upcasts are limited to changes in marker
|
||||||
|
|
|
@ -35,10 +35,10 @@ fn codegen_field<'tcx>(
|
||||||
let unaligned_offset = field_offset.bytes();
|
let unaligned_offset = field_offset.bytes();
|
||||||
let (_, unsized_align) = crate::unsize::size_and_align_of_dst(fx, field_layout, extra);
|
let (_, unsized_align) = crate::unsize::size_and_align_of_dst(fx, field_layout, extra);
|
||||||
|
|
||||||
let one = fx.bcx.ins().iconst(pointer_ty(fx.codegen_cx.tcx), 1);
|
let one = fx.bcx.ins().iconst(pointer_ty(fx.cx.tcx), 1);
|
||||||
let align_sub_1 = fx.bcx.ins().isub(unsized_align, one);
|
let align_sub_1 = fx.bcx.ins().isub(unsized_align, one);
|
||||||
let and_lhs = fx.bcx.ins().iadd_imm(align_sub_1, unaligned_offset as i64);
|
let and_lhs = fx.bcx.ins().iadd_imm(align_sub_1, unaligned_offset as i64);
|
||||||
let zero = fx.bcx.ins().iconst(pointer_ty(fx.codegen_cx.tcx), 0);
|
let zero = fx.bcx.ins().iconst(pointer_ty(fx.cx.tcx), 0);
|
||||||
let and_rhs = fx.bcx.ins().isub(zero, unsized_align);
|
let and_rhs = fx.bcx.ins().isub(zero, unsized_align);
|
||||||
let offset = fx.bcx.ins().band(and_lhs, and_rhs);
|
let offset = fx.bcx.ins().band(and_lhs, and_rhs);
|
||||||
|
|
||||||
|
@ -119,9 +119,9 @@ impl<'tcx> CValue<'tcx> {
|
||||||
match self.0 {
|
match self.0 {
|
||||||
CValueInner::ByRef(ptr, None) => {
|
CValueInner::ByRef(ptr, None) => {
|
||||||
let clif_ty = match layout.abi {
|
let clif_ty = match layout.abi {
|
||||||
Abi::Scalar(ref scalar) => scalar_to_clif_type(fx.codegen_cx.tcx, scalar.clone()),
|
Abi::Scalar(ref scalar) => scalar_to_clif_type(fx.cx.tcx, scalar.clone()),
|
||||||
Abi::Vector { ref element, count } => {
|
Abi::Vector { ref element, count } => {
|
||||||
scalar_to_clif_type(fx.codegen_cx.tcx, element.clone())
|
scalar_to_clif_type(fx.cx.tcx, element.clone())
|
||||||
.by(u16::try_from(count).unwrap()).unwrap()
|
.by(u16::try_from(count).unwrap()).unwrap()
|
||||||
}
|
}
|
||||||
_ => unreachable!("{:?}", layout.ty),
|
_ => unreachable!("{:?}", layout.ty),
|
||||||
|
@ -146,9 +146,9 @@ impl<'tcx> CValue<'tcx> {
|
||||||
Abi::ScalarPair(a, b) => (a, b),
|
Abi::ScalarPair(a, b) => (a, b),
|
||||||
_ => unreachable!("load_scalar_pair({:?})", self),
|
_ => unreachable!("load_scalar_pair({:?})", self),
|
||||||
};
|
};
|
||||||
let b_offset = scalar_pair_calculate_b_offset(fx.codegen_cx.tcx, a_scalar, b_scalar);
|
let b_offset = scalar_pair_calculate_b_offset(fx.cx.tcx, a_scalar, b_scalar);
|
||||||
let clif_ty1 = scalar_to_clif_type(fx.codegen_cx.tcx, a_scalar.clone());
|
let clif_ty1 = scalar_to_clif_type(fx.cx.tcx, a_scalar.clone());
|
||||||
let clif_ty2 = scalar_to_clif_type(fx.codegen_cx.tcx, b_scalar.clone());
|
let clif_ty2 = scalar_to_clif_type(fx.cx.tcx, b_scalar.clone());
|
||||||
let val1 = ptr.load(fx, clif_ty1, MemFlags::new());
|
let val1 = ptr.load(fx, clif_ty1, MemFlags::new());
|
||||||
let val2 = ptr.offset(fx, b_offset).load(fx, clif_ty2, MemFlags::new());
|
let val2 = ptr.offset(fx, b_offset).load(fx, clif_ty2, MemFlags::new());
|
||||||
(val1, val2)
|
(val1, val2)
|
||||||
|
@ -419,13 +419,13 @@ impl<'tcx> CPlace<'tcx> {
|
||||||
assert_assignable(fx, a, b);
|
assert_assignable(fx, a, b);
|
||||||
}
|
}
|
||||||
(ty::FnPtr(_), ty::FnPtr(_)) => {
|
(ty::FnPtr(_), ty::FnPtr(_)) => {
|
||||||
let from_sig = fx.codegen_cx.tcx.normalize_erasing_late_bound_regions(
|
let from_sig = fx.cx.tcx.normalize_erasing_late_bound_regions(
|
||||||
ParamEnv::reveal_all(),
|
ParamEnv::reveal_all(),
|
||||||
&from_ty.fn_sig(fx.codegen_cx.tcx),
|
&from_ty.fn_sig(fx.cx.tcx),
|
||||||
);
|
);
|
||||||
let to_sig = fx.codegen_cx.tcx.normalize_erasing_late_bound_regions(
|
let to_sig = fx.cx.tcx.normalize_erasing_late_bound_regions(
|
||||||
ParamEnv::reveal_all(),
|
ParamEnv::reveal_all(),
|
||||||
&to_ty.fn_sig(fx.codegen_cx.tcx),
|
&to_ty.fn_sig(fx.cx.tcx),
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
from_sig, to_sig,
|
from_sig, to_sig,
|
||||||
|
@ -436,10 +436,10 @@ impl<'tcx> CPlace<'tcx> {
|
||||||
}
|
}
|
||||||
(ty::Dynamic(from_traits, _), ty::Dynamic(to_traits, _)) => {
|
(ty::Dynamic(from_traits, _), ty::Dynamic(to_traits, _)) => {
|
||||||
let from_traits = fx
|
let from_traits = fx
|
||||||
.codegen_cx.tcx
|
.cx.tcx
|
||||||
.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), from_traits);
|
.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), from_traits);
|
||||||
let to_traits = fx
|
let to_traits = fx
|
||||||
.codegen_cx.tcx
|
.cx.tcx
|
||||||
.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), to_traits);
|
.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), to_traits);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
from_traits, to_traits,
|
from_traits, to_traits,
|
||||||
|
@ -569,7 +569,7 @@ impl<'tcx> CPlace<'tcx> {
|
||||||
}
|
}
|
||||||
Abi::ScalarPair(ref a_scalar, ref b_scalar) => {
|
Abi::ScalarPair(ref a_scalar, ref b_scalar) => {
|
||||||
let (value, extra) = from.load_scalar_pair(fx);
|
let (value, extra) = from.load_scalar_pair(fx);
|
||||||
let b_offset = scalar_pair_calculate_b_offset(fx.codegen_cx.tcx, a_scalar, b_scalar);
|
let b_offset = scalar_pair_calculate_b_offset(fx.cx.tcx, a_scalar, b_scalar);
|
||||||
to_ptr.store(fx, value, MemFlags::new());
|
to_ptr.store(fx, value, MemFlags::new());
|
||||||
to_ptr.offset(fx, b_offset).store(fx, extra, MemFlags::new());
|
to_ptr.offset(fx, b_offset).store(fx, extra, MemFlags::new());
|
||||||
return;
|
return;
|
||||||
|
@ -595,7 +595,7 @@ impl<'tcx> CPlace<'tcx> {
|
||||||
let src_align = src_layout.align.abi.bytes() as u8;
|
let src_align = src_layout.align.abi.bytes() as u8;
|
||||||
let dst_align = dst_layout.align.abi.bytes() as u8;
|
let dst_align = dst_layout.align.abi.bytes() as u8;
|
||||||
fx.bcx.emit_small_memory_copy(
|
fx.bcx.emit_small_memory_copy(
|
||||||
fx.codegen_cx.module.target_config(),
|
fx.cx.module.target_config(),
|
||||||
to_addr,
|
to_addr,
|
||||||
from_addr,
|
from_addr,
|
||||||
size,
|
size,
|
||||||
|
@ -673,7 +673,7 @@ impl<'tcx> CPlace<'tcx> {
|
||||||
|
|
||||||
pub(crate) fn place_deref(self, fx: &mut FunctionCx<'_, 'tcx, impl Backend>) -> CPlace<'tcx> {
|
pub(crate) fn place_deref(self, fx: &mut FunctionCx<'_, 'tcx, impl Backend>) -> CPlace<'tcx> {
|
||||||
let inner_layout = fx.layout_of(self.layout().ty.builtin_deref(true).unwrap().ty);
|
let inner_layout = fx.layout_of(self.layout().ty.builtin_deref(true).unwrap().ty);
|
||||||
if has_ptr_meta(fx.codegen_cx.tcx, inner_layout.ty) {
|
if has_ptr_meta(fx.cx.tcx, inner_layout.ty) {
|
||||||
let (addr, extra) = self.to_cvalue(fx).load_scalar_pair(fx);
|
let (addr, extra) = self.to_cvalue(fx).load_scalar_pair(fx);
|
||||||
CPlace::for_ptr_with_extra(Pointer::new(addr), extra, inner_layout)
|
CPlace::for_ptr_with_extra(Pointer::new(addr), extra, inner_layout)
|
||||||
} else {
|
} else {
|
||||||
|
@ -682,7 +682,7 @@ impl<'tcx> CPlace<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn write_place_ref(self, fx: &mut FunctionCx<'_, 'tcx, impl Backend>, dest: CPlace<'tcx>) {
|
pub(crate) fn write_place_ref(self, fx: &mut FunctionCx<'_, 'tcx, impl Backend>, dest: CPlace<'tcx>) {
|
||||||
if has_ptr_meta(fx.codegen_cx.tcx, self.layout().ty) {
|
if has_ptr_meta(fx.cx.tcx, self.layout().ty) {
|
||||||
let (ptr, extra) = self.to_ptr_maybe_unsized();
|
let (ptr, extra) = self.to_ptr_maybe_unsized();
|
||||||
let ptr = CValue::by_val_pair(
|
let ptr = CValue::by_val_pair(
|
||||||
ptr.get_addr(fx),
|
ptr.get_addr(fx),
|
||||||
|
|
|
@ -13,9 +13,9 @@ fn vtable_memflags() -> MemFlags {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn drop_fn_of_obj(fx: &mut FunctionCx<'_, '_, impl Backend>, vtable: Value) -> Value {
|
pub(crate) fn drop_fn_of_obj(fx: &mut FunctionCx<'_, '_, impl Backend>, vtable: Value) -> Value {
|
||||||
let usize_size = fx.layout_of(fx.codegen_cx.tcx.types.usize).size.bytes() as usize;
|
let usize_size = fx.layout_of(fx.cx.tcx.types.usize).size.bytes() as usize;
|
||||||
fx.bcx.ins().load(
|
fx.bcx.ins().load(
|
||||||
pointer_ty(fx.codegen_cx.tcx),
|
pointer_ty(fx.cx.tcx),
|
||||||
vtable_memflags(),
|
vtable_memflags(),
|
||||||
vtable,
|
vtable,
|
||||||
(DROP_FN_INDEX * usize_size) as i32,
|
(DROP_FN_INDEX * usize_size) as i32,
|
||||||
|
@ -23,9 +23,9 @@ pub(crate) fn drop_fn_of_obj(fx: &mut FunctionCx<'_, '_, impl Backend>, vtable:
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn size_of_obj(fx: &mut FunctionCx<'_, '_, impl Backend>, vtable: Value) -> Value {
|
pub(crate) fn size_of_obj(fx: &mut FunctionCx<'_, '_, impl Backend>, vtable: Value) -> Value {
|
||||||
let usize_size = fx.layout_of(fx.codegen_cx.tcx.types.usize).size.bytes() as usize;
|
let usize_size = fx.layout_of(fx.cx.tcx.types.usize).size.bytes() as usize;
|
||||||
fx.bcx.ins().load(
|
fx.bcx.ins().load(
|
||||||
pointer_ty(fx.codegen_cx.tcx),
|
pointer_ty(fx.cx.tcx),
|
||||||
vtable_memflags(),
|
vtable_memflags(),
|
||||||
vtable,
|
vtable,
|
||||||
(SIZE_INDEX * usize_size) as i32,
|
(SIZE_INDEX * usize_size) as i32,
|
||||||
|
@ -33,9 +33,9 @@ pub(crate) fn size_of_obj(fx: &mut FunctionCx<'_, '_, impl Backend>, vtable: Val
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn min_align_of_obj(fx: &mut FunctionCx<'_, '_, impl Backend>, vtable: Value) -> Value {
|
pub(crate) fn min_align_of_obj(fx: &mut FunctionCx<'_, '_, impl Backend>, vtable: Value) -> Value {
|
||||||
let usize_size = fx.layout_of(fx.codegen_cx.tcx.types.usize).size.bytes() as usize;
|
let usize_size = fx.layout_of(fx.cx.tcx.types.usize).size.bytes() as usize;
|
||||||
fx.bcx.ins().load(
|
fx.bcx.ins().load(
|
||||||
pointer_ty(fx.codegen_cx.tcx),
|
pointer_ty(fx.cx.tcx),
|
||||||
vtable_memflags(),
|
vtable_memflags(),
|
||||||
vtable,
|
vtable,
|
||||||
(ALIGN_INDEX * usize_size) as i32,
|
(ALIGN_INDEX * usize_size) as i32,
|
||||||
|
@ -57,9 +57,9 @@ pub(crate) fn get_ptr_and_method_ref<'tcx>(
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
let usize_size = fx.layout_of(fx.codegen_cx.tcx.types.usize).size.bytes();
|
let usize_size = fx.layout_of(fx.cx.tcx.types.usize).size.bytes();
|
||||||
let func_ref = fx.bcx.ins().load(
|
let func_ref = fx.bcx.ins().load(
|
||||||
pointer_ty(fx.codegen_cx.tcx),
|
pointer_ty(fx.cx.tcx),
|
||||||
vtable_memflags(),
|
vtable_memflags(),
|
||||||
vtable,
|
vtable,
|
||||||
((idx + 3) * usize_size as usize) as i32,
|
((idx + 3) * usize_size as usize) as i32,
|
||||||
|
@ -72,15 +72,15 @@ pub(crate) fn get_vtable<'tcx>(
|
||||||
layout: TyAndLayout<'tcx>,
|
layout: TyAndLayout<'tcx>,
|
||||||
trait_ref: Option<ty::PolyExistentialTraitRef<'tcx>>,
|
trait_ref: Option<ty::PolyExistentialTraitRef<'tcx>>,
|
||||||
) -> Value {
|
) -> Value {
|
||||||
let data_id = if let Some(data_id) = fx.codegen_cx.vtables.get(&(layout.ty, trait_ref)) {
|
let data_id = if let Some(data_id) = fx.cx.vtables.get(&(layout.ty, trait_ref)) {
|
||||||
*data_id
|
*data_id
|
||||||
} else {
|
} else {
|
||||||
let data_id = build_vtable(fx, layout, trait_ref);
|
let data_id = build_vtable(fx, layout, trait_ref);
|
||||||
fx.codegen_cx.vtables.insert((layout.ty, trait_ref), data_id);
|
fx.cx.vtables.insert((layout.ty, trait_ref), data_id);
|
||||||
data_id
|
data_id
|
||||||
};
|
};
|
||||||
|
|
||||||
let local_data_id = fx.codegen_cx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
|
let local_data_id = fx.cx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
|
||||||
fx.bcx.ins().global_value(fx.pointer_type, local_data_id)
|
fx.bcx.ins().global_value(fx.pointer_type, local_data_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,11 +89,11 @@ fn build_vtable<'tcx>(
|
||||||
layout: TyAndLayout<'tcx>,
|
layout: TyAndLayout<'tcx>,
|
||||||
trait_ref: Option<ty::PolyExistentialTraitRef<'tcx>>,
|
trait_ref: Option<ty::PolyExistentialTraitRef<'tcx>>,
|
||||||
) -> DataId {
|
) -> DataId {
|
||||||
let tcx = fx.codegen_cx.tcx;
|
let tcx = fx.cx.tcx;
|
||||||
let usize_size = fx.layout_of(fx.codegen_cx.tcx.types.usize).size.bytes() as usize;
|
let usize_size = fx.layout_of(fx.cx.tcx.types.usize).size.bytes() as usize;
|
||||||
|
|
||||||
let drop_in_place_fn =
|
let drop_in_place_fn =
|
||||||
import_function(tcx, &mut fx.codegen_cx.module, Instance::resolve_drop_in_place(tcx, layout.ty).polymorphize(fx.codegen_cx.tcx));
|
import_function(tcx, &mut fx.cx.module, Instance::resolve_drop_in_place(tcx, layout.ty).polymorphize(fx.cx.tcx));
|
||||||
|
|
||||||
let mut components: Vec<_> = vec![Some(drop_in_place_fn), None, None];
|
let mut components: Vec<_> = vec![Some(drop_in_place_fn), None, None];
|
||||||
|
|
||||||
|
@ -108,8 +108,8 @@ fn build_vtable<'tcx>(
|
||||||
opt_mth.map_or(None, |(def_id, substs)| {
|
opt_mth.map_or(None, |(def_id, substs)| {
|
||||||
Some(import_function(
|
Some(import_function(
|
||||||
tcx,
|
tcx,
|
||||||
&mut fx.codegen_cx.module,
|
&mut fx.cx.module,
|
||||||
Instance::resolve_for_vtable(tcx, ParamEnv::reveal_all(), def_id, substs).unwrap().polymorphize(fx.codegen_cx.tcx),
|
Instance::resolve_for_vtable(tcx, ParamEnv::reveal_all(), def_id, substs).unwrap().polymorphize(fx.cx.tcx),
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
@ -121,19 +121,19 @@ fn build_vtable<'tcx>(
|
||||||
.collect::<Vec<u8>>()
|
.collect::<Vec<u8>>()
|
||||||
.into_boxed_slice();
|
.into_boxed_slice();
|
||||||
|
|
||||||
write_usize(fx.codegen_cx.tcx, &mut data, SIZE_INDEX, layout.size.bytes());
|
write_usize(fx.cx.tcx, &mut data, SIZE_INDEX, layout.size.bytes());
|
||||||
write_usize(fx.codegen_cx.tcx, &mut data, ALIGN_INDEX, layout.align.abi.bytes());
|
write_usize(fx.cx.tcx, &mut data, ALIGN_INDEX, layout.align.abi.bytes());
|
||||||
data_ctx.define(data);
|
data_ctx.define(data);
|
||||||
|
|
||||||
for (i, component) in components.into_iter().enumerate() {
|
for (i, component) in components.into_iter().enumerate() {
|
||||||
if let Some(func_id) = component {
|
if let Some(func_id) = component {
|
||||||
let func_ref = fx.codegen_cx.module.declare_func_in_data(func_id, &mut data_ctx);
|
let func_ref = fx.cx.module.declare_func_in_data(func_id, &mut data_ctx);
|
||||||
data_ctx.write_function_addr((i * usize_size) as u32, func_ref);
|
data_ctx.write_function_addr((i * usize_size) as u32, func_ref);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let data_id = fx
|
let data_id = fx
|
||||||
.codegen_cx.module
|
.cx.module
|
||||||
.declare_data(
|
.declare_data(
|
||||||
&format!(
|
&format!(
|
||||||
"__vtable.{}.for.{:?}.{}",
|
"__vtable.{}.for.{:?}.{}",
|
||||||
|
@ -142,13 +142,13 @@ fn build_vtable<'tcx>(
|
||||||
.map(|trait_ref| format!("{:?}", trait_ref.skip_binder()).into())
|
.map(|trait_ref| format!("{:?}", trait_ref.skip_binder()).into())
|
||||||
.unwrap_or(std::borrow::Cow::Borrowed("???")),
|
.unwrap_or(std::borrow::Cow::Borrowed("???")),
|
||||||
layout.ty,
|
layout.ty,
|
||||||
fx.codegen_cx.vtables.len(),
|
fx.cx.vtables.len(),
|
||||||
),
|
),
|
||||||
Linkage::Local,
|
Linkage::Local,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
Some(
|
Some(
|
||||||
fx.codegen_cx.tcx
|
fx.cx.tcx
|
||||||
.data_layout
|
.data_layout
|
||||||
.pointer_align
|
.pointer_align
|
||||||
.pref
|
.pref
|
||||||
|
@ -159,7 +159,7 @@ fn build_vtable<'tcx>(
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
fx.codegen_cx.module.define_data(data_id, &data_ctx).unwrap();
|
fx.cx.module.define_data(data_id, &data_ctx).unwrap();
|
||||||
|
|
||||||
data_id
|
data_id
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue