This change takes loops of the form:

  for (int <i> = 0; <i> < FIRST_PSEUDO_REGISTER; <i>++)
    if (TEST_HARD_REG_BIT (<set>, <i>))
      <body that doesn't change i or set>

and carries out the necessary refactoring to rewrite them as:

  hard_reg_set_iterator hrsi; [...]
  EXECUTE_IF_SET_IN_HARD_REG_SET (<set>, 0, <i>, hrsi)
    <body that doesn't change i or set>

in loops where expressing <set> does not involve <i>.

gcc/
        * caller-save.cc: Analyzed all hits, replaced those matching the 
pattern.

Signed-off-by: Kevin Stefanov <[email protected]>
---
I do not have write access to the GCC repo, as this is my first ever
contribution to free and open source software. I made sure to rerun
the GCC testsuite on the objdir with my changes and compare it to the
run made on the pristine objdir with a cleanly cloned and built GCC. 
When comparing the test result differences, I believe everything is good,
the only weird thing I get, which I'm not 100% sure should be cause for 
alarm or not, is that one test gets reported to have passed, which wasn't
passing before (in the clean GCC) and then that same test is reported to
have disappeared in the test run in my changed objdir. The test in question is:
g++: g++.dg/modules/compile-std1.C module-cmi <bits/stdc++.h>.
This is the only difference found in my test runs, could somebody confirm it's 
nothing to worry about? I made sure to write my commit message and the ChangeLog
therein as correctly as I can, I took example from existing commit messages.
Let me know if I haven't done something right and I will work on fixing it.
When everything is ready, could somebody please commit this on my behalf?
Also, I have a list of hits for FIRST_PSEUDO_REGISTER in caller-save.cc
that were in loops but were not applicable for this rewrite, along with
reasons why. Do I post it as a comment under the bugzilla page for this?

 gcc/caller-save.cc | 59 +++++++++++++++++++++++++---------------------
 1 file changed, 32 insertions(+), 27 deletions(-)

diff --git a/gcc/caller-save.cc b/gcc/caller-save.cc
index 281aa0bb009..ab812964624 100644
--- a/gcc/caller-save.cc
+++ b/gcc/caller-save.cc
@@ -187,6 +187,7 @@ init_caller_save (void)
   int offset;
   rtx address;
   int i, j;
+  unsigned int k;
 
   if (caller_save_initialized_p)
     return;
@@ -216,16 +217,16 @@ init_caller_save (void)
      and by finding the smallest power of two that is a valid offset from
      that register in every mode we will use to save registers.  */
 
-  for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
-    if (TEST_HARD_REG_BIT
-       (reg_class_contents
-        [(int) base_reg_class (regno_save_mode[i][1], ADDR_SPACE_GENERIC,
-                               PLUS, CONST_INT)], i))
-      break;
+  hard_reg_set_iterator hrsi;
+  EXECUTE_IF_SET_IN_HARD_REG_SET
+  (reg_class_contents
+   [(int) base_reg_class (regno_save_mode[k][1], ADDR_SPACE_GENERIC,
+                          PLUS, CONST_INT)], 0, k, hrsi)
+    break;
 
-  gcc_assert (i < FIRST_PSEUDO_REGISTER);
+  gcc_assert (k < FIRST_PSEUDO_REGISTER);
 
-  addr_reg = gen_rtx_REG (Pmode, i);
+  addr_reg = gen_rtx_REG (Pmode, k);
 
   for (offset = 1 << (HOST_BITS_PER_INT / 2); offset; offset >>= 1)
     {
@@ -442,15 +443,17 @@ setup_save_areas (void)
 
       used_regs &= ~(fixed_reg_set | this_insn_sets);
       hard_regs_to_save &= used_regs & savable_regs;
-      for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
-       if (TEST_HARD_REG_BIT (hard_regs_to_save, regno))
-         {
-           if (hard_reg_map[regno] != NULL)
-             hard_reg_map[regno]->call_freq += freq;
-           else
-             new_saved_hard_reg (regno, freq);
-           SET_HARD_REG_BIT (hard_regs_used, regno);
-         }
+
+      hard_reg_set_iterator hrsi;
+      EXECUTE_IF_SET_IN_HARD_REG_SET (hard_regs_to_save, 0, regno, hrsi)
+      {
+        if (hard_reg_map[regno] != NULL)
+          hard_reg_map[regno]->call_freq += freq;
+        else
+          new_saved_hard_reg (regno, freq);
+        SET_HARD_REG_BIT (hard_regs_used, regno);
+      }
+
       cheap = find_reg_note (insn, REG_RETURNED, NULL);
       if (cheap)
        cheap = XEXP (cheap, 0);
@@ -526,13 +529,15 @@ setup_save_areas (void)
 
          used_regs &= ~(fixed_reg_set | this_insn_sets);
          hard_regs_to_save &= used_regs & savable_regs;
-         for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
-           if (TEST_HARD_REG_BIT (hard_regs_to_save, regno))
-             {
-               gcc_assert (hard_reg_map[regno] != NULL);
-               call_saved_regs[call_saved_regs_num++] = hard_reg_map[regno];
-             }
-         /* Look through all live pseudos, mark their hard registers.  */
+
+      hard_reg_set_iterator hrsi;
+      EXECUTE_IF_SET_IN_HARD_REG_SET (hard_regs_to_save, 0, regno, hrsi)
+      {
+        gcc_assert (hard_reg_map[regno] != NULL);
+        call_saved_regs[call_saved_regs_num++] = hard_reg_map[regno];
+      }
+
+      /* Look through all live pseudos, mark their hard registers.  */
          EXECUTE_IF_SET_IN_REG_SET
            (&chain->live_throughout, FIRST_PSEUDO_REGISTER, regno, rsi)
            {
@@ -848,9 +853,9 @@ save_call_clobbered_regs (void)
 
              /* Must recompute n_regs_saved.  */
              n_regs_saved = 0;
-             for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
-               if (TEST_HARD_REG_BIT (hard_regs_saved, regno))
-                 n_regs_saved++;
+          hard_reg_set_iterator hrsi;
+          EXECUTE_IF_SET_IN_HARD_REG_SET (hard_regs_saved, 0, regno, hrsi)
+            n_regs_saved++;
 
              if (cheap
                  && HARD_REGISTER_P (cheap)
-- 
2.53.0

Reply via email to