OSDN Git Service

* toplev.h (flag_delete_null_pointer_checks): Move from here to...
[pf3gnuchains/gcc-fork.git] / gcc / tree-flow.h
1 /* Data and Control Flow Analysis for Trees.
2    Copyright (C) 2001, 2003, 2004 Free Software Foundation, Inc.
3    Contributed by Diego Novillo <dnovillo@redhat.com>
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING.  If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.  */
21
22 #ifndef _TREE_FLOW_H
23 #define _TREE_FLOW_H 1
24
25 #include "bitmap.h"
26 #include "hard-reg-set.h"
27 #include "basic-block.h"
28 #include "hashtab.h"
29 #include "tree-gimple.h"
30 #include "tree-ssa-operands.h"
31
32 /* Forward declare structures for the garbage collector GTY markers.  */
33 #ifndef GCC_BASIC_BLOCK_H
34 struct edge_def;
35 typedef struct edge_def *edge;
36 struct basic_block_def;
37 typedef struct basic_block_def *basic_block;
38 #endif
39
40 /*---------------------------------------------------------------------------
41                    Tree annotations stored in tree_common.ann
42 ---------------------------------------------------------------------------*/
43 enum tree_ann_type { TREE_ANN_COMMON, VAR_ANN, STMT_ANN, SSA_NAME_ANN };
44
45 struct tree_ann_common_d GTY(())
46 {
47   /* Annotation type.  */
48   enum tree_ann_type type;
49 };
50
51 /* It is advantageous to avoid things like life analysis for variables which
52    do not need PHI nodes.  This enum describes whether or not a particular
53    variable may need a PHI node.  */
54
55 enum need_phi_state {
56   /* This is the default.  If we are still in this state after finding
57      all the definition and use sites, then we will assume the variable
58      needs PHI nodes.  This is probably an overly conservative assumption.  */
59   NEED_PHI_STATE_UNKNOWN,
60
61   /* This state indicates that we have seen one or more sets of the 
62      variable in a single basic block and that the sets dominate all
63      uses seen so far.  If after finding all definition and use sites
64      we are still in this state, then the variable does not need any
65      PHI nodes.  */
66   NEED_PHI_STATE_NO,
67
68   /* This state indicates that we have either seen multiple definitions of
69      the variable in multiple blocks, or that we encountered a use in a
70      block that was not dominated by the block containing the set(s) of
71      this variable.  This variable is assumed to need PHI nodes.  */
72   NEED_PHI_STATE_MAYBE
73 };
74
75
76 /* When computing aliasing information, we represent the memory pointed-to
77    by pointers with artificial variables called "memory tags" (MT).  There
78    are two kinds of tags: type and name.  Type tags (TMT) are used in
79    type-based alias analysis, they represent all the pointed-to locations
80    and variables of the same alias set class.  Name tags (NMT) are used in
81    flow-sensitive points-to alias analysis, they represent the variables
82    and memory locations pointed-to by a specific SSA_NAME pointer.  */
83 enum mem_tag_kind {
84   /* This variable is not a memory tag.  */
85   NOT_A_TAG,
86
87   /* This variable is a type memory tag (TMT).  */
88   TYPE_TAG,
89
90   /* This variable is a name memory tag (NMT).  */
91   NAME_TAG
92 };
93
94 struct var_ann_d GTY(())
95 {
96   struct tree_ann_common_d common;
97
98   /* Nonzero if this variable has uses which may not appear
99      in the IL.  This can happen in the following cases:
100
101        1. If the variable is used in a variable length
102           array declaration.
103
104         2. If the variable is the return value in a C++
105            function where the named return value optimization
106            has been performed.  */
107   unsigned has_hidden_use : 1;
108
109   /* Used by the out of SSA pass to determine whether this variable has
110      been seen yet or not.  */
111   unsigned out_of_ssa_tag : 1;
112
113   /* Used when building root_var structures in tree_ssa_live.[ch].  */
114   unsigned root_var_processed : 1;
115
116   /* If nonzero, this variable is a memory tag.  */
117   ENUM_BITFIELD (mem_tag_kind) mem_tag_kind : 2;
118
119   /* Nonzero if this variable is an alias tag that represents references to
120      other variables (i.e., this variable appears in the MAY_ALIASES array
121      of other variables).  */
122   unsigned is_alias_tag : 1;
123
124   /* Nonzero if this variable was used after SSA optimizations were
125      applied.  We set this when translating out of SSA form.  */
126   unsigned used : 1;
127
128   /* This field indicates whether or not the variable may need PHI nodes.
129      See the enum's definition for more detailed information about the
130      states.  */
131   ENUM_BITFIELD (need_phi_state) need_phi_state : 2;
132
133   /* An artificial variable representing the memory location pointed-to by
134      all the pointers that TBAA (type-based alias analysis) considers
135      to be aliased.  If the variable is not a pointer or if it is never
136      dereferenced, this must be NULL.  */
137   tree type_mem_tag;
138
139   /* Variables that may alias this variable.  */
140   varray_type may_aliases;
141
142   /* Unique ID of this variable.  */
143   size_t uid;
144
145   /* Used when going out of SSA form to indicate which partition this
146      variable represents storage for.  */
147   unsigned partition;
148
149   /* Used by the root-var object in tree-ssa-live.[ch].  */
150   unsigned root_index;
151
152   /* Default definition for this symbol.  If this field is not NULL, it
153      means that the first reference to this variable in the function is a
154      USE or a VUSE.  In those cases, the SSA renamer creates an SSA name
155      for this variable with an empty defining statement.  */
156   tree default_def;
157
158   /* During into-ssa and the dominator optimizer, this field holds the
159      current version of this variable (an SSA_NAME). 
160
161      This was previously two varrays (one in into-ssa the other in the
162      dominator optimizer).  That is wasteful, particularly since the
163      dominator optimizer calls into-ssa resulting in having two varrays
164      live at the same time and this can happen for each call to the
165      dominator optimizer.  */
166   tree current_def;
167 };
168
169
170 struct dataflow_d GTY(())
171 {
172   /* Immediate uses.  This is a list of all the statements and PHI nodes
173      that are immediately reached by the definitions made in this
174      statement.  */
175   varray_type immediate_uses;
176
177   /* Use this array for very small numbers of uses instead of the varray.  */
178   tree uses[2];
179
180   /* Reached uses.  This is a list of all the possible program statements
181      that may be reached directly or indirectly by definitions made in this
182      statement.  Notice that this is a superset of IMMEDIATE_USES.
183      For instance, given the following piece of code:
184
185             1   a1 = 10;
186             2   if (a1 > 3)
187             3     a2 = a1 + 5;
188             4   a3 = PHI (a1, a2)
189             5   b1 = a3 - 2;
190
191      IMMEDIATE_USES for statement #1 are all those statements that use a1
192      directly (i.e., #2, #3 and #4).  REACHED_USES for statement #1 also
193      includes statement #5 because 'a1' could reach 'a3' via the PHI node
194      at statement #4.  The set of REACHED_USES is then the transitive
195      closure over all the PHI nodes in the IMMEDIATE_USES set.  */
196
197   /* Reaching definitions.  Similarly to REACHED_USES, the set
198      REACHING_DEFS is the set of all the statements that make definitions
199      that may reach this statement.  Notice that we don't need to have a
200      similar entry for immediate definitions, as these are represented by
201      the SSA_NAME nodes themselves (each SSA_NAME node contains a pointer
202      to the statement that makes that definition).  */
203 };
204
205 typedef struct dataflow_d *dataflow_t;
206
207
208 struct stmt_ann_d GTY(())
209 {
210   struct tree_ann_common_d common;
211
212   /* Nonzero if the statement has been modified (meaning that the operands
213      need to be scanned again).  */
214   unsigned modified : 1;
215
216   /* Nonzero if the statement is in the CCP worklist and has not been
217      "cancelled".  If we ever need to use this bit outside CCP, then
218      it should be renamed.  */
219   unsigned in_ccp_worklist: 1;
220
221   /* Nonzero if the statement makes aliased loads.  */
222   unsigned makes_aliased_loads : 1;
223
224   /* Nonzero if the statement makes aliased stores.  */
225   unsigned makes_aliased_stores : 1;
226
227   /* Nonzero if the statement makes references to volatile storage.  */
228   unsigned has_volatile_ops : 1;
229
230   /* Nonzero if the statement makes a function call that may clobber global
231      and local addressable variables.  */
232   unsigned makes_clobbering_call : 1;
233
234   /* Basic block that contains this statement.  */
235   basic_block GTY ((skip (""))) bb;
236
237   /* Statement operands.  */
238   struct def_optype_d * GTY (()) def_ops;
239   struct use_optype_d * GTY (()) use_ops;
240
241   /* Virtual operands (VDEF and VUSE).  */
242   struct vdef_optype_d * GTY (()) vdef_ops;
243   struct vuse_optype_d * GTY (()) vuse_ops;
244
245   /* Dataflow information.  */
246   dataflow_t df;
247
248   /* Set of variables that have had their address taken in the statement.  */
249   bitmap addresses_taken;
250
251   /* Unique identifier for this statement.  These ID's are to be created
252      by each pass on an as-needed basis in any order convenient for the
253      pass which needs statement UIDs.  */
254   unsigned int uid;
255 };
256
257
258 struct ssa_name_ann_d GTY(())
259 {
260   struct tree_ann_common_d common;
261
262   /* Nonzero if points-to analysis couldn't determine where this pointer
263      is pointing to.  */
264   unsigned int pt_anything : 1;
265
266   /* Nonzero if this pointer is the result of a call to malloc.  */
267   unsigned int pt_malloc : 1;
268
269   /* Nonzero if the value of this pointer escapes the current function.  */
270   unsigned int value_escapes_p : 1;
271
272   /* Set of variables that this pointer may point to.  */
273   bitmap pt_vars;
274
275   /* If this pointer has been dereferenced, and points-to information is
276      more precise than type-based aliasing, indirect references to this
277      pointer will be represented by this memory tag, instead of the type
278      tag computed by TBAA.  */
279   tree name_mem_tag;
280 };
281
282
283 union tree_ann_d GTY((desc ("ann_type ((tree_ann)&%h)")))
284 {
285   struct tree_ann_common_d GTY((tag ("TREE_ANN_COMMON"))) common;
286   struct var_ann_d GTY((tag ("VAR_ANN"))) decl;
287   struct stmt_ann_d GTY((tag ("STMT_ANN"))) stmt;
288   struct ssa_name_ann_d GTY((tag ("SSA_NAME_ANN"))) ssa_name;
289 };
290
291 typedef union tree_ann_d *tree_ann;
292 typedef struct var_ann_d *var_ann_t;
293 typedef struct stmt_ann_d *stmt_ann_t;
294 typedef struct ssa_name_ann_d *ssa_name_ann_t;
295
296 static inline var_ann_t var_ann (tree);
297 static inline var_ann_t get_var_ann (tree);
298 static inline stmt_ann_t stmt_ann (tree);
299 static inline stmt_ann_t get_stmt_ann (tree);
300 static inline ssa_name_ann_t ssa_name_ann (tree);
301 static inline ssa_name_ann_t get_ssa_name_ann (tree);
302 static inline enum tree_ann_type ann_type (tree_ann);
303 static inline basic_block bb_for_stmt (tree);
304 extern void set_bb_for_stmt (tree, basic_block);
305 static inline void modify_stmt (tree);
306 static inline void unmodify_stmt (tree);
307 static inline bool stmt_modified_p (tree);
308 static inline varray_type may_aliases (tree);
309 static inline int get_lineno (tree);
310 static inline const char *get_filename (tree);
311 static inline bool is_exec_stmt (tree);
312 static inline bool is_label_stmt (tree);
313 static inline vdef_optype get_vdef_ops (stmt_ann_t);
314 static inline vuse_optype get_vuse_ops (stmt_ann_t);
315 static inline use_optype get_use_ops (stmt_ann_t);
316 static inline def_optype get_def_ops (stmt_ann_t);
317 static inline bitmap addresses_taken (tree);
318 static inline int num_immediate_uses (dataflow_t);
319 static inline tree immediate_use (dataflow_t, int);
320 static inline dataflow_t get_immediate_uses (tree);
321 static inline bool has_hidden_use (tree);
322 static inline void set_has_hidden_use (tree);
323 static inline void set_default_def (tree, tree);
324 static inline tree default_def (tree);
325 static inline bool may_be_aliased (tree);
326
327 /*---------------------------------------------------------------------------
328                   Structure representing predictions in tree level.
329 ---------------------------------------------------------------------------*/
330 struct edge_prediction GTY((chain_next ("%h.next")))
331 {
332   struct edge_prediction *next;
333   edge edge;
334   enum br_predictor predictor;
335   int probability;
336 };
337
338 /*---------------------------------------------------------------------------
339                   Block annotations stored in basic_block.tree_annotations
340 ---------------------------------------------------------------------------*/
341 struct bb_ann_d GTY(())
342 {
343   /* Chain of PHI nodes for this block.  */
344   tree phi_nodes;
345
346   /* Chain of EPHI nodes created in this block.  */
347   tree ephi_nodes;
348   
349   /* Number of predecessors for this block.  This is only valid during
350      SSA rewriting.  It is not maintained after conversion into SSA form.  */
351   int num_preds;
352
353   /* Nonzero if this block is forwardable during cfg cleanups.  This is also
354      used to detect loops during cfg cleanups.  */
355   unsigned forwardable: 1;
356
357   /* Nonzero if this block contains an escape point (see is_escape_site).  */
358   unsigned has_escape_site : 1;
359
360   struct edge_prediction *predictions;
361 };
362
363 typedef struct bb_ann_d *bb_ann_t;
364
365 /* Accessors for basic block annotations.  */
366 static inline bb_ann_t bb_ann (basic_block);
367 static inline tree phi_nodes (basic_block);
368 static inline void set_phi_nodes (basic_block, tree);
369
370 /*---------------------------------------------------------------------------
371                               Global declarations
372 ---------------------------------------------------------------------------*/
373 /* Array of all variables referenced in the function.  */
374 extern GTY(()) varray_type referenced_vars;
375
376 #define num_referenced_vars VARRAY_ACTIVE_SIZE (referenced_vars)
377 #define referenced_var(i) VARRAY_TREE (referenced_vars, i)
378
379 /* Artificial variable used to model the effects of function calls.  */
380 extern GTY(()) tree global_var;
381
382 /* Call clobbered variables in the function.  If bit I is set, then
383    REFERENCED_VARS (I) is call-clobbered.  */
384 extern bitmap call_clobbered_vars;
385
386 /* 'true' after aliases have been computed (see compute_may_aliases).  */
387 extern bool aliases_computed_p;
388
389 /* Macros for showing usage statistics.  */
390 #define SCALE(x) ((unsigned long) ((x) < 1024*10        \
391                   ? (x)                                 \
392                   : ((x) < 1024*1024*10                 \
393                      ? (x) / 1024                       \
394                      : (x) / (1024*1024))))
395
396 #define LABEL(x) ((x) < 1024*10 ? 'b' : ((x) < 1024*1024*10 ? 'k' : 'M'))
397
398 #define PERCENT(x,y) ((float)(x) * 100.0 / (float)(y))
399
400
401 /*---------------------------------------------------------------------------
402                               Block iterators
403 ---------------------------------------------------------------------------*/
404
405 typedef struct {
406   tree_stmt_iterator tsi;
407   basic_block bb;
408 } block_stmt_iterator;
409
410 static inline block_stmt_iterator bsi_start (basic_block);
411 static inline block_stmt_iterator bsi_last (basic_block);
412 static inline bool bsi_end_p (block_stmt_iterator);
413 static inline void bsi_next (block_stmt_iterator *);
414 static inline void bsi_prev (block_stmt_iterator *);
415 static inline tree bsi_stmt (block_stmt_iterator);
416 static inline tree * bsi_stmt_ptr (block_stmt_iterator);
417
418 extern void bsi_remove (block_stmt_iterator *);
419 extern void bsi_move_before (block_stmt_iterator *, block_stmt_iterator *);
420 extern void bsi_move_after (block_stmt_iterator *, block_stmt_iterator *);
421 extern void bsi_move_to_bb_end (block_stmt_iterator *, basic_block);
422
423 enum bsi_iterator_update
424 {
425   /* Note that these are intentionally in the same order as TSI_FOO.  They
426      mean exactly the same as their TSI_* counterparts.  */
427   BSI_NEW_STMT,
428   BSI_SAME_STMT,
429   BSI_CHAIN_START,
430   BSI_CHAIN_END,
431   BSI_CONTINUE_LINKING
432 };
433
434 extern void bsi_insert_before (block_stmt_iterator *, tree,
435                                enum bsi_iterator_update);
436 extern void bsi_insert_after (block_stmt_iterator *, tree,
437                               enum bsi_iterator_update);
438
439 extern void bsi_replace (const block_stmt_iterator *, tree, bool);
440
441 /*---------------------------------------------------------------------------
442                               Function prototypes
443 ---------------------------------------------------------------------------*/
444 /* In tree-cfg.c  */
445
446 /* Location to track pending stmt for edge insertion.  */
447 #define PENDING_STMT(e) ((e)->insns.t)
448
449 extern void delete_tree_cfg (void);
450 extern void disband_implicit_edges (void);
451 extern bool stmt_ends_bb_p (tree);
452 extern bool is_ctrl_stmt (tree);
453 extern bool is_ctrl_altering_stmt (tree);
454 extern bool computed_goto_p (tree);
455 extern bool simple_goto_p (tree);
456 extern void tree_dump_bb (basic_block, FILE *, int);
457 extern void debug_tree_bb (basic_block);
458 extern basic_block debug_tree_bb_n (int);
459 extern void dump_tree_cfg (FILE *, int);
460 extern void debug_tree_cfg (int);
461 extern void dump_cfg_stats (FILE *);
462 extern void debug_cfg_stats (void);
463 extern void debug_loop_ir (void);
464 extern void print_loop_ir (FILE *);
465 extern void cleanup_tree_cfg (void);
466 extern tree first_stmt (basic_block);
467 extern tree last_stmt (basic_block);
468 extern tree *last_stmt_ptr (basic_block);
469 extern tree last_and_only_stmt (basic_block);
470 extern edge find_taken_edge (basic_block, tree);
471 extern void cfg_remove_useless_stmts (void);
472 extern edge thread_edge (edge, basic_block);
473 extern basic_block label_to_block (tree);
474 extern void tree_optimize_tail_calls (bool, enum tree_dump_index);
475 extern edge tree_block_forwards_to (basic_block bb);
476 extern void bsi_insert_on_edge (edge, tree);
477 extern void bsi_commit_edge_inserts (int *);
478 extern void notice_special_calls (tree);
479 extern void clear_special_calls (void);
480 extern void compute_dominance_frontiers (bitmap *);
481 extern void verify_stmts (void);
482 extern void extract_true_false_edges_from_block (basic_block, edge *, edge *);
483
484 /* In tree-pretty-print.c.  */
485 extern void dump_generic_bb (FILE *, basic_block, int, int);
486
487 /* In tree-dfa.c  */
488 extern var_ann_t create_var_ann (tree);
489 extern stmt_ann_t create_stmt_ann (tree);
490 extern ssa_name_ann_t create_ssa_name_ann (tree);
491 extern tree create_phi_node (tree, basic_block);
492 extern void add_phi_arg (tree *, tree, edge);
493 extern void remove_phi_arg (tree, basic_block);
494 extern void remove_phi_arg_num (tree, int);
495 extern void remove_phi_node (tree, tree, basic_block);
496 extern void remove_all_phi_nodes_for (bitmap);
497 extern void dump_dfa_stats (FILE *);
498 extern void debug_dfa_stats (void);
499 extern void debug_referenced_vars (void);
500 extern void dump_referenced_vars (FILE *);
501 extern void dump_variable (FILE *, tree);
502 extern void debug_variable (tree);
503 extern void dump_immediate_uses (FILE *);
504 extern void debug_immediate_uses (void);
505 extern void dump_immediate_uses_for (FILE *, tree);
506 extern void debug_immediate_uses_for (tree);
507 extern void compute_immediate_uses (int, bool (*)(tree));
508 extern void free_df (void);
509 extern tree get_virtual_var (tree);
510 extern void add_referenced_tmp_var (tree var);
511 extern void mark_new_vars_to_rename (tree, bitmap);
512 extern void redirect_immediate_uses (tree, tree);
513 extern tree make_rename_temp (tree, const char *);
514
515 /* Flags used when computing reaching definitions and reached uses.  */
516 #define TDFA_USE_OPS            1 << 0
517 #define TDFA_USE_VOPS           1 << 1
518
519 /* In gimple-low.c  */
520 struct lower_data;
521 extern void lower_stmt_body (tree, struct lower_data *);
522 extern void expand_used_vars (void);
523 extern void record_vars (tree);
524 extern bool block_may_fallthru (tree block);
525
526 /* In tree-ssa-alias.c  */
527 extern void dump_may_aliases_for (FILE *, tree);
528 extern void debug_may_aliases_for (tree);
529 extern void dump_alias_info (FILE *);
530 extern void debug_alias_info (void);
531 extern void dump_points_to_info (FILE *);
532 extern void debug_points_to_info (void);
533
534 /* Call-back function for walk_use_def_chains().  At each reaching
535    definition, a function with this prototype is called.  */
536 typedef bool (*walk_use_def_chains_fn) (tree, tree, void *);
537
538 /* In tree-ssa.c  */
539 extern void init_tree_ssa (void);
540 extern void rewrite_vars_out_of_ssa (bitmap);
541 extern void dump_reaching_defs (FILE *);
542 extern void debug_reaching_defs (void);
543 extern void dump_tree_ssa (FILE *);
544 extern void debug_tree_ssa (void);
545 extern void debug_def_blocks (void);
546 extern void dump_tree_ssa_stats (FILE *);
547 extern void debug_tree_ssa_stats (void);
548 extern void ssa_remove_edge (edge);
549 extern edge ssa_redirect_edge (edge, basic_block);
550 extern void set_is_used (tree);
551 extern bool tree_ssa_useless_type_conversion (tree);
552 extern bool tree_ssa_useless_type_conversion_1 (tree, tree);
553 extern void verify_ssa (void);
554 extern void delete_tree_ssa (void);
555 extern void register_new_def (tree, varray_type *);
556 extern void walk_use_def_chains (tree, walk_use_def_chains_fn, void *);
557
558 /* In tree-into-ssa.c  */
559 extern void rewrite_into_ssa (void);
560
561 extern unsigned int highest_ssa_version;
562
563 /* In tree-ssa-pre.c  */
564 extern void tree_perform_ssapre (tree, enum tree_dump_index);
565
566 /* In tree-ssa-ccp.c  */
567 bool fold_stmt (tree *);
568 tree widen_bitfield (tree, tree, tree);
569
570 /* In tree-ssa-dom.c  */
571 extern void dump_dominator_optimization_stats (FILE *);
572 extern void debug_dominator_optimization_stats (void);
573
574 /* In tree-ssa-copy.c  */
575 extern void propagate_value (tree *, tree);
576 extern void replace_exp (tree *, tree);
577 extern bool cprop_into_stmt (tree, varray_type);
578 extern void cprop_into_successor_phis (basic_block, varray_type, bitmap);
579
580 /* In tree-flow-inline.h  */
581 static inline int phi_arg_from_edge (tree, edge);
582 static inline struct phi_arg_d *phi_element_for_edge (tree, edge);
583 static inline bool may_propagate_copy (tree, tree);
584 static inline bool is_call_clobbered (tree);
585 static inline void mark_call_clobbered (tree);
586
587 /* In tree-eh.c  */
588 extern void make_eh_edges (tree);
589 extern bool tree_could_trap_p (tree);
590 extern bool tree_could_throw_p (tree);
591 extern bool tree_can_throw_internal (tree);
592 extern bool tree_can_throw_external (tree);
593 extern void add_stmt_to_eh_region (tree, int);
594
595 #include "tree-flow-inline.h"
596
597 #endif /* _TREE_FLOW_H  */