public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/vendors/ARM/heads/morello)] Add CAP_ADDR_EXPR
@ 2022-05-05 12:08 Matthew Malcomson
  0 siblings, 0 replies; only message in thread
From: Matthew Malcomson @ 2022-05-05 12:08 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:f2a98ec40e702c976fcd98b15a17c1e2afa6ac60

commit f2a98ec40e702c976fcd98b15a17c1e2afa6ac60
Author: Richard Sandiford <richard.sandiford@arm.com>
Date:   Tue Apr 12 08:54:43 2022 +0100

    Add CAP_ADDR_EXPR
    
    This patch adds a new tree code, CAP_ADDR_EXPR, that returns
    a capability pointer or reference to a given object.  It also
    restricts NONCAP_ADDR_EXPR to non-capability pointer and
    reference types.
    
    As a follow-on, it would probably be useful to add more sanity
    checking, to make sure that CAP_ADDR_EXPR isn't used with
    non-capability types and that NONCAP_ADDR_EXPR isn't used
    with capability types, but I think that would be better as
    a separate, less mechanical change.

Diff:
---
 gcc/ada/gcc-interface/ada-tree.def |  2 +-
 gcc/cp/cp-tree.h                   |  4 ++--
 gcc/doc/generic.texi               | 15 ++++++++++-----
 gcc/doc/gimple.texi                |  5 +++--
 gcc/genmatch.c                     |  2 +-
 gcc/match.pd                       |  1 +
 gcc/range-op.cc                    |  2 ++
 gcc/tree-core.h                    |  2 ++
 gcc/tree.c                         |  4 ++--
 gcc/tree.def                       |  3 +++
 gcc/tree.h                         |  9 +++++----
 11 files changed, 32 insertions(+), 17 deletions(-)

diff --git a/gcc/ada/gcc-interface/ada-tree.def b/gcc/ada/gcc-interface/ada-tree.def
index 818b7d48cf2..0abcd99f31e 100644
--- a/gcc/ada/gcc-interface/ada-tree.def
+++ b/gcc/ada/gcc-interface/ada-tree.def
@@ -52,7 +52,7 @@ DEFTREECODE (MINUS_NOMOD_EXPR, "minus_nomod_expr", tcc_binary, 2)
    used internally to describe fixed point types scale factors.  */
 DEFTREECODE (POWER_EXPR, "power_expr", tcc_binary, 2)
 
-/* Same as NONCAP_ADDR_EXPR, except that if the operand represents
+/* Same as {NON,}CAP_ADDR_EXPR, except that if the operand represents
    a bit field, return the address of the byte containing the bit.
    This is used for the Address attribute and never shows up in the tree.  */
 DEFTREECODE (ATTR_ADDR_EXPR, "attr_addr_expr", tcc_reference, 1)
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index cf8cb8490fd..3f41cfc2016 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -4498,8 +4498,8 @@ more_aggr_init_expr_args_p (const aggr_init_expr_arg_iterator *iter)
 /* Indicates when overload resolution may resolve to a pointer to
    member function. [expr.unary.op]/3 */
 #define PTRMEM_OK_P(NODE) \
-  TREE_LANG_FLAG_0 (TREE_CHECK3 ((NODE), NONCAP_ADDR_EXPR, OFFSET_REF, \
-				 SCOPE_REF))
+  TREE_LANG_FLAG_0 (TREE_CHECK4 ((NODE), NONCAP_ADDR_EXPR, CAP_ADDR_EXPR, \
+				 OFFSET_REF, SCOPE_REF))
 
 /* Get the POINTER_TYPE to the METHOD_TYPE associated with this
    pointer to member function.  TYPE_PTRMEMFUNC_P _must_ be true,
diff --git a/gcc/doc/generic.texi b/gcc/doc/generic.texi
index ec200dfabc9..05c1abafd92 100644
--- a/gcc/doc/generic.texi
+++ b/gcc/doc/generic.texi
@@ -1190,6 +1190,7 @@ the others being multipliers that are applied to the runtime parameters.
 @node Storage References
 @subsection References to storage
 @tindex NONCAP_ADDR_EXPR
+@tindex CAP_ADDR_EXPR
 @tindex INDIRECT_REF
 @tindex MEM_REF
 @tindex ARRAY_REF
@@ -1236,13 +1237,17 @@ is preserved for the purposes of the RTL alias analysis.  The seventh
 argument is a tag representing the results of tree level alias analysis.
 
 @item NONCAP_ADDR_EXPR
-These nodes are used to represent the address of an object.  (These
-expressions will always have pointer or reference type.)  The operand may
-be another expression, or it may be a declaration.
+@itemx CAP_ADDR_EXPR
+These nodes are used to represent the address of an object.
+The operand may be another expression, or it may be a declaration.
+
+These expressions alway have a pointer or reference type.  For
+@code{CAP_ADDR_EXPR} this type is a capability type whereas for
+@code{NONCAP_ADDR_EXPR} it is a non-capability type.
 
 As an extension, GCC allows users to take the address of a label.  In
-this case, the operand of the @code{NONCAP_ADDR_EXPR} will be a
-@code{LABEL_DECL}.  The type of such an expression is @code{void*}.
+this case, the operand of the @code{NONCAP_ADDR_EXPR} or @code{CAP_ADDR_EXPR}
+will be a @code{LABEL_DECL}.  The type of such an expression is @code{void*}.
 
 If the object addressed is not an lvalue, a temporary is created, and
 the address of the temporary is used.
diff --git a/gcc/doc/gimple.texi b/gcc/doc/gimple.texi
index 4aa9e60e9ba..00ee82912cf 100644
--- a/gcc/doc/gimple.texi
+++ b/gcc/doc/gimple.texi
@@ -798,8 +798,9 @@ global variable but not of a local one).
 @end deftypefn
 
 @deftypefn {GIMPLE function} bool is_gimple_ip_invariant_address (tree t)
-Return true if t is a @code{NONCAP_ADDR_EXPR} that does not change once the
-program is running (and which is valid in all functions).
+Return true if t is a @code{NONCAP_ADDR_EXPR} or @code{CAP_ADDR_EXPR} that
+does not change once the program is running (and which is valid in all
+functions).
 @end deftypefn
 
 
diff --git a/gcc/genmatch.c b/gcc/genmatch.c
index 3ffdcf1e502..bbd1077bcc4 100644
--- a/gcc/genmatch.c
+++ b/gcc/genmatch.c
@@ -257,7 +257,7 @@ enum combined_fn {
 static inline bool
 ADDR_EXPR_CODE_P (tree_code code)
 {
-  return code == NONCAP_ADDR_EXPR;
+  return code == NONCAP_ADDR_EXPR || code == CAP_ADDR_EXPR;
 }
 
 /* Return true if CODE represents a commutative tree code.  Otherwise
diff --git a/gcc/match.pd b/gcc/match.pd
index fb13535c8e8..200afaa0ef3 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -111,6 +111,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
       && tree_nop_conversion_p (TREE_TYPE (type), TREE_TYPE (TREE_TYPE (@0))))))
 
 (match (any_addr) (NONCAP_ADDR_EXPR))
+(match (any_addr) (CAP_ADDR_EXPR))
 
 /* Transform likes of (char) ABS_EXPR <(int) x> into (char) ABSU_EXPR <x>
    ABSU_EXPR returns unsigned absolute value of the operand and the operand
diff --git a/gcc/range-op.cc b/gcc/range-op.cc
index 3510fc2c335..b7adf97b224 100644
--- a/gcc/range-op.cc
+++ b/gcc/range-op.cc
@@ -3235,6 +3235,7 @@ integral_table::integral_table ()
   set (ABSU_EXPR, op_absu);
   set (NEGATE_EXPR, op_negate);
   set (NONCAP_ADDR_EXPR, op_addr);
+  set (CAP_ADDR_EXPR, op_addr);
 }
 
 // Instantiate a range op table for pointer operations.
@@ -3261,6 +3262,7 @@ pointer_table::pointer_table ()
   set (GE_EXPR, op_ge);
   set (SSA_NAME, op_identity);
   set (NONCAP_ADDR_EXPR, op_addr);
+  set (CAP_ADDR_EXPR, op_addr);
   set (NOP_EXPR, op_convert);
   set (CONVERT_EXPR, op_convert);
 
diff --git a/gcc/tree-core.h b/gcc/tree-core.h
index 5947fcb33fd..c738a118ba2 100644
--- a/gcc/tree-core.h
+++ b/gcc/tree-core.h
@@ -1107,6 +1107,7 @@ struct GTY(()) tree_base {
 
        TREE_NO_TRAMPOLINE in
            NONCAP_ADDR_EXPR
+           CAP_ADDR_EXPR
 
        BINFO_VIRTUAL_P in
            TREE_BINFO
@@ -1371,6 +1372,7 @@ struct GTY(()) tree_base {
 
        FUNC_ADDR_BY_DESCRIPTOR in
            NONCAP_ADDR_EXPR
+           CAP_ADDR_EXPR
 
        CALL_EXPR_BY_DESCRIPTOR in
            CALL_EXPR
diff --git a/gcc/tree.c b/gcc/tree.c
index d95291292f6..e0d3bbeb7c8 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -14190,9 +14190,8 @@ addr_expr_code (const_tree res_type)
 #else
   if (!POINTER_TYPE_P (res_type))
     res_type = ptr_type_node;
-  (void) res_type;
 #endif
-  return NONCAP_ADDR_EXPR;
+  return capability_type_p (res_type) ? CAP_ADDR_EXPR : NONCAP_ADDR_EXPR;
 }
 
 /* Return the *ADDR_EXPR code that should be used if the type of the
@@ -16322,6 +16321,7 @@ test_fold_drop_capability (void)
 	- TARGET_EXPR
 	- COND_EXPR
 	- NONCAP_ADDR_EXPR
+	- CAP_ADDR_EXPR
 	- PREDECREMENT_EXPR
 	- PREINCREMENT_EXPR
 	- POSTDECREMENT_EXPR
diff --git a/gcc/tree.def b/gcc/tree.def
index 6e8bc255910..b0920f06d65 100644
--- a/gcc/tree.def
+++ b/gcc/tree.def
@@ -873,6 +873,9 @@ DEFTREECODE (SAVE_EXPR, "save_expr", tcc_expression, 1)
    Result mode is a valid non-capability pointer mode.  */
 DEFTREECODE (NONCAP_ADDR_EXPR, "noncap_addr_expr", tcc_expression, 1)
 
+/* Likewise, but returning a capability type.  */
+DEFTREECODE (CAP_ADDR_EXPR, "cap_addr_expr", tcc_expression, 1)
+
 /* Operand0 is a function constant; result is part N of a function
    descriptor of type ptr_mode.  */
 DEFTREECODE (FDESC_EXPR, "fdesc_expr", tcc_expression, 2)
diff --git a/gcc/tree.h b/gcc/tree.h
index 0e498f24a68..aebea940439 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -474,7 +474,7 @@ extern void omp_clause_range_check_failed (const_tree, const char *, int,
 static inline bool
 ADDR_EXPR_CODE_P (tree_code code)
 {
-  return code == NONCAP_ADDR_EXPR;
+  return code == NONCAP_ADDR_EXPR || code == CAP_ADDR_EXPR;
 }
 
 /* Test if EXP takes the address of an object.  If so, the object
@@ -483,7 +483,8 @@ ADDR_EXPR_CODE_P (tree_code code)
 
 /* Case statements for codes that satisfy ADDR_EXPR_CODE_P.  */
 #define CASE_ADDR_EXPR \
-  case NONCAP_ADDR_EXPR
+  case NONCAP_ADDR_EXPR: \
+  case CAP_ADDR_EXPR
 
 /* Tests if CODE is a conversion expr (NOP_EXPR or CONVERT_EXPR).  */
 #define CONVERT_EXPR_CODE_P(CODE)				\
@@ -704,7 +705,7 @@ ADDR_EXPR_CODE_P (tree_code code)
 
 /* In an *ADDR_EXPR, nonzero means do not use a trampoline.  */
 #define TREE_NO_TRAMPOLINE(NODE) \
-  (NONCAP_ADDR_EXPR_CHECK (NODE)->base.static_flag)
+  (TREE_CHECK2 (NODE, NONCAP_ADDR_EXPR, CAP_ADDR_EXPR)->base.static_flag)
 
 /* In a TARGET_EXPR or WITH_CLEANUP_EXPR, means that the pertinent cleanup
    should only be executed if an exception is thrown, not on normal exit
@@ -1013,7 +1014,7 @@ ADDR_EXPR_CODE_P (tree_code code)
 /* In an *ADDR_EXPR, indicates that this is a pointer to nested function
    represented by a descriptor instead of a trampoline.  */
 #define FUNC_ADDR_BY_DESCRIPTOR(NODE) \
-  (TREE_CHECK (NODE, NONCAP_ADDR_EXPR)->base.default_def_flag)
+  (TREE_CHECK2 (NODE, NONCAP_ADDR_EXPR, CAP_ADDR_EXPR)->base.default_def_flag)
 
 /* In a CALL_EXPR, indicates that this is an indirect call for which
    pointers to nested function are descriptors instead of trampolines.  */


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-05-05 12:08 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:08 [gcc(refs/vendors/ARM/heads/morello)] Add CAP_ADDR_EXPR 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).