2 * This file is part of libFirm.
3 * Copyright (C) 2012 University of Karlsruhe.
8 * @brief Manager for transformation passes.
11 #ifndef FIRM_IR_PASS_H
12 #define FIRM_IR_PASS_H
14 #include "firm_types.h"
18 * Creates a new ir_graph pass manager.
20 * @param name the name of the manager
21 * @param verify_all if non-zero, all passes of this manager will be verified
22 * @param dump_all if non-zero, all passes results will be dumped
24 * @return the newly created manager
26 FIRM_API ir_graph_pass_manager_t *new_graph_pass_mgr(const char *name,
31 * Adds an ir_graph pass to a graph pass manager.
33 * @param mgr the ir_graph pass manager
34 * @param pass the pass to add
36 FIRM_API void ir_graph_pass_mgr_add(ir_graph_pass_manager_t *mgr,
37 ir_graph_pass_t *pass);
40 * Runs all passes of an ir_graph pass manager.
42 * @param mgr the manager
44 * @return 0 if all passes return 0, else 1
46 FIRM_API int ir_graph_pass_mgr_run(ir_graph_pass_manager_t *mgr);
49 * Terminates an ir_graph pass manager and all owned passes.
51 * @param mgr the manager
53 FIRM_API void term_graph_pass_mgr(ir_graph_pass_manager_t *mgr);
56 * Creates a new ir_prog pass manager.
58 * @param name the name of the manager
59 * @param verify_all if non-zero, all passes of this manager will be verified
60 * @param dump_all if non-zero, all passes results will be dumped
62 * @return the newly created manager
64 FIRM_API ir_prog_pass_manager_t *new_prog_pass_mgr(const char *name,
69 * Adds an ir_prog pass to an ir_prog pass manager.
71 * @param mgr the ir_prog pass manager
72 * @param pass the pass to add
74 FIRM_API void ir_prog_pass_mgr_add(ir_prog_pass_manager_t *mgr,
75 ir_prog_pass_t *pass);
78 * Adds an ir_graph_pass_manager as a pass to an ir_prog pass manager.
80 * @param mgr the ir_prog pass manager
81 * @param graph_mgr the ir_graph pass manager to be added
83 FIRM_API void ir_prog_pass_mgr_add_graph_mgr(ir_prog_pass_manager_t *mgr,
84 ir_graph_pass_manager_t *graph_mgr);
87 * Adds an ir_graph_pass as a pass to an ir_prog pass manager.
89 * @param mgr the ir_prog pass manager
90 * @param pass the ir_graph pass to be added
92 FIRM_API void ir_prog_pass_mgr_add_graph_pass(ir_prog_pass_manager_t *mgr,
93 ir_graph_pass_t *pass);
96 * Runs all passes of an ir_prog pass manager.
98 * @param mgr the manager
100 * @return 0 if all passes return 0, else 1
102 FIRM_API int ir_prog_pass_mgr_run(ir_prog_pass_manager_t *mgr);
105 * Terminates an ir_prog pass manager and all owned passes.
107 * @param mgr the manager
109 FIRM_API void term_prog_pass_mgr(ir_prog_pass_manager_t *mgr);
112 * Sets the run index for an irgraph pass manager.
114 * @param mgr the manager
115 * @param run_idx the index for the first pass of this manager
117 FIRM_API void ir_graph_pass_mgr_set_run_idx(
118 ir_graph_pass_manager_t *mgr, unsigned run_idx);
121 * Creates an ir_graph pass for running void function(ir_graph *irg).
122 * Uses the default verifier and dumper.
123 * The pass returns always 0.
125 * @param name the name of this pass
126 * @param function the function to run
128 * @return the newly created ir_graph pass
130 FIRM_API ir_graph_pass_t *def_graph_pass(
131 const char *name, void (*function)(ir_graph *irg));
134 * Creates an ir_graph pass for running int function(ir_graph *irg).
135 * Uses the default verifier and dumper.
136 * The pass returns the return value of function.
138 * @param name the name of this pass
139 * @param function the function to run
141 * @return the newly created ir_graph pass
143 FIRM_API ir_graph_pass_t *def_graph_pass_ret(
144 const char *name, int (*function)(ir_graph *irg));
147 * Creates an ir_graph pass for running int function(ir_graph *irg).
148 * Uses the default verifier and dumper.
149 * The pass returns the return value of function.
151 * @param memory if non-NULL, an already allocated ir_graph_pass_t
152 * @param name the name of this pass
153 * @param function the function to run
155 * @return the newly created ir_graph pass
157 FIRM_API ir_graph_pass_t *def_graph_pass_constructor(
158 ir_graph_pass_t *memory,
159 const char *name, int (*function)(ir_graph *irg, void *context));
162 * Sets the run_parallel property of a graph pass.
163 * If the flag is set to non-zero, the pass can be executed
164 * parallel on all graphs of a ir_prog.
166 * @param pass the pass
167 * @param flag new flag setting
169 FIRM_API void ir_graph_pass_set_parallel(ir_graph_pass_t *pass, int flag);
172 * Creates an ir_prog pass for running void function().
173 * Uses the default verifier and dumper.
174 * The pass returns always 0.
176 * @param name the name of this pass
177 * @param function the function to run
179 * @return the newly created ir_graph pass
181 FIRM_API ir_prog_pass_t *def_prog_pass(
182 const char *name, void (*function)(void));
185 * Creates an ir_prog pass for running void function().
186 * Uses the default verifier and dumper.
187 * The pass returns always 0.
189 * @param memory if non-NULL, an already allocated ir_prog_pass_t
190 * @param name the name of this pass
191 * @param function the function to run
193 * @return the newly created ir_prog pass
195 FIRM_API ir_prog_pass_t *def_prog_pass_constructor(
196 ir_prog_pass_t *memory,
197 const char *name, int (*function)(ir_prog *irp, void *context));
200 * Creates a pass that calls some function.
201 * This pass calls the given function, but has no dump nor verify.
203 * @param name the name of this pass
204 * @param function the function to run
205 * @param context context parameter
207 * @return the newly created ir_prog pass
209 FIRM_API ir_prog_pass_t *call_function_pass(
210 const char *name, void (*function)(void *context), void *context);
213 * Sets the run index for an irprog pass manager.
215 * @param mgr the manager
216 * @param run_idx the index for the first pass of this manager
218 FIRM_API void ir_prog_pass_mgr_set_run_idx(
219 ir_prog_pass_manager_t *mgr, unsigned run_idx);