public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/vendors/ARM/heads/morello)] Hybrid Morello fix for convert_debug_memory_address
@ 2022-05-05 12:09 Matthew Malcomson
0 siblings, 0 replies; only message in thread
From: Matthew Malcomson @ 2022-05-05 12:09 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:7fd4e1ea35cb19c7dbf39a89dea2b244a208e31f
commit 7fd4e1ea35cb19c7dbf39a89dea2b244a208e31f
Author: Richard Sandiford <richard.sandiford@arm.com>
Date: Wed Apr 20 08:09:18 2022 +0100
Hybrid Morello fix for convert_debug_memory_address
When expanding hybrid Morello code like:
int x;
...
... __CAP_ADDR x ...
it's inevitable that we'll be asked to convert the non-capability
address of x into a capability address. This is because expanding
__CAP_ADDR x involves expanding x to a MEM and then converting the
address of that MEM to the required mode. But the MEM obtained from
expanding x is simply x's DECL_RTL; it isn't something we recalculate
from scratch on demand, and so isn't something that's influenced by
the consumer of the final value. On targets without address spaces,
this MEM DECL_RTL will always have a Pmode or ptr_mode address.
convert_memory_address_addr_space_1 has the following code to cope
with this case:
gcc_assert (! CAPABILITY_MODE_P (to_mode)
|| GET_CODE (x) == LABEL_REF
|| GET_CODE (x) == SYMBOL_REF
|| GET_CODE (x) == CONST);
For the allowed LABEL_REF, SYMBOL_REF and CONST cases, the function
recreates the constant address with the new capability mode in place of
the original non-capability mode. The resulting pointer therefore has
the right bounds, rather than being implicitly derived from DDC.
However, as the existing TODO says, capability permissions and bounds
aren't really relevant for an address calculated within a debugger
(or other consumer of the debug information). And since DWARF is
not strongly typed, there isn't really a distinction in DWARF
between Pmode and CADImode symbolic constants.
So debug expressions are laxer in two ways: they don't need to worry
about preserving provenance, and they don't need to worry (too much)
about strong typing. Despite that, the expressions created during
debug expansion are first represented as RTL, rather than directly
as DWARF, and RTL only allows us to relax the provenance side,
not the typing side.
The easiest fix therefore seems to be:
- allow any address conversion for debug purposes (only)
- calculate the address normally
- wrap the address in (pointer_plus (const_null) X) when it needs
to be converted from a non-capability to a capability
There is already code in loc_descriptor to optimise this
pointer_plus away.
Diff:
---
gcc/cfgexpand.c | 33 ++++++++++++++--------
.../aarch64/morello/hybrid-addr-expr-4.c | 2 +-
.../aarch64/morello/hybrid-addr-expr-5.c | 2 +-
.../aarch64/morello/hybrid-addr-expr-6.c | 2 +-
.../aarch64/morello/hybrid-addr-expr-7.c | 2 +-
.../aarch64/morello/hybrid-addr-expr-8.c | 2 +-
6 files changed, 27 insertions(+), 16 deletions(-)
diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c
index d685e3968da..305c2d07233 100644
--- a/gcc/cfgexpand.c
+++ b/gcc/cfgexpand.c
@@ -4066,19 +4066,30 @@ convert_debug_memory_address (scalar_addr_mode mode, rtx x,
if (GET_MODE (x) == mode || GET_MODE (x) == VOIDmode)
return x;
- /* We can't convert a mode to a capability mode.
- However, in debug expressions this doesn't really matter since the
- pointer will not actually be used for dereferencing.
- MORELLO TODO
- We're adding this line here just to alert us when we try and convert to a
- capability mode, but it's probably better to do something like just use
- the noncapability_mode since I guess that will be all the debugger can
- use. */
- gcc_assert (! CAPABILITY_MODE_P (mode));
-
/* X must have some form of address mode already. */
scalar_addr_mode xmode = as_a <scalar_addr_mode> (GET_MODE (x));
- if (GET_MODE_PRECISION (mode) < GET_MODE_PRECISION (xmode))
+ if (CAPABILITY_MODE_P (mode) && !CAPABILITY_MODE_P (xmode))
+ {
+ /* The debug information can't (and doesn't need to) add valid
+ metadata to a non-capability pointer. It just needs to specify
+ the capability value. However, the rtl we create here still has
+ to be type-correct, so wrap the capability value in a
+
+ (pointer_plus (const_null) VALUE)
+
+ We can optimize this scaffolding away when outputting the
+ information.
+
+ Note that consumers of the debug information are expected
+ to perform address arithmetic in the precision of offset_mode (mode)
+ rather than in the precision of mode, so that there is no problem
+ with excess precision. */
+ rtx off = convert_debug_memory_address (offset_mode (mode), x, as);
+ x = gen_pointer_plus (mode, CONST0_RTX (mode), off);
+ if (CONSTANT_P (off))
+ x = gen_rtx_CONST (mode, x);
+ }
+ else if (GET_MODE_PRECISION (mode) < GET_MODE_PRECISION (xmode))
x = lowpart_subreg (mode, x, xmode);
else if (POINTERS_EXTEND_UNSIGNED > 0)
x = gen_rtx_ZERO_EXTEND (mode, x);
diff --git a/gcc/testsuite/gcc.target/aarch64/morello/hybrid-addr-expr-4.c b/gcc/testsuite/gcc.target/aarch64/morello/hybrid-addr-expr-4.c
index 9f6ab6a54ce..6c75c03cc36 100644
--- a/gcc/testsuite/gcc.target/aarch64/morello/hybrid-addr-expr-4.c
+++ b/gcc/testsuite/gcc.target/aarch64/morello/hybrid-addr-expr-4.c
@@ -1,5 +1,5 @@
/* { dg-do assemble } */
-/* { dg-additional-options "-mcmodel=small -fPIC -fgimple -g0 -save-temps" } */
+/* { dg-additional-options "-mcmodel=small -fPIC -fgimple -save-temps" } */
/* { dg-final { check-function-bodies "**" "" } } */
/* { dg-skip-if "" { *-*-* } { "-O0" "-mabi=purecap" "-mfake-capability" } { "" } } */
diff --git a/gcc/testsuite/gcc.target/aarch64/morello/hybrid-addr-expr-5.c b/gcc/testsuite/gcc.target/aarch64/morello/hybrid-addr-expr-5.c
index 53368e6dfab..336af2385f9 100644
--- a/gcc/testsuite/gcc.target/aarch64/morello/hybrid-addr-expr-5.c
+++ b/gcc/testsuite/gcc.target/aarch64/morello/hybrid-addr-expr-5.c
@@ -1,5 +1,5 @@
/* { dg-do assemble } */
-/* { dg-additional-options "-mcmodel=small -fno-PIC -mpc-relative-literal-loads -fgimple -g0 -save-temps" } */
+/* { dg-additional-options "-mcmodel=small -fno-PIC -mpc-relative-literal-loads -fgimple -save-temps" } */
/* { dg-final { check-function-bodies "**" "" } } */
/* { dg-skip-if "" { *-*-* } { "-O0" "-mabi=purecap" "-mfake-capability" } { "" } } */
diff --git a/gcc/testsuite/gcc.target/aarch64/morello/hybrid-addr-expr-6.c b/gcc/testsuite/gcc.target/aarch64/morello/hybrid-addr-expr-6.c
index 7ed909424db..b2de53702bd 100644
--- a/gcc/testsuite/gcc.target/aarch64/morello/hybrid-addr-expr-6.c
+++ b/gcc/testsuite/gcc.target/aarch64/morello/hybrid-addr-expr-6.c
@@ -1,5 +1,5 @@
/* { dg-do assemble } */
-/* { dg-additional-options "-mcmodel=small -fPIC -mpc-relative-literal-loads -fgimple -g0 -save-temps" } */
+/* { dg-additional-options "-mcmodel=small -fPIC -mpc-relative-literal-loads -fgimple -save-temps" } */
/* { dg-final { check-function-bodies "**" "" } } */
/* { dg-skip-if "" { *-*-* } { "-O0" "-mabi=purecap" "-mfake-capability" } { "" } } */
diff --git a/gcc/testsuite/gcc.target/aarch64/morello/hybrid-addr-expr-7.c b/gcc/testsuite/gcc.target/aarch64/morello/hybrid-addr-expr-7.c
index 89ba1759861..28815382ad4 100644
--- a/gcc/testsuite/gcc.target/aarch64/morello/hybrid-addr-expr-7.c
+++ b/gcc/testsuite/gcc.target/aarch64/morello/hybrid-addr-expr-7.c
@@ -1,5 +1,5 @@
/* { dg-do assemble } */
-/* { dg-additional-options "-mcmodel=large -fno-PIC -fgimple -g0 -save-temps" } */
+/* { dg-additional-options "-mcmodel=large -fno-PIC -fgimple -save-temps" } */
/* { dg-final { check-function-bodies "**" "" } } */
/* { dg-skip-if "" { *-*-* } { "-O0" "-mabi=purecap" "-mfake-capability" } { "" } } */
diff --git a/gcc/testsuite/gcc.target/aarch64/morello/hybrid-addr-expr-8.c b/gcc/testsuite/gcc.target/aarch64/morello/hybrid-addr-expr-8.c
index ef2129371c1..e3af4896246 100644
--- a/gcc/testsuite/gcc.target/aarch64/morello/hybrid-addr-expr-8.c
+++ b/gcc/testsuite/gcc.target/aarch64/morello/hybrid-addr-expr-8.c
@@ -1,5 +1,5 @@
/* { dg-do assemble } */
-/* { dg-additional-options "-mcmodel=large -fno-PIC -mpc-relative-literal-loads -fgimple -g0 -save-temps" } */
+/* { dg-additional-options "-mcmodel=large -fno-PIC -mpc-relative-literal-loads -fgimple -save-temps" } */
/* { dg-final { check-function-bodies "**" "" } } */
/* { dg-skip-if "" { *-*-* } { "-O0" "-mabi=purecap" "-mfake-capability" } { "" } } */
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-05-05 12:09 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-05 12:09 [gcc(refs/vendors/ARM/heads/morello)] Hybrid Morello fix for convert_debug_memory_address Matthew Malcomson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).