d: Merge upstream dmd 56589f0f4, druntime 651389b5, phobos 1516ecad9.
[official-gcc.git] / gcc / tree-ssa-threadedge.h
blobca70b33f5edd07e9d3b20ae197dcf2ed502f4dae
1 /* Header file for SSA jump threading.
2 Copyright (C) 2013-2022 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #ifndef GCC_TREE_SSA_THREADEDGE_H
21 #define GCC_TREE_SSA_THREADEDGE_H
23 // Class used to maintain path state in the jump threader and pass it
24 // to the jump threader simplifier.
26 class jt_state
28 public:
29 virtual ~jt_state () { }
30 virtual void push (edge);
31 virtual void pop ();
32 virtual void register_equiv (tree dest, tree src, bool update_range);
33 virtual void register_equivs_edge (edge e);
34 virtual void register_equivs_stmt (gimple *, basic_block,
35 class jt_simplifier *);
36 virtual void record_ranges_from_stmt (gimple *stmt, bool temporary);
37 void get_path (vec<basic_block> &);
38 void append_path (basic_block);
39 void dump (FILE *);
40 void debug ();
42 private:
43 auto_vec<basic_block> m_blocks;
44 static const basic_block BB_MARKER;
47 // Statement simplifier callback for the jump threader.
49 class jt_simplifier
51 public:
52 virtual ~jt_simplifier () { }
53 virtual tree simplify (gimple *, gimple *, basic_block, jt_state *) = 0;
56 class hybrid_jt_state : public jt_state
58 private:
59 void register_equivs_stmt (gimple *, basic_block, jt_simplifier *) override
61 // Ranger has no need to simplify anything.
65 class hybrid_jt_simplifier : public jt_simplifier
67 public:
68 hybrid_jt_simplifier (class gimple_ranger *r, class path_range_query *q);
69 tree simplify (gimple *stmt, gimple *, basic_block, jt_state *) override;
71 private:
72 void compute_ranges_from_state (gimple *stmt, jt_state *);
74 gimple_ranger *m_ranger;
75 path_range_query *m_query;
76 auto_vec<basic_block> m_path;
79 // This is the high level threader. The entry point is
80 // thread_outgoing_edges(), which calculates and registers paths to be
81 // threaded. When all candidates have been registered,
82 // thread_through_all_blocks() is called to actually change the CFG.
84 class jump_threader
86 public:
87 jump_threader (jt_simplifier *, class jt_state *);
88 ~jump_threader ();
89 void thread_outgoing_edges (basic_block);
90 void remove_jump_threads_including (edge_def *);
91 bool thread_through_all_blocks (bool may_peel_loop_headers);
93 private:
94 tree simplify_control_stmt_condition (edge, gimple *);
95 tree simplify_control_stmt_condition_1 (edge,
96 gimple *,
97 tree op0,
98 tree_code cond_code,
99 tree op1,
100 unsigned limit);
102 bool thread_around_empty_blocks (vec<class jump_thread_edge *> *path,
103 edge, bitmap visited);
104 int thread_through_normal_block (vec<jump_thread_edge *> *path,
105 edge, bitmap visited);
106 void thread_across_edge (edge);
107 bool record_temporary_equivalences_from_phis (edge);
108 gimple *record_temporary_equivalences_from_stmts_at_dest (edge);
110 // Dummy condition to avoid creating lots of throw away statements.
111 gcond *dummy_cond;
113 class fwd_jt_path_registry *m_registry;
114 jt_simplifier *m_simplifier;
115 jt_state *m_state;
118 extern void propagate_threaded_block_debug_into (basic_block, basic_block);
119 extern bool single_succ_to_potentially_threadable_block (basic_block);
121 // ?? All this ssa_name_values stuff is the store of values for
122 // avail_exprs_stack and const_and_copies, so it really belongs in the
123 // jump_threader class. However, it's probably not worth touching
124 // this, since all this windable state is slated to go with the
125 // ranger.
126 extern vec<tree> ssa_name_values;
127 #define SSA_NAME_VALUE(x) \
128 (SSA_NAME_VERSION (x) < ssa_name_values.length () \
129 ? ssa_name_values[SSA_NAME_VERSION (x)] \
130 : NULL_TREE)
131 extern void set_ssa_name_value (tree, tree);
133 #endif /* GCC_TREE_SSA_THREADEDGE_H */