]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Add phi_arg_edge_from_use helper
authorRichard Biener <rguenther@suse.de>
Tue, 20 Jan 2026 09:22:49 +0000 (10:22 +0100)
committerRichard Biener <rguenth@gcc.gnu.org>
Tue, 20 Jan 2026 10:30:22 +0000 (11:30 +0100)
I've needed this a few times now and indenting nested
phi_arg_index_from_use inside gimple_phi_arg_edge is difficult.

* tree-phinodes.h (phi_arg_index_from_use): Use gphi *.
(phi_arg_edge_from_use): New helper composing
phi_arg_index_from_use and gimple_phi_arg_edge.

gcc/tree-phinodes.h

index a3e7254306bd7f37748213d05616aba35c66cc8d..b6fa492cb248f4d0e1a7838d0b34da6ae3a108fd 100644 (file)
@@ -50,13 +50,13 @@ phi_arg_index_from_use (use_operand_p use)
 {
   struct phi_arg_d *element, *root;
   size_t index;
-  gimple *phi;
+  gphi *phi;
 
   /* Since the use is the first thing in a PHI argument element, we can
      calculate its index based on casting it to an argument, and performing
      pointer arithmetic.  */
 
-  phi = USE_STMT (use);
+  phi = as_a <gphi *> (USE_STMT (use));
 
   element = (struct phi_arg_d *)use;
   root = gimple_phi_arg (phi, 0);
@@ -71,4 +71,13 @@ phi_arg_index_from_use (use_operand_p use)
  return index;
 }
 
+/* Return the edge into the PHI node USE.  */
+
+inline edge
+phi_arg_edge_from_use (use_operand_p use)
+{
+  gphi *phi = as_a <gphi *> (USE_STMT (use));
+  return gimple_phi_arg_edge (phi, phi_arg_index_from_use (use));
+}
+
 #endif /* GCC_TREE_PHINODES_H */