1*38fd1498Szrj /* Header file for PHI node routines
2*38fd1498Szrj Copyright (C) 2013-2018 Free Software Foundation, Inc.
3*38fd1498Szrj
4*38fd1498Szrj This file is part of GCC.
5*38fd1498Szrj
6*38fd1498Szrj GCC is free software; you can redistribute it and/or modify it under
7*38fd1498Szrj the terms of the GNU General Public License as published by the Free
8*38fd1498Szrj Software Foundation; either version 3, or (at your option) any later
9*38fd1498Szrj version.
10*38fd1498Szrj
11*38fd1498Szrj GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12*38fd1498Szrj WARRANTY; without even the implied warranty of MERCHANTABILITY or
13*38fd1498Szrj FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14*38fd1498Szrj for more details.
15*38fd1498Szrj
16*38fd1498Szrj You should have received a copy of the GNU General Public License
17*38fd1498Szrj along with GCC; see the file COPYING3. If not see
18*38fd1498Szrj <http://www.gnu.org/licenses/>. */
19*38fd1498Szrj
20*38fd1498Szrj #ifndef GCC_TREE_PHINODES_H
21*38fd1498Szrj #define GCC_TREE_PHINODES_H
22*38fd1498Szrj
23*38fd1498Szrj extern void phinodes_print_statistics (void);
24*38fd1498Szrj extern void reserve_phi_args_for_new_edge (basic_block);
25*38fd1498Szrj extern void add_phi_node_to_bb (gphi *phi, basic_block bb);
26*38fd1498Szrj extern gphi *create_phi_node (tree, basic_block);
27*38fd1498Szrj extern void add_phi_arg (gphi *, tree, edge, source_location);
28*38fd1498Szrj extern void remove_phi_args (edge);
29*38fd1498Szrj extern void remove_phi_node (gimple_stmt_iterator *, bool);
30*38fd1498Szrj extern void remove_phi_nodes (basic_block);
31*38fd1498Szrj extern tree degenerate_phi_result (gphi *);
32*38fd1498Szrj extern void set_phi_nodes (basic_block, gimple_seq);
33*38fd1498Szrj
34*38fd1498Szrj static inline use_operand_p
gimple_phi_arg_imm_use_ptr(gimple * gs,int i)35*38fd1498Szrj gimple_phi_arg_imm_use_ptr (gimple *gs, int i)
36*38fd1498Szrj {
37*38fd1498Szrj return &gimple_phi_arg (gs, i)->imm_use;
38*38fd1498Szrj }
39*38fd1498Szrj
40*38fd1498Szrj /* Return the phi argument which contains the specified use. */
41*38fd1498Szrj
42*38fd1498Szrj static inline int
phi_arg_index_from_use(use_operand_p use)43*38fd1498Szrj phi_arg_index_from_use (use_operand_p use)
44*38fd1498Szrj {
45*38fd1498Szrj struct phi_arg_d *element, *root;
46*38fd1498Szrj size_t index;
47*38fd1498Szrj gimple *phi;
48*38fd1498Szrj
49*38fd1498Szrj /* Since the use is the first thing in a PHI argument element, we can
50*38fd1498Szrj calculate its index based on casting it to an argument, and performing
51*38fd1498Szrj pointer arithmetic. */
52*38fd1498Szrj
53*38fd1498Szrj phi = USE_STMT (use);
54*38fd1498Szrj
55*38fd1498Szrj element = (struct phi_arg_d *)use;
56*38fd1498Szrj root = gimple_phi_arg (phi, 0);
57*38fd1498Szrj index = element - root;
58*38fd1498Szrj
59*38fd1498Szrj /* Make sure the calculation doesn't have any leftover bytes. If it does,
60*38fd1498Szrj then imm_use is likely not the first element in phi_arg_d. */
61*38fd1498Szrj gcc_checking_assert ((((char *)element - (char *)root)
62*38fd1498Szrj % sizeof (struct phi_arg_d)) == 0
63*38fd1498Szrj && index < gimple_phi_capacity (phi));
64*38fd1498Szrj
65*38fd1498Szrj return index;
66*38fd1498Szrj }
67*38fd1498Szrj
68*38fd1498Szrj #endif /* GCC_TREE_PHINODES_H */
69