tree-pretty-print.c (dump_generic_node): Provide -gimple variant for MEM_REF.
authorRichard Biener <rguenther@suse.de>
Thu, 12 Jan 2017 08:33:09 +0000 (08:33 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Thu, 12 Jan 2017 08:33:09 +0000 (08:33 +0000)
2017-01-12  Richard Biener  <rguenther@suse.de>

* tree-pretty-print.c (dump_generic_node): Provide -gimple
variant for MEM_REF.  Sanitize INTEGER_CST for -gimple.

c/
* gimple-parser.c (c_parser_gimple_postfix_expression): Parse
__MEM.

* gcc.dg/gimplefe-21.c: New testcase.

From-SVN: r244350

gcc/ChangeLog
gcc/c/ChangeLog
gcc/c/gimple-parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/gimplefe-21.c [new file with mode: 0644]
gcc/tree-pretty-print.c

index 20da95331ea5741a4c3854e51bee10f287b9b24f..012c095c78f7511c2ee6140f632e49b48f946e45 100644 (file)
@@ -1,3 +1,8 @@
+2017-01-12  Richard Biener  <rguenther@suse.de>
+
+       * tree-pretty-print.c (dump_generic_node): Provide -gimple
+       variant for MEM_REF.  Sanitize INTEGER_CST for -gimple.
+
 2017-01-12  Richard Biener  <rguenther@suse.de>
 
        * tree.c (initialize_tree_contains_struct): Make TS_OPTIMIZATION
index 341407a21def24b8afddf950d7f1a6e3e5e49061..65531aa34754a3bcaf89d6b5af4d1f012270d63c 100644 (file)
@@ -1,3 +1,8 @@
+2017-01-12  Richard Biener  <rguenther@suse.de>
+
+       * gimple-parser.c (c_parser_gimple_postfix_expression): Parse
+       __MEM.
+
 2017-01-11  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/72813
index 37e792ac35554d60206803056511b592638fd7d2..ee8a01a7f93861738237896906d7591176c9656c 100644 (file)
@@ -727,6 +727,79 @@ c_parser_gimple_postfix_expression (c_parser *parser)
       if (c_parser_peek_token (parser)->id_kind == C_ID_ID)
        {
          tree id = c_parser_peek_token (parser)->value;
+         if (strcmp (IDENTIFIER_POINTER (id), "__MEM") == 0)
+           {
+             /* __MEM '<' type-name [ ',' number ] '>'
+                      '(' [ '(' type-name ')' ] unary-expression
+                          [ '+' number ] ')'  */
+             location_t loc = c_parser_peek_token (parser)->location;
+             c_parser_consume_token (parser);
+             struct c_type_name *type_name = NULL;
+             tree alignment = NULL_TREE;
+             if (c_parser_require (parser, CPP_LESS, "expected %<<%>"))
+               {
+                 type_name = c_parser_type_name (parser);
+                 /* Optional alignment.  */
+                 if (c_parser_next_token_is (parser, CPP_COMMA))
+                   {
+                     c_parser_consume_token (parser);
+                     alignment
+                       = c_parser_gimple_postfix_expression (parser).value;
+                   }
+                 c_parser_skip_until_found (parser,
+                                            CPP_GREATER, "expected %<>%>");
+               }
+             struct c_expr ptr;
+             ptr.value = error_mark_node;
+             tree alias_off = NULL_TREE;
+             if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
+               {
+                 tree alias_type = NULL_TREE;
+                 /* Optional alias-type cast.  */
+                 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
+                   {
+                     c_parser_consume_token (parser);
+                     struct c_type_name *alias_type_name
+                       = c_parser_type_name (parser);
+                     c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
+                                                "expected %<)%>");
+                     if (alias_type_name)
+                       {
+                         tree tem;
+                         alias_type = groktypename (alias_type_name,
+                                                    &tem, NULL);
+                       }
+                   }
+                 ptr = c_parser_gimple_unary_expression (parser);
+                 if (! alias_type)
+                   alias_type = TREE_TYPE (ptr.value);
+                 /* Optional constant offset.  */
+                 if (c_parser_next_token_is (parser, CPP_PLUS))
+                   {
+                     c_parser_consume_token (parser);
+                     alias_off
+                       = c_parser_gimple_postfix_expression (parser).value;
+                     alias_off = fold_convert (alias_type, alias_off);
+                   }
+                 if (! alias_off)
+                   alias_off = build_int_cst (alias_type, 0);
+                 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
+                                            "expected %<)%>");
+               }
+             if (! type_name || c_parser_error (parser))
+               {
+                 c_parser_set_error (parser, false);
+                 return expr;
+               }
+             tree tem = NULL_TREE;
+             tree type = groktypename (type_name, &tem, NULL);
+             if (alignment)
+               type = build_aligned_type (type, tree_to_uhwi (alignment));
+             expr.value = build2_loc (loc, MEM_REF,
+                                      type, ptr.value, alias_off);
+             break;
+           }
+         /* SSA name.  */
          unsigned version, ver_offset;
          if (! lookup_name (id)
              && c_parser_parse_ssa_name_id (id, &version, &ver_offset))
index b10c036071090e3f303a61b8ca1c82a98d873a57..561bd3fe5398003d722105cb0172131395a34805 100644 (file)
@@ -1,3 +1,7 @@
+2017-01-12  Richard Biener  <rguenther@suse.de>
+
+       * gcc.dg/gimplefe-21.c: New testcase.
+
 2017-01-12  Michael Collison  <michael.collison@arm.com>
 
        * gcc.dg/zero_bits_compound-2.c: Fix test for aarch64.
diff --git a/gcc/testsuite/gcc.dg/gimplefe-21.c b/gcc/testsuite/gcc.dg/gimplefe-21.c
new file mode 100644 (file)
index 0000000..55ea0b8
--- /dev/null
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-options "-fgimple" } */
+
+float __GIMPLE ()
+foo (int * p)
+{
+  float f;
+  float D1800;
+  unsigned int D1799;
+
+  D1799 = __MEM <unsigned int, 8> ((char *)p + 1);
+  __MEM <unsigned int, 16> ((char *)&f + 0xfffffffffffffffe) = D1799;
+  __MEM <int> (p) = 1;
+  __MEM <int, 2> (p) = 1;
+  __MEM <int> (p + 2) = 1;
+  __MEM <int> ((char *)p) = 1;
+  D1800 = f;
+  return D1800;
+}
index 36b29d538783f40dd22c597184089a7d5000119a..87b404475eeeb7f3873a81dbac952cbaea034319 100644 (file)
@@ -1459,7 +1459,38 @@ dump_generic_node (pretty_printer *pp, tree node, int spc, int flags,
 
     case MEM_REF:
       {
-       if (integer_zerop (TREE_OPERAND (node, 1))
+       if (flags & TDF_GIMPLE)
+         {
+           pp_string (pp, "__MEM <");
+           dump_generic_node (pp, TREE_TYPE (node),
+                              spc, flags | TDF_SLIM, false);
+           if (TYPE_ALIGN (TREE_TYPE (node))
+               != TYPE_ALIGN (TYPE_MAIN_VARIANT (TREE_TYPE (node))))
+             {
+               pp_string (pp, ", ");
+               pp_decimal_int (pp, TYPE_ALIGN (TREE_TYPE (node)));
+             }
+           pp_greater (pp);
+           pp_string (pp, " (");
+           if (TREE_TYPE (TREE_OPERAND (node, 0))
+               != TREE_TYPE (TREE_OPERAND (node, 1)))
+             {
+               pp_left_paren (pp);
+               dump_generic_node (pp, TREE_TYPE (TREE_OPERAND (node, 1)),
+                                  spc, flags | TDF_SLIM, false);
+               pp_right_paren (pp);
+             }
+           dump_generic_node (pp, TREE_OPERAND (node, 0),
+                              spc, flags | TDF_SLIM, false);
+           if (! integer_zerop (TREE_OPERAND (node, 1)))
+             {
+               pp_string (pp, " + ");
+               dump_generic_node (pp, TREE_OPERAND (node, 1),
+                                  spc, flags | TDF_SLIM, false);
+             }
+           pp_right_paren (pp);
+         }
+       else if (integer_zerop (TREE_OPERAND (node, 1))
            /* Dump the types of INTEGER_CSTs explicitly, for we can't
               infer them and MEM_ATTR caching will share MEM_REFs
               with differently-typed op0s.  */
@@ -1633,7 +1664,8 @@ dump_generic_node (pretty_printer *pp, tree node, int spc, int flags,
       break;
 
     case INTEGER_CST:
-      if (TREE_CODE (TREE_TYPE (node)) == POINTER_TYPE)
+      if (TREE_CODE (TREE_TYPE (node)) == POINTER_TYPE
+         && ! (flags & TDF_GIMPLE))
        {
          /* In the case of a pointer, one may want to divide by the
             size of the pointed-to type.  Unfortunately, this not
@@ -1661,7 +1693,11 @@ dump_generic_node (pretty_printer *pp, tree node, int spc, int flags,
       else if (tree_fits_shwi_p (node))
        pp_wide_integer (pp, tree_to_shwi (node));
       else if (tree_fits_uhwi_p (node))
-       pp_unsigned_wide_integer (pp, tree_to_uhwi (node));
+       {
+         pp_unsigned_wide_integer (pp, tree_to_uhwi (node));
+         if (flags & TDF_GIMPLE)
+           pp_character (pp, 'U');
+       }
       else
        {
          wide_int val = node;