OSDN Git Service

gcc/ada/
[pf3gnuchains/gcc-fork.git] / gcc / tree-flow.h
1 /* Data and Control Flow Analysis for Trees.
2    Copyright (C) 2001, 2003, 2004, 2005, 2006, 2007
3    Free Software Foundation, Inc.
4    Contributed by Diego Novillo <dnovillo@redhat.com>
5
6 This file is part of GCC.
7
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.
12
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.
17
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/>.  */
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 #include "cgraph.h"
32 #include "ipa-reference.h"
33
34 /* Forward declare structures for the garbage collector GTY markers.  */
35 #ifndef GCC_BASIC_BLOCK_H
36 struct edge_def;
37 typedef struct edge_def *edge;
38 struct basic_block_def;
39 typedef struct basic_block_def *basic_block;
40 #endif
41 struct static_var_ann_d;
42
43 /* Memory reference statistics for individual memory symbols,
44    collected during alias analysis.  */
45 struct mem_sym_stats_d GTY(())
46 {
47   /* Memory symbol.  */
48   tree var;
49
50   /* Nonzero if this entry has been assigned a partition.  */
51   unsigned int partitioned_p : 1;
52
53   /* Nonzero if VAR is a memory partition tag that already contains
54      call-clobbered variables in its partition set.  */
55   unsigned int has_call_clobbered_vars : 1;
56
57   /* Number of direct reference sites.  A direct reference to VAR is any
58      reference of the form 'VAR = ' or ' = VAR'.  For GIMPLE reg
59      pointers, this is the number of sites where the pointer is
60      dereferenced.  */
61   long num_direct_writes;
62   long num_direct_reads;
63
64   /* Number of indirect reference sites.  An indirect reference to VAR
65      is any reference via a pointer that contains VAR in its points-to
66      set or, in the case of call-clobbered symbols, a function call.  */
67   long num_indirect_writes;
68   long num_indirect_reads;
69
70   /* Execution frequency.  This is the sum of the execution
71      frequencies of all the statements that reference this object
72      weighted by the number of references in each statement.  This is
73      the main key used to sort the list of symbols to partition.
74      Symbols with high execution frequencies are put at the bottom of
75      the work list (ie, they are partitioned last).
76      Execution frequencies are taken directly from each basic block,
77      so compiling with PGO enabled will increase the precision of this
78      estimate.  */
79   long frequency_reads;
80   long frequency_writes;
81
82   /* Set of memory tags that contain VAR in their alias set.  */
83   bitmap parent_tags;
84 };
85
86 typedef struct mem_sym_stats_d *mem_sym_stats_t;
87 DEF_VEC_P(mem_sym_stats_t);
88 DEF_VEC_ALLOC_P(mem_sym_stats_t, heap);
89
90 /* Memory reference statistics collected during alias analysis.  */
91 struct mem_ref_stats_d GTY(())
92 {
93   /* Number of statements that make memory references.  */
94   long num_mem_stmts;
95
96   /* Number of statements that make function calls.  */
97   long num_call_sites;
98
99   /* Number of statements that make calls to pure/const functions.  */
100   long num_pure_const_call_sites;
101
102   /* Number of ASM statements.  */
103   long num_asm_sites;
104
105   /* Estimated number of virtual operands needed as computed by
106    compute_memory_partitions.  */
107   long num_vuses;
108   long num_vdefs;
109
110   /* This maps every symbol used to make "memory" references
111      (pointers, arrays, structures, etc) to an instance of struct
112      mem_sym_stats_d describing reference statistics for the symbol.  */
113   struct pointer_map_t * GTY((skip)) mem_sym_stats;
114 };
115
116
117 /* Gimple dataflow datastructure. All publicly available fields shall have
118    gimple_ accessor defined in tree-flow-inline.h, all publicly modifiable
119    fields should have gimple_set accessor.  */
120 struct gimple_df GTY(())
121 {
122   /* Array of all variables referenced in the function.  */
123   htab_t GTY((param_is (struct int_tree_map))) referenced_vars;
124
125   /* A list of all the noreturn calls passed to modify_stmt.
126      cleanup_control_flow uses it to detect cases where a mid-block
127      indirect call has been turned into a noreturn call.  When this
128      happens, all the instructions after the call are no longer
129      reachable and must be deleted as dead.  */
130   VEC(tree,gc) *modified_noreturn_calls;
131
132   /* Array of all SSA_NAMEs used in the function.  */
133   VEC(tree,gc) *ssa_names;
134
135   /* Artificial variable used to model the effects of function calls.  */
136   tree global_var;
137
138   /* Artificial variable used to model the effects of nonlocal
139      variables.  */
140   tree nonlocal_all;
141
142   /* Call clobbered variables in the function.  If bit I is set, then
143      REFERENCED_VARS (I) is call-clobbered.  */
144   bitmap call_clobbered_vars;
145
146   /* Addressable variables in the function.  If bit I is set, then
147      REFERENCED_VARS (I) has had its address taken.  Note that
148      CALL_CLOBBERED_VARS and ADDRESSABLE_VARS are not related.  An
149      addressable variable is not necessarily call-clobbered (e.g., a
150      local addressable whose address does not escape) and not all
151      call-clobbered variables are addressable (e.g., a local static
152      variable).  */
153   bitmap addressable_vars;
154
155   /* Free list of SSA_NAMEs.  */
156   tree free_ssanames;
157
158   /* Hashtable holding definition for symbol.  If this field is not NULL, it
159      means that the first reference to this variable in the function is a
160      USE or a VUSE.  In those cases, the SSA renamer creates an SSA name
161      for this variable with an empty defining statement.  */
162   htab_t GTY((param_is (struct int_tree_map))) default_defs;
163
164   /* 'true' after aliases have been computed (see compute_may_aliases).  */
165   unsigned int aliases_computed_p : 1;
166
167   /* True if the code is in ssa form.  */
168   unsigned int in_ssa_p : 1;
169
170   struct ssa_operands ssa_operands;
171
172   /* Hashtable of variables annotations.  Used for static variables only;
173      local variables have direct pointer in the tree node.  */
174   htab_t GTY((param_is (struct static_var_ann_d))) var_anns;
175
176   /* Memory reference statistics collected during alias analysis.
177      This information is used to drive the memory partitioning
178      heuristics in compute_memory_partitions.  */
179   struct mem_ref_stats_d mem_ref_stats;
180 };
181
182 /* Accessors for internal use only.  Generic code should use abstraction
183    provided by tree-flow-inline.h or specific modules.  */
184 #define FREE_SSANAMES(fun) (fun)->gimple_df->free_ssanames
185 #define SSANAMES(fun) (fun)->gimple_df->ssa_names
186 #define MODIFIED_NORETURN_CALLS(fun) (fun)->gimple_df->modified_noreturn_calls
187 #define DEFAULT_DEFS(fun) (fun)->gimple_df->default_defs
188
189 typedef struct
190 {
191   htab_t htab;
192   PTR *slot;
193   PTR *limit;
194 } htab_iterator;
195
196 /* Iterate through the elements of hashtable HTAB, using htab_iterator ITER,
197    storing each element in RESULT, which is of type TYPE.  */
198 #define FOR_EACH_HTAB_ELEMENT(HTAB, RESULT, TYPE, ITER) \
199   for (RESULT = (TYPE) first_htab_element (&(ITER), (HTAB)); \
200         !end_htab_p (&(ITER)); \
201         RESULT = (TYPE) next_htab_element (&(ITER)))
202
203 /*---------------------------------------------------------------------------
204                       Attributes for SSA_NAMEs.
205   
206   NOTE: These structures are stored in struct tree_ssa_name
207   but are only used by the tree optimizers, so it makes better sense
208   to declare them here to avoid recompiling unrelated files when
209   making changes.
210 ---------------------------------------------------------------------------*/
211
212 /* Aliasing information for SSA_NAMEs representing pointer variables.  */
213 struct ptr_info_def GTY(())
214 {
215   /* Nonzero if points-to analysis couldn't determine where this pointer
216      is pointing to.  */
217   unsigned int pt_anything : 1;
218
219   /* Nonzero if the value of this pointer escapes the current function.  */
220   unsigned int value_escapes_p : 1;
221
222   /* Nonzero if this pointer is dereferenced.  */
223   unsigned int is_dereferenced : 1;
224
225   /* Nonzero if this pointer points to a global variable.  */
226   unsigned int pt_global_mem : 1;
227
228   /* Nonzero if this pointer points to NULL.  */
229   unsigned int pt_null : 1;
230
231   /* Set of variables that this pointer may point to.  */
232   bitmap pt_vars;
233
234   /* If this pointer has been dereferenced, and points-to information is
235      more precise than type-based aliasing, indirect references to this
236      pointer will be represented by this memory tag, instead of the type
237      tag computed by TBAA.  */
238   tree name_mem_tag;
239
240   /* Mask of reasons this pointer's value escapes the function  */
241   unsigned int escape_mask;
242 };
243
244
245 /*---------------------------------------------------------------------------
246                    Tree annotations stored in tree_base.ann
247 ---------------------------------------------------------------------------*/
248 enum tree_ann_type { TREE_ANN_COMMON, VAR_ANN, FUNCTION_ANN, STMT_ANN };
249
250 struct tree_ann_common_d GTY(())
251 {
252   /* Annotation type.  */
253   enum tree_ann_type type;
254
255  /* Auxiliary info specific to a pass.  At all times, this
256     should either point to valid data or be NULL.  */ 
257   PTR GTY ((skip (""))) aux; 
258
259   /* The value handle for this expression.  Used by GVN-PRE.  */
260   tree GTY((skip)) value_handle;
261 };
262
263 /* It is advantageous to avoid things like life analysis for variables which
264    do not need PHI nodes.  This enum describes whether or not a particular
265    variable may need a PHI node.  */
266
267 enum need_phi_state {
268   /* This is the default.  If we are still in this state after finding
269      all the definition and use sites, then we will assume the variable
270      needs PHI nodes.  This is probably an overly conservative assumption.  */
271   NEED_PHI_STATE_UNKNOWN,
272
273   /* This state indicates that we have seen one or more sets of the 
274      variable in a single basic block and that the sets dominate all
275      uses seen so far.  If after finding all definition and use sites
276      we are still in this state, then the variable does not need any
277      PHI nodes.  */
278   NEED_PHI_STATE_NO,
279
280   /* This state indicates that we have either seen multiple definitions of
281      the variable in multiple blocks, or that we encountered a use in a
282      block that was not dominated by the block containing the set(s) of
283      this variable.  This variable is assumed to need PHI nodes.  */
284   NEED_PHI_STATE_MAYBE
285 };
286
287
288 /* The "no alias" attribute allows alias analysis to make more
289    aggressive assumptions when assigning alias sets, computing
290    points-to information and memory partitions.  These attributes
291    are the result of user annotations or flags (e.g.,
292    -fargument-noalias).  */
293 enum noalias_state {
294     /* Default state.  No special assumptions can be made about this
295        symbol.  */
296     MAY_ALIAS = 0,
297
298     /* The symbol does not alias with other symbols that have a
299        NO_ALIAS* attribute.  */
300     NO_ALIAS,
301
302     /* The symbol does not alias with other symbols that have a
303        NO_ALIAS*, and it may not alias with global symbols.  */
304     NO_ALIAS_GLOBAL,
305
306     /* The symbol does not alias with any other symbols.  */
307     NO_ALIAS_ANYTHING
308 };
309
310
311 struct subvar;
312 typedef struct subvar *subvar_t;
313
314 /* This structure represents a fake sub-variable for a structure field.  */
315 struct subvar GTY(())
316 {
317   /* Fake variable.  */
318   tree var;
319
320   /* Next subvar for this structure.  */
321   subvar_t next;
322 };
323
324 struct var_ann_d GTY(())
325 {
326   struct tree_ann_common_d common;
327
328   /* Used by the out of SSA pass to determine whether this variable has
329      been seen yet or not.  */
330   unsigned out_of_ssa_tag : 1;
331
332   /* Used when building base variable structures in a var_map.  */
333   unsigned base_var_processed : 1;
334
335   /* Nonzero if this variable was used after SSA optimizations were
336      applied.  We set this when translating out of SSA form.  */
337   unsigned used : 1;
338
339   /* This field indicates whether or not the variable may need PHI nodes.
340      See the enum's definition for more detailed information about the
341      states.  */
342   ENUM_BITFIELD (need_phi_state) need_phi_state : 2;
343
344   /* Used during operand processing to determine if this variable is already 
345      in the VUSE list.  */
346   unsigned in_vuse_list : 1;
347
348   /* Used during operand processing to determine if this variable is already 
349      in the VDEF list.  */
350   unsigned in_vdef_list : 1;
351
352   /* True for HEAP artificial variables.  These variables represent
353      the memory area allocated by a call to malloc.  */
354   unsigned is_heapvar : 1;
355
356   /* True if the variable is call clobbered.  */
357   unsigned int call_clobbered : 1;
358
359   /* This field describes several "no alias" attributes that some
360      symbols are known to have.  See the enum's definition for more
361      information on each attribute.  */
362   ENUM_BITFIELD (noalias_state) noalias_state : 2;
363
364   /* Memory partition tag assigned to this symbol.  */
365   tree mpt;
366
367   /* If this variable is a pointer P that has been dereferenced, this
368      field is an artificial variable that represents the memory
369      location *P.  Every other pointer Q that is type-compatible with
370      P will also have the same memory tag.  If the variable is not a
371      pointer or if it is never dereferenced, this must be NULL.
372      FIXME, do we really need this here?  How much slower would it be
373      to convert to hash table?  */
374   tree symbol_mem_tag;
375
376   /* Used when going out of SSA form to indicate which partition this
377      variable represents storage for.  */
378   unsigned partition;
379
380   /* Used by var_map for the base index of ssa base variables.  */
381   unsigned base_index;
382
383   /* During into-ssa and the dominator optimizer, this field holds the
384      current version of this variable (an SSA_NAME).  */
385   tree current_def;
386
387   /* If this variable is a structure, this fields holds a list of
388      symbols representing each of the fields of the structure.  */
389   subvar_t subvars;
390
391   /* Mask of values saying the reasons why this variable has escaped
392      the function.  */
393   unsigned int escape_mask;
394 };
395
396 /* Container for variable annotation used by hashtable for annotations for
397    static variables.  */
398 struct static_var_ann_d GTY(())
399 {
400   struct var_ann_d ann;
401   unsigned int uid;
402 };
403
404 struct function_ann_d GTY(())
405 {
406   struct tree_ann_common_d common;
407
408   /* Pointer to the structure that contains the sets of global
409      variables modified by function calls.  This field is only used
410      for FUNCTION_DECLs.  */
411   ipa_reference_vars_info_t GTY ((skip)) reference_vars_info;
412 };
413
414 typedef struct immediate_use_iterator_d
415 {
416   /* This is the current use the iterator is processing.  */
417   ssa_use_operand_t *imm_use;
418   /* This marks the last use in the list (use node from SSA_NAME)  */
419   ssa_use_operand_t *end_p;
420   /* This node is inserted and used to mark the end of the uses for a stmt.  */
421   ssa_use_operand_t iter_node;
422   /* This is the next ssa_name to visit.  IMM_USE may get removed before
423      the next one is traversed to, so it must be cached early.  */
424   ssa_use_operand_t *next_imm_name;
425 } imm_use_iterator;
426
427
428 /* Use this iterator when simply looking at stmts.  Adding, deleting or
429    modifying stmts will cause this iterator to malfunction.  */
430
431 #define FOR_EACH_IMM_USE_FAST(DEST, ITER, SSAVAR)                       \
432   for ((DEST) = first_readonly_imm_use (&(ITER), (SSAVAR));     \
433        !end_readonly_imm_use_p (&(ITER));                       \
434        (DEST) = next_readonly_imm_use (&(ITER)))
435   
436 /* Use this iterator to visit each stmt which has a use of SSAVAR.  */
437
438 #define FOR_EACH_IMM_USE_STMT(STMT, ITER, SSAVAR)               \
439   for ((STMT) = first_imm_use_stmt (&(ITER), (SSAVAR));         \
440        !end_imm_use_stmt_p (&(ITER));                           \
441        (STMT) = next_imm_use_stmt (&(ITER)))
442
443 /* Use this to terminate the FOR_EACH_IMM_USE_STMT loop early.  Failure to 
444    do so will result in leaving a iterator marker node in the immediate
445    use list, and nothing good will come from that.   */
446 #define BREAK_FROM_IMM_USE_STMT(ITER)                           \
447    {                                                            \
448      end_imm_use_stmt_traverse (&(ITER));                       \
449      break;                                                     \
450    }
451
452
453 /* Use this iterator in combination with FOR_EACH_IMM_USE_STMT to 
454    get access to each occurrence of ssavar on the stmt returned by
455    that iterator..  for instance:
456
457      FOR_EACH_IMM_USE_STMT (stmt, iter, var)
458        {
459          FOR_EACH_IMM_USE_ON_STMT (use_p, iter)
460            {
461              SET_USE (use_p) = blah;
462            }
463          update_stmt (stmt);
464        }                                                         */
465
466 #define FOR_EACH_IMM_USE_ON_STMT(DEST, ITER)                    \
467   for ((DEST) = first_imm_use_on_stmt (&(ITER));                \
468        !end_imm_use_on_stmt_p (&(ITER));                        \
469        (DEST) = next_imm_use_on_stmt (&(ITER)))
470
471
472
473 struct stmt_ann_d GTY(())
474 {
475   struct tree_ann_common_d common;
476
477   /* Basic block that contains this statement.  */
478   basic_block bb;
479
480   /* Operand cache for stmt.  */
481   struct stmt_operands_d GTY ((skip (""))) operands;
482
483   /* Set of variables that have had their address taken in the statement.  */
484   bitmap addresses_taken;
485
486   /* Unique identifier for this statement.  These ID's are to be created
487      by each pass on an as-needed basis in any order convenient for the
488      pass which needs statement UIDs.  */
489   unsigned int uid;
490
491   /* Nonzero if the statement references memory (at least one of its
492      expressions contains a non-register operand).  */
493   unsigned references_memory : 1;
494
495   /* Nonzero if the statement has been modified (meaning that the operands
496      need to be scanned again).  */
497   unsigned modified : 1;
498
499   /* Nonzero if the statement makes references to volatile storage.  */
500   unsigned has_volatile_ops : 1;
501 };
502
503 union tree_ann_d GTY((desc ("ann_type ((tree_ann_t)&%h)")))
504 {
505   struct tree_ann_common_d GTY((tag ("TREE_ANN_COMMON"))) common;
506   struct var_ann_d GTY((tag ("VAR_ANN"))) vdecl;
507   struct function_ann_d GTY((tag ("FUNCTION_ANN"))) fdecl;
508   struct stmt_ann_d GTY((tag ("STMT_ANN"))) stmt;
509 };
510
511 typedef union tree_ann_d *tree_ann_t;
512 typedef struct var_ann_d *var_ann_t;
513 typedef struct function_ann_d *function_ann_t;
514 typedef struct stmt_ann_d *stmt_ann_t;
515 typedef struct tree_ann_common_d *tree_ann_common_t;
516
517 static inline tree_ann_common_t tree_common_ann (const_tree);
518 static inline tree_ann_common_t get_tree_common_ann (tree);
519 static inline var_ann_t var_ann (const_tree);
520 static inline var_ann_t get_var_ann (tree);
521 static inline function_ann_t function_ann (const_tree);
522 static inline function_ann_t get_function_ann (tree);
523 static inline stmt_ann_t stmt_ann (tree);
524 static inline bool has_stmt_ann (tree);
525 static inline stmt_ann_t get_stmt_ann (tree);
526 static inline enum tree_ann_type ann_type (tree_ann_t);
527 static inline basic_block bb_for_stmt (tree);
528 extern void set_bb_for_stmt (tree, basic_block);
529 static inline bool noreturn_call_p (tree);
530 static inline void update_stmt (tree);
531 static inline bool stmt_modified_p (tree);
532 static inline bitmap may_aliases (const_tree);
533 static inline int get_lineno (const_tree);
534 static inline bitmap addresses_taken (tree);
535
536 /*---------------------------------------------------------------------------
537                   Structure representing predictions in tree level.
538 ---------------------------------------------------------------------------*/
539 struct edge_prediction GTY((chain_next ("%h.ep_next")))
540 {
541   struct edge_prediction *ep_next;
542   edge ep_edge;
543   enum br_predictor ep_predictor;
544   int ep_probability;
545 };
546
547 /* Accessors for basic block annotations.  */
548 static inline tree phi_nodes (const_basic_block);
549 static inline void set_phi_nodes (basic_block, tree);
550
551 /*---------------------------------------------------------------------------
552                               Global declarations
553 ---------------------------------------------------------------------------*/
554 struct int_tree_map GTY(())
555 {
556   
557   unsigned int uid;
558   tree to;
559 };
560
561 extern unsigned int int_tree_map_hash (const void *);
562 extern int int_tree_map_eq (const void *, const void *);
563
564 typedef struct 
565 {
566   htab_iterator hti;
567 } referenced_var_iterator;
568
569
570 /* This macro loops over all the referenced vars, one at a time, putting the
571    current var in VAR.  Note:  You are not allowed to add referenced variables
572    to the hashtable while using this macro.  Doing so may cause it to behave
573    erratically.  */
574
575 #define FOR_EACH_REFERENCED_VAR(VAR, ITER) \
576   for ((VAR) = first_referenced_var (&(ITER)); \
577        !end_referenced_vars_p (&(ITER)); \
578        (VAR) = next_referenced_var (&(ITER))) 
579
580
581 typedef struct
582 {
583   int i;
584 } safe_referenced_var_iterator;
585
586 /* This macro loops over all the referenced vars, one at a time, putting the
587    current var in VAR.  You are allowed to add referenced variables during the
588    execution of this macro, however, the macro will not iterate over them.  It
589    requires a temporary vector of trees, VEC, whose lifetime is controlled by
590    the caller.  The purpose of the vector is to temporarily store the
591    referenced_variables hashtable so that adding referenced variables does not
592    affect the hashtable.  */
593
594 #define FOR_EACH_REFERENCED_VAR_SAFE(VAR, VEC, ITER) \
595   for ((ITER).i = 0, fill_referenced_var_vec (&(VEC)); \
596        VEC_iterate (tree, (VEC), (ITER).i, (VAR)); \
597        (ITER).i++)
598
599 extern tree referenced_var_lookup (unsigned int);
600 extern bool referenced_var_check_and_insert (tree);
601 #define num_referenced_vars htab_elements (gimple_referenced_vars (cfun))
602 #define referenced_var(i) referenced_var_lookup (i)
603
604 #define num_ssa_names (VEC_length (tree, cfun->gimple_df->ssa_names))
605 #define ssa_name(i) (VEC_index (tree, cfun->gimple_df->ssa_names, (i)))
606
607 /* Macros for showing usage statistics.  */
608 #define SCALE(x) ((unsigned long) ((x) < 1024*10        \
609                   ? (x)                                 \
610                   : ((x) < 1024*1024*10                 \
611                      ? (x) / 1024                       \
612                      : (x) / (1024*1024))))
613
614 #define LABEL(x) ((x) < 1024*10 ? 'b' : ((x) < 1024*1024*10 ? 'k' : 'M'))
615
616 #define PERCENT(x,y) ((float)(x) * 100.0 / (float)(y))
617
618 /*---------------------------------------------------------------------------
619                               Block iterators
620 ---------------------------------------------------------------------------*/
621
622 typedef struct {
623   tree_stmt_iterator tsi;
624   basic_block bb;
625 } block_stmt_iterator;
626
627 static inline block_stmt_iterator bsi_start (basic_block);
628 static inline block_stmt_iterator bsi_last (basic_block);
629 static inline block_stmt_iterator bsi_after_labels (basic_block);
630 block_stmt_iterator bsi_for_stmt (tree);
631 static inline bool bsi_end_p (block_stmt_iterator);
632 static inline void bsi_next (block_stmt_iterator *);
633 static inline void bsi_prev (block_stmt_iterator *);
634 static inline tree bsi_stmt (block_stmt_iterator);
635 static inline tree * bsi_stmt_ptr (block_stmt_iterator);
636
637 extern void bsi_remove (block_stmt_iterator *, bool);
638 extern void bsi_move_before (block_stmt_iterator *, block_stmt_iterator *);
639 extern void bsi_move_after (block_stmt_iterator *, block_stmt_iterator *);
640 extern void bsi_move_to_bb_end (block_stmt_iterator *, basic_block);
641
642 enum bsi_iterator_update
643 {
644   /* Note that these are intentionally in the same order as TSI_FOO.  They
645      mean exactly the same as their TSI_* counterparts.  */
646   BSI_NEW_STMT,
647   BSI_SAME_STMT,
648   BSI_CHAIN_START,
649   BSI_CHAIN_END,
650   BSI_CONTINUE_LINKING
651 };
652
653 extern void bsi_insert_before (block_stmt_iterator *, tree,
654                                enum bsi_iterator_update);
655 extern void bsi_insert_after (block_stmt_iterator *, tree,
656                               enum bsi_iterator_update);
657
658 extern void bsi_replace (const block_stmt_iterator *, tree, bool);
659
660 /*---------------------------------------------------------------------------
661                               OpenMP Region Tree
662 ---------------------------------------------------------------------------*/
663
664 /* Parallel region information.  Every parallel and workshare
665    directive is enclosed between two markers, the OMP_* directive
666    and a corresponding OMP_RETURN statement.  */
667
668 struct omp_region
669 {
670   /* The enclosing region.  */
671   struct omp_region *outer;
672
673   /* First child region.  */
674   struct omp_region *inner;
675
676   /* Next peer region.  */
677   struct omp_region *next;
678
679   /* Block containing the omp directive as its last stmt.  */
680   basic_block entry;
681
682   /* Block containing the OMP_RETURN as its last stmt.  */
683   basic_block exit;
684
685   /* Block containing the OMP_CONTINUE as its last stmt.  */
686   basic_block cont;
687
688   /* If this is a combined parallel+workshare region, this is a list
689      of additional arguments needed by the combined parallel+workshare
690      library call.  */
691   tree ws_args;
692
693   /* The code for the omp directive of this region.  */
694   enum tree_code type;
695
696   /* Schedule kind, only used for OMP_FOR type regions.  */
697   enum omp_clause_schedule_kind sched_kind;
698
699   /* True if this is a combined parallel+workshare region.  */
700   bool is_combined_parallel;
701 };
702
703 extern struct omp_region *root_omp_region;
704 extern struct omp_region *new_omp_region (basic_block, enum tree_code,
705                                           struct omp_region *);
706 extern void free_omp_regions (void);
707 extern tree find_omp_clause (tree, enum tree_code);
708 tree copy_var_decl (tree, tree, tree);
709
710 /*---------------------------------------------------------------------------
711                               Function prototypes
712 ---------------------------------------------------------------------------*/
713 /* In tree-cfg.c  */
714
715 /* Location to track pending stmt for edge insertion.  */
716 #define PENDING_STMT(e) ((e)->insns.t)
717
718 extern void delete_tree_cfg_annotations (void);
719 extern bool stmt_ends_bb_p (const_tree);
720 extern bool is_ctrl_stmt (const_tree);
721 extern bool is_ctrl_altering_stmt (const_tree);
722 extern bool computed_goto_p (const_tree);
723 extern bool simple_goto_p (const_tree);
724 extern bool tree_can_make_abnormal_goto (const_tree);
725 extern basic_block single_noncomplex_succ (basic_block bb);
726 extern void tree_dump_bb (basic_block, FILE *, int);
727 extern void debug_tree_bb (basic_block);
728 extern basic_block debug_tree_bb_n (int);
729 extern void dump_tree_cfg (FILE *, int);
730 extern void debug_tree_cfg (int);
731 extern void dump_cfg_stats (FILE *);
732 extern void debug_cfg_stats (void);
733 extern void debug_loop_ir (void);
734 extern void print_loop_ir (FILE *);
735 extern void cleanup_dead_labels (void);
736 extern void group_case_labels (void);
737 extern tree first_stmt (basic_block);
738 extern tree last_stmt (basic_block);
739 extern tree last_and_only_stmt (basic_block);
740 extern edge find_taken_edge (basic_block, tree);
741 extern basic_block label_to_block_fn (struct function *, tree);
742 #define label_to_block(t) (label_to_block_fn (cfun, t))
743 extern void bsi_insert_on_edge (edge, tree);
744 extern basic_block bsi_insert_on_edge_immediate (edge, tree);
745 extern void bsi_commit_one_edge_insert (edge, basic_block *);
746 extern void bsi_commit_edge_inserts (void);
747 extern void notice_special_calls (tree);
748 extern void clear_special_calls (void);
749 extern void verify_stmts (void);
750 extern void verify_gimple (void);
751 extern void verify_gimple_1 (tree);
752 extern tree tree_block_label (basic_block);
753 extern void extract_true_false_edges_from_block (basic_block, edge *, edge *);
754 extern bool tree_duplicate_sese_region (edge, edge, basic_block *, unsigned,
755                                         basic_block *);
756 extern void add_phi_args_after_copy_bb (basic_block);
757 extern void add_phi_args_after_copy (basic_block *, unsigned);
758 extern bool tree_purge_dead_abnormal_call_edges (basic_block);
759 extern bool tree_purge_dead_eh_edges (basic_block);
760 extern bool tree_purge_all_dead_eh_edges (const_bitmap);
761 extern tree gimplify_val (block_stmt_iterator *, tree, tree);
762 extern tree gimplify_build1 (block_stmt_iterator *, enum tree_code,
763                              tree, tree);
764 extern tree gimplify_build2 (block_stmt_iterator *, enum tree_code,
765                              tree, tree, tree);
766 extern tree gimplify_build3 (block_stmt_iterator *, enum tree_code,
767                              tree, tree, tree, tree);
768 extern void init_empty_tree_cfg (void);
769 extern void fold_cond_expr_cond (void);
770 extern void make_abnormal_goto_edges (basic_block, bool);
771 extern void replace_uses_by (tree, tree);
772 extern void start_recording_case_labels (void);
773 extern void end_recording_case_labels (void);
774 extern basic_block move_sese_region_to_fn (struct function *, basic_block,
775                                            basic_block);
776 void remove_edge_and_dominated_blocks (edge);
777
778 /* In tree-cfgcleanup.c  */
779 extern bitmap cfgcleanup_altered_bbs;
780 extern bool cleanup_tree_cfg (void);
781
782 /* In tree-pretty-print.c.  */
783 extern void dump_generic_bb (FILE *, basic_block, int, int);
784 extern const char *op_symbol_code (enum tree_code);
785
786 /* In tree-dfa.c  */
787 extern var_ann_t create_var_ann (tree);
788 extern function_ann_t create_function_ann (tree);
789 extern stmt_ann_t create_stmt_ann (tree);
790 extern tree_ann_common_t create_tree_common_ann (tree);
791 extern void dump_dfa_stats (FILE *);
792 extern void debug_dfa_stats (void);
793 extern void debug_referenced_vars (void);
794 extern void dump_referenced_vars (FILE *);
795 extern void dump_variable (FILE *, tree);
796 extern void debug_variable (tree);
797 extern void dump_subvars_for (FILE *, tree);
798 extern void debug_subvars_for (tree);
799 extern tree get_virtual_var (tree);
800 extern void add_referenced_var (tree);
801 extern void remove_referenced_var (tree);
802 extern void mark_symbols_for_renaming (tree);
803 extern void find_new_referenced_vars (tree *);
804 extern tree make_rename_temp (tree, const char *);
805 extern void set_default_def (tree, tree);
806 extern tree gimple_default_def (struct function *, tree);
807 extern struct mem_sym_stats_d *mem_sym_stats (struct function *, tree);
808
809 /* In tree-phinodes.c  */
810 extern void reserve_phi_args_for_new_edge (basic_block);
811 extern tree create_phi_node (tree, basic_block);
812 extern void add_phi_arg (tree, tree, edge);
813 extern void remove_phi_args (edge);
814 extern void remove_phi_node (tree, tree, bool);
815 extern tree phi_reverse (tree);
816
817 /* In gimple-low.c  */
818 extern void record_vars_into (tree, tree);
819 extern void record_vars (tree);
820 extern bool block_may_fallthru (const_tree);
821
822 /* In tree-ssa-alias.c  */
823 extern unsigned int compute_may_aliases (void);
824 extern void dump_may_aliases_for (FILE *, tree);
825 extern void debug_may_aliases_for (tree);
826 extern void dump_alias_info (FILE *);
827 extern void debug_alias_info (void);
828 extern void dump_points_to_info (FILE *);
829 extern void debug_points_to_info (void);
830 extern void dump_points_to_info_for (FILE *, tree);
831 extern void debug_points_to_info_for (tree);
832 extern bool may_be_aliased (tree);
833 extern struct ptr_info_def *get_ptr_info (tree);
834 extern void new_type_alias (tree, tree, tree);
835 extern void count_uses_and_derefs (tree, tree, unsigned *, unsigned *,
836                                    unsigned *);
837 static inline subvar_t get_subvars_for_var (tree);
838 static inline tree get_subvar_at (tree, unsigned HOST_WIDE_INT);
839 static inline bool ref_contains_array_ref (const_tree);
840 static inline bool array_ref_contains_indirect_ref (const_tree);
841 extern tree get_ref_base_and_extent (tree, HOST_WIDE_INT *,
842                                      HOST_WIDE_INT *, HOST_WIDE_INT *);
843 static inline bool var_can_have_subvars (const_tree);
844 static inline bool overlap_subvar (unsigned HOST_WIDE_INT,
845                                    unsigned HOST_WIDE_INT,
846                                    const_tree, bool *);
847 extern tree create_tag_raw (enum tree_code, tree, const char *);
848 extern void delete_mem_ref_stats (struct function *);
849 extern void dump_mem_ref_stats (FILE *);
850 extern void debug_mem_ref_stats (void);
851 extern void debug_memory_partitions (void);
852 extern void debug_mem_sym_stats (tree var);
853 extern void debug_all_mem_sym_stats (void);
854
855 /* Call-back function for walk_use_def_chains().  At each reaching
856    definition, a function with this prototype is called.  */
857 typedef bool (*walk_use_def_chains_fn) (tree, tree, void *);
858
859 /* In tree-ssa-alias-warnings.c  */
860 extern void strict_aliasing_warning_backend (void);
861
862 /* In tree-ssa.c  */
863 extern void init_tree_ssa (void);
864 extern edge ssa_redirect_edge (edge, basic_block);
865 extern void flush_pending_stmts (edge);
866 extern bool tree_ssa_useless_type_conversion (tree);
867 extern bool useless_type_conversion_p (tree, tree);
868 extern bool types_compatible_p (tree, tree);
869 extern void verify_ssa (bool);
870 extern void delete_tree_ssa (void);
871 extern void walk_use_def_chains (tree, walk_use_def_chains_fn, void *, bool);
872 extern bool stmt_references_memory_p (tree);
873
874 /* In tree-into-ssa.c  */
875 void update_ssa (unsigned);
876 void delete_update_ssa (void);
877 void register_new_name_mapping (tree, tree);
878 tree create_new_def_for (tree, tree, def_operand_p);
879 bool need_ssa_update_p (void);
880 bool name_mappings_registered_p (void);
881 bool name_registered_for_update_p (tree);
882 bitmap ssa_names_to_replace (void);
883 void release_ssa_name_after_update_ssa (tree);
884 void compute_global_livein (bitmap, bitmap);
885 tree duplicate_ssa_name (tree, tree);
886 void mark_sym_for_renaming (tree);
887 void mark_set_for_renaming (bitmap);
888 tree get_current_def (tree);
889 void set_current_def (tree, tree);
890
891 /* In tree-ssa-ccp.c  */
892 bool fold_stmt (tree *);
893 bool fold_stmt_inplace (tree);
894 tree widen_bitfield (tree, tree, tree);
895
896 /* In tree-vrp.c  */
897 tree vrp_evaluate_conditional (tree, tree);
898 void simplify_stmt_using_ranges (tree);
899
900 /* In tree-ssa-dom.c  */
901 extern void dump_dominator_optimization_stats (FILE *);
902 extern void debug_dominator_optimization_stats (void);
903 int loop_depth_of_name (tree);
904
905 /* In tree-ssa-copy.c  */
906 extern void merge_alias_info (tree, tree);
907 extern void propagate_value (use_operand_p, tree);
908 extern void propagate_tree_value (tree *, tree);
909 extern void replace_exp (use_operand_p, tree);
910 extern bool may_propagate_copy (tree, tree);
911 extern bool may_propagate_copy_into_asm (tree);
912
913 /* Affine iv.  */
914
915 typedef struct
916 {
917   /* Iv = BASE + STEP * i.  */
918   tree base, step;
919
920   /* True if this iv does not overflow.  */
921   bool no_overflow;
922 } affine_iv;
923
924 /* Description of number of iterations of a loop.  All the expressions inside
925    the structure can be evaluated at the end of the loop's preheader
926    (and due to ssa form, also anywhere inside the body of the loop).  */
927
928 struct tree_niter_desc
929 {
930   tree assumptions;     /* The boolean expression.  If this expression evaluates
931                            to false, then the other fields in this structure
932                            should not be used; there is no guarantee that they
933                            will be correct.  */
934   tree may_be_zero;     /* The boolean expression.  If it evaluates to true,
935                            the loop will exit in the first iteration (i.e.
936                            its latch will not be executed), even if the niter
937                            field says otherwise.  */
938   tree niter;           /* The expression giving the number of iterations of
939                            a loop (provided that assumptions == true and
940                            may_be_zero == false), more precisely the number
941                            of executions of the latch of the loop.  */
942   double_int max;       /* The upper bound on the number of iterations of
943                            the loop.  */
944
945   /* The simplified shape of the exit condition.  The loop exits if
946      CONTROL CMP BOUND is false, where CMP is one of NE_EXPR,
947      LT_EXPR, or GT_EXPR, and step of CONTROL is positive if CMP is
948      LE_EXPR and negative if CMP is GE_EXPR.  This information is used
949      by loop unrolling.  */
950   affine_iv control;
951   tree bound;
952   enum tree_code cmp;
953 };
954
955 /* In tree-vectorizer.c */
956 unsigned vectorize_loops (void);
957 extern bool vect_can_force_dr_alignment_p (const_tree, unsigned int);
958 extern tree get_vectype_for_scalar_type (tree);
959
960 /* In tree-ssa-phiopt.c */
961 bool empty_block_p (basic_block);
962 basic_block *blocks_in_phiopt_order (void);
963
964 /* In tree-ssa-loop*.c  */
965
966 void tree_ssa_lim (void);
967 unsigned int tree_ssa_unswitch_loops (void);
968 unsigned int canonicalize_induction_variables (void);
969 unsigned int tree_unroll_loops_completely (bool);
970 unsigned int tree_ssa_prefetch_arrays (void);
971 unsigned int remove_empty_loops (void);
972 void tree_ssa_iv_optimize (void);
973 unsigned tree_predictive_commoning (void);
974
975 bool number_of_iterations_exit (struct loop *, edge,
976                                 struct tree_niter_desc *niter, bool);
977 tree find_loop_niter (struct loop *, edge *);
978 tree loop_niter_by_eval (struct loop *, edge);
979 tree find_loop_niter_by_eval (struct loop *, edge *);
980 void estimate_numbers_of_iterations (void);
981 bool scev_probably_wraps_p (tree, tree, tree, struct loop *, bool);
982 bool convert_affine_scev (struct loop *, tree, tree *, tree *, tree, bool);
983
984 bool nowrap_type_p (tree);
985 enum ev_direction {EV_DIR_GROWS, EV_DIR_DECREASES, EV_DIR_UNKNOWN};
986 enum ev_direction scev_direction (const_tree);
987
988 void free_numbers_of_iterations_estimates (void);
989 void free_numbers_of_iterations_estimates_loop (struct loop *);
990 void rewrite_into_loop_closed_ssa (bitmap, unsigned);
991 void verify_loop_closed_ssa (void);
992 bool for_each_index (tree *, bool (*) (tree, tree *, void *), void *);
993 void create_iv (tree, tree, tree, struct loop *, block_stmt_iterator *, bool,
994                 tree *, tree *);
995 void split_loop_exit_edge (edge);
996 unsigned force_expr_to_var_cost (tree);
997 void standard_iv_increment_position (struct loop *, block_stmt_iterator *,
998                                      bool *);
999 basic_block ip_end_pos (struct loop *);
1000 basic_block ip_normal_pos (struct loop *);
1001 bool tree_duplicate_loop_to_header_edge (struct loop *, edge,
1002                                          unsigned int, sbitmap,
1003                                          edge, VEC (edge, heap) **,
1004                                          int);
1005 struct loop *tree_ssa_loop_version (struct loop *, tree,
1006                                     basic_block *);
1007 tree expand_simple_operations (tree);
1008 void substitute_in_loop_info (struct loop *, tree, tree);
1009 edge single_dom_exit (struct loop *);
1010 bool can_unroll_loop_p (struct loop *loop, unsigned factor,
1011                         struct tree_niter_desc *niter);
1012 void tree_unroll_loop (struct loop *, unsigned,
1013                        edge, struct tree_niter_desc *);
1014 typedef void (*transform_callback)(struct loop *, void *);
1015 void tree_transform_and_unroll_loop (struct loop *, unsigned,
1016                                      edge, struct tree_niter_desc *,
1017                                      transform_callback, void *);
1018 bool contains_abnormal_ssa_name_p (tree);
1019 bool stmt_dominates_stmt_p (tree, tree);
1020 void mark_virtual_ops_for_renaming (tree);
1021
1022 /* In tree-ssa-threadedge.c */
1023 extern bool potentially_threadable_block (basic_block);
1024 extern void thread_across_edge (tree, edge, bool,
1025                                 VEC(tree, heap) **, tree (*) (tree, tree));
1026
1027 /* In tree-ssa-loop-im.c  */
1028 /* The possibilities of statement movement.  */
1029
1030 enum move_pos
1031   {
1032     MOVE_IMPOSSIBLE,            /* No movement -- side effect expression.  */
1033     MOVE_PRESERVE_EXECUTION,    /* Must not cause the non-executed statement
1034                                    become executed -- memory accesses, ... */
1035     MOVE_POSSIBLE               /* Unlimited movement.  */
1036   };
1037 extern enum move_pos movement_possibility (tree);
1038 char *get_lsm_tmp_name (tree, unsigned);
1039
1040 /* The reasons a variable may escape a function.  */
1041 enum escape_type 
1042 {
1043   NO_ESCAPE = 0,                        /* Doesn't escape.  */
1044   ESCAPE_STORED_IN_GLOBAL = 1 << 1,
1045   ESCAPE_TO_ASM = 1 << 2,               /* Passed by address to an assembly
1046                                            statement.  */
1047   ESCAPE_TO_CALL = 1 << 3,              /* Escapes to a function call.  */
1048   ESCAPE_BAD_CAST = 1 << 4,             /* Cast from pointer to integer */
1049   ESCAPE_TO_RETURN = 1 << 5,            /* Returned from function.  */
1050   ESCAPE_TO_PURE_CONST = 1 << 6,        /* Escapes to a pure or constant
1051                                            function call.  */
1052   ESCAPE_IS_GLOBAL = 1 << 7,            /* Is a global variable.  */
1053   ESCAPE_IS_PARM = 1 << 8,              /* Is an incoming function argument.  */
1054   ESCAPE_UNKNOWN = 1 << 9               /* We believe it escapes for
1055                                            some reason not enumerated
1056                                            above.  */
1057 };
1058
1059 /* In tree-flow-inline.h  */
1060 static inline bool is_call_clobbered (const_tree);
1061 static inline void mark_call_clobbered (tree, unsigned int);
1062 static inline void set_is_used (tree);
1063 static inline bool unmodifiable_var_p (const_tree);
1064
1065 /* In tree-eh.c  */
1066 extern void make_eh_edges (tree);
1067 extern bool tree_could_trap_p (tree);
1068 extern bool tree_could_throw_p (tree);
1069 extern bool tree_can_throw_internal (const_tree);
1070 extern bool tree_can_throw_external (tree);
1071 extern int lookup_stmt_eh_region (const_tree);
1072 extern void add_stmt_to_eh_region (tree, int);
1073 extern bool remove_stmt_from_eh_region (tree);
1074 extern bool maybe_clean_or_replace_eh_stmt (tree, tree);
1075
1076 /* In tree-ssa-pre.c  */
1077 void add_to_value (tree, tree);
1078 void debug_value_expressions (tree);
1079 void print_value_expressions (FILE *, tree);
1080
1081
1082 /* In tree-vn.c  */
1083 tree make_value_handle (tree);
1084 void set_value_handle (tree, tree);
1085 bool expressions_equal_p (tree, tree);
1086 static inline tree get_value_handle (tree);
1087 void sort_vuses (VEC (tree, gc) *);
1088 void sort_vuses_heap (VEC (tree, heap) *);
1089 tree vn_lookup_or_add (tree);
1090 tree vn_lookup_or_add_with_stmt (tree, tree);
1091 tree vn_lookup_or_add_with_vuses (tree, VEC (tree, gc) *);
1092 void vn_add (tree, tree);
1093 void vn_add_with_vuses (tree, tree, VEC (tree, gc) *);
1094 tree vn_lookup_with_stmt (tree, tree);
1095 tree vn_lookup (tree);
1096 tree vn_lookup_with_vuses (tree, VEC (tree, gc) *);
1097
1098 /* In tree-ssa-sink.c  */
1099 bool is_hidden_global_store (tree);
1100
1101 /* In tree-sra.c  */
1102 void insert_edge_copies (tree, basic_block);
1103 void sra_insert_before (block_stmt_iterator *, tree);
1104 void sra_insert_after (block_stmt_iterator *, tree);
1105 void sra_init_cache (void);
1106 bool sra_type_can_be_decomposed_p (tree);
1107
1108 /* In tree-loop-linear.c  */
1109 extern void linear_transform_loops (void);
1110
1111 /* In tree-data-ref.c  */
1112 extern void tree_check_data_deps (void);
1113
1114 /* In tree-ssa-loop-ivopts.c  */
1115 bool expr_invariant_in_loop_p (struct loop *, tree);
1116 bool multiplier_allowed_in_address_p (HOST_WIDE_INT, enum machine_mode);
1117 unsigned multiply_by_cost (HOST_WIDE_INT, enum machine_mode);
1118
1119 /* In tree-ssa-threadupdate.c.  */
1120 extern bool thread_through_all_blocks (bool);
1121 extern void register_jump_thread (edge, edge);
1122
1123 /* In gimplify.c  */
1124 tree force_gimple_operand (tree, tree *, bool, tree);
1125 tree force_gimple_operand_bsi (block_stmt_iterator *, tree, bool, tree,
1126                                bool, enum bsi_iterator_update);
1127
1128 /* In tree-ssa-structalias.c */
1129 bool find_what_p_points_to (tree);
1130
1131 /* In tree-ssa-live.c */
1132 extern void remove_unused_locals (void);
1133
1134 /* In tree-ssa-address.c  */
1135
1136 /* Description of a memory address.  */
1137
1138 struct mem_address
1139 {
1140   tree symbol, base, index, step, offset;
1141 };
1142
1143 struct affine_tree_combination;
1144 tree create_mem_ref (block_stmt_iterator *, tree, 
1145                      struct affine_tree_combination *);
1146 rtx addr_for_mem_ref (struct mem_address *, bool);
1147 void get_address_description (tree, struct mem_address *);
1148 tree maybe_fold_tmr (tree);
1149
1150 /* This structure is simply used during pushing fields onto the fieldstack
1151    to track the offset of the field, since bitpos_of_field gives it relative
1152    to its immediate containing type, and we want it relative to the ultimate
1153    containing object.  */
1154
1155 struct fieldoff
1156 {
1157   tree type;
1158   tree size;
1159   tree decl;
1160   HOST_WIDE_INT offset;  
1161   alias_set_type alias_set;
1162 };
1163 typedef struct fieldoff fieldoff_s;
1164
1165 DEF_VEC_O(fieldoff_s);
1166 DEF_VEC_ALLOC_O(fieldoff_s,heap);
1167 int push_fields_onto_fieldstack (tree, VEC(fieldoff_s,heap) **,
1168                                  HOST_WIDE_INT, bool *, tree);
1169 void sort_fieldstack (VEC(fieldoff_s,heap) *);
1170
1171 void init_alias_heapvars (void);
1172 void delete_alias_heapvars (void);
1173 unsigned int execute_fixup_cfg (void);
1174
1175 #include "tree-flow-inline.h"
1176
1177 void swap_tree_operands (tree, tree *, tree *);
1178
1179 int least_common_multiple (int, int);
1180
1181 #endif /* _TREE_FLOW_H  */