Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit cdf4f42

Browse files
committed
Remove easy_call
1 parent 718574a commit cdf4f42

File tree

6 files changed

+100
-115
lines changed

6 files changed

+100
-115
lines changed

src/abi/mod.rs

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -125,42 +125,12 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> {
125125
}
126126
let call_inst = self.bcx.ins().call(func_ref, args);
127127
if self.clif_comments.enabled() {
128-
self.add_comment(call_inst, format!("easy_call {}", name));
128+
self.add_comment(call_inst, format!("lib_call {}", name));
129129
}
130130
let results = self.bcx.inst_results(call_inst);
131131
assert!(results.len() <= 2, "{}", results.len());
132132
results
133133
}
134-
135-
pub(crate) fn easy_call(
136-
&mut self,
137-
name: &str,
138-
args: &[CValue<'tcx>],
139-
return_ty: Ty<'tcx>,
140-
) -> CValue<'tcx> {
141-
let (input_tys, args): (Vec<_>, Vec<_>) = args
142-
.iter()
143-
.map(|arg| {
144-
(AbiParam::new(self.clif_type(arg.layout().ty).unwrap()), arg.load_scalar(self))
145-
})
146-
.unzip();
147-
let return_layout = self.layout_of(return_ty);
148-
let return_tys = if let ty::Tuple(tup) = return_ty.kind() {
149-
tup.iter().map(|ty| AbiParam::new(self.clif_type(ty).unwrap())).collect()
150-
} else {
151-
vec![AbiParam::new(self.clif_type(return_ty).unwrap())]
152-
};
153-
let ret_vals = self.lib_call(name, input_tys, return_tys, &args);
154-
match *ret_vals {
155-
[] => CValue::by_ref(
156-
Pointer::const_addr(self, i64::from(self.pointer_type.bytes())),
157-
return_layout,
158-
),
159-
[val] => CValue::by_val(val, return_layout),
160-
[val, extra] => CValue::by_val_pair(val, extra, return_layout),
161-
_ => unreachable!(),
162-
}
163-
}
164134
}
165135

166136
/// Make a [`CPlace`] capable of holding value of the specified type.

src/cast.rs

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,12 @@ pub(crate) fn clif_int_or_float_cast(
6464
},
6565
);
6666

67-
let from_rust_ty = if from_signed { fx.tcx.types.i128 } else { fx.tcx.types.u128 };
68-
69-
let to_rust_ty = match to_ty {
70-
types::F32 => fx.tcx.types.f32,
71-
types::F64 => fx.tcx.types.f64,
72-
_ => unreachable!(),
73-
};
74-
75-
return fx
76-
.easy_call(&name, &[CValue::by_val(from, fx.layout_of(from_rust_ty))], to_rust_ty)
77-
.load_scalar(fx);
67+
return fx.lib_call(
68+
&name,
69+
vec![AbiParam::new(types::I128)],
70+
vec![AbiParam::new(to_ty)],
71+
&[from],
72+
)[0];
7873
}
7974

8075
// int-like -> float
@@ -101,16 +96,12 @@ pub(crate) fn clif_int_or_float_cast(
10196
},
10297
);
10398

104-
let from_rust_ty = match from_ty {
105-
types::F32 => fx.tcx.types.f32,
106-
types::F64 => fx.tcx.types.f64,
107-
_ => unreachable!(),
108-
};
109-
110-
let to_rust_ty = if to_signed { fx.tcx.types.i128 } else { fx.tcx.types.u128 };
111-
112-
fx.easy_call(&name, &[CValue::by_val(from, fx.layout_of(from_rust_ty))], to_rust_ty)
113-
.load_scalar(fx)
99+
fx.lib_call(
100+
&name,
101+
vec![AbiParam::new(from_ty)],
102+
vec![AbiParam::new(types::I128)],
103+
&[from],
104+
)[0]
114105
} else if to_ty == types::I8 || to_ty == types::I16 {
115106
// FIXME implement fcvt_to_*int_sat.i8/i16
116107
let val = if to_signed {

src/codegen_i128.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,14 @@ pub(crate) fn maybe_codegen<'tcx>(
5353
);
5454
Some(ret_place.to_cvalue(fx))
5555
} else {
56-
Some(fx.easy_call("__multi3", &[lhs, rhs], val_ty))
56+
let args: Vec<_> = vec![lhs.load_scalar(fx), rhs.load_scalar(fx)];
57+
let ret_val = fx.lib_call(
58+
"__multi3",
59+
vec![AbiParam::new(types::I128), AbiParam::new(types::I128)],
60+
vec![AbiParam::new(types::I128)],
61+
&args,
62+
)[0];
63+
Some(CValue::by_val(ret_val, fx.layout_of(val_ty)))
5764
}
5865
} else {
5966
let out_ty = fx.tcx.mk_tup([lhs.layout().ty, fx.tcx.types.bool].iter());
@@ -141,7 +148,14 @@ pub(crate) fn maybe_codegen<'tcx>(
141148
ret_place.to_ptr().store(fx, ret, MemFlags::trusted());
142149
Some(ret_place.to_cvalue(fx))
143150
} else {
144-
Some(fx.easy_call(name, &[lhs, rhs], lhs.layout().ty))
151+
let args: Vec<_> = vec![lhs.load_scalar(fx), rhs.load_scalar(fx)];
152+
let ret_val = fx.lib_call(
153+
name,
154+
vec![AbiParam::new(types::I128), AbiParam::new(types::I128)],
155+
vec![AbiParam::new(types::I128)],
156+
&args,
157+
)[0];
158+
Some(CValue::by_val(ret_val, lhs.layout()))
145159
}
146160
}
147161
BinOp::Lt | BinOp::Le | BinOp::Eq | BinOp::Ge | BinOp::Gt | BinOp::Ne => {

src/intrinsics/mod.rs

Lines changed: 59 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -251,41 +251,41 @@ fn codegen_float_intrinsic_call<'tcx>(
251251
args: &[mir::Operand<'tcx>],
252252
ret: CPlace<'tcx>,
253253
) -> bool {
254-
let (name, arg_count, ty) = match intrinsic {
255-
sym::expf32 => ("expf", 1, fx.tcx.types.f32),
256-
sym::expf64 => ("exp", 1, fx.tcx.types.f64),
257-
sym::exp2f32 => ("exp2f", 1, fx.tcx.types.f32),
258-
sym::exp2f64 => ("exp2", 1, fx.tcx.types.f64),
259-
sym::sqrtf32 => ("sqrtf", 1, fx.tcx.types.f32),
260-
sym::sqrtf64 => ("sqrt", 1, fx.tcx.types.f64),
261-
sym::powif32 => ("__powisf2", 2, fx.tcx.types.f32), // compiler-builtins
262-
sym::powif64 => ("__powidf2", 2, fx.tcx.types.f64), // compiler-builtins
263-
sym::powf32 => ("powf", 2, fx.tcx.types.f32),
264-
sym::powf64 => ("pow", 2, fx.tcx.types.f64),
265-
sym::logf32 => ("logf", 1, fx.tcx.types.f32),
266-
sym::logf64 => ("log", 1, fx.tcx.types.f64),
267-
sym::log2f32 => ("log2f", 1, fx.tcx.types.f32),
268-
sym::log2f64 => ("log2", 1, fx.tcx.types.f64),
269-
sym::log10f32 => ("log10f", 1, fx.tcx.types.f32),
270-
sym::log10f64 => ("log10", 1, fx.tcx.types.f64),
271-
sym::fabsf32 => ("fabsf", 1, fx.tcx.types.f32),
272-
sym::fabsf64 => ("fabs", 1, fx.tcx.types.f64),
273-
sym::fmaf32 => ("fmaf", 3, fx.tcx.types.f32),
274-
sym::fmaf64 => ("fma", 3, fx.tcx.types.f64),
275-
sym::copysignf32 => ("copysignf", 2, fx.tcx.types.f32),
276-
sym::copysignf64 => ("copysign", 2, fx.tcx.types.f64),
277-
sym::floorf32 => ("floorf", 1, fx.tcx.types.f32),
278-
sym::floorf64 => ("floor", 1, fx.tcx.types.f64),
279-
sym::ceilf32 => ("ceilf", 1, fx.tcx.types.f32),
280-
sym::ceilf64 => ("ceil", 1, fx.tcx.types.f64),
281-
sym::truncf32 => ("truncf", 1, fx.tcx.types.f32),
282-
sym::truncf64 => ("trunc", 1, fx.tcx.types.f64),
283-
sym::roundf32 => ("roundf", 1, fx.tcx.types.f32),
284-
sym::roundf64 => ("round", 1, fx.tcx.types.f64),
285-
sym::sinf32 => ("sinf", 1, fx.tcx.types.f32),
286-
sym::sinf64 => ("sin", 1, fx.tcx.types.f64),
287-
sym::cosf32 => ("cosf", 1, fx.tcx.types.f32),
288-
sym::cosf64 => ("cos", 1, fx.tcx.types.f64),
254+
let (name, arg_count, ty, clif_ty) = match intrinsic {
255+
sym::expf32 => ("expf", 1, fx.tcx.types.f32, types::F32),
256+
sym::expf64 => ("exp", 1, fx.tcx.types.f64, types::F64),
257+
sym::exp2f32 => ("exp2f", 1, fx.tcx.types.f32, types::F32),
258+
sym::exp2f64 => ("exp2", 1, fx.tcx.types.f64, types::F64),
259+
sym::sqrtf32 => ("sqrtf", 1, fx.tcx.types.f32, types::F32),
260+
sym::sqrtf64 => ("sqrt", 1, fx.tcx.types.f64, types::F64),
261+
sym::powif32 => ("__powisf2", 2, fx.tcx.types.f32, types::F32), // compiler-builtins
262+
sym::powif64 => ("__powidf2", 2, fx.tcx.types.f64, types::F64), // compiler-builtins
263+
sym::powf32 => ("powf", 2, fx.tcx.types.f32, types::F32),
264+
sym::powf64 => ("pow", 2, fx.tcx.types.f64, types::F64),
265+
sym::logf32 => ("logf", 1, fx.tcx.types.f32, types::F32),
266+
sym::logf64 => ("log", 1, fx.tcx.types.f64, types::F64),
267+
sym::log2f32 => ("log2f", 1, fx.tcx.types.f32, types::F32),
268+
sym::log2f64 => ("log2", 1, fx.tcx.types.f64, types::F64),
269+
sym::log10f32 => ("log10f", 1, fx.tcx.types.f32, types::F32),
270+
sym::log10f64 => ("log10", 1, fx.tcx.types.f64, types::F64),
271+
sym::fabsf32 => ("fabsf", 1, fx.tcx.types.f32, types::F32),
272+
sym::fabsf64 => ("fabs", 1, fx.tcx.types.f64, types::F64),
273+
sym::fmaf32 => ("fmaf", 3, fx.tcx.types.f32, types::F32),
274+
sym::fmaf64 => ("fma", 3, fx.tcx.types.f64, types::F64),
275+
sym::copysignf32 => ("copysignf", 2, fx.tcx.types.f32, types::F32),
276+
sym::copysignf64 => ("copysign", 2, fx.tcx.types.f64, types::F64),
277+
sym::floorf32 => ("floorf", 1, fx.tcx.types.f32, types::F32),
278+
sym::floorf64 => ("floor", 1, fx.tcx.types.f64, types::F64),
279+
sym::ceilf32 => ("ceilf", 1, fx.tcx.types.f32, types::F32),
280+
sym::ceilf64 => ("ceil", 1, fx.tcx.types.f64, types::F64),
281+
sym::truncf32 => ("truncf", 1, fx.tcx.types.f32, types::F32),
282+
sym::truncf64 => ("trunc", 1, fx.tcx.types.f64, types::F64),
283+
sym::roundf32 => ("roundf", 1, fx.tcx.types.f32, types::F32),
284+
sym::roundf64 => ("round", 1, fx.tcx.types.f64, types::F64),
285+
sym::sinf32 => ("sinf", 1, fx.tcx.types.f32, types::F32),
286+
sym::sinf64 => ("sin", 1, fx.tcx.types.f64, types::F64),
287+
sym::cosf32 => ("cosf", 1, fx.tcx.types.f32, types::F32),
288+
sym::cosf64 => ("cos", 1, fx.tcx.types.f64, types::F64),
289289
_ => return false,
290290
};
291291

@@ -296,15 +296,19 @@ fn codegen_float_intrinsic_call<'tcx>(
296296
let (a, b, c);
297297
let args = match args {
298298
[x] => {
299-
a = [codegen_operand(fx, x)];
299+
a = [codegen_operand(fx, x).load_scalar(fx)];
300300
&a as &[_]
301301
}
302302
[x, y] => {
303-
b = [codegen_operand(fx, x), codegen_operand(fx, y)];
303+
b = [codegen_operand(fx, x).load_scalar(fx), codegen_operand(fx, y).load_scalar(fx)];
304304
&b
305305
}
306306
[x, y, z] => {
307-
c = [codegen_operand(fx, x), codegen_operand(fx, y), codegen_operand(fx, z)];
307+
c = [
308+
codegen_operand(fx, x).load_scalar(fx),
309+
codegen_operand(fx, y).load_scalar(fx),
310+
codegen_operand(fx, z).load_scalar(fx),
311+
];
308312
&c
309313
}
310314
_ => unreachable!(),
@@ -313,15 +317,10 @@ fn codegen_float_intrinsic_call<'tcx>(
313317
let layout = fx.layout_of(ty);
314318
let res = match intrinsic {
315319
sym::fmaf32 | sym::fmaf64 => {
316-
let a = args[0].load_scalar(fx);
317-
let b = args[1].load_scalar(fx);
318-
let c = args[2].load_scalar(fx);
319-
CValue::by_val(fx.bcx.ins().fma(a, b, c), layout)
320+
CValue::by_val(fx.bcx.ins().fma(args[0], args[1], args[2]), layout)
320321
}
321322
sym::copysignf32 | sym::copysignf64 => {
322-
let a = args[0].load_scalar(fx);
323-
let b = args[1].load_scalar(fx);
324-
CValue::by_val(fx.bcx.ins().fcopysign(a, b), layout)
323+
CValue::by_val(fx.bcx.ins().fcopysign(args[0], args[1]), layout)
325324
}
326325
sym::fabsf32
327326
| sym::fabsf64
@@ -331,21 +330,29 @@ fn codegen_float_intrinsic_call<'tcx>(
331330
| sym::ceilf64
332331
| sym::truncf32
333332
| sym::truncf64 => {
334-
let a = args[0].load_scalar(fx);
335-
336333
let val = match intrinsic {
337-
sym::fabsf32 | sym::fabsf64 => fx.bcx.ins().fabs(a),
338-
sym::floorf32 | sym::floorf64 => fx.bcx.ins().floor(a),
339-
sym::ceilf32 | sym::ceilf64 => fx.bcx.ins().ceil(a),
340-
sym::truncf32 | sym::truncf64 => fx.bcx.ins().trunc(a),
334+
sym::fabsf32 | sym::fabsf64 => fx.bcx.ins().fabs(args[0]),
335+
sym::floorf32 | sym::floorf64 => fx.bcx.ins().floor(args[0]),
336+
sym::ceilf32 | sym::ceilf64 => fx.bcx.ins().ceil(args[0]),
337+
sym::truncf32 | sym::truncf64 => fx.bcx.ins().trunc(args[0]),
341338
_ => unreachable!(),
342339
};
343340

344341
CValue::by_val(val, layout)
345342
}
343+
346344
// These intrinsics aren't supported natively by Cranelift.
347345
// Lower them to a libcall.
348-
_ => fx.easy_call(name, &args, ty),
346+
sym::powif32 | sym::powif64 => {
347+
let input_tys: Vec<_> = vec![AbiParam::new(clif_ty), AbiParam::new(types::I32)];
348+
let ret_val = fx.lib_call(name, input_tys, vec![AbiParam::new(clif_ty)], &args)[0];
349+
CValue::by_val(ret_val, fx.layout_of(ty))
350+
}
351+
_ => {
352+
let input_tys: Vec<_> = args.iter().map(|_| AbiParam::new(clif_ty)).collect();
353+
let ret_val = fx.lib_call(name, input_tys, vec![AbiParam::new(clif_ty)], &args)[0];
354+
CValue::by_val(ret_val, fx.layout_of(ty))
355+
}
349356
};
350357

351358
ret.write_cvalue(fx, res);

src/num.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,12 +347,20 @@ pub(crate) fn codegen_float_binop<'tcx>(
347347
BinOp::Mul => b.fmul(lhs, rhs),
348348
BinOp::Div => b.fdiv(lhs, rhs),
349349
BinOp::Rem => {
350-
let name = match in_lhs.layout().ty.kind() {
351-
ty::Float(FloatTy::F32) => "fmodf",
352-
ty::Float(FloatTy::F64) => "fmod",
350+
let (name, ty) = match in_lhs.layout().ty.kind() {
351+
ty::Float(FloatTy::F32) => ("fmodf", types::F32),
352+
ty::Float(FloatTy::F64) => ("fmod", types::F64),
353353
_ => bug!(),
354354
};
355-
return fx.easy_call(name, &[in_lhs, in_rhs], in_lhs.layout().ty);
355+
356+
let ret_val = fx.lib_call(
357+
name,
358+
vec![AbiParam::new(ty), AbiParam::new(ty)],
359+
vec![AbiParam::new(ty)],
360+
&[lhs, rhs],
361+
)[0];
362+
363+
return CValue::by_val(ret_val, in_lhs.layout());
356364
}
357365
BinOp::Eq | BinOp::Lt | BinOp::Le | BinOp::Ne | BinOp::Ge | BinOp::Gt => {
358366
let fltcc = match bin_op {

src/pointer.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ impl Pointer {
3030
Pointer { base: PointerBase::Stack(stack_slot), offset: Offset32::new(0) }
3131
}
3232

33-
pub(crate) fn const_addr(fx: &mut FunctionCx<'_, '_, '_>, addr: i64) -> Self {
34-
let addr = fx.bcx.ins().iconst(fx.pointer_type, addr);
35-
Pointer { base: PointerBase::Addr(addr), offset: Offset32::new(0) }
36-
}
37-
3833
pub(crate) fn dangling(align: Align) -> Self {
3934
Pointer { base: PointerBase::Dangling(align), offset: Offset32::new(0) }
4035
}

0 commit comments

Comments
 (0)