Mercurial > hg > CbC > CbC_gcc
comparison gcc/domwalk.c @ 131:84e7813d76e9
gcc-8.2
author | mir3636 |
---|---|
date | Thu, 25 Oct 2018 07:37:49 +0900 |
parents | 04ced10e8804 |
children | 1830386684a0 |
comparison
equal
deleted
inserted
replaced
111:04ced10e8804 | 131:84e7813d76e9 |
---|---|
1 /* Generic dominator tree walker | 1 /* Generic dominator tree walker |
2 Copyright (C) 2003-2017 Free Software Foundation, Inc. | 2 Copyright (C) 2003-2018 Free Software Foundation, Inc. |
3 Contributed by Diego Novillo <dnovillo@redhat.com> | 3 Contributed by Diego Novillo <dnovillo@redhat.com> |
4 | 4 |
5 This file is part of GCC. | 5 This file is part of GCC. |
6 | 6 |
7 GCC is free software; you can redistribute it and/or modify | 7 GCC is free software; you can redistribute it and/or modify |
167 } | 167 } |
168 else | 168 else |
169 qsort (bbs, n, sizeof *bbs, cmp_bb_postorder); | 169 qsort (bbs, n, sizeof *bbs, cmp_bb_postorder); |
170 } | 170 } |
171 | 171 |
172 /* Constructor for a dom walker. | 172 /* Set EDGE_EXECUTABLE on every edge within FN's CFG. */ |
173 | 173 |
174 If SKIP_UNREACHBLE_BLOCKS is true, then we need to set | 174 void |
175 EDGE_EXECUTABLE on every edge in the CFG. */ | 175 set_all_edges_as_executable (function *fn) |
176 { | |
177 basic_block bb; | |
178 FOR_ALL_BB_FN (bb, fn) | |
179 { | |
180 edge_iterator ei; | |
181 edge e; | |
182 FOR_EACH_EDGE (e, ei, bb->succs) | |
183 e->flags |= EDGE_EXECUTABLE; | |
184 } | |
185 } | |
186 | |
187 /* Constructor for a dom walker. */ | |
188 | |
176 dom_walker::dom_walker (cdi_direction direction, | 189 dom_walker::dom_walker (cdi_direction direction, |
177 bool skip_unreachable_blocks, | 190 enum reachability reachability, |
178 int *bb_index_to_rpo) | 191 int *bb_index_to_rpo) |
179 : m_dom_direction (direction), | 192 : m_dom_direction (direction), |
180 m_skip_unreachable_blocks (skip_unreachable_blocks), | 193 m_skip_unreachable_blocks (reachability != ALL_BLOCKS), |
181 m_user_bb_to_rpo (bb_index_to_rpo != NULL), | 194 m_user_bb_to_rpo (true), |
182 m_unreachable_dom (NULL), | 195 m_unreachable_dom (NULL), |
183 m_bb_to_rpo (bb_index_to_rpo) | 196 m_bb_to_rpo (bb_index_to_rpo) |
184 { | 197 { |
185 /* Compute the basic-block index to RPO mapping if not provided by | 198 /* Set up edge flags if need be. */ |
186 the user. */ | 199 switch (reachability) |
187 if (! m_bb_to_rpo && direction == CDI_DOMINATORS) | 200 { |
201 default: | |
202 gcc_unreachable (); | |
203 case ALL_BLOCKS: | |
204 /* No need to touch edge flags. */ | |
205 break; | |
206 | |
207 case REACHABLE_BLOCKS: | |
208 set_all_edges_as_executable (cfun); | |
209 break; | |
210 | |
211 case REACHABLE_BLOCKS_PRESERVING_FLAGS: | |
212 /* Preserve the edge flags. */ | |
213 break; | |
214 } | |
215 } | |
216 | |
217 /* Constructor for a dom walker. */ | |
218 | |
219 dom_walker::dom_walker (cdi_direction direction, | |
220 enum reachability reachability) | |
221 : m_dom_direction (direction), | |
222 m_skip_unreachable_blocks (reachability != ALL_BLOCKS), | |
223 m_user_bb_to_rpo (false), | |
224 m_unreachable_dom (NULL), | |
225 m_bb_to_rpo (NULL) | |
226 { | |
227 /* Compute the basic-block index to RPO mapping. */ | |
228 if (direction == CDI_DOMINATORS) | |
188 { | 229 { |
189 int *postorder = XNEWVEC (int, n_basic_blocks_for_fn (cfun)); | 230 int *postorder = XNEWVEC (int, n_basic_blocks_for_fn (cfun)); |
190 int postorder_num = pre_and_rev_post_order_compute (NULL, postorder, | 231 int postorder_num = pre_and_rev_post_order_compute (NULL, postorder, |
191 true); | 232 true); |
192 m_bb_to_rpo = XNEWVEC (int, last_basic_block_for_fn (cfun)); | 233 m_bb_to_rpo = XNEWVEC (int, last_basic_block_for_fn (cfun)); |
193 for (int i = 0; i < postorder_num; ++i) | 234 for (int i = 0; i < postorder_num; ++i) |
194 m_bb_to_rpo[postorder[i]] = i; | 235 m_bb_to_rpo[postorder[i]] = i; |
195 free (postorder); | 236 free (postorder); |
196 } | 237 } |
197 | 238 |
198 /* If we are not skipping unreachable blocks, then there is nothing | 239 /* Set up edge flags if need be. */ |
199 further to do. */ | 240 switch (reachability) |
200 if (!m_skip_unreachable_blocks) | 241 { |
201 return; | 242 default: |
202 | 243 gcc_unreachable (); |
203 basic_block bb; | 244 case ALL_BLOCKS: |
204 FOR_ALL_BB_FN (bb, cfun) | 245 /* No need to touch edge flags. */ |
205 { | 246 break; |
206 edge_iterator ei; | 247 |
207 edge e; | 248 case REACHABLE_BLOCKS: |
208 FOR_EACH_EDGE (e, ei, bb->succs) | 249 set_all_edges_as_executable (cfun); |
209 e->flags |= EDGE_EXECUTABLE; | 250 break; |
251 | |
252 case REACHABLE_BLOCKS_PRESERVING_FLAGS: | |
253 /* Preserve the edge flags. */ | |
254 break; | |
210 } | 255 } |
211 } | 256 } |
212 | 257 |
213 /* Destructor. */ | 258 /* Destructor. */ |
214 | 259 |
329 { | 374 { |
330 int saved_sp = sp; | 375 int saved_sp = sp; |
331 for (dest = first_dom_son (m_dom_direction, bb); | 376 for (dest = first_dom_son (m_dom_direction, bb); |
332 dest; dest = next_dom_son (m_dom_direction, dest)) | 377 dest; dest = next_dom_son (m_dom_direction, dest)) |
333 worklist[sp++] = dest; | 378 worklist[sp++] = dest; |
334 if (sp - saved_sp > 1 && m_dom_direction == CDI_DOMINATORS) | 379 /* Sort worklist after RPO order if requested. */ |
380 if (sp - saved_sp > 1 | |
381 && m_dom_direction == CDI_DOMINATORS | |
382 && m_bb_to_rpo) | |
335 sort_bbs_postorder (&worklist[saved_sp], sp - saved_sp); | 383 sort_bbs_postorder (&worklist[saved_sp], sp - saved_sp); |
336 } | 384 } |
337 } | 385 } |
338 /* NULL is used to mark pop operations in the recursion stack. */ | 386 /* NULL is used to mark pop operations in the recursion stack. */ |
339 while (sp > 0 && !worklist[sp - 1]) | 387 while (sp > 0 && !worklist[sp - 1]) |