https://gcc.gnu.org/g:82305f37dbedaded25014d3f45736e503d564bb2

commit r16-5901-g82305f37dbedaded25014d3f45736e503d564bb2
Author: Richard Biener <[email protected]>
Date:   Fri Dec 5 10:29:07 2025 +0100

    Add clique/base parsing and dumping to the GIMPLE FE
    
    The following adds clique/base on __MEM to the GIMPLE parser and
    to -gimple dumping.
    
    gcc/c/
            * gimple-parser.cc (c_parser_gimple_postfix_expression):
            Parse optional clique : base specifier on __MEM.
    
    gcc/
            * tree-pretty-print.cc (dump_mem_ref): Dump clique : base
            specifier for MEM_REF and TARGET_MEM_REF when dumping
            GIMPLE format.
    
    gcc/testsuite/
            * gcc.dg/gimplefe-58.c: New testcase.

Diff:
---
 gcc/c/gimple-parser.cc             | 32 +++++++++++++++++++++++++++++++-
 gcc/testsuite/gcc.dg/gimplefe-58.c | 17 +++++++++++++++++
 gcc/tree-pretty-print.cc           |  7 +++++++
 3 files changed, 55 insertions(+), 1 deletion(-)

diff --git a/gcc/c/gimple-parser.cc b/gcc/c/gimple-parser.cc
index d4c5001623e8..52819a6587f7 100644
--- a/gcc/c/gimple-parser.cc
+++ b/gcc/c/gimple-parser.cc
@@ -1529,7 +1529,8 @@ c_parser_gimple_postfix_expression (gimple_parser &parser)
            {
              /* __MEM '<' type-name [ ',' number ] '>'
                       '(' [ '(' type-name ')' ] unary-expression
-                          [ '+' number ] ')'  */
+                          [ '+' number ]
+                          [ ',' number ':' number ] ')'  */
              location_t loc = c_parser_peek_token (parser)->location;
              c_parser_consume_token (parser);
              tree type = c_parser_gimple_typespec (parser);
@@ -1539,6 +1540,8 @@ c_parser_gimple_postfix_expression (gimple_parser &parser)
              step.value = NULL_TREE;
              index.value = NULL_TREE;
              index2.value = NULL_TREE;
+             unsigned short clique = 0;
+             unsigned short base = 0;
              if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
                {
                  tree alias_type = NULL_TREE;
@@ -1620,6 +1623,27 @@ c_parser_gimple_postfix_expression (gimple_parser 
&parser)
                                  "expected constant step for %<__MEM%> "
                                  "operand");
                    }
+                 if (c_parser_next_token_is (parser, CPP_COMMA))
+                   {
+                     struct c_expr cl, ba;
+                     c_parser_consume_token (parser);
+                     cl = c_parser_gimple_postfix_expression (parser);
+                     if (c_parser_require (parser,
+                                           CPP_COLON, "expected %<:%>"))
+                       {
+                         ba = c_parser_gimple_postfix_expression (parser);
+                         if (!tree_fits_uhwi_p (cl.value)
+                             || !tree_fits_uhwi_p (ba.value)
+                             || compare_tree_int (cl.value,
+                                                  (clique = tree_to_uhwi
+                                                               (cl.value)))
+                             || compare_tree_int (ba.value,
+                                                  (base = tree_to_uhwi
+                                                                (ba.value))))
+                           error_at (cl.get_start (),
+                                     "invalid clique/base pair");
+                       }
+                   }
                  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
                                             "expected %<)%>");
                }
@@ -1635,6 +1659,12 @@ c_parser_gimple_postfix_expression (gimple_parser 
&parser)
              else
                expr.value = build2_loc (loc, MEM_REF,
                                         type, ptr.value, alias_off.value);
+             if (clique != 0)
+               {
+                 cfun->last_clique = MAX (cfun->last_clique, clique);
+                 MR_DEPENDENCE_CLIQUE (expr.value) = clique;
+                 MR_DEPENDENCE_BASE (expr.value) = base;
+               }
              break;
            }
          else if (strcmp (IDENTIFIER_POINTER (id), "__VIEW_CONVERT") == 0)
diff --git a/gcc/testsuite/gcc.dg/gimplefe-58.c 
b/gcc/testsuite/gcc.dg/gimplefe-58.c
new file mode 100644
index 000000000000..b209ab6d5469
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/gimplefe-58.c
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+/* { dg-options "-fgimple" } */
+
+int __GIMPLE (ssa)
+foo (int * restrict p, int * q)
+{
+  int x;
+  int _1;
+  int _7;
+
+  __BB(2):
+  x_4 = __MEM <int> (q_3(D), 1:0);
+  __MEM <int> ((int *)p_5(D), 1 :1) = 1;
+  _1 = __MEM <int> (q_3(D), 1: 0);
+  _7 = _1 + x_4;
+  return _7;
+}
diff --git a/gcc/tree-pretty-print.cc b/gcc/tree-pretty-print.cc
index ba04911ae905..12e093206833 100644
--- a/gcc/tree-pretty-print.cc
+++ b/gcc/tree-pretty-print.cc
@@ -2004,6 +2004,13 @@ dump_mem_ref (pretty_printer *pp, tree node, int spc, 
dump_flags_t flags)
                                 spc, flags | TDF_SLIM, false);
            }
        }
+      if (MR_DEPENDENCE_CLIQUE (node) != 0)
+       {
+         pp_string (pp, ", ");
+         pp_decimal_int (pp, MR_DEPENDENCE_CLIQUE (node));
+         pp_colon (pp);
+         pp_decimal_int (pp, MR_DEPENDENCE_BASE (node));
+       }
       pp_right_paren (pp);
     }
   else if (TREE_CODE (node) == MEM_REF

Reply via email to