GCC Middle and Back End API Reference
tree-pass.h
Go to the documentation of this file.
1 /* Definitions for describing one tree-ssa optimization pass.
2  Copyright (C) 2004-2013 Free Software Foundation, Inc.
3  Contributed by Richard Henderson <rth@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 3, 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 COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
20 
21 
22 #ifndef GCC_TREE_PASS_H
23 #define GCC_TREE_PASS_H 1
24 
25 #include "timevar.h"
26 #include "dumpfile.h"
27 
28 /* Optimization pass type. */
29 enum opt_pass_type
30 {
32  RTL_PASS,
35 };
36 
37 /* Metadata for a pass, non-varying across all instances of a pass. */
38 struct pass_data
39 {
40  /* Optimization pass type. */
42 
43  /* Terse name of the pass used as a fragment of the dump file
44  name. If the name starts with a star, no dump happens. */
45  const char *name;
46 
47  /* The -fopt-info optimization group flags as defined in dumpfile.h. */
48  unsigned int optinfo_flags;
49 
50  /* If true, this pass has its own implementation of the opt_pass::gate
51  method. */
52  bool has_gate;
53 
54  /* If true, this pass has its own implementation of the opt_pass::execute
55  method. */
56  bool has_execute;
57 
58  /* The timevar id associated with this pass. */
59  /* ??? Ideally would be dynamically assigned. */
61 
62  /* Sets of properties input and output from this pass. */
63  unsigned int properties_required;
64  unsigned int properties_provided;
65  unsigned int properties_destroyed;
66 
67  /* Flags indicating common sets things to do before and after. */
68  unsigned int todo_flags_start;
69  unsigned int todo_flags_finish;
70 };
71 
72 namespace gcc
73 {
74  class context;
75 } // namespace gcc
76 
77 /* An instance of a pass. This is also "pass_data" to minimize the
78  changes in existing code. */
79 class opt_pass : public pass_data
80 {
81 public:
82  virtual ~opt_pass () { }
83 
84  /* Create a copy of this pass.
85 
86  Passes that can have multiple instances must provide their own
87  implementation of this, to ensure that any sharing of state between
88  this instance and the copy is "wired up" correctly.
89 
90  The default implementation prints an error message and aborts. */
91  virtual opt_pass *clone ();
92 
93  /* If has_gate is set, this pass and all sub-passes are executed only if
94  the function returns true.
95  The default implementation returns true. */
96  virtual bool gate ();
97 
98  /* This is the code to run. If has_execute is false, then there should
99  be sub-passes otherwise this pass does nothing.
100  The return value contains TODOs to execute in addition to those in
101  TODO_flags_finish. */
102  virtual unsigned int execute ();
103 
104 protected:
105  opt_pass (const pass_data&, gcc::context *);
106 
107 public:
108  /* A list of sub-passes to run, dependent on gate predicate. */
109  struct opt_pass *sub;
110 
111  /* Next in the list of passes to run, independent of gate predicate. */
112  struct opt_pass *next;
113 
114  /* Static pass number, used as a fragment of the dump file name. */
115  int static_pass_number;
116 
117 protected:
119 };
120 
121 /* Description of GIMPLE pass. */
122 class gimple_opt_pass : public opt_pass
123 {
124 protected:
126  : opt_pass (data, ctxt)
127  {
128  }
129 };
131 /* Description of RTL pass. */
132 class rtl_opt_pass : public opt_pass
133 {
134 protected:
135  rtl_opt_pass (const pass_data& data, gcc::context *ctxt)
136  : opt_pass (data, ctxt)
137  {
138  }
139 };
140 
141 struct varpool_node;
142 struct cgraph_node;
143 struct lto_symtab_encoder_d;
144 
145 /* Description of IPA pass with generate summary, write, execute, read and
146  transform stages. */
147 class ipa_opt_pass_d : public opt_pass
148 {
149 public:
150  /* IPA passes can analyze function body and variable initializers
151  using this hook and produce summary. */
152  void (*generate_summary) (void);
154  /* This hook is used to serialize IPA summaries on disk. */
155  void (*write_summary) (void);
157  /* This hook is used to deserialize IPA summaries from disk. */
158  void (*read_summary) (void);
159 
160  /* This hook is used to serialize IPA optimization summaries on disk. */
161  void (*write_optimization_summary) (void);
162 
163  /* This hook is used to deserialize IPA summaries from disk. */
164  void (*read_optimization_summary) (void);
165 
166  /* Hook to convert gimple stmt uids into true gimple statements. The second
167  parameter is an array of statements indexed by their uid. */
168  void (*stmt_fixup) (struct cgraph_node *, gimple *);
170  /* Results of interprocedural propagation of an IPA pass is applied to
171  function body via this hook. */
173  unsigned int (*function_transform) (struct cgraph_node *);
174  void (*variable_transform) (struct varpool_node *);
176 protected:
177  ipa_opt_pass_d (const pass_data& data, gcc::context *ctxt,
178  void (*generate_summary) (void),
179  void (*write_summary) (void),
180  void (*read_summary) (void),
181  void (*write_optimization_summary) (void),
182  void (*read_optimization_summary) (void),
183  void (*stmt_fixup) (struct cgraph_node *, gimple *),
185  unsigned int (*function_transform) (struct cgraph_node *),
186  void (*variable_transform) (struct varpool_node *))
187  : opt_pass (data, ctxt),
194  function_transform_todo_flags_start (function_transform_todo_flags_start),
197  {
198  }
199 };
200 
201 /* Description of simple IPA pass. Simple IPA passes have just one execute
202  hook. */
204 {
205 protected:
207  : opt_pass (data, ctxt)
208  {
209  }
210 };
211 
212 /* Pass properties. */
213 #define PROP_gimple_any (1 << 0) /* entire gimple grammar */
214 #define PROP_gimple_lcf (1 << 1) /* lowered control flow */
215 #define PROP_gimple_leh (1 << 2) /* lowered eh */
216 #define PROP_cfg (1 << 3)
217 #define PROP_ssa (1 << 5)
218 #define PROP_no_crit_edges (1 << 6)
219 #define PROP_rtl (1 << 7)
220 #define PROP_gimple_lomp (1 << 8) /* lowered OpenMP directives */
221 #define PROP_cfglayout (1 << 9) /* cfglayout mode on RTL */
222 #define PROP_gimple_lcx (1 << 10) /* lowered complex */
223 #define PROP_loops (1 << 11) /* preserve loop structures */
224 #define PROP_gimple_lvec (1 << 12) /* lowered vector */
225 
226 #define PROP_trees \
227  (PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh | PROP_gimple_lomp)
228 
229 /* To-do flags. */
230 #define TODO_do_not_ggc_collect (1 << 1)
231 #define TODO_verify_ssa (1 << 2)
232 #define TODO_verify_flow (1 << 3)
233 #define TODO_verify_stmts (1 << 4)
234 #define TODO_cleanup_cfg (1 << 5)
235 #define TODO_dump_symtab (1 << 7)
236 #define TODO_remove_functions (1 << 8)
237 #define TODO_rebuild_frequencies (1 << 9)
238 #define TODO_verify_rtl_sharing (1 << 10)
239 
240 /* To-do flags for calls to update_ssa. */
241 
242 /* Update the SSA form inserting PHI nodes for newly exposed symbols
243  and virtual names marked for updating. When updating real names,
244  only insert PHI nodes for a real name O_j in blocks reached by all
245  the new and old definitions for O_j. If the iterated dominance
246  frontier for O_j is not pruned, we may end up inserting PHI nodes
247  in blocks that have one or more edges with no incoming definition
248  for O_j. This would lead to uninitialized warnings for O_j's
249  symbol. */
250 #define TODO_update_ssa (1 << 11)
252 /* Update the SSA form without inserting any new PHI nodes at all.
253  This is used by passes that have either inserted all the PHI nodes
254  themselves or passes that need only to patch use-def and def-def
255  chains for virtuals (e.g., DCE). */
256 #define TODO_update_ssa_no_phi (1 << 12)
258 /* Insert PHI nodes everywhere they are needed. No pruning of the
259  IDF is done. This is used by passes that need the PHI nodes for
260  O_j even if it means that some arguments will come from the default
261  definition of O_j's symbol.
263  WARNING: If you need to use this flag, chances are that your pass
264  may be doing something wrong. Inserting PHI nodes for an old name
265  where not all edges carry a new replacement may lead to silent
266  codegen errors or spurious uninitialized warnings. */
267 #define TODO_update_ssa_full_phi (1 << 13)
269 /* Passes that update the SSA form on their own may want to delegate
270  the updating of virtual names to the generic updater. Since FUD
271  chains are easier to maintain, this simplifies the work they need
272  to do. NOTE: If this flag is used, any OLD->NEW mappings for real
273  names are explicitly destroyed and only the symbols marked for
274  renaming are processed. */
275 #define TODO_update_ssa_only_virtuals (1 << 14)
276 
277 /* Some passes leave unused local variables that can be removed from
278  cfun->local_decls. This reduces the size of dump files
279  and the memory footprint for VAR_DECLs. */
280 #define TODO_remove_unused_locals (1 << 15)
281 
282 /* Call df_finish at the end of the pass. This is done after all of
283  the dumpers have been allowed to run so that they have access to
284  the instance before it is destroyed. */
285 #define TODO_df_finish (1 << 17)
286 
287 /* Call df_verify at the end of the pass if checking is enabled. */
288 #define TODO_df_verify (1 << 18)
289 
290 /* Internally used for the first instance of a pass. */
291 #define TODO_mark_first_instance (1 << 19)
292 
293 /* Rebuild aliasing info. */
294 #define TODO_rebuild_alias (1 << 20)
295 
296 /* Rebuild the addressable-vars bitmap and do register promotion. */
297 #define TODO_update_address_taken (1 << 21)
298 
299 /* Rebuild the callgraph edges. */
300 #define TODO_rebuild_cgraph_edges (1 << 22)
301 
302 /* Internally used in execute_function_todo(). */
303 #define TODO_update_ssa_any \
304  (TODO_update_ssa \
305  | TODO_update_ssa_no_phi \
306  | TODO_update_ssa_full_phi \
307  | TODO_update_ssa_only_virtuals)
308 
309 #define TODO_verify_all \
310  (TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts)
311 
313 /* Register pass info. */
314 
316 {
317  PASS_POS_INSERT_AFTER, /* Insert after the reference pass. */
318  PASS_POS_INSERT_BEFORE, /* Insert before the reference pass. */
319  PASS_POS_REPLACE /* Replace the reference pass. */
320 };
321 
322 struct register_pass_info
323 {
324  struct opt_pass *pass; /* New pass to register. */
325  const char *reference_pass_name; /* Name of the reference pass for hooking
326  up the new pass. */
327  int ref_pass_instance_number; /* Insert the pass at the specified
328  instance number of the reference pass.
329  Do it for every instance if it is 0. */
330  enum pass_positioning_ops pos_op; /* how to insert the new pass. */
331 };
333 /* Registers a new pass. Either fill out the register_pass_info or specify
334  the individual parameters. The pass object is expected to have been
335  allocated using operator new and the pass manager takes the ownership of
336  the pass object. */
337 extern void register_pass (register_pass_info *);
338 extern void register_pass (opt_pass* pass, pass_positioning_ops pos,
339  const char* ref_pass_name, int ref_pass_inst_number);
393 extern unsigned int tail_merge_optimize (unsigned int);
434  *ctxt);
449 
450 /* IPA Passes */
452 extern simple_ipa_opt_pass
455 
457 
459  *ctxt);
462  *ctxt);
466  *ctxt);
476 
478  *ctxt);
481 
489 extern rtl_opt_pass *make_pass_cse (gcc::context *ctxt);
502 
505 
513 
514 extern rtl_opt_pass *make_pass_web (gcc::context *ctxt);
524 extern rtl_opt_pass *make_pass_ree (gcc::context *ctxt);
531 extern rtl_opt_pass *make_pass_sms (gcc::context *ctxt);
533 extern rtl_opt_pass *make_pass_ira (gcc::context *ctxt);
538  *ctxt);
543  *ctxt);
545  *ctxt);
553  *ctxt);
581 
582 /* Current optimization pass. */
583 extern struct opt_pass *current_pass;
584 
585 extern bool execute_one_pass (struct opt_pass *);
586 extern void execute_pass_list (struct opt_pass *);
587 extern void execute_ipa_pass_list (struct opt_pass *);
588 extern void execute_ipa_summary_passes (struct ipa_opt_pass_d *);
589 extern void execute_all_ipa_transforms (void);
590 extern void execute_all_ipa_stmt_fixups (struct cgraph_node *, gimple *);
591 extern bool pass_init_dump_file (struct opt_pass *);
592 extern void pass_fini_dump_file (struct opt_pass *);
593 
594 extern const char *get_current_pass_name (void);
595 extern void print_current_pass (FILE *);
596 extern void debug_pass (void);
597 extern void ipa_write_summaries (void);
599 extern void ipa_read_summaries (void);
600 extern void ipa_read_optimization_summaries (void);
601 extern void register_one_dump_file (struct opt_pass *);
602 extern bool function_called_by_processed_nodes_p (void);
603 
604 /* Set to true if the pass is called the first time during compilation of the
605  current function. Note that using this information in the optimization
606  passes is considered not to be clean, and it should be avoided if possible.
607  This flag is currently used to prevent loops from being peeled repeatedly
608  in jump threading; it will be removed once we preserve loop structures
609  throughout the compilation -- we will be able to mark the affected loops
610  directly in jump threading, and avoid peeling them next time. */
611 extern bool first_pass_instance;
612 
613 /* Declare for plugins. */
614 extern void do_per_function_toporder (void (*) (void *), void *);
615 
616 extern void disable_pass (const char *);
617 extern void enable_pass (const char *);
618 extern void dump_passes (void);
619 
620 #endif /* GCC_TREE_PASS_H */