annotate gcc/domwalk.h @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 /* Generic dominator tree walker
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2 Copyright (C) 2003-2018 Free Software Foundation, Inc.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 Contributed by Diego Novillo <dnovillo@redhat.com>
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 This file is part of GCC.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 GCC is free software; you can redistribute it and/or modify
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 it under the terms of the GNU General Public License as published by
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 the Free Software Foundation; either version 3, or (at your option)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 any later version.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 GCC is distributed in the hope that it will be useful,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 GNU General Public License for more details.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 along with GCC; see the file COPYING3. If not see
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 <http://www.gnu.org/licenses/>. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20
111
kono
parents: 55
diff changeset
21 #ifndef GCC_DOM_WALK_H
kono
parents: 55
diff changeset
22 #define GCC_DOM_WALK_H
kono
parents: 55
diff changeset
23
kono
parents: 55
diff changeset
24 /**
kono
parents: 55
diff changeset
25 * This is the main class for the dominator walker. It is expected that
kono
parents: 55
diff changeset
26 * consumers will have a custom class inheriting from it, which will over ride
kono
parents: 55
diff changeset
27 * at least one of before_dom_children and after_dom_children to implement the
kono
parents: 55
diff changeset
28 * custom behavior.
kono
parents: 55
diff changeset
29 */
kono
parents: 55
diff changeset
30 class dom_walker
kono
parents: 55
diff changeset
31 {
kono
parents: 55
diff changeset
32 public:
kono
parents: 55
diff changeset
33 static const edge STOP;
kono
parents: 55
diff changeset
34
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
35 /* An enum for determining whether the dom walk should be constrained to
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
36 blocks reachable by executable edges. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
37
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
38 enum reachability
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
39 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
40 /* Walk all blocks within the CFG. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
41 ALL_BLOCKS,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
42
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
43 /* Use REACHABLE_BLOCKS when your subclass can discover that some edges
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
44 are not executable.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
45
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
46 If a subclass can discover that a COND, SWITCH or GOTO has a static
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
47 target in the before_dom_children callback, the taken edge should
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
48 be returned. The generic walker will clear EDGE_EXECUTABLE on all
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
49 edges it can determine are not executable.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
50
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
51 With REACHABLE_BLOCKS, EDGE_EXECUTABLE will be set on every edge in
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
52 the dom_walker ctor; the flag will then be cleared on edges that are
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
53 determined to be not executable. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
54 REACHABLE_BLOCKS,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
55
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
56 /* Identical to REACHABLE_BLOCKS, but the initial state of EDGE_EXECUTABLE
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
57 will instead be preserved in the ctor, allowing for information about
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
58 non-executable edges to be merged in from an earlier analysis (and
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
59 potentially for additional edges to be marked as non-executable). */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
60 REACHABLE_BLOCKS_PRESERVING_FLAGS
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
61 };
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
62
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
63 dom_walker (cdi_direction direction, enum reachability = ALL_BLOCKS);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
64
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
65 /* You can provide a mapping of basic-block index to RPO if you
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
66 have that readily available or you do multiple walks. If you
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
67 specify NULL as BB_INDEX_TO_RPO dominator children will not be
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
68 walked in RPO order. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
69 dom_walker (cdi_direction direction, enum reachability, int *bb_index_to_rpo);
111
kono
parents: 55
diff changeset
70
kono
parents: 55
diff changeset
71 ~dom_walker ();
kono
parents: 55
diff changeset
72
kono
parents: 55
diff changeset
73 /* Walk the dominator tree. */
kono
parents: 55
diff changeset
74 void walk (basic_block);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
75
111
kono
parents: 55
diff changeset
76 /* Function to call before the recursive walk of the dominator children.
kono
parents: 55
diff changeset
77
kono
parents: 55
diff changeset
78 Return value is the always taken edge if the block has multiple outgoing
kono
parents: 55
diff changeset
79 edges, NULL otherwise. When skipping unreachable blocks, the walker
kono
parents: 55
diff changeset
80 uses the taken edge information to clear EDGE_EXECUTABLE on the other
kono
parents: 55
diff changeset
81 edges, exposing unreachable blocks. A NULL return value means all
kono
parents: 55
diff changeset
82 outgoing edges should still be considered executable. A return value
kono
parents: 55
diff changeset
83 of STOP means to stop the domwalk from processing dominated blocks from
kono
parents: 55
diff changeset
84 here. This can be used to process a SEME region only (note domwalk
kono
parents: 55
diff changeset
85 will still do work linear in function size). */
kono
parents: 55
diff changeset
86 virtual edge before_dom_children (basic_block) { return NULL; }
kono
parents: 55
diff changeset
87
kono
parents: 55
diff changeset
88 /* Function to call after the recursive walk of the dominator children. */
kono
parents: 55
diff changeset
89 virtual void after_dom_children (basic_block) {}
kono
parents: 55
diff changeset
90
kono
parents: 55
diff changeset
91 private:
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 /* This is the direction of the dominator tree we want to walk. i.e.,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 if it is set to CDI_DOMINATORS, then we walk the dominator tree,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 if it is set to CDI_POST_DOMINATORS, then we walk the post
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 dominator tree. */
111
kono
parents: 55
diff changeset
96 const ENUM_BITFIELD (cdi_direction) m_dom_direction : 2;
kono
parents: 55
diff changeset
97 bool m_skip_unreachable_blocks;
kono
parents: 55
diff changeset
98 bool m_user_bb_to_rpo;
kono
parents: 55
diff changeset
99 basic_block m_unreachable_dom;
kono
parents: 55
diff changeset
100 int *m_bb_to_rpo;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
101
111
kono
parents: 55
diff changeset
102 /* Query whether or not the given block is reachable or not. */
kono
parents: 55
diff changeset
103 bool bb_reachable (struct function *, basic_block);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
104
111
kono
parents: 55
diff changeset
105 /* Given an unreachable block, propagate that property to outgoing
kono
parents: 55
diff changeset
106 and possibly incoming edges for the block. Typically called after
kono
parents: 55
diff changeset
107 determining a block is unreachable in the before_dom_children
kono
parents: 55
diff changeset
108 callback. */
kono
parents: 55
diff changeset
109 void propagate_unreachable_to_edges (basic_block, FILE *, dump_flags_t);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
110
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 };
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
112
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
113 extern void set_all_edges_as_executable (function *fn);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
114
111
kono
parents: 55
diff changeset
115 #endif