From 4da7aec5a2c43e32ca09e98a37f9f805b1fb1e1c Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Tue, 25 Oct 2016 20:55:57 -0400
Subject: [PATCH 23/28] FIXME: reinstate INSN_UID in function_reader

---
 gcc/read-rtl-function.c                            | 66 +++++++---------------
 gcc/read-rtl.c                                     |  3 +-
 gcc/testsuite/selftests/asr_div1.rtl               |  4 +-
 gcc/testsuite/selftests/cfg-test.rtl               |  8 +--
 gcc/testsuite/selftests/const-int.rtl              |  8 +--
 .../selftests/copy-hard-reg-into-frame.rtl         | 14 ++---
 gcc/testsuite/selftests/insn-with-mode.rtl         |  2 +-
 gcc/testsuite/selftests/jump-to-label-ref.rtl      |  4 +-
 gcc/testsuite/selftests/jump-to-return.rtl         |  2 +-
 gcc/testsuite/selftests/jump-to-simple-return.rtl  |  2 +-
 gcc/testsuite/selftests/note-insn-deleted.rtl      |  2 +-
 gcc/testsuite/selftests/note_insn_basic_block.rtl  |  2 +-
 gcc/testsuite/selftests/simple-cse.rtl             | 16 +++---
 gcc/testsuite/selftests/symbol-ref.rtl             |  2 +-
 gcc/testsuite/selftests/x86_64/call-insn.rtl       |  2 +-
 gcc/testsuite/selftests/x86_64/times-two.rtl       | 18 +++---
 gcc/testsuite/selftests/x86_64/unspec.rtl          |  4 +-
 17 files changed, 66 insertions(+), 93 deletions(-)

diff --git a/gcc/read-rtl-function.c b/gcc/read-rtl-function.c
index 6a0298b..3b977b3 100644
--- a/gcc/read-rtl-function.c
+++ b/gcc/read-rtl-function.c
@@ -139,7 +139,7 @@ class function_reader : public rtx_reader
   rtx consolidate_singletons (rtx x);
   void maybe_read_location (int operand_idx, rtx insn);
 
-  void assign_insn_uids ();
+  void handle_insn_uids ();
   void apply_fixups ();
 
  private:
@@ -499,7 +499,7 @@ function_reader::parse_function ()
 	fatal_with_file_and_line ("missing 'crtl'");
     }
 
-  assign_insn_uids ();
+  handle_insn_uids ();
 
   apply_fixups ();
 
@@ -510,17 +510,6 @@ function_reader::parse_function ()
      LABEL_REFs have their LABEL_REF_LABEL set up.  */
   rebuild_jump_labels (get_insns ());
 
-
-  /* Ensure x_cur_insn_uid is 1 more than the biggest insn UID seen.
-     This is normally updated by the various make_*insn_raw functions.  */
-  {
-    rtx_insn *insn;
-    int max_uid = 0;
-    for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
-      max_uid = MAX (max_uid, INSN_UID (insn));
-    crtl->emit.x_cur_insn_uid = max_uid + 1;
-  }
-
   crtl->init_stack_alignment ();
 }
 
@@ -1597,41 +1586,26 @@ function_reader::maybe_read_location (int operand_idx, rtx insn)
 }
 
 /* Postprocessing subroutine of function_reader::parse_function.
-   At this point, only CODE_LABELs have INSN_UID values (based
-   on the values seen in the dump).
-   Give everything else an INSN_UID, ensuring no duplication,
-   preserving the values in CODE_LABELs, and setting up
-   crtl->emit.x_cur_insn_uid.  */
+   Populate m_insns_by_uid.  */
 
 void
-function_reader::assign_insn_uids ()
+function_reader::handle_insn_uids ()
 {
   /* Locate the currently assigned INSN_UID values, storing
      them in m_insns_by_uid.  */
-  for (rtx_insn *insn = get_insns (); insn; insn = NEXT_INSN (insn))
-    if (INSN_UID (insn))
-      {
-	gcc_assert (GET_CODE (insn) == CODE_LABEL);
-
-	m_insns_by_uid.put (INSN_UID (insn), insn);
-      }
-
-  /* Give everything else an INSN_UID.  */
+  int max_uid = 0;
   for (rtx_insn *insn = get_insns (); insn; insn = NEXT_INSN (insn))
     {
-      if (!INSN_UID (insn))
-	{
-	  /* Generate a non-duplicate INSN_UID value.  */
-	  int uid;
-	  do
-	    uid = crtl->emit.x_cur_insn_uid++;
-	  while (m_insns_by_uid.get (uid));
-
-	  /* Set the UID for "insn" and record it.  */
-	  INSN_UID (insn) = uid;
-	  m_insns_by_uid.put (uid, insn);
-	}
+      if (m_insns_by_uid.get (INSN_UID (insn)))
+	error ("duplicate insn UID: %i", INSN_UID (insn));
+      m_insns_by_uid.put (INSN_UID (insn), insn);
+      if (INSN_UID (insn) > max_uid)
+	max_uid = INSN_UID (insn);
     }
+
+  /* Ensure x_cur_insn_uid is 1 more than the biggest insn UID seen.
+     This is normally updated by the various make_*insn_raw functions.  */
+  crtl->emit.x_cur_insn_uid = max_uid + 1;
 }
 
 /* Apply all of the recorded fixups.  */
@@ -2253,13 +2227,13 @@ test_loading_full_dump_x86_64 ()
   rtx_insn *insn_1 = get_insn_by_uid (1);
   ASSERT_EQ (NOTE, GET_CODE (insn_1));
 
-  rtx_insn *insn_6 = get_insn_by_uid (6);
-  ASSERT_EQ (INSN, GET_CODE (insn_6));
-  ASSERT_EQ (PARALLEL, GET_CODE (PATTERN (insn_6)));
+  rtx_insn *insn_7 = get_insn_by_uid (7);
+  ASSERT_EQ (INSN, GET_CODE (insn_7));
+  ASSERT_EQ (PARALLEL, GET_CODE (PATTERN (insn_7)));
 
-  rtx_insn *insn_9 = get_insn_by_uid (9);
-  ASSERT_EQ (INSN, GET_CODE (insn_9));
-  ASSERT_EQ (USE, GET_CODE (PATTERN (insn_9)));
+  rtx_insn *insn_15 = get_insn_by_uid (15);
+  ASSERT_EQ (INSN, GET_CODE (insn_15));
+  ASSERT_EQ (USE, GET_CODE (PATTERN (insn_15)));
 
   /* Verify crtl->return_rtx.  */
   ASSERT_EQ (REG, GET_CODE (crtl->return_rtx));
diff --git a/gcc/read-rtl.c b/gcc/read-rtl.c
index 131a198..b8ec397 100644
--- a/gcc/read-rtl.c
+++ b/gcc/read-rtl.c
@@ -1314,8 +1314,7 @@ rtx_reader::read_rtx_code (const char *code_name)
   else
     unread_char (c);
 
-  if (INSN_CHAIN_CODE_P (code)
-      && (code == CODE_LABEL || !is_compact ()))
+  if (INSN_CHAIN_CODE_P (code))
     {
       read_name (&name);
       INSN_UID (return_rtx) = atoi (name.string);
diff --git a/gcc/testsuite/selftests/asr_div1.rtl b/gcc/testsuite/selftests/asr_div1.rtl
index 857dd86..1507893 100644
--- a/gcc/testsuite/selftests/asr_div1.rtl
+++ b/gcc/testsuite/selftests/asr_div1.rtl
@@ -6,13 +6,13 @@
   (insn-chain
     (block 2
       (edge-from entry (flags "FALLTHRU"))
-      (cinsn (set (reg:DI %2)
+      (cinsn 1 (set (reg:DI %2)
         (lshiftrt:DI (reg:DI %0)
             (const_int 32)))
         "../../src/gcc/testsuite/gcc.dg/asr_div1.c":14
         (expr_list:REG_DEAD (reg:DI %0)
           (nil)))
-      (cinsn (set (reg:SI %1)
+      (cinsn 2 (set (reg:SI %1)
         (ashiftrt:SI (subreg:SI (reg:DI %2) 0)
             (const_int 3)))
         "../../src/gcc/testsuite/gcc.dg/asr_div1.c":14
diff --git a/gcc/testsuite/selftests/cfg-test.rtl b/gcc/testsuite/selftests/cfg-test.rtl
index 874b9e5..08a0e22 100644
--- a/gcc/testsuite/selftests/cfg-test.rtl
+++ b/gcc/testsuite/selftests/cfg-test.rtl
@@ -13,24 +13,24 @@
   (insn-chain
      (block 2
        (edge-from entry (flags "FALLTHRU"))
-       (cnote [bb 2] NOTE_INSN_BASIC_BLOCK)
+       (cnote 1 [bb 2] NOTE_INSN_BASIC_BLOCK)
        (edge-to 3 (flags "TRUE_VALUE"))
        (edge-to 4 (flags "FALSE_VALUE"))
      ) ;; block 2
      (block 3
        (edge-from 2 (flags "TRUE_VALUE"))
-       (cnote [bb 3] NOTE_INSN_BASIC_BLOCK)
+       (cnote 2 [bb 3] NOTE_INSN_BASIC_BLOCK)
        (edge-to 5 (flags "FALLTHRU"))
      ) ;; block 3
      (block 4
        (edge-from 2 (flags "FALSE_VALUE"))
-       (cnote [bb 4] NOTE_INSN_BASIC_BLOCK)
+       (cnote 3 [bb 4] NOTE_INSN_BASIC_BLOCK)
        (edge-to 5 (flags "FALLTHRU"))
      ) ;; block 4
      (block 5
        (edge-from 3 (flags "FALLTHRU"))
        (edge-from 4 (flags "FALLTHRU"))
-       (cnote [bb 5] NOTE_INSN_BASIC_BLOCK)
+       (cnote 4 [bb 5] NOTE_INSN_BASIC_BLOCK)
        (edge-to exit (flags "FALLTHRU"))
      ) ;; block 5
   ) ;; insn-chain
diff --git a/gcc/testsuite/selftests/const-int.rtl b/gcc/testsuite/selftests/const-int.rtl
index b4fc771..e50dd88 100644
--- a/gcc/testsuite/selftests/const-int.rtl
+++ b/gcc/testsuite/selftests/const-int.rtl
@@ -2,16 +2,16 @@
   (insn-chain
     (block 2
       (edge-from entry (flags "FALLTHRU"))
-      (cinsn
+      (cinsn 1
         (set (reg:SI %0) (const_int 0))
         "test.c":2 (nil))
-      (cinsn
+      (cinsn 2
         (set (reg:SI %1) (const_int 1))
         "test.c":2 (nil))
-      (cinsn
+      (cinsn 3
         (set (reg:SI %2) (const_int -1))
         "test.c":2 (nil))
-      (cinsn
+      (cinsn 4
         (set (reg:SI %3) (const_int 256))
         "test.c":2 (nil))
       (edge-to exit (flags "FALLTHRU"))
diff --git a/gcc/testsuite/selftests/copy-hard-reg-into-frame.rtl b/gcc/testsuite/selftests/copy-hard-reg-into-frame.rtl
index 24a89e4..4598a1c 100644
--- a/gcc/testsuite/selftests/copy-hard-reg-into-frame.rtl
+++ b/gcc/testsuite/selftests/copy-hard-reg-into-frame.rtl
@@ -2,13 +2,13 @@
   (insn-chain
     (block 2
       (edge-from entry (flags "FALLTHRU"))
-      (cinsn (set (mem/c:SI
-                    (plus:DI
-                      (reg/f:DI frame)
-                      (const_int -4))
-                    [1 i+0 S4 A32])
-             (reg:SI di [ i ])) "test.c":2
-             (nil))
+      (cinsn 1 (set (mem/c:SI
+                      (plus:DI
+                        (reg/f:DI frame)
+                        (const_int -4))
+                      [1 i+0 S4 A32])
+               (reg:SI di [ i ])) "test.c":2
+               (nil))
       (edge-to exit (flags "FALLTHRU"))
     ) ;; block 2
   ) ;; insn-chain
diff --git a/gcc/testsuite/selftests/insn-with-mode.rtl b/gcc/testsuite/selftests/insn-with-mode.rtl
index 82e343c..8c4609b 100644
--- a/gcc/testsuite/selftests/insn-with-mode.rtl
+++ b/gcc/testsuite/selftests/insn-with-mode.rtl
@@ -1,7 +1,7 @@
 (function "insn_with_mode"
   (insn-chain
     (block 2
-      (insn:TI (set (reg:SI %0) (reg:SI %1)) (nil))
+      (insn:TI 1 (set (reg:SI %0) (reg:SI %1)) (nil))
     ) ;; block
   ) ;; insn-chain
 ) ;; function
diff --git a/gcc/testsuite/selftests/jump-to-label-ref.rtl b/gcc/testsuite/selftests/jump-to-label-ref.rtl
index 80efa05..1464503 100644
--- a/gcc/testsuite/selftests/jump-to-label-ref.rtl
+++ b/gcc/testsuite/selftests/jump-to-label-ref.rtl
@@ -2,12 +2,12 @@
   (insn-chain
     (block 4
       (edge-from entry (flags "FALLTHRU"))
-      (cjump_insn (set (pc) (label_ref 100))
+      (cjump_insn 1 (set (pc) (label_ref 100))
         "../../src/gcc/testsuite/rtl.dg/test.c":4
         (nil))
       (edge-to 5)
     ) ;; block 4
-    (cbarrier)
+    (cbarrier 2)
     (block 5   
       (edge-from 4)
       (clabel 100 2 (nil) [1 uses])
diff --git a/gcc/testsuite/selftests/jump-to-return.rtl b/gcc/testsuite/selftests/jump-to-return.rtl
index 3652fea..9da89ef 100644
--- a/gcc/testsuite/selftests/jump-to-return.rtl
+++ b/gcc/testsuite/selftests/jump-to-return.rtl
@@ -2,7 +2,7 @@
   (insn-chain
     (block 4
       (edge-from entry (flags "FALLTHRU"))
-      (cjump_insn (return)
+      (cjump_insn 1 (return)
         "../../src/gcc/testsuite/rtl.dg/test.c":4
         (nil))
       (edge-to exit (flags "FALLTHRU"))
diff --git a/gcc/testsuite/selftests/jump-to-simple-return.rtl b/gcc/testsuite/selftests/jump-to-simple-return.rtl
index f8d0cc8..5a9c1d5 100644
--- a/gcc/testsuite/selftests/jump-to-simple-return.rtl
+++ b/gcc/testsuite/selftests/jump-to-simple-return.rtl
@@ -2,7 +2,7 @@
   (insn-chain
     (block 4
       (edge-from entry (flags "FALLTHRU"))
-      (cjump_insn (simple_return)
+      (cjump_insn 1 (simple_return)
         "../../src/gcc/testsuite/rtl.dg/test.c":4
         (nil))
       (edge-to exit (flags "FALLTHRU"))
diff --git a/gcc/testsuite/selftests/note-insn-deleted.rtl b/gcc/testsuite/selftests/note-insn-deleted.rtl
index fc398ee..a388acd 100644
--- a/gcc/testsuite/selftests/note-insn-deleted.rtl
+++ b/gcc/testsuite/selftests/note-insn-deleted.rtl
@@ -1,5 +1,5 @@
 (function "example_note"
   (insn-chain
-    (cnote NOTE_INSN_DELETED)
+    (cnote 1 NOTE_INSN_DELETED)
   ) ;; insn-chain
 ) ;; function
diff --git a/gcc/testsuite/selftests/note_insn_basic_block.rtl b/gcc/testsuite/selftests/note_insn_basic_block.rtl
index 6be1eee..e792d98 100644
--- a/gcc/testsuite/selftests/note_insn_basic_block.rtl
+++ b/gcc/testsuite/selftests/note_insn_basic_block.rtl
@@ -2,7 +2,7 @@
   (insn-chain
     (block 2
       (edge-from entry (flags "FALLTHRU"))
-      (cnote [bb 2] NOTE_INSN_BASIC_BLOCK)
+      (cnote 1 [bb 2] NOTE_INSN_BASIC_BLOCK)
       (edge-to exit (flags "FALLTHRU"))
     ) ;; block 2
   ) ;; insn-chain
diff --git a/gcc/testsuite/selftests/simple-cse.rtl b/gcc/testsuite/selftests/simple-cse.rtl
index f393664..5fe745d 100644
--- a/gcc/testsuite/selftests/simple-cse.rtl
+++ b/gcc/testsuite/selftests/simple-cse.rtl
@@ -2,14 +2,14 @@
   (insn-chain
     (block 2
       (edge-from entry (flags "FALLTHRU"))
-      (cinsn (set (reg:SI %1)
-                  (plus:SI (reg:SI %0)
-                           (const_int 1))) (nil))
-      (cinsn (set (reg:SI %2)
-                  (plus:SI (reg:SI %0)
-                           (const_int 1))) (nil))
-      (cinsn (set (mem:SI (reg:SI %3) [1 i+0 S4 A32])
-                  (mult:SI (reg:SI %1) (reg:SI %2))) (nil))
+      (cinsn 1 (set (reg:SI %1)
+                    (plus:SI (reg:SI %0)
+                             (const_int 1))) (nil))
+      (cinsn 2 (set (reg:SI %2)
+                    (plus:SI (reg:SI %0)
+                             (const_int 1))) (nil))
+      (cinsn 3 (set (mem:SI (reg:SI %3) [1 i+0 S4 A32])
+                    (mult:SI (reg:SI %1) (reg:SI %2))) (nil))
       (edge-to exit (flags "FALLTHRU"))
     ) ;; block 2
   ) ;; insn-chain
diff --git a/gcc/testsuite/selftests/symbol-ref.rtl b/gcc/testsuite/selftests/symbol-ref.rtl
index 0b2d6e8..8339eca 100644
--- a/gcc/testsuite/selftests/symbol-ref.rtl
+++ b/gcc/testsuite/selftests/symbol-ref.rtl
@@ -2,7 +2,7 @@
   (insn-chain
     (block 2
       (edge-from entry (flags "FALLTHRU"))
-      (insn
+      (cinsn 1
         (set (reg:SI %0)
              (high:SI (symbol_ref:SI ("isl_obj_map_vtable") [flags 0xc0] <var_decl 0x7fa0363ea240 isl_obj_map_vtable>)))
         "y.c":12702
diff --git a/gcc/testsuite/selftests/x86_64/call-insn.rtl b/gcc/testsuite/selftests/x86_64/call-insn.rtl
index b47dd19..8f3a781 100644
--- a/gcc/testsuite/selftests/x86_64/call-insn.rtl
+++ b/gcc/testsuite/selftests/x86_64/call-insn.rtl
@@ -2,7 +2,7 @@
   (insn-chain
     (block 2
       (edge-from entry (flags "FALLTHRU"))
-      (ccall_insn/j
+      (ccall_insn/j 1
         (set (reg:DF xmm0)
              (call (mem:QI (symbol_ref:DI ("sqrt") [flags 0x41]  <function_decl 0x7f82b1429d00 sqrt>) [0 __builtin_sqrt S1 A8])
                     (const_int 0))) "test.c":19
diff --git a/gcc/testsuite/selftests/x86_64/times-two.rtl b/gcc/testsuite/selftests/x86_64/times-two.rtl
index 017effc..a26d888 100644
--- a/gcc/testsuite/selftests/x86_64/times-two.rtl
+++ b/gcc/testsuite/selftests/x86_64/times-two.rtl
@@ -9,20 +9,20 @@
 
 (function "times_two"
   (insn-chain
-    (cnote NOTE_INSN_DELETED)
+    (cnote 1 NOTE_INSN_DELETED)
     (block 2
       (edge-from entry (flags "FALLTHRU"))
-      (cnote [bb 2] NOTE_INSN_BASIC_BLOCK)
-      (cinsn (set (mem/c:SI (plus:DI (reg/f:DI virtual-stack-vars)
+      (cnote 4 [bb 2] NOTE_INSN_BASIC_BLOCK)
+      (cinsn 2 (set (mem/c:SI (plus:DI (reg/f:DI virtual-stack-vars)
                             (const_int -4)) [1 i+0 S4 A32])
                     (reg:SI di [ i ])) "../../src/times-two.c":2
                  (nil))
-      (cnote NOTE_INSN_FUNCTION_BEG)
-      (cinsn (set (reg:SI %2)
+      (cnote 3 NOTE_INSN_FUNCTION_BEG)
+      (cinsn 6 (set (reg:SI %2)
                     (mem/c:SI (plus:DI (reg/f:DI virtual-stack-vars)
                             (const_int -4)) [1 i+0 S4 A32])) "../../src/times-two.c":3
                  (nil))
-      (cinsn (parallel [
+      (cinsn 7 (parallel [
                         (set (reg:SI %0 [ _2 ])
                             (ashift:SI (reg:SI %2)
                                 (const_int 1)))
@@ -32,13 +32,13 @@
                                 (const_int -4)) [1 i+0 S4 A32])
                         (const_int 1))
                     (nil)))
-      (cinsn (set (reg:SI %1 [ <retval> ])
+      (cinsn 10 (set (reg:SI %1 [ <retval> ])
                     (reg:SI %0 [ _2 ])) "../../src/times-two.c":3
                  (nil))
-      (cinsn (set (reg/i:SI ax)
+      (cinsn 14 (set (reg/i:SI ax)
                     (reg:SI %1 [ <retval> ])) "../../src/times-two.c":4
                  (nil))
-      (cinsn (use (reg/i:SI ax)) "../../src/times-two.c":4
+      (cinsn 15 (use (reg/i:SI ax)) "../../src/times-two.c":4
                  (nil))
       (edge-to exit (flags "FALLTHRU"))
     ) ;; block 2
diff --git a/gcc/testsuite/selftests/x86_64/unspec.rtl b/gcc/testsuite/selftests/x86_64/unspec.rtl
index 5d886dd..ac822ac 100644
--- a/gcc/testsuite/selftests/x86_64/unspec.rtl
+++ b/gcc/testsuite/selftests/x86_64/unspec.rtl
@@ -2,13 +2,13 @@
   (insn-chain
     (block 2
       (edge-from entry (flags "FALLTHRU"))
-      (cinsn (set (mem/v:BLK (0|scratch:DI) [0  A8])
+      (cinsn 1 (set (mem/v:BLK (0|scratch:DI) [0  A8])
                     (unspec:BLK [
                             (mem/v:BLK (reuse_rtx 0) [0  A8])
                         ] UNSPEC_MEMORY_BLOCKAGE)) "../../src/gcc/testsuite/gcc.dg/rtl/test.c":2
                  (nil))
 
-      (cinsn (set (mem/v:BLK (1|scratch:DI) [0  A8])
+      (cinsn 2 (set (mem/v:BLK (1|scratch:DI) [0  A8])
                     (unspec_volatile:BLK [
                             (mem/v:BLK (reuse_rtx 1) [0  A8])
                         ] UNSPECV_RDTSCP)) "../../src/gcc/testsuite/gcc.dg/rtl/test.c":2
-- 
1.8.5.3

