public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/vendors/riscv/heads/gcc-13-with-riscv-opts)] mode-switching: Avoid quadractic list operation
@ 2023-11-21  4:11 Jeff Law
  0 siblings, 0 replies; only message in thread
From: Jeff Law @ 2023-11-21  4:11 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:05de0ef2e53ad1ad82feac0954aa61626304317f

commit 05de0ef2e53ad1ad82feac0954aa61626304317f
Author: Richard Sandiford <richard.sandiford@arm.com>
Date:   Sat Nov 11 17:28:55 2023 +0000

    mode-switching: Avoid quadractic list operation
    
    add_seginfo chained insn information to the end of a list
    by starting at the head of the list.  This patch avoids the
    quadraticness by keeping track of the tail pointer.
    
    gcc/
            * mode-switching.cc (add_seginfo): Replace head pointer with
            a pointer to the tail pointer.
            (optimize_mode_switching): Update calls accordingly.
    
    (cherry picked from commit 174ee5115a3004d3664165e9d619535b579111d4)

Diff:
---
 gcc/mode-switching.cc | 24 ++++++++----------------
 1 file changed, 8 insertions(+), 16 deletions(-)

diff --git a/gcc/mode-switching.cc b/gcc/mode-switching.cc
index 8577069bde1..bebe89d5fd2 100644
--- a/gcc/mode-switching.cc
+++ b/gcc/mode-switching.cc
@@ -162,23 +162,14 @@ new_seginfo (int mode, rtx_insn *insn, const HARD_REG_SET &regs_live)
 }
 
 /* Add a seginfo element to the end of a list.
-   HEAD is a pointer to the list beginning.
+   TAIL is a pointer to the list's null terminator.
    INFO is the structure to be linked in.  */
 
 static void
-add_seginfo (struct bb_info *head, struct seginfo *info)
+add_seginfo (struct seginfo ***tail_ptr, struct seginfo *info)
 {
-  struct seginfo *ptr;
-
-  if (head->seginfo == NULL)
-    head->seginfo = info;
-  else
-    {
-      ptr = head->seginfo;
-      while (ptr->next != NULL)
-	ptr = ptr->next;
-      ptr->next = info;
-    }
+  **tail_ptr = info;
+  *tail_ptr = &info->next;
 }
 
 /* Record in LIVE that register REG died.  */
@@ -574,6 +565,7 @@ optimize_mode_switching (void)
 	 Also compute the initial transparency settings.  */
       FOR_EACH_BB_FN (bb, cfun)
 	{
+	  struct seginfo **tail_ptr = &info[bb->index].seginfo;
 	  struct seginfo *ptr;
 	  int last_mode = no_mode;
 	  bool any_set_required = false;
@@ -599,7 +591,7 @@ optimize_mode_switching (void)
 		if (ins_pos != BB_END (bb))
 		  ins_pos = NEXT_INSN (ins_pos);
 		ptr = new_seginfo (no_mode, ins_pos, live_now);
-		add_seginfo (info + bb->index, ptr);
+		add_seginfo (&tail_ptr, ptr);
 		for (i = 0; i < no_mode; i++)
 		  clear_mode_bit (transp[bb->index], j, i);
 	      }
@@ -617,7 +609,7 @@ optimize_mode_switching (void)
 		      any_set_required = true;
 		      last_mode = mode;
 		      ptr = new_seginfo (mode, insn, live_now);
-		      add_seginfo (info + bb->index, ptr);
+		      add_seginfo (&tail_ptr, ptr);
 		      for (i = 0; i < no_mode; i++)
 			clear_mode_bit (transp[bb->index], j, i);
 		    }
@@ -646,7 +638,7 @@ optimize_mode_switching (void)
 	  if (!any_set_required)
 	    {
 	      ptr = new_seginfo (no_mode, BB_END (bb), live_now);
-	      add_seginfo (info + bb->index, ptr);
+	      add_seginfo (&tail_ptr, ptr);
 	      if (last_mode != no_mode)
 		for (i = 0; i < no_mode; i++)
 		  clear_mode_bit (transp[bb->index], j, i);

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

only message in thread, other threads:[~2023-11-21  4:11 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-21  4:11 [gcc(refs/vendors/riscv/heads/gcc-13-with-riscv-opts)] mode-switching: Avoid quadractic list operation Jeff Law

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).