Skip to content

Commit 6546da2

Browse files
authored
pulley: Implement lowering for stack_addr (#9661)
This'll be needed for various purposes of trampolines and functions in Wasmtime and it's easy enough to have a lowering for.
1 parent bc656c7 commit 6546da2

File tree

3 files changed

+102
-0
lines changed

3 files changed

+102
-0
lines changed

cranelift/codegen/src/isa/pulley_shared/lower.isle

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,3 +230,14 @@
230230
src
231231
ty
232232
flags)))
233+
234+
;;;; Rules for `stack_addr` ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
235+
236+
(rule (lower (stack_addr stack_slot offset))
237+
(lower_stack_addr stack_slot offset))
238+
239+
(decl lower_stack_addr (StackSlot Offset32) XReg)
240+
(rule (lower_stack_addr stack_slot offset)
241+
(let ((dst WritableXReg (temp_writable_xreg))
242+
(_ Unit (emit (abi_stackslot_addr dst stack_slot offset))))
243+
dst))
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
test compile precise-output
2+
target pulley32
3+
4+
function %ret_stack() -> i32 {
5+
ss0 = explicit_slot 4
6+
block0():
7+
v0 = stack_addr.i32 ss0
8+
return v0
9+
}
10+
11+
; VCode:
12+
; x30 = xconst8 -16
13+
; x27 = xadd32 x27, x30
14+
; store64 sp+8, x28 // flags = notrap aligned
15+
; store64 sp+0, x29 // flags = notrap aligned
16+
; x29 = xmov x27
17+
; x30 = xconst8 -16
18+
; x27 = xadd32 x27, x30
19+
; block0:
20+
; x0 = load_addr Slot(0)
21+
; x30 = xconst8 16
22+
; x27 = xadd32 x27, x30
23+
; x28 = load64_u sp+8 // flags = notrap aligned
24+
; x29 = load64_u sp+0 // flags = notrap aligned
25+
; x30 = xconst8 16
26+
; x27 = xadd32 x27, x30
27+
; ret
28+
;
29+
; Disassembled:
30+
; 0: 14 1e f0 xconst8 spilltmp0, -16
31+
; 3: 18 7b 7b xadd32 sp, sp, spilltmp0
32+
; 6: 32 1b 08 1c store64_offset8 sp, 8, lr
33+
; a: 30 1b 1d store64 sp, fp
34+
; d: 11 1d 1b xmov fp, sp
35+
; 10: 14 1e f0 xconst8 spilltmp0, -16
36+
; 13: 18 7b 7b xadd32 sp, sp, spilltmp0
37+
; 16: 11 00 1b xmov x0, sp
38+
; 19: 14 1e 10 xconst8 spilltmp0, 16
39+
; 1c: 18 7b 7b xadd32 sp, sp, spilltmp0
40+
; 1f: 2b 1c 1b 08 load64_offset8 lr, sp, 8
41+
; 23: 28 1d 1b load64 fp, sp
42+
; 26: 14 1e 10 xconst8 spilltmp0, 16
43+
; 29: 18 7b 7b xadd32 sp, sp, spilltmp0
44+
; 2c: 00 ret
45+
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
test compile precise-output
2+
target pulley64
3+
4+
function %ret_stack() -> i64 {
5+
ss0 = explicit_slot 4
6+
block0():
7+
v0 = stack_addr.i64 ss0
8+
return v0
9+
}
10+
11+
; VCode:
12+
; x30 = xconst8 -16
13+
; x27 = xadd32 x27, x30
14+
; store64 sp+8, x28 // flags = notrap aligned
15+
; store64 sp+0, x29 // flags = notrap aligned
16+
; x29 = xmov x27
17+
; x30 = xconst8 -16
18+
; x27 = xadd32 x27, x30
19+
; block0:
20+
; x0 = load_addr Slot(0)
21+
; x30 = xconst8 16
22+
; x27 = xadd32 x27, x30
23+
; x28 = load64_u sp+8 // flags = notrap aligned
24+
; x29 = load64_u sp+0 // flags = notrap aligned
25+
; x30 = xconst8 16
26+
; x27 = xadd32 x27, x30
27+
; ret
28+
;
29+
; Disassembled:
30+
; 0: 14 1e f0 xconst8 spilltmp0, -16
31+
; 3: 18 7b 7b xadd32 sp, sp, spilltmp0
32+
; 6: 32 1b 08 1c store64_offset8 sp, 8, lr
33+
; a: 30 1b 1d store64 sp, fp
34+
; d: 11 1d 1b xmov fp, sp
35+
; 10: 14 1e f0 xconst8 spilltmp0, -16
36+
; 13: 18 7b 7b xadd32 sp, sp, spilltmp0
37+
; 16: 11 00 1b xmov x0, sp
38+
; 19: 14 1e 10 xconst8 spilltmp0, 16
39+
; 1c: 18 7b 7b xadd32 sp, sp, spilltmp0
40+
; 1f: 2b 1c 1b 08 load64_offset8 lr, sp, 8
41+
; 23: 28 1d 1b load64 fp, sp
42+
; 26: 14 1e 10 xconst8 spilltmp0, 16
43+
; 29: 18 7b 7b xadd32 sp, sp, spilltmp0
44+
; 2c: 00 ret
45+
46+

0 commit comments

Comments
 (0)