Skip to content

Commit 2d33eea

Browse files
committed
cranelift: Emit argument location uses eagerly in gen_arg
This reverts the key parts of e3a08d4 (#8151), because it turns out that we didn't need that abstraction. Several changes in the last month have enabled this: - #8292 and then #8316 allow us to refer to either incoming or outgoing argument areas in a (mostly) consistent way - #8327, #8377, and #8383 demonstrate that we never need to delay writing stack arguments directly to their final location prtest:full
1 parent 47f2589 commit 2d33eea

File tree

3 files changed

+38
-67
lines changed

3 files changed

+38
-67
lines changed

cranelift/codegen/src/isa/x64/lower.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,7 @@ fn emit_vm_call(
178178
assert_eq!(inputs.len(), abi.num_args(ctx.sigs()));
179179

180180
for (i, input) in inputs.iter().enumerate() {
181-
let moves = abi.gen_arg(ctx, i, ValueRegs::one(*input));
182-
abi.emit_arg_moves(ctx, moves);
181+
abi.gen_arg(ctx, i, ValueRegs::one(*input));
183182
}
184183

185184
let mut retval_insts: SmallInstVec<_> = smallvec![];

cranelift/codegen/src/machinst/abi.rs

Lines changed: 36 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -2051,19 +2051,6 @@ impl<M: ABIMachineSpec> Callee<M> {
20512051
}
20522052
}
20532053

2054-
/// The register or stack slot location of an argument.
2055-
#[derive(Clone, Debug)]
2056-
pub enum ArgLoc {
2057-
/// The physical register that the value will be passed through.
2058-
Reg(PReg),
2059-
2060-
/// The offset into the argument area where this value will be passed. It's up to the consumer
2061-
/// of the `ArgLoc::Stack` variant to decide how to find the argument area that the `offset`
2062-
/// value is relative to. Depending on the abi, this may end up being relative to SP or FP, for
2063-
/// example with a tail call where the frame is reused.
2064-
Stack { offset: i64, ty: ir::Type },
2065-
}
2066-
20672054
/// An input argument to a call instruction: the vreg that is used,
20682055
/// and the preg it is constrained to (per the ABI).
20692056
#[derive(Clone, Debug)]
@@ -2298,38 +2285,17 @@ impl<M: ABIMachineSpec> CallSite<M> {
22982285
}
22992286
}
23002287

2301-
/// Emit moves or uses for the moves list generated by [`Self::gen_arg`].
2302-
pub fn emit_arg_moves(&mut self, ctx: &mut Lower<M::I>, moves: SmallVec<[(VReg, ArgLoc); 2]>) {
2303-
for (vreg, loc) in moves {
2304-
let vreg = vreg.into();
2305-
match loc {
2306-
ArgLoc::Reg(preg) => self.uses.push(CallArgPair {
2307-
vreg,
2308-
preg: preg.into(),
2309-
}),
2310-
ArgLoc::Stack { offset, ty } => {
2311-
let amode = if self.is_tail_call() {
2312-
StackAMode::IncomingArg(offset, ctx.sigs()[self.sig].sized_stack_arg_space)
2313-
} else {
2314-
StackAMode::OutgoingArg(offset)
2315-
};
2316-
ctx.emit(M::gen_store_stack(amode, vreg, ty))
2317-
}
2318-
}
2319-
}
2320-
}
2321-
23222288
/// Add a constraint for an argument value from a source register.
23232289
/// For large arguments with associated stack buffer, this may
23242290
/// load the address of the buffer into the argument register, if
23252291
/// required by the ABI.
2326-
pub fn gen_arg(
2327-
&mut self,
2328-
ctx: &mut Lower<M::I>,
2329-
idx: usize,
2330-
from_regs: ValueRegs<Reg>,
2331-
) -> SmallVec<[(VReg, ArgLoc); 2]> {
2332-
let mut locs = smallvec![];
2292+
pub fn gen_arg(&mut self, ctx: &mut Lower<M::I>, idx: usize, from_regs: ValueRegs<Reg>) {
2293+
let stack_arg_space = ctx.sigs()[self.sig].sized_stack_arg_space;
2294+
let stack_arg = if self.is_tail_call() {
2295+
StackAMode::IncomingArg
2296+
} else {
2297+
|offset, _| StackAMode::OutgoingArg(offset)
2298+
};
23332299
let word_rc = M::word_reg_class();
23342300
let word_bits = M::word_bits() as usize;
23352301

@@ -2342,7 +2308,9 @@ impl<M: ABIMachineSpec> CallSite<M> {
23422308
reg, ty, extension, ..
23432309
} => {
23442310
let ext = M::get_ext_mode(ctx.sigs()[self.sig].call_conv, extension);
2345-
if ext != ir::ArgumentExtension::None && ty_bits(ty) < word_bits {
2311+
let vreg = if ext != ir::ArgumentExtension::None
2312+
&& ty_bits(ty) < word_bits
2313+
{
23462314
assert_eq!(word_rc, reg.class());
23472315
let signed = match ext {
23482316
ir::ArgumentExtension::Uext => false,
@@ -2358,7 +2326,7 @@ impl<M: ABIMachineSpec> CallSite<M> {
23582326
ty_bits(ty) as u8,
23592327
word_bits as u8,
23602328
));
2361-
locs.push((extend_result.to_reg().into(), ArgLoc::Reg(reg.into())));
2329+
extend_result.to_reg()
23622330
} else if ty.is_ref() {
23632331
// Reference-typed args need to be
23642332
// passed as a copy; the original vreg
@@ -2367,10 +2335,13 @@ impl<M: ABIMachineSpec> CallSite<M> {
23672335
let ref_copy = ctx.alloc_tmp(M::word_type()).only_reg().unwrap();
23682336
ctx.emit(M::gen_move(ref_copy, *from_reg, M::word_type()));
23692337

2370-
locs.push((ref_copy.to_reg().into(), ArgLoc::Reg(reg.into())));
2338+
ref_copy.to_reg()
23712339
} else {
2372-
locs.push((from_reg.into(), ArgLoc::Reg(reg.into())));
2373-
}
2340+
*from_reg
2341+
};
2342+
2343+
let preg = reg.into();
2344+
self.uses.push(CallArgPair { vreg, preg });
23742345
}
23752346
&ABIArgSlot::Stack {
23762347
offset,
@@ -2401,7 +2372,11 @@ impl<M: ABIMachineSpec> CallSite<M> {
24012372
} else {
24022373
(*from_reg, ty)
24032374
};
2404-
locs.push((data.into(), ArgLoc::Stack { offset, ty }));
2375+
ctx.emit(M::gen_store_stack(
2376+
stack_arg(offset, stack_arg_space),
2377+
data,
2378+
ty,
2379+
));
24052380
}
24062381
}
24072382
}
@@ -2422,18 +2397,19 @@ impl<M: ABIMachineSpec> CallSite<M> {
24222397
ctx.emit(M::gen_get_stack_addr(amode, tmp));
24232398
let tmp = tmp.to_reg();
24242399
ctx.emit(M::gen_store_base_offset(tmp, 0, vreg, ty));
2425-
let loc = match pointer {
2426-
ABIArgSlot::Reg { reg, .. } => ArgLoc::Reg(reg.into()),
2427-
ABIArgSlot::Stack { offset, .. } => {
2428-
let ty = M::word_type();
2429-
ArgLoc::Stack { offset, ty }
2430-
}
2431-
};
2432-
locs.push((tmp.into(), loc));
2400+
match pointer {
2401+
ABIArgSlot::Reg { reg, .. } => self.uses.push(CallArgPair {
2402+
vreg: tmp,
2403+
preg: reg.into(),
2404+
}),
2405+
ABIArgSlot::Stack { offset, .. } => ctx.emit(M::gen_store_stack(
2406+
stack_arg(offset, stack_arg_space),
2407+
tmp,
2408+
M::word_type(),
2409+
)),
2410+
}
24332411
}
24342412
}
2435-
2436-
locs
24372413
}
24382414

24392415
/// Call `gen_arg` for each non-hidden argument and emit all instructions
@@ -2451,8 +2427,7 @@ impl<M: ABIMachineSpec> CallSite<M> {
24512427
self.emit_copy_regs_to_buffer(ctx, i, *arg_regs);
24522428
}
24532429
for (i, value_regs) in arg_value_regs.iter().enumerate() {
2454-
let moves = self.gen_arg(ctx, i, *value_regs);
2455-
self.emit_arg_moves(ctx, moves);
2430+
self.gen_arg(ctx, i, *value_regs);
24562431
}
24572432
}
24582433

@@ -2464,8 +2439,7 @@ impl<M: ABIMachineSpec> CallSite<M> {
24642439
"if the tail callee has a return pointer, then the tail caller \
24652440
must as well",
24662441
);
2467-
let moves = self.gen_arg(ctx, i.into(), ValueRegs::one(ret_area_ptr.to_reg()));
2468-
self.emit_arg_moves(ctx, moves);
2442+
self.gen_arg(ctx, i.into(), ValueRegs::one(ret_area_ptr.to_reg()));
24692443
}
24702444
}
24712445

@@ -2564,8 +2538,7 @@ impl<M: ABIMachineSpec> CallSite<M> {
25642538
StackAMode::OutgoingArg(ret_area_base),
25652539
rd,
25662540
));
2567-
let moves = self.gen_arg(ctx, i.into(), ValueRegs::one(rd.to_reg()));
2568-
self.emit_arg_moves(ctx, moves);
2541+
self.gen_arg(ctx, i.into(), ValueRegs::one(rd.to_reg()));
25692542
}
25702543

25712544
let (uses, defs) = (

cranelift/codegen/src/machinst/isle.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -826,8 +826,7 @@ macro_rules! isle_prelude_method_helpers {
826826
call_site.emit_copy_regs_to_buffer(self.lower_ctx, i, *arg_regs);
827827
}
828828
for (i, arg_regs) in arg_regs.iter().enumerate() {
829-
let moves = call_site.gen_arg(self.lower_ctx, i, *arg_regs);
830-
call_site.emit_arg_moves(self.lower_ctx, moves);
829+
call_site.gen_arg(self.lower_ctx, i, *arg_regs);
831830
}
832831
}
833832

0 commit comments

Comments
 (0)