1*38fd1498Szrj /* Data structures and function declarations for the SSA value propagation
2*38fd1498Szrj engine.
3*38fd1498Szrj Copyright (C) 2004-2018 Free Software Foundation, Inc.
4*38fd1498Szrj Contributed by Diego Novillo <dnovillo@redhat.com>
5*38fd1498Szrj
6*38fd1498Szrj This file is part of GCC.
7*38fd1498Szrj
8*38fd1498Szrj GCC is free software; you can redistribute it and/or modify
9*38fd1498Szrj it under the terms of the GNU General Public License as published by
10*38fd1498Szrj the Free Software Foundation; either version 3, or (at your option)
11*38fd1498Szrj any later version.
12*38fd1498Szrj
13*38fd1498Szrj GCC is distributed in the hope that it will be useful,
14*38fd1498Szrj but WITHOUT ANY WARRANTY; without even the implied warranty of
15*38fd1498Szrj MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16*38fd1498Szrj GNU General Public License for more details.
17*38fd1498Szrj
18*38fd1498Szrj You should have received a copy of the GNU General Public License
19*38fd1498Szrj along with GCC; see the file COPYING3. If not see
20*38fd1498Szrj <http://www.gnu.org/licenses/>. */
21*38fd1498Szrj
22*38fd1498Szrj #ifndef _TREE_SSA_PROPAGATE_H
23*38fd1498Szrj #define _TREE_SSA_PROPAGATE_H 1
24*38fd1498Szrj
25*38fd1498Szrj /* If SIM_P is true, statement S will be simulated again. */
26*38fd1498Szrj
27*38fd1498Szrj static inline void
prop_set_simulate_again(gimple * s,bool visit_p)28*38fd1498Szrj prop_set_simulate_again (gimple *s, bool visit_p)
29*38fd1498Szrj {
30*38fd1498Szrj gimple_set_visited (s, visit_p);
31*38fd1498Szrj }
32*38fd1498Szrj
33*38fd1498Szrj /* Return true if statement T should be simulated again. */
34*38fd1498Szrj
35*38fd1498Szrj static inline bool
prop_simulate_again_p(gimple * s)36*38fd1498Szrj prop_simulate_again_p (gimple *s)
37*38fd1498Szrj {
38*38fd1498Szrj return gimple_visited_p (s);
39*38fd1498Szrj }
40*38fd1498Szrj
41*38fd1498Szrj /* Lattice values used for propagation purposes. Specific instances
42*38fd1498Szrj of a propagation engine must return these values from the statement
43*38fd1498Szrj and PHI visit functions to direct the engine. */
44*38fd1498Szrj enum ssa_prop_result {
45*38fd1498Szrj /* The statement produces nothing of interest. No edges will be
46*38fd1498Szrj added to the work lists. */
47*38fd1498Szrj SSA_PROP_NOT_INTERESTING,
48*38fd1498Szrj
49*38fd1498Szrj /* The statement produces an interesting value. The set SSA_NAMEs
50*38fd1498Szrj returned by SSA_PROP_VISIT_STMT should be added to
51*38fd1498Szrj INTERESTING_SSA_EDGES. If the statement being visited is a
52*38fd1498Szrj conditional jump, SSA_PROP_VISIT_STMT should indicate which edge
53*38fd1498Szrj out of the basic block should be marked executable. */
54*38fd1498Szrj SSA_PROP_INTERESTING,
55*38fd1498Szrj
56*38fd1498Szrj /* The statement produces a varying (i.e., useless) value and
57*38fd1498Szrj should not be simulated again. If the statement being visited
58*38fd1498Szrj is a conditional jump, all the edges coming out of the block
59*38fd1498Szrj will be considered executable. */
60*38fd1498Szrj SSA_PROP_VARYING
61*38fd1498Szrj };
62*38fd1498Szrj
63*38fd1498Szrj
64*38fd1498Szrj extern bool valid_gimple_rhs_p (tree);
65*38fd1498Szrj extern void move_ssa_defining_stmt_for_defs (gimple *, gimple *);
66*38fd1498Szrj extern bool update_gimple_call (gimple_stmt_iterator *, tree, int, ...);
67*38fd1498Szrj extern bool update_call_from_tree (gimple_stmt_iterator *, tree);
68*38fd1498Szrj extern bool stmt_makes_single_store (gimple *);
69*38fd1498Szrj extern bool may_propagate_copy (tree, tree);
70*38fd1498Szrj extern bool may_propagate_copy_into_stmt (gimple *, tree);
71*38fd1498Szrj extern bool may_propagate_copy_into_asm (tree);
72*38fd1498Szrj extern void propagate_value (use_operand_p, tree);
73*38fd1498Szrj extern void replace_exp (use_operand_p, tree);
74*38fd1498Szrj extern void propagate_tree_value (tree *, tree);
75*38fd1498Szrj extern void propagate_tree_value_into_stmt (gimple_stmt_iterator *, tree);
76*38fd1498Szrj
77*38fd1498Szrj /* Public interface into the SSA propagation engine. Clients should inherit
78*38fd1498Szrj from this class and provide their own visitors. */
79*38fd1498Szrj
80*38fd1498Szrj class ssa_propagation_engine
81*38fd1498Szrj {
82*38fd1498Szrj public:
83*38fd1498Szrj
~ssa_propagation_engine(void)84*38fd1498Szrj virtual ~ssa_propagation_engine (void) { }
85*38fd1498Szrj
86*38fd1498Szrj /* Virtual functions the clients must provide to visit statements
87*38fd1498Szrj and phi nodes respectively. */
88*38fd1498Szrj virtual enum ssa_prop_result visit_stmt (gimple *, edge *, tree *) = 0;
89*38fd1498Szrj virtual enum ssa_prop_result visit_phi (gphi *) = 0;
90*38fd1498Szrj
91*38fd1498Szrj /* Main interface into the propagation engine. */
92*38fd1498Szrj void ssa_propagate (void);
93*38fd1498Szrj
94*38fd1498Szrj private:
95*38fd1498Szrj /* Internal implementation details. */
96*38fd1498Szrj void simulate_stmt (gimple *stmt);
97*38fd1498Szrj void simulate_block (basic_block);
98*38fd1498Szrj };
99*38fd1498Szrj
100*38fd1498Szrj class substitute_and_fold_engine
101*38fd1498Szrj {
102*38fd1498Szrj public:
~substitute_and_fold_engine(void)103*38fd1498Szrj virtual ~substitute_and_fold_engine (void) { }
fold_stmt(gimple_stmt_iterator *)104*38fd1498Szrj virtual bool fold_stmt (gimple_stmt_iterator *) { return false; }
get_value(tree)105*38fd1498Szrj virtual tree get_value (tree) { return NULL_TREE; }
106*38fd1498Szrj
107*38fd1498Szrj bool substitute_and_fold (void);
108*38fd1498Szrj bool replace_uses_in (gimple *);
109*38fd1498Szrj bool replace_phi_args_in (gphi *);
110*38fd1498Szrj };
111*38fd1498Szrj
112*38fd1498Szrj #endif /* _TREE_SSA_PROPAGATE_H */
113