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
25 #ifndef FIRM_IR_PASS_H
26 #define FIRM_IR_PASS_H
28 #include "firm_types.h"
32 * Creates a new ir_graph pass manager.
34 * @param name the name of the manager
35 * @param verify_all if non-zero, all passes of this manager will be verified
36 * @param dump_all if non-zero, all passes results will be dumped
38 * @return the newly created manager
40 FIRM_API ir_graph_pass_manager_t *new_graph_pass_mgr(const char *name,
45 * Add an ir_graph pass to a graph pass manager.
47 * @param mgr the ir_graph pass manager
48 * @param pass the pass to add
50 FIRM_API void ir_graph_pass_mgr_add(ir_graph_pass_manager_t *mgr,
51 ir_graph_pass_t *pass);
54 * Run all passes of an ir_graph pass manager.
56 * @param mgr the manager
58 * @return 0 if all passes return 0, else 1
60 FIRM_API int ir_graph_pass_mgr_run(ir_graph_pass_manager_t *mgr);
63 * Terminate an ir_graph pass manager and all owned passes.
65 * @param mgr the manager
67 FIRM_API void term_graph_pass_mgr(ir_graph_pass_manager_t *mgr);
70 * Creates a new ir_prog pass manager.
72 * @param name the name of the manager
73 * @param verify_all if non-zero, all passes of this manager will be verified
74 * @param dump_all if non-zero, all passes results will be dumped
76 * @return the newly created manager
78 FIRM_API ir_prog_pass_manager_t *new_prog_pass_mgr(const char *name,
83 * Add an ir_prog pass to an ir_prog pass manager.
85 * @param mgr the ir_prog pass manager
86 * @param pass the pass to add
88 FIRM_API void ir_prog_pass_mgr_add(ir_prog_pass_manager_t *mgr,
89 ir_prog_pass_t *pass);
92 * Add an ir_graph_pass_manager as a pass to an ir_prog pass manager.
94 * @param mgr the ir_prog pass manager
95 * @param graph_mgr the ir_graph pass manager to be added
97 FIRM_API void ir_prog_pass_mgr_add_graph_mgr(ir_prog_pass_manager_t *mgr,
98 ir_graph_pass_manager_t *graph_mgr);
101 * Add an ir_graph_pass as a pass to an ir_prog pass manager.
103 * @param mgr the ir_prog pass manager
104 * @param pass the ir_graph pass to be added
106 FIRM_API void ir_prog_pass_mgr_add_graph_pass(ir_prog_pass_manager_t *mgr,
107 ir_graph_pass_t *pass);
110 * Run all passes of an ir_prog pass manager.
112 * @param mgr the manager
114 * @return 0 if all passes return 0, else 1
116 FIRM_API int ir_prog_pass_mgr_run(ir_prog_pass_manager_t *mgr);
119 * Terminate an ir_prog pass manager and all owned passes.
121 * @param mgr the manager
123 FIRM_API void term_prog_pass_mgr(ir_prog_pass_manager_t *mgr);
126 * Set the run index for an irgraph pass manager.
128 * @param mgr the manager
129 * @param run_idx the index for the first pass of this manager
131 FIRM_API void ir_graph_pass_mgr_set_run_idx(
132 ir_graph_pass_manager_t *mgr, unsigned run_idx);
135 * Creates an ir_graph pass for running void function(ir_graph *irg).
136 * Uses the default verifier and dumper.
137 * The pass returns always 0.
139 * @param name the name of this pass
140 * @param function the function to run
142 * @return the newly created ir_graph pass
144 FIRM_API ir_graph_pass_t *def_graph_pass(
145 const char *name, void (*function)(ir_graph *irg));
148 * Creates an ir_graph pass for running int function(ir_graph *irg).
149 * Uses the default verifier and dumper.
150 * The pass returns the return value of function.
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_ret(
158 const char *name, int (*function)(ir_graph *irg));
161 * Creates an ir_graph pass for running int function(ir_graph *irg).
162 * Uses the default verifier and dumper.
163 * The pass returns the return value of function.
165 * @param memory if non-NULL, an already allocated ir_graph_pass_t
166 * @param name the name of this pass
167 * @param function the function to run
169 * @return the newly created ir_graph pass
171 FIRM_API ir_graph_pass_t *def_graph_pass_constructor(
172 ir_graph_pass_t *memory,
173 const char *name, int (*function)(ir_graph *irg, void *context));
176 * Set the run_parallel property of a graph pass.
177 * If the flag is set to non-zero, the pass can be executed
178 * parallel on all graphs of a ir_prog.
180 * @param pass the pass
181 * @param flag new flag setting
183 FIRM_API void ir_graph_pass_set_parallel(ir_graph_pass_t *pass, int flag);
186 * Creates an ir_prog pass for running void function().
187 * Uses the default verifier and dumper.
188 * The pass returns always 0.
190 * @param name the name of this pass
191 * @param function the function to run
193 * @return the newly created ir_graph pass
195 FIRM_API ir_prog_pass_t *def_prog_pass(
196 const char *name, void (*function)(void));
199 * Creates an ir_prog pass for running void function().
200 * Uses the default verifier and dumper.
201 * The pass returns always 0.
203 * @param memory if non-NULL, an already allocated ir_prog_pass_t
204 * @param name the name of this pass
205 * @param function the function to run
207 * @return the newly created ir_prog pass
209 FIRM_API ir_prog_pass_t *def_prog_pass_constructor(
210 ir_prog_pass_t *memory,
211 const char *name, int (*function)(ir_prog *irp, void *context));
214 * Create a pass that calls some function.
215 * This pass calls the given function, but has no dump nor verify.
217 * @param name the name of this pass
218 * @param function the function to run
219 * @param context context parameter
221 * @return the newly created ir_prog pass
223 FIRM_API ir_prog_pass_t *call_function_pass(
224 const char *name, void (*function)(void *context), void *context);
227 * Set the run index for an irprog pass manager.
229 * @param mgr the manager
230 * @param run_idx the index for the first pass of this manager
232 FIRM_API void ir_prog_pass_mgr_set_run_idx(
233 ir_prog_pass_manager_t *mgr, unsigned run_idx);