Skip to content

Commit 2652900

Browse files
committed
Address review comments.
1 parent 08353fc commit 2652900

File tree

9 files changed

+40
-34
lines changed

9 files changed

+40
-34
lines changed

cranelift/codegen/src/isa/aarch64/abi.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,8 @@ fn in_int_reg(ty: ir::Type) -> bool {
404404
match ty {
405405
types::I8 | types::I16 | types::I32 | types::I64 => true,
406406
types::B1 | types::B8 | types::B16 | types::B32 | types::B64 => true,
407-
types::R32 | types::R64 => true,
407+
types::R64 => true,
408+
types::R32 => panic!("Unexpected 32-bit reference on a 64-bit platform!"),
408409
_ => false,
409410
}
410411
}
@@ -1134,7 +1135,8 @@ impl ABIBody for AArch64ABIBody {
11341135
}
11351136

11361137
// N.B.: "nominal SP", which we use to refer to stackslots and
1137-
// spillslots, is right here.
1138+
// spillslots, is defined to be equal to the stack pointer at this point
1139+
// in the prologue.
11381140
//
11391141
// If we push any clobbers below, we emit a virtual-SP adjustment
11401142
// meta-instruction so that the nominal-SP references behave as if SP
@@ -1322,9 +1324,21 @@ impl ABIBody for AArch64ABIBody {
13221324
}
13231325
}
13241326

1327+
/// Return a type either from an optional type hint, or if not, from the default
1328+
/// type associated with the given register's class. This is used to generate
1329+
/// loads/spills appropriately given the type of value loaded/stored (which may
1330+
/// be narrower than the spillslot). We usually have the type because the
1331+
/// regalloc usually provides the vreg being spilled/reloaded, and we know every
1332+
/// vreg's type. However, the regalloc *can* request a spill/reload without an
1333+
/// associated vreg when needed to satisfy a safepoint (which requires all
1334+
/// ref-typed values, even those in real registers in the original vcode, to be
1335+
/// in spillslots).
13251336
fn ty_from_ty_hint_or_reg_class(r: Reg, ty: Option<Type>) -> Type {
13261337
match (ty, r.get_class()) {
1338+
// If the type is provided
13271339
(Some(t), _) => t,
1340+
// If no type is provided, this should be a register spill for a
1341+
// safepoint, so we only expect I64 (integer) registers.
13281342
(None, RegClass::I64) => I64,
13291343
_ => panic!("Unexpected register class!"),
13301344
}

cranelift/codegen/src/isa/aarch64/inst/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2138,7 +2138,7 @@ impl MachInst for Inst {
21382138
44
21392139
}
21402140

2141-
fn ref_type_rc(_: &settings::Flags) -> RegClass {
2141+
fn ref_type_regclass(_: &settings::Flags) -> RegClass {
21422142
RegClass::I64
21432143
}
21442144
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,9 +588,21 @@ impl ABIBody for X64ABIBody {
588588
}
589589
}
590590

591+
/// Return a type either from an optional type hint, or if not, from the default
592+
/// type associated with the given register's class. This is used to generate
593+
/// loads/spills appropriately given the type of value loaded/stored (which may
594+
/// be narrower than the spillslot). We usually have the type because the
595+
/// regalloc usually provides the vreg being spilled/reloaded, and we know every
596+
/// vreg's type. However, the regalloc *can* request a spill/reload without an
597+
/// associated vreg when needed to satisfy a safepoint (which requires all
598+
/// ref-typed values, even those in real registers in the original vcode, to be
599+
/// in spillslots).
591600
fn ty_from_ty_hint_or_reg_class(r: Reg, ty: Option<Type>) -> Type {
592601
match (ty, r.get_class()) {
602+
// If the type is provided
593603
(Some(t), _) => t,
604+
// If no type is provided, this should be a register spill for a
605+
// safepoint, so we only expect I64 (integer) registers.
594606
(None, RegClass::I64) => I64,
595607
_ => panic!("Unexpected register class!"),
596608
}

cranelift/codegen/src/isa/x64/inst/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1258,7 +1258,7 @@ impl MachInst for Inst {
12581258
15
12591259
}
12601260

1261-
fn ref_type_rc(_: &settings::Flags) -> RegClass {
1261+
fn ref_type_regclass(_: &settings::Flags) -> RegClass {
12621262
RegClass::I64
12631263
}
12641264

cranelift/codegen/src/machinst/buffer.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,8 +1318,9 @@ pub struct MachSrcLoc {
13181318
pub struct MachStackMap {
13191319
/// The code offset at which this stackmap applies.
13201320
pub offset: CodeOffset,
1321-
/// The code offset at the *end* of the instruction at which this stackmap
1322-
/// applies.
1321+
/// The code offset just past the "end" of the instruction: that is, the
1322+
/// offset of the first byte of the following instruction, or equivalently,
1323+
/// the start offset plus the instruction length.
13231324
pub offset_end: CodeOffset,
13241325
/// The Stackmap itself.
13251326
pub stackmap: Stackmap,

cranelift/codegen/src/machinst/lower.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
55
use crate::entity::SecondaryMap;
66
use crate::fx::{FxHashMap, FxHashSet};
7-
use crate::inst_predicates::is_safepoint;
87
use crate::inst_predicates::{has_side_effect_or_load, is_constant_64bit};
98
use crate::ir::instructions::BranchInfo;
109
use crate::ir::types::I64;
@@ -94,8 +93,6 @@ pub trait LowerCtx {
9493
/// every side-effecting op; the backend should not try to merge across
9594
/// side-effect colors unless the op being merged is known to be pure.
9695
fn inst_color(&self, ir_inst: Inst) -> InstColor;
97-
/// Determine whether an instruction is a safepoint.
98-
fn is_safepoint(&self, ir_inst: Inst) -> bool;
9996

10097
// Instruction input/output queries:
10198

@@ -899,13 +896,6 @@ impl<'func, I: VCodeInst> LowerCtx for Lower<'func, I> {
899896
self.inst_colors[ir_inst]
900897
}
901898

902-
fn is_safepoint(&self, ir_inst: Inst) -> bool {
903-
// There is no safepoint metadata at all if we have no reftyped values
904-
// in this function; lack of metadata implies "nothing to trace", and
905-
// avoids overhead.
906-
self.vcode.have_ref_values() && is_safepoint(self.f, ir_inst)
907-
}
908-
909899
fn num_inputs(&self, ir_inst: Inst) -> usize {
910900
self.f.dfg.inst_args(ir_inst).len()
911901
}

cranelift/codegen/src/machinst/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ pub trait MachInst: Clone + Debug {
193193

194194
/// What is the register class used for reference types (GC-observable pointers)? Can
195195
/// be dependent on compilation flags.
196-
fn ref_type_rc(_flags: &Flags) -> RegClass;
196+
fn ref_type_regclass(_flags: &Flags) -> RegClass;
197197

198198
/// A label-use kind: a type that describes the types of label references that
199199
/// can occur in an instruction.

cranelift/codegen/src/machinst/vcode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ pub struct VCodeBuilder<I: VCodeInst> {
132132
impl<I: VCodeInst> VCodeBuilder<I> {
133133
/// Create a new VCodeBuilder.
134134
pub fn new(abi: Box<dyn ABIBody<I = I>>, block_order: BlockLoweringOrder) -> VCodeBuilder<I> {
135-
let reftype_class = I::ref_type_rc(abi.flags());
135+
let reftype_class = I::ref_type_regclass(abi.flags());
136136
let vcode = VCode::new(abi, block_order);
137137
let stackmap_info = StackmapRequestInfo {
138138
reftype_class,
@@ -257,7 +257,7 @@ fn is_redundant_move<I: VCodeInst>(insn: &I) -> bool {
257257

258258
/// Is this type a reference type?
259259
fn is_reftype(ty: Type) -> bool {
260-
ty == types::R32 || ty == types::R64
260+
ty == types::R64 || ty == types::R32
261261
}
262262

263263
impl<I: VCodeInst> VCode<I> {

cranelift/filetests/filetests/vcode/aarch64/reftypes.clif

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,7 @@ block0(v0: r64):
1212
; nextln: ldp fp, lr, [sp], #16
1313
; nextln: ret
1414

15-
function %f1(r32) -> r32 {
16-
block0(v0: r32):
17-
return v0
18-
}
19-
20-
; check: stp fp, lr, [sp, #-16]!
21-
; nextln: mov fp, sp
22-
; nextln: mov sp, fp
23-
; nextln: ldp fp, lr, [sp], #16
24-
; nextln: ret
25-
26-
function %f2(r64) -> b1 {
15+
function %f1(r64) -> b1 {
2716
block0(v0: r64):
2817
v1 = is_null v0
2918
return v1
@@ -37,7 +26,7 @@ block0(v0: r64):
3726
; nextln: ldp fp, lr, [sp], #16
3827
; nextln: ret
3928

40-
function %f3(r64) -> b1 {
29+
function %f2(r64) -> b1 {
4130
block0(v0: r64):
4231
v1 = is_invalid v0
4332
return v1
@@ -51,7 +40,7 @@ block0(v0: r64):
5140
; nextln: ldp fp, lr, [sp], #16
5241
; nextln: ret
5342

54-
function %f4() -> r64 {
43+
function %f3() -> r64 {
5544
block0:
5645
v0 = null.r64
5746
return v0
@@ -64,7 +53,7 @@ block0:
6453
; nextln: ldp fp, lr, [sp], #16
6554
; nextln: ret
6655

67-
function %f5(r64, r64) -> r64, r64, r64 {
56+
function %f4(r64, r64) -> r64, r64, r64 {
6857
fn0 = %f(r64) -> b1
6958
ss0 = explicit_slot 8
7059

0 commit comments

Comments
 (0)