Rework aarch64 stack frame implementation.
This PR changes the aarch64 ABI implementation to use positive offsets from SP, rather than negative offsets from FP, to refer to spill slots and stack-local storage. This allows for better addressing-mode options, and hence slightly better code: e.g., the unsigned scaled 12-bit offset mode can be used to reach anywhere in a 32KB frame without extra address-construction instructions, whereas negative offsets are limited to a signed 9-bit unscaled mode (-256 bytes). To enable this, the PR introduces a notion of "nominal SP offsets" as a virtual addressing mode, lowered during the emission pass. The offsets are relative to "SP after adjusting downward to allocate stack/spill slots", but before pushing clobbers. This allows the addressing-mode expressions to be generated before register allocation (or during it, for spill/reload sequences). To convert these offsets into *true* offsets from SP, we need to track how much further SP is moved downward, and compensate for this. We do so with "virtual SP offset adjustment" pseudo-instructions: these are seen by the emission pass, and result in no instruction (0 byte output), but update state that is now threaded through each instruction emission in turn. In this way, we can push e.g. stack args for a call and adjust the virtual SP offset, allowing reloads from nominal-SP-relative spillslots while we do the argument setup with "real SP offsets" at the same time.
This commit is contained in:
@@ -11,8 +11,8 @@ block0(v0: i64):
|
||||
|
||||
; check: stp fp, lr, [sp, #-16]!
|
||||
; nextln: mov fp, sp
|
||||
; nextln: ldr x15, 8 ; b 12 ; data
|
||||
; nextln: blr x15
|
||||
; nextln: ldr x16, 8 ; b 12 ; data
|
||||
; nextln: blr x16
|
||||
; nextln: mov sp, fp
|
||||
; nextln: ldp fp, lr, [sp], #16
|
||||
; nextln: ret
|
||||
|
||||
@@ -45,8 +45,8 @@ block0(v0: i64):
|
||||
; nextln: subs xzr, sp, x0
|
||||
; nextln: b.hs 8
|
||||
; nextln: udf
|
||||
; nextln: ldr x15
|
||||
; nextln: blr x15
|
||||
; nextln: ldr x16
|
||||
; nextln: blr x16
|
||||
; nextln: mov sp, fp
|
||||
; nextln: ldp fp, lr, [sp], #16
|
||||
; nextln: ret
|
||||
@@ -64,13 +64,13 @@ block0(v0: i64):
|
||||
|
||||
; check: stp fp, lr, [sp, #-16]!
|
||||
; nextln: mov fp, sp
|
||||
; nextln: ldr x15, [x0]
|
||||
; nextln: ldr x15, [x15, #4]
|
||||
; nextln: subs xzr, sp, x15
|
||||
; nextln: ldr x16, [x0]
|
||||
; nextln: ldr x16, [x16, #4]
|
||||
; nextln: subs xzr, sp, x16
|
||||
; nextln: b.hs 8
|
||||
; nextln: udf
|
||||
; nextln: ldr x15
|
||||
; nextln: blr x15
|
||||
; nextln: ldr x16
|
||||
; nextln: blr x16
|
||||
; nextln: mov sp, fp
|
||||
; nextln: ldp fp, lr, [sp], #16
|
||||
; nextln: ret
|
||||
@@ -84,8 +84,8 @@ block0(v0: i64):
|
||||
|
||||
; check: stp fp, lr, [sp, #-16]!
|
||||
; nextln: mov fp, sp
|
||||
; nextln: add x15, x0, #176
|
||||
; nextln: subs xzr, sp, x15
|
||||
; nextln: add x16, x0, #176
|
||||
; nextln: subs xzr, sp, x16
|
||||
; nextln: b.hs 8
|
||||
; nextln: udf
|
||||
; nextln: sub sp, sp, #176
|
||||
@@ -104,14 +104,14 @@ block0(v0: i64):
|
||||
; nextln: subs xzr, sp, x0
|
||||
; nextln: b.hs 8
|
||||
; nextln: udf
|
||||
; nextln: movz x16, #6784
|
||||
; nextln: movk x16, #6, LSL #16
|
||||
; nextln: add x15, x0, x16, UXTX
|
||||
; nextln: subs xzr, sp, x15
|
||||
; nextln: movz x17, #6784
|
||||
; nextln: movk x17, #6, LSL #16
|
||||
; nextln: add x16, x0, x17, UXTX
|
||||
; nextln: subs xzr, sp, x16
|
||||
; nextln: b.hs 8
|
||||
; nextln: udf
|
||||
; nextln: ldr x15, 8 ; b 12 ; data 400000
|
||||
; nextln: sub sp, sp, x15, UXTX
|
||||
; nextln: ldr x16, 8 ; b 12 ; data 400000
|
||||
; nextln: sub sp, sp, x16, UXTX
|
||||
; nextln: mov sp, fp
|
||||
; nextln: ldp fp, lr, [sp], #16
|
||||
; nextln: ret
|
||||
@@ -128,10 +128,10 @@ block0(v0: i64):
|
||||
|
||||
; check: stp fp, lr, [sp, #-16]!
|
||||
; nextln: mov fp, sp
|
||||
; nextln: ldr x15, [x0]
|
||||
; nextln: ldr x15, [x15, #4]
|
||||
; nextln: add x15, x15, #32
|
||||
; nextln: subs xzr, sp, x15
|
||||
; nextln: ldr x16, [x0]
|
||||
; nextln: ldr x16, [x16, #4]
|
||||
; nextln: add x16, x16, #32
|
||||
; nextln: subs xzr, sp, x16
|
||||
; nextln: b.hs 8
|
||||
; nextln: udf
|
||||
; nextln: sub sp, sp, #32
|
||||
@@ -151,19 +151,19 @@ block0(v0: i64):
|
||||
|
||||
; check: stp fp, lr, [sp, #-16]!
|
||||
; nextln: mov fp, sp
|
||||
; nextln: ldr x15, [x0]
|
||||
; nextln: ldr x15, [x15, #4]
|
||||
; nextln: subs xzr, sp, x15
|
||||
; nextln: ldr x16, [x0]
|
||||
; nextln: ldr x16, [x16, #4]
|
||||
; nextln: subs xzr, sp, x16
|
||||
; nextln: b.hs 8
|
||||
; nextln: udf
|
||||
; nextln: movz x16, #6784
|
||||
; nextln: movk x16, #6, LSL #16
|
||||
; nextln: add x15, x15, x16, UXTX
|
||||
; nextln: subs xzr, sp, x15
|
||||
; nextln: movz x17, #6784
|
||||
; nextln: movk x17, #6, LSL #16
|
||||
; nextln: add x16, x16, x17, UXTX
|
||||
; nextln: subs xzr, sp, x16
|
||||
; nextln: b.hs 8
|
||||
; nextln: udf
|
||||
; nextln: ldr x15, 8 ; b 12 ; data 400000
|
||||
; nextln: sub sp, sp, x15, UXTX
|
||||
; nextln: ldr x16, 8 ; b 12 ; data 400000
|
||||
; nextln: sub sp, sp, x16, UXTX
|
||||
; nextln: mov sp, fp
|
||||
; nextln: ldp fp, lr, [sp], #16
|
||||
; nextln: ret
|
||||
@@ -179,11 +179,11 @@ block0(v0: i64):
|
||||
|
||||
; check: stp fp, lr, [sp, #-16]!
|
||||
; nextln: mov fp, sp
|
||||
; nextln: movz x15, #6784
|
||||
; nextln: movk x15, #6, LSL #16
|
||||
; nextln: ldr x15, [x0, x15]
|
||||
; nextln: add x15, x15, #32
|
||||
; nextln: subs xzr, sp, x15
|
||||
; nextln: movz x16, #6784
|
||||
; nextln: movk x16, #6, LSL #16
|
||||
; nextln: ldr x16, [x0, x16]
|
||||
; nextln: add x16, x16, #32
|
||||
; nextln: subs xzr, sp, x16
|
||||
; nextln: b.hs 8
|
||||
; nextln: udf
|
||||
; nextln: sub sp, sp, #32
|
||||
|
||||
@@ -12,7 +12,7 @@ block0:
|
||||
; check: stp fp, lr, [sp, #-16]!
|
||||
; nextln: mov fp, sp
|
||||
; nextln: sub sp, sp, #16
|
||||
; nextln: sub x0, fp, #8
|
||||
; nextln: mov x0, sp
|
||||
; nextln: mov sp, fp
|
||||
; nextln: ldp fp, lr, [sp], #16
|
||||
; nextln: ret
|
||||
@@ -29,9 +29,9 @@ block0:
|
||||
|
||||
; check: stp fp, lr, [sp, #-16]!
|
||||
; nextln: mov fp, sp
|
||||
; nextln: ldr x15, 8 ; b 12 ; data 100016
|
||||
; nextln: sub sp, sp, x15, UXTX
|
||||
; nextln: movz x0, #34472; movk x0, #1, LSL #16; sub x0, fp, x0
|
||||
; nextln: ldr x16, 8 ; b 12 ; data 100016
|
||||
; nextln: sub sp, sp, x16, UXTX
|
||||
; nextln: mov x0, sp
|
||||
; nextln: mov sp, fp
|
||||
; nextln: ldp fp, lr, [sp], #16
|
||||
; nextln: ret
|
||||
@@ -50,7 +50,7 @@ block0:
|
||||
; check: stp fp, lr, [sp, #-16]!
|
||||
; nextln: mov fp, sp
|
||||
; nextln: sub sp, sp, #16
|
||||
; nextln: sub x0, fp, #8
|
||||
; nextln: mov x0, sp
|
||||
; nextln: ldur x0, [x0]
|
||||
; nextln: mov sp, fp
|
||||
; nextln: ldp fp, lr, [sp], #16
|
||||
@@ -68,9 +68,9 @@ block0:
|
||||
|
||||
; check: stp fp, lr, [sp, #-16]!
|
||||
; nextln: mov fp, sp
|
||||
; nextln: ldr x15, 8 ; b 12 ; data 100016
|
||||
; nextln: sub sp, sp, x15, UXTX
|
||||
; nextln: movz x0, #34472; movk x0, #1, LSL #16; sub x0, fp, x0
|
||||
; nextln: ldr x16, 8 ; b 12 ; data 100016
|
||||
; nextln: sub sp, sp, x16, UXTX
|
||||
; nextln: mov x0, sp
|
||||
; nextln: ldur x0, [x0]
|
||||
; nextln: mov sp, fp
|
||||
; nextln: ldp fp, lr, [sp], #16
|
||||
@@ -88,7 +88,7 @@ block0(v0: i64):
|
||||
; check: stp fp, lr, [sp, #-16]!
|
||||
; nextln: mov fp, sp
|
||||
; nextln: sub sp, sp, #16
|
||||
; nextln: sub x1, fp, #8
|
||||
; nextln: mov x1, sp
|
||||
; nextln: stur x0, [x1]
|
||||
; nextln: mov sp, fp
|
||||
; nextln: ldp fp, lr, [sp], #16
|
||||
@@ -106,9 +106,9 @@ block0(v0: i64):
|
||||
|
||||
; check: stp fp, lr, [sp, #-16]!
|
||||
; nextln: mov fp, sp
|
||||
; nextln: ldr x15, 8 ; b 12 ; data 100016
|
||||
; nextln: sub sp, sp, x15, UXTX
|
||||
; nextln: movz x1, #34472; movk x1, #1, LSL #16; sub x1, fp, x1
|
||||
; nextln: ldr x16, 8 ; b 12 ; data 100016
|
||||
; nextln: sub sp, sp, x16, UXTX
|
||||
; nextln: mov x1, sp
|
||||
; nextln: stur x0, [x1]
|
||||
; nextln: mov sp, fp
|
||||
; nextln: ldp fp, lr, [sp], #16
|
||||
|
||||
Reference in New Issue
Block a user