2 * Copyright (C) 1995-2009 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
6 * This file may be distributed and/or modified under the terms of the
7 * GNU General Public License version 2 as published by the Free Software
8 * Foundation and appearing in the file LICENSE.GPL included in the
9 * packaging of this file.
11 * Licensees holding valid libFirm Professional Edition licenses may use
12 * this file in accordance with the libFirm Commercial License.
13 * Agreement provided with the Software.
15 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * @brief Manager for transformation passes.
23 * @author Michael Beck
26 #ifndef FIRM_IR_PASS_H
27 #define FIRM_IR_PASS_H
29 #include "firm_types.h"
33 * Creates a new ir_graph pass manager.
35 * @param name the name of the manager
36 * @param verify_all if non-zero, all passes of this manager will be verified
37 * @param dump_all if non-zero, all passes results will be dumped
39 * @return the newly created manager
41 FIRM_API ir_graph_pass_manager_t *new_graph_pass_mgr(const char *name,
46 * Add an ir_graph pass to a graph pass manager.
48 * @param mgr the ir_graph pass manager
49 * @param pass the pass to add
51 FIRM_API void ir_graph_pass_mgr_add(ir_graph_pass_manager_t *mgr,
52 ir_graph_pass_t *pass);
55 * Run all passes of an ir_graph pass manager.
57 * @param mgr the manager
59 * @return 0 if all passes return 0, else 1
61 FIRM_API int ir_graph_pass_mgr_run(ir_graph_pass_manager_t *mgr);
64 * Terminate an ir_graph pass manager and all owned passes.
66 * @param mgr the manager
68 FIRM_API void term_graph_pass_mgr(ir_graph_pass_manager_t *mgr);
71 * Creates a new ir_prog pass manager.
73 * @param name the name of the manager
74 * @param verify_all if non-zero, all passes of this manager will be verified
75 * @param dump_all if non-zero, all passes results will be dumped
77 * @return the newly created manager
79 FIRM_API ir_prog_pass_manager_t *new_prog_pass_mgr(const char *name,
84 * Add an ir_prog pass to an ir_prog pass manager.
86 * @param mgr the ir_prog pass manager
87 * @param pass the pass to add
89 FIRM_API void ir_prog_pass_mgr_add(ir_prog_pass_manager_t *mgr,
90 ir_prog_pass_t *pass);
93 * Add an ir_graph_pass_manager as a pass to an ir_prog pass manager.
95 * @param mgr the ir_prog pass manager
96 * @param graph_mgr the ir_graph pass manager to be added
98 FIRM_API void ir_prog_pass_mgr_add_graph_mgr(ir_prog_pass_manager_t *mgr,
99 ir_graph_pass_manager_t *graph_mgr);
102 * Add an ir_graph_pass as a pass to an ir_prog pass manager.
104 * @param mgr the ir_prog pass manager
105 * @param pass the ir_graph pass to be added
107 FIRM_API void ir_prog_pass_mgr_add_graph_pass(ir_prog_pass_manager_t *mgr,
108 ir_graph_pass_t *pass);
111 * Run all passes of an ir_prog pass manager.
113 * @param mgr the manager
115 * @return 0 if all passes return 0, else 1
117 FIRM_API int ir_prog_pass_mgr_run(ir_prog_pass_manager_t *mgr);
120 * Terminate an ir_prog pass manager and all owned passes.
122 * @param mgr the manager
124 FIRM_API void term_prog_pass_mgr(ir_prog_pass_manager_t *mgr);
127 * Set the run index for an irgraph pass manager.
129 * @param mgr the manager
130 * @param run_idx the index for the first pass of this manager
132 FIRM_API void ir_graph_pass_mgr_set_run_idx(
133 ir_graph_pass_manager_t *mgr, unsigned run_idx);
136 * Creates an ir_graph pass for running void function(ir_graph *irg).
137 * Uses the default verifier and dumper.
138 * The pass returns always 0.
140 * @param name the name of this pass
141 * @param function the function to run
143 * @return the newly created ir_graph pass
145 FIRM_API ir_graph_pass_t *def_graph_pass(
146 const char *name, void (*function)(ir_graph *irg));
149 * Creates an ir_graph pass for running int function(ir_graph *irg).
150 * Uses the default verifier and dumper.
151 * The pass returns the return value of function.
153 * @param name the name of this pass
154 * @param function the function to run
156 * @return the newly created ir_graph pass
158 FIRM_API ir_graph_pass_t *def_graph_pass_ret(
159 const char *name, int (*function)(ir_graph *irg));
162 * Creates an ir_graph pass for running int function(ir_graph *irg).
163 * Uses the default verifier and dumper.
164 * The pass returns the return value of function.
166 * @param memory if non-NULL, an already allocated ir_graph_pass_t
167 * @param name the name of this pass
168 * @param function the function to run
170 * @return the newly created ir_graph pass
172 FIRM_API ir_graph_pass_t *def_graph_pass_constructor(
173 ir_graph_pass_t *memory,
174 const char *name, int (*function)(ir_graph *irg, void *context));
177 * Set the run_parallel property of a graph pass.
178 * If the flag is set to non-zero, the pass can be executed
179 * parallel on all graphs of a ir_prog.
181 * @param pass the pass
182 * @param flag new flag setting
184 FIRM_API void ir_graph_pass_set_parallel(ir_graph_pass_t *pass, int flag);
187 * Creates an ir_prog pass for running void function().
188 * Uses the default verifier and dumper.
189 * The pass returns always 0.
191 * @param name the name of this pass
192 * @param function the function to run
194 * @return the newly created ir_graph pass
196 FIRM_API ir_prog_pass_t *def_prog_pass(
197 const char *name, void (*function)(void));
200 * Creates an ir_prog pass for running void function().
201 * Uses the default verifier and dumper.
202 * The pass returns always 0.
204 * @param memory if non-NULL, an already allocated ir_prog_pass_t
205 * @param name the name of this pass
206 * @param function the function to run
208 * @return the newly created ir_prog pass
210 FIRM_API ir_prog_pass_t *def_prog_pass_constructor(
211 ir_prog_pass_t *memory,
212 const char *name, int (*function)(ir_prog *irp, void *context));
215 * Create a pass that calls some function.
216 * This pass calls the given function, but has no dump nor verify.
218 * @param name the name of this pass
219 * @param function the function to run
220 * @param context context parameter
222 * @return the newly created ir_prog pass
224 FIRM_API ir_prog_pass_t *call_function_pass(
225 const char *name, void (*function)(void *context), void *context);
228 * Set the run index for an irprog pass manager.
230 * @param mgr the manager
231 * @param run_idx the index for the first pass of this manager
233 FIRM_API void ir_prog_pass_mgr_set_run_idx(
234 ir_prog_pass_manager_t *mgr, unsigned run_idx);