annotate gcc/cfg.h @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* Control flow graph manipulation code header file.
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2 Copyright (C) 2014-2020 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
3
kono
parents:
diff changeset
4 This file is part of GCC.
kono
parents:
diff changeset
5
kono
parents:
diff changeset
6 GCC is free software; you can redistribute it and/or modify it under
kono
parents:
diff changeset
7 the terms of the GNU General Public License as published by the Free
kono
parents:
diff changeset
8 Software Foundation; either version 3, or (at your option) any later
kono
parents:
diff changeset
9 version.
kono
parents:
diff changeset
10
kono
parents:
diff changeset
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
kono
parents:
diff changeset
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
kono
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
kono
parents:
diff changeset
14 for more details.
kono
parents:
diff changeset
15
kono
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
kono
parents:
diff changeset
17 along with GCC; see the file COPYING3. If not see
kono
parents:
diff changeset
18 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
19
kono
parents:
diff changeset
20 #ifndef GCC_CFG_H
kono
parents:
diff changeset
21 #define GCC_CFG_H
kono
parents:
diff changeset
22
kono
parents:
diff changeset
23 #include "dominance.h"
kono
parents:
diff changeset
24
kono
parents:
diff changeset
25 /* What sort of profiling information we have. */
kono
parents:
diff changeset
26 enum profile_status_d
kono
parents:
diff changeset
27 {
kono
parents:
diff changeset
28 PROFILE_ABSENT,
kono
parents:
diff changeset
29 PROFILE_GUESSED,
kono
parents:
diff changeset
30 PROFILE_READ,
kono
parents:
diff changeset
31 PROFILE_LAST /* Last value, used by profile streaming. */
kono
parents:
diff changeset
32 };
kono
parents:
diff changeset
33
kono
parents:
diff changeset
34 /* A structure to group all the per-function control flow graph data.
kono
parents:
diff changeset
35 The x_* prefixing is necessary because otherwise references to the
kono
parents:
diff changeset
36 fields of this struct are interpreted as the defines for backward
kono
parents:
diff changeset
37 source compatibility following the definition of this struct. */
kono
parents:
diff changeset
38 struct GTY(()) control_flow_graph {
kono
parents:
diff changeset
39 /* Block pointers for the exit and entry of a function.
kono
parents:
diff changeset
40 These are always the head and tail of the basic block list. */
kono
parents:
diff changeset
41 basic_block x_entry_block_ptr;
kono
parents:
diff changeset
42 basic_block x_exit_block_ptr;
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 /* Index by basic block number, get basic block struct info. */
kono
parents:
diff changeset
45 vec<basic_block, va_gc> *x_basic_block_info;
kono
parents:
diff changeset
46
kono
parents:
diff changeset
47 /* Number of basic blocks in this flow graph. */
kono
parents:
diff changeset
48 int x_n_basic_blocks;
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 /* Number of edges in this flow graph. */
kono
parents:
diff changeset
51 int x_n_edges;
kono
parents:
diff changeset
52
kono
parents:
diff changeset
53 /* The first free basic block number. */
kono
parents:
diff changeset
54 int x_last_basic_block;
kono
parents:
diff changeset
55
kono
parents:
diff changeset
56 /* UIDs for LABEL_DECLs. */
kono
parents:
diff changeset
57 int last_label_uid;
kono
parents:
diff changeset
58
kono
parents:
diff changeset
59 /* Mapping of labels to their associated blocks. At present
kono
parents:
diff changeset
60 only used for the gimple CFG. */
kono
parents:
diff changeset
61 vec<basic_block, va_gc> *x_label_to_block_map;
kono
parents:
diff changeset
62
kono
parents:
diff changeset
63 enum profile_status_d x_profile_status;
kono
parents:
diff changeset
64
kono
parents:
diff changeset
65 /* Whether the dominators and the postdominators are available. */
kono
parents:
diff changeset
66 enum dom_state x_dom_computed[2];
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 /* Number of basic blocks in the dominance tree. */
kono
parents:
diff changeset
69 unsigned x_n_bbs_in_dom_tree[2];
kono
parents:
diff changeset
70
kono
parents:
diff changeset
71 /* Maximal number of entities in the single jumptable. Used to estimate
kono
parents:
diff changeset
72 final flowgraph size. */
kono
parents:
diff changeset
73 int max_jumptable_ents;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
74
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
75 /* Maximal count of BB in function. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
76 profile_count count_max;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
77
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
78 /* Dynamically allocated edge/bb flags. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
79 int edge_flags_allocated;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
80 int bb_flags_allocated;
111
kono
parents:
diff changeset
81 };
kono
parents:
diff changeset
82
kono
parents:
diff changeset
83
kono
parents:
diff changeset
84 extern void init_flow (function *);
kono
parents:
diff changeset
85 extern void clear_edges (function *);
kono
parents:
diff changeset
86 extern basic_block alloc_block (void);
kono
parents:
diff changeset
87 extern void link_block (basic_block, basic_block);
kono
parents:
diff changeset
88 extern void unlink_block (basic_block);
kono
parents:
diff changeset
89 extern void compact_blocks (void);
kono
parents:
diff changeset
90 extern void expunge_block (basic_block);
kono
parents:
diff changeset
91 extern edge unchecked_make_edge (basic_block, basic_block, int);
kono
parents:
diff changeset
92 extern edge cached_make_edge (sbitmap, basic_block, basic_block, int);
kono
parents:
diff changeset
93 extern edge make_edge (basic_block, basic_block, int);
kono
parents:
diff changeset
94 extern edge make_single_succ_edge (basic_block, basic_block, int);
kono
parents:
diff changeset
95 extern void remove_edge_raw (edge);
kono
parents:
diff changeset
96 extern void redirect_edge_succ (edge, basic_block);
kono
parents:
diff changeset
97 extern void redirect_edge_pred (edge, basic_block);
kono
parents:
diff changeset
98 extern void clear_bb_flags (void);
kono
parents:
diff changeset
99 extern void dump_edge_info (FILE *, edge, dump_flags_t, int);
kono
parents:
diff changeset
100 extern void debug (edge_def &ref);
kono
parents:
diff changeset
101 extern void debug (edge_def *ptr);
kono
parents:
diff changeset
102 extern void alloc_aux_for_blocks (int);
kono
parents:
diff changeset
103 extern void clear_aux_for_blocks (void);
kono
parents:
diff changeset
104 extern void free_aux_for_blocks (void);
kono
parents:
diff changeset
105 extern void alloc_aux_for_edge (edge, int);
kono
parents:
diff changeset
106 extern void alloc_aux_for_edges (int);
kono
parents:
diff changeset
107 extern void clear_aux_for_edges (void);
kono
parents:
diff changeset
108 extern void free_aux_for_edges (void);
kono
parents:
diff changeset
109 extern void debug_bb (basic_block);
kono
parents:
diff changeset
110 extern basic_block debug_bb_n (int);
kono
parents:
diff changeset
111 extern void dump_bb_info (FILE *, basic_block, int, dump_flags_t, bool, bool);
kono
parents:
diff changeset
112 extern void brief_dump_cfg (FILE *, dump_flags_t);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
113 extern void update_bb_profile_for_threading (basic_block, profile_count, edge);
111
kono
parents:
diff changeset
114 extern void scale_bbs_frequencies_profile_count (basic_block *, int,
kono
parents:
diff changeset
115 profile_count, profile_count);
kono
parents:
diff changeset
116 extern void scale_bbs_frequencies (basic_block *, int, profile_probability);
kono
parents:
diff changeset
117 extern void initialize_original_copy_tables (void);
kono
parents:
diff changeset
118 extern void reset_original_copy_tables (void);
kono
parents:
diff changeset
119 extern void free_original_copy_tables (void);
kono
parents:
diff changeset
120 extern bool original_copy_tables_initialized_p (void);
kono
parents:
diff changeset
121 extern void set_bb_original (basic_block, basic_block);
kono
parents:
diff changeset
122 extern basic_block get_bb_original (basic_block);
kono
parents:
diff changeset
123 extern void set_bb_copy (basic_block, basic_block);
kono
parents:
diff changeset
124 extern basic_block get_bb_copy (basic_block);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
125 void set_loop_copy (class loop *, class loop *);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
126 class loop *get_loop_copy (class loop *);
111
kono
parents:
diff changeset
127
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
128 /* Generic RAII class to allocate a bit from storage of integer type T.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
129 The allocated bit is accessible as mask with the single bit set
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
130 via the conversion operator to T. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
132 template <class T>
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
133 class auto_flag
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
134 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
135 public:
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
136 /* static assert T is integer type of max HOST_WIDE_INT precision. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
137 auto_flag (T *sptr)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
138 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
139 m_sptr = sptr;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
140 int free_bit = ffs_hwi (~*sptr);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
141 /* If there are no unset bits... */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
142 if (free_bit == 0)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
143 gcc_unreachable ();
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
144 m_flag = HOST_WIDE_INT_1U << (free_bit - 1);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
145 /* ...or if T is signed and thus the complement is sign-extended,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
146 check if we ran out of bits. We could spare us this bit
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
147 if we could use C++11 std::make_unsigned<T>::type to pass
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
148 ~*sptr to ffs_hwi. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
149 if (m_flag == 0)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
150 gcc_unreachable ();
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
151 gcc_checking_assert ((*sptr & m_flag) == 0);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
152 *sptr |= m_flag;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
153 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
154 ~auto_flag ()
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
155 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
156 gcc_checking_assert ((*m_sptr & m_flag) == m_flag);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
157 *m_sptr &= ~m_flag;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
158 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
159 operator T () const { return m_flag; }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
160 private:
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
161 T *m_sptr;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
162 T m_flag;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
163 };
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
164
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
165 /* RAII class to allocate an edge flag for temporary use. You have
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
166 to clear the flag from all edges when you are finished using it. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
167
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
168 class auto_edge_flag : public auto_flag<int>
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
169 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
170 public:
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
171 auto_edge_flag (function *fun)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
172 : auto_flag<int> (&fun->cfg->edge_flags_allocated) {}
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
173 };
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
174
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
175 /* RAII class to allocate a bb flag for temporary use. You have
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
176 to clear the flag from all edges when you are finished using it. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
177 class auto_bb_flag : public auto_flag<int>
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
178 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
179 public:
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
180 auto_bb_flag (function *fun)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
181 : auto_flag<int> (&fun->cfg->bb_flags_allocated) {}
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
182 };
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
183
111
kono
parents:
diff changeset
184 #endif /* GCC_CFG_H */