]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Abstract interesting ssa-names from GORI.
authorAndrew MacLeod <amacleod@redhat.com>
Tue, 16 Aug 2022 17:18:37 +0000 (13:18 -0400)
committerAndrew MacLeod <amacleod@redhat.com>
Wed, 17 Aug 2022 01:09:00 +0000 (21:09 -0400)
Provide a routine to pick out the ssa-names from interesting statements.

* gimple-range-fold.cc (gimple_range_ssa_names): New.
* gimple-range-fold.h (gimple_range_ssa_names): New prototype.
* gimple-range-gori.cc (range_def_chain::get_def_chain): Move
  code to new routine.

gcc/gimple-range-fold.cc
gcc/gimple-range-fold.h
gcc/gimple-range-gori.cc

index 689d8279627de2c39bf353e220d4066dfcda2ab2..b0b221063206708a85cf3edfdff67c7ab7496977 100644 (file)
@@ -1580,3 +1580,36 @@ fur_source::register_outgoing_edges (gcond *s, irange &lhs_range, edge e0, edge
        }
     }
 }
+
+// Given stmt S, fill VEC, up to VEC_SIZE elements, with relevant ssa-names
+// on the statement.  For efficiency, it is an error to not pass in enough
+// elements for the vector.  Return the number of ssa-names.
+
+unsigned
+gimple_range_ssa_names (tree *vec, unsigned vec_size, gimple *stmt)
+{
+  tree ssa;
+  int count = 0;
+
+  if (range_op_handler (stmt))
+    {
+      gcc_checking_assert (vec_size >= 2);
+      if ((ssa = gimple_range_ssa_p (gimple_range_operand1 (stmt))))
+       vec[count++] = ssa;
+      if ((ssa = gimple_range_ssa_p (gimple_range_operand2 (stmt))))
+       vec[count++] = ssa;
+    }
+  else if (is_a<gassign *> (stmt)
+          && gimple_assign_rhs_code (stmt) == COND_EXPR)
+    {
+      gcc_checking_assert (vec_size >= 3);
+      gassign *st = as_a<gassign *> (stmt);
+      if ((ssa = gimple_range_ssa_p (gimple_assign_rhs1 (st))))
+       vec[count++] = ssa;
+      if ((ssa = gimple_range_ssa_p (gimple_assign_rhs2 (st))))
+       vec[count++] = ssa;
+      if ((ssa = gimple_range_ssa_p (gimple_assign_rhs3 (st))))
+       vec[count++] = ssa;
+    }
+  return count;
+}
index c2f381dffec16297706de32baa6f9128182d482a..f2eab72021375c053857ee4195ee88000e016103 100644 (file)
@@ -96,6 +96,14 @@ range_compatible_p (tree type1, tree type2)
          && TYPE_SIGN (type1) == TYPE_SIGN (type2));
 }
 
+extern tree gimple_range_operand1 (const gimple *s);
+extern tree gimple_range_operand2 (const gimple *s);
+
+// Given stmt S, fill VEC, up to VEC_SIZE elements, with relevant ssa-names
+// on the statement.  For efficiency, it is an error to not pass in enough
+// elements for the vector.  Return the number of ssa-names.
+
+unsigned gimple_range_ssa_names (tree *vec, unsigned vec_size, gimple *stmt);
 
 // Source of all operands for fold_using_range and gori_compute.
 // It abstracts out the source of an operand so it can come from a stmt or
@@ -150,9 +158,6 @@ protected:
   relation_oracle *m_oracle;
 };
 
-extern tree gimple_range_operand1 (const gimple *s);
-extern tree gimple_range_operand2 (const gimple *s);
-
 // This class uses ranges to fold a gimple statement producinf a range for
 // the LHS.  The source of all operands is supplied via the fur_source class
 // which provides a range_query as well as a source location and any other
index 8879e44cba11c3736f587621e0aa2b050cf52ddc..957b8d543fa4bfa0260cc63d31f0aea2efa01d44 100644 (file)
@@ -331,7 +331,7 @@ range_def_chain::has_def_chain (tree name)
 bitmap
 range_def_chain::get_def_chain (tree name)
 {
-  tree ssa1, ssa2, ssa3;
+  tree ssa[3];
   unsigned v = SSA_NAME_VERSION (name);
 
   // If it has already been processed, just return the cached value.
@@ -347,23 +347,10 @@ range_def_chain::get_def_chain (tree name)
     }
 
   gimple *stmt = SSA_NAME_DEF_STMT (name);
-  if (range_op_handler (stmt))
+  unsigned count = gimple_range_ssa_names (ssa, 3, stmt);
+  if (count == 0)
     {
-      ssa1 = gimple_range_ssa_p (gimple_range_operand1 (stmt));
-      ssa2 = gimple_range_ssa_p (gimple_range_operand2 (stmt));
-      ssa3 = NULL_TREE;
-    }
-  else if (is_a<gassign *> (stmt)
-          && gimple_assign_rhs_code (stmt) == COND_EXPR)
-    {
-      gassign *st = as_a<gassign *> (stmt);
-      ssa1 = gimple_range_ssa_p (gimple_assign_rhs1 (st));
-      ssa2 = gimple_range_ssa_p (gimple_assign_rhs2 (st));
-      ssa3 = gimple_range_ssa_p (gimple_assign_rhs3 (st));
-    }
-  else
-    {
-      // Stmts not understood are always imports.
+      // Stmts not understood or with no operands are always imports.
       set_import (m_def_chain[v], name, NULL);
       return NULL;
     }
@@ -373,17 +360,13 @@ range_def_chain::get_def_chain (tree name)
     return NULL;
 
   // Increase the depth if we have a pair of ssa-names.
-  if (ssa1 && ssa2)
+  if (count > 1)
     m_logical_depth++;
 
-  register_dependency (name, ssa1, gimple_bb (stmt));
-  register_dependency (name, ssa2, gimple_bb (stmt));
-  register_dependency (name, ssa3, gimple_bb (stmt));
-  // Stmts with no understandable operands are also imports.
-  if (!ssa1 && !ssa2 & !ssa3)
-    set_import (m_def_chain[v], name, NULL);
+  for (unsigned x = 0; x < count; x++)
+    register_dependency (name, ssa[x], gimple_bb (stmt));
 
-  if (ssa1 && ssa2)
+  if (count > 1)
     m_logical_depth--;
 
   return m_def_chain[v].bm;