* inclhack.def (AAB_aix_fcntl): New fix.
[official-gcc.git] / gcc / tree-ssa-live.h
blob70a3aa60fd3a051719728259d557a06f49b40c95
1 /* Routines for liveness in SSA trees.
2 Copyright (C) 2003, 2004, 2005, 2007, 2008, 2010
3 Free Software Foundation, Inc.
4 Contributed by Andrew MacLeod <amacleod@redhat.com>
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
11 any later version.
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
23 #ifndef _TREE_SSA_LIVE_H
24 #define _TREE_SSA_LIVE_H 1
26 #include "partition.h"
27 #include "vecprim.h"
31 /* Used to create the variable mapping when we go out of SSA form.
33 Mapping from an ssa_name to a partition number is maintained, as well as
34 partition number back to ssa_name.
36 This data structure also supports "views", which work on a subset of all
37 partitions. This allows the coalescer to decide what partitions are
38 interesting to it, and only work with those partitions. Whenever the view
39 is changed, the partition numbers change, but none of the partition groupings
40 change. (ie, it is truly a view since it doesn't change anything)
42 The final component of the data structure is the basevar map. This provides
43 a list of all the different base variables which occur in a partition view,
44 and a unique index for each one. Routines are provided to quickly produce
45 the base variable of a partition.
47 Note that members of a partition MUST all have the same base variable. */
49 typedef struct _var_map
51 /* The partition manager of all variables. */
52 partition var_partition;
54 /* Vector for managing partitions views. */
55 int *partition_to_view;
56 int *view_to_partition;
58 /* Current number of partitions in var_map based on the current view. */
59 unsigned int num_partitions;
61 /* Original full partition size. */
62 unsigned int partition_size;
64 /* Number of base variables in the base var list. */
65 int num_basevars;
67 /* Map of partitions numbers to base variable table indexes. */
68 int *partition_to_base_index;
69 } *var_map;
72 /* Value used to represent no partition number. */
73 #define NO_PARTITION -1
75 extern var_map init_var_map (int);
76 extern void delete_var_map (var_map);
77 extern void dump_var_map (FILE *, var_map);
78 extern int var_union (var_map, tree, tree);
79 extern void partition_view_normal (var_map, bool);
80 extern void partition_view_bitmap (var_map, bitmap, bool);
81 #ifdef ENABLE_CHECKING
82 extern void register_ssa_partition_check (tree ssa_var);
83 #endif
86 /* Return number of partitions in MAP. */
88 static inline unsigned
89 num_var_partitions (var_map map)
91 return map->num_partitions;
95 /* Given partition index I from MAP, return the variable which represents that
96 partition. */
98 static inline tree
99 partition_to_var (var_map map, int i)
101 tree name;
102 if (map->view_to_partition)
103 i = map->view_to_partition[i];
104 i = partition_find (map->var_partition, i);
105 name = ssa_name (i);
106 return name;
110 /* Given ssa_name VERSION, if it has a partition in MAP, return the var it
111 is associated with. Otherwise return NULL. */
113 static inline tree
114 version_to_var (var_map map, int version)
116 int part;
117 part = partition_find (map->var_partition, version);
118 if (map->partition_to_view)
119 part = map->partition_to_view[part];
120 if (part == NO_PARTITION)
121 return NULL_TREE;
123 return partition_to_var (map, part);
127 /* Given VAR, return the partition number in MAP which contains it.
128 NO_PARTITION is returned if it's not in any partition. */
130 static inline int
131 var_to_partition (var_map map, tree var)
133 int part;
135 part = partition_find (map->var_partition, SSA_NAME_VERSION (var));
136 if (map->partition_to_view)
137 part = map->partition_to_view[part];
138 return part;
142 /* Given VAR, return the variable which represents the entire partition
143 it is a member of in MAP. NULL is returned if it is not in a partition. */
145 static inline tree
146 var_to_partition_to_var (var_map map, tree var)
148 int part;
150 part = var_to_partition (map, var);
151 if (part == NO_PARTITION)
152 return NULL_TREE;
153 return partition_to_var (map, part);
157 /* Return the index into the basevar table for PARTITION's base in MAP. */
159 static inline int
160 basevar_index (var_map map, int partition)
162 gcc_checking_assert (partition >= 0
163 && partition <= (int) num_var_partitions (map));
164 return map->partition_to_base_index[partition];
168 /* Return the number of different base variables in MAP. */
170 static inline int
171 num_basevars (var_map map)
173 return map->num_basevars;
178 /* This routine registers a partition for SSA_VAR with MAP. Any unregistered
179 partitions may be filtered out by a view later. */
181 static inline void
182 register_ssa_partition (var_map map ATTRIBUTE_UNUSED,
183 tree ssa_var ATTRIBUTE_UNUSED)
185 #if defined ENABLE_CHECKING
186 register_ssa_partition_check (ssa_var);
187 #endif
191 /* ---------------- live on entry/exit info ------------------------------
193 This structure is used to represent live range information on SSA based
194 trees. A partition map must be provided, and based on the active partitions,
195 live-on-entry information and live-on-exit information can be calculated.
196 As well, partitions are marked as to whether they are global (live
197 outside the basic block they are defined in).
199 The live-on-entry information is per block. It provide a bitmap for
200 each block which has a bit set for each partition that is live on entry to
201 that block.
203 The live-on-exit information is per block. It provides a bitmap for each
204 block indicating which partitions are live on exit from the block.
206 For the purposes of this implementation, we treat the elements of a PHI
207 as follows:
209 Uses in a PHI are considered LIVE-ON-EXIT to the block from which they
210 originate. They are *NOT* considered live on entry to the block
211 containing the PHI node.
213 The Def of a PHI node is *not* considered live on entry to the block.
214 It is considered to be "define early" in the block. Picture it as each
215 block having a stmt (or block-preheader) before the first real stmt in
216 the block which defines all the variables that are defined by PHIs.
218 ----------------------------------------------------------------------- */
221 typedef struct tree_live_info_d
223 /* Var map this relates to. */
224 var_map map;
226 /* Bitmap indicating which partitions are global. */
227 bitmap global;
229 /* Bitmaps of live on entry blocks for partition elements. */
230 bitmap_head *livein;
232 /* Bitmaps of what variables are live on exit for a basic blocks. */
233 bitmap_head *liveout;
235 /* Number of basic blocks when live on exit calculated. */
236 int num_blocks;
238 /* Vector used when creating live ranges as a visited stack. */
239 int *work_stack;
241 /* Top of workstack. */
242 int *stack_top;
243 } *tree_live_info_p;
246 extern tree_live_info_p calculate_live_ranges (var_map);
247 extern void calculate_live_on_exit (tree_live_info_p);
248 extern void delete_tree_live_info (tree_live_info_p);
250 #define LIVEDUMP_ENTRY 0x01
251 #define LIVEDUMP_EXIT 0x02
252 #define LIVEDUMP_ALL (LIVEDUMP_ENTRY | LIVEDUMP_EXIT)
253 extern void dump_live_info (FILE *, tree_live_info_p, int);
256 /* Return TRUE if P is marked as a global in LIVE. */
258 static inline int
259 partition_is_global (tree_live_info_p live, int p)
261 gcc_checking_assert (live->global);
262 return bitmap_bit_p (live->global, p);
266 /* Return the bitmap from LIVE representing the live on entry blocks for
267 partition P. */
269 static inline bitmap
270 live_on_entry (tree_live_info_p live, basic_block bb)
272 gcc_checking_assert (live->livein
273 && bb != ENTRY_BLOCK_PTR
274 && bb != EXIT_BLOCK_PTR);
276 return &live->livein[bb->index];
280 /* Return the bitmap from LIVE representing the live on exit partitions from
281 block BB. */
283 static inline bitmap
284 live_on_exit (tree_live_info_p live, basic_block bb)
286 gcc_checking_assert (live->liveout
287 && bb != ENTRY_BLOCK_PTR
288 && bb != EXIT_BLOCK_PTR);
290 return &live->liveout[bb->index];
294 /* Return the partition map which the information in LIVE utilizes. */
296 static inline var_map
297 live_var_map (tree_live_info_p live)
299 return live->map;
303 /* Merge the live on entry information in LIVE for partitions P1 and P2. Place
304 the result into P1. Clear P2. */
306 static inline void
307 live_merge_and_clear (tree_live_info_p live, int p1, int p2)
309 gcc_checking_assert (&live->livein[p1] && &live->livein[p2]);
310 bitmap_ior_into (&live->livein[p1], &live->livein[p2]);
311 bitmap_zero (&live->livein[p2]);
315 /* Mark partition P as live on entry to basic block BB in LIVE. */
317 static inline void
318 make_live_on_entry (tree_live_info_p live, basic_block bb , int p)
320 bitmap_set_bit (&live->livein[bb->index], p);
321 bitmap_set_bit (live->global, p);
325 /* From tree-ssa-coalesce.c */
326 extern var_map coalesce_ssa_name (void);
329 /* From tree-ssa-ter.c */
330 extern bitmap find_replaceable_exprs (var_map);
331 extern void dump_replaceable_exprs (FILE *, bitmap);
334 #endif /* _TREE_SSA_LIVE_H */