This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] remove some usage of expr_list from read_rtx


From: Trevor Saunders <tbsaunde+gcc@tbsaunde.org>

Hi,

It seems much simpler for read_rtx to just add rtxs to a vector than to deal
with a bunch of expr list rtxen.


bootstrapped + regtested on x86_64-linux-gnu, ok?

Trev

gcc/ChangeLog:

2015-07-12  Trevor Saunders  <tbsaunde+gcc@tbsaunde.org>

	* gensupport.c (rtx_handle_directive): Adjust.
	* read-rtl.c (apply_iterators): Take vector to add rtxs to
	instead of expr list rtx.
	(add_define_attr_for_define_subst): Likewise.
	(add_define_subst_attr): Likewise.
	(read_subst_mapping): Likewise.
	(read_rtx): Likewise.
	* rtl.h (read_rtx): Adjust.
---
 gcc/gensupport.c | 12 ++++++++----
 gcc/read-rtl.c   | 47 ++++++++++++++++-------------------------------
 gcc/rtl.h        |  2 +-
 3 files changed, 25 insertions(+), 36 deletions(-)

diff --git a/gcc/gensupport.c b/gcc/gensupport.c
index 729366c..e673b5c 100644
--- a/gcc/gensupport.c
+++ b/gcc/gensupport.c
@@ -26,6 +26,7 @@
 #include "errors.h"
 #include "read-md.h"
 #include "gensupport.h"
+#include "vec.h"
 
 #define MAX_OPERANDS 40
 
@@ -2248,11 +2249,14 @@ process_define_subst (void)
 static void
 rtx_handle_directive (int lineno, const char *rtx_name)
 {
-  rtx queue, x;
+  auto_vec<rtx, 10> subrtxs;
+  if (!read_rtx (rtx_name, &subrtxs))
+    return;
 
-  if (read_rtx (rtx_name, &queue))
-    for (x = queue; x; x = XEXP (x, 1))
-      process_rtx (XEXP (x, 0), lineno);
+  rtx x;
+  unsigned int i;
+  FOR_EACH_VEC_ELT (subrtxs, i, x)
+    process_rtx (x, lineno);
 }
 
 /* Comparison function for the mnemonic hash table.  */
diff --git a/gcc/read-rtl.c b/gcc/read-rtl.c
index e8c849f..0f9e618 100644
--- a/gcc/read-rtl.c
+++ b/gcc/read-rtl.c
@@ -506,7 +506,7 @@ add_current_iterators (void **slot, void *data ATTRIBUTE_UNUSED)
    Build a list of expanded rtxes in the EXPR_LIST pointed to by QUEUE.  */
 
 static void
-apply_iterators (rtx original, rtx *queue)
+apply_iterators (rtx original, vec<rtx> *queue)
 {
   unsigned int i;
   const char *condition;
@@ -519,8 +519,7 @@ apply_iterators (rtx original, rtx *queue)
     {
       /* Raise an error if any attributes were used.  */
       apply_attribute_uses ();
-      XEXP (*queue, 0) = original;
-      XEXP (*queue, 1) = NULL_RTX;
+      queue->safe_push (original);
       return;
     }
 
@@ -572,8 +571,7 @@ apply_iterators (rtx original, rtx *queue)
 	    }
 	}
       /* Add the new rtx to the end of the queue.  */
-      XEXP (*queue, 0) = x;
-      XEXP (*queue, 1) = NULL_RTX;
+      queue->safe_push (x);
 
       /* Lexicographically increment the iterator value sequence.
 	 That is, cycle through iterator values, starting from the right,
@@ -590,10 +588,6 @@ apply_iterators (rtx original, rtx *queue)
 	    break;
 	  iterator->current_value = iterator->values;
 	}
-
-      /* At least one more rtx to go.  Allocate room for it.  */
-      XEXP (*queue, 1) = rtx_alloc (EXPR_LIST);
-      queue = &XEXP (*queue, 1);
     }
 }
 
@@ -945,7 +939,7 @@ read_mapping (struct iterator_group *group, htab_t table)
    define_subst ATTR_NAME should be applied.  This attribute is set and
    defined implicitly and automatically.  */
 static void
-add_define_attr_for_define_subst (const char *attr_name, rtx *queue)
+add_define_attr_for_define_subst (const char *attr_name, vec<rtx> *queue)
 {
   rtx const_str, return_rtx;
 
@@ -960,14 +954,13 @@ add_define_attr_for_define_subst (const char *attr_name, rtx *queue)
   XSTR (return_rtx, 1) = xstrdup ("no,yes");
   XEXP (return_rtx, 2) = const_str;
 
-  XEXP (*queue, 0) = return_rtx;
-  XEXP (*queue, 1) = NULL_RTX;
+  queue->safe_push (return_rtx);
 }
 
 /* This routine generates DEFINE_SUBST_ATTR expression with operands
    ATTR_OPERANDS and places it to QUEUE.  */
 static void
-add_define_subst_attr (const char **attr_operands, rtx *queue)
+add_define_subst_attr (const char **attr_operands, vec<rtx> *queue)
 {
   rtx return_rtx;
   int i;
@@ -978,8 +971,7 @@ add_define_subst_attr (const char **attr_operands, rtx *queue)
   for (i = 0; i < 4; i++)
     XSTR (return_rtx, i) = xstrdup (attr_operands[i]);
 
-  XEXP (*queue, 0) = return_rtx;
-  XEXP (*queue, 1) = NULL_RTX;
+  queue->safe_push (return_rtx);
 }
 
 /* Read define_subst_attribute construction.  It has next form:
@@ -992,18 +984,17 @@ add_define_subst_attr (const char **attr_operands, rtx *queue)
 
 static void
 read_subst_mapping (htab_t subst_iters_table, htab_t subst_attrs_table,
-		    rtx *queue)
+		    vec<rtx> *queue)
 {
   struct mapping *m;
   struct map_value **end_ptr;
   const char *attr_operands[4];
-  rtx * queue_elem = queue;
   int i;
 
   for (i = 0; i < 4; i++)
     attr_operands[i] = read_string (false);
 
-  add_define_subst_attr (attr_operands, queue_elem);
+  add_define_subst_attr (attr_operands, queue);
 
   bind_subst_iter_and_attr (attr_operands[1], attr_operands[0]);
 
@@ -1015,11 +1006,7 @@ read_subst_mapping (htab_t subst_iters_table, htab_t subst_attrs_table,
       end_ptr = add_map_value (end_ptr, 1, "");
       end_ptr = add_map_value (end_ptr, 2, "");
 
-      /* Add element to the queue.  */
-      XEXP (*queue, 1) = rtx_alloc (EXPR_LIST);
-      queue_elem = &XEXP (*queue, 1);
-
-      add_define_attr_for_define_subst (attr_operands[1], queue_elem);
+      add_define_attr_for_define_subst (attr_operands[1], queue);
     }
 
   m = add_mapping (&substs, subst_attrs_table, attr_operands[0]);
@@ -1050,15 +1037,15 @@ check_code_iterator (struct mapping *iterator)
    store the list of rtxes as an EXPR_LIST in *X.  */
 
 bool
-read_rtx (const char *rtx_name, rtx *x)
+read_rtx (const char *rtx_name, vec<rtx> *rtxen)
 {
-  static rtx queue_head;
+  static bool initialized = false;
 
   /* Do one-time initialization.  */
-  if (queue_head == 0)
+  if (!initialized)
     {
       initialize_iterators ();
-      queue_head = rtx_alloc (EXPR_LIST);
+      initialized = true;
     }
 
   /* Handle various rtx-related declarations that aren't themselves
@@ -1100,19 +1087,17 @@ read_rtx (const char *rtx_name, rtx *x)
     }
   if (strcmp (rtx_name, "define_subst_attr") == 0)
     {
-      read_subst_mapping (substs.iterators, substs.attrs, &queue_head);
-      *x = queue_head;
+      read_subst_mapping (substs.iterators, substs.attrs, rtxen);
 
       /* READ_SUBST_MAPPING could generate a new DEFINE_ATTR.  Return
 	 TRUE to process it.  */
       return true;
     }
 
-  apply_iterators (read_rtx_code (rtx_name), &queue_head);
+  apply_iterators (read_rtx_code (rtx_name), rtxen);
   iterator_uses.truncate (0);
   attribute_uses.truncate (0);
 
-  *x = queue_head;
   return true;
 }
 
diff --git a/gcc/rtl.h b/gcc/rtl.h
index d74c20f..77221d2 100644
--- a/gcc/rtl.h
+++ b/gcc/rtl.h
@@ -3619,7 +3619,7 @@ extern void init_varasm_once (void);
 extern rtx make_debug_expr_from_rtl (const_rtx);
 
 /* In read-rtl.c */
-extern bool read_rtx (const char *, rtx *);
+extern bool read_rtx (const char *, vec<rtx> *);
 
 /* In alias.c */
 extern rtx canon_rtx (rtx);
-- 
2.4.0


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]