https://gcc.gnu.org/g:1acf01fcb6c66bb16577ee2d452cba3104cf3d96

commit r16-6914-g1acf01fcb6c66bb16577ee2d452cba3104cf3d96
Author: Richard Biener <[email protected]>
Date:   Tue Jan 20 10:22:49 2026 +0100

    Add phi_arg_edge_from_use helper
    
    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.

Diff:
---
 gcc/tree-phinodes.h | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/gcc/tree-phinodes.h b/gcc/tree-phinodes.h
index a3e7254306bd..b6fa492cb248 100644
--- a/gcc/tree-phinodes.h
+++ b/gcc/tree-phinodes.h
@@ -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 */

Reply via email to