2 * Copyright (C) 1995-2008 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 code selection (transform FIRM into TEMPLATE FIRM)
28 #include "irgraph_t.h"
37 #include "../benode.h"
38 #include "bearch_TEMPLATE_t.h"
40 #include "TEMPLATE_nodes_attr.h"
41 #include "TEMPLATE_transform.h"
42 #include "TEMPLATE_new_nodes.h"
44 #include "gen_TEMPLATE_regalloc_if.h"
46 DEBUG_ONLY(static firm_dbg_module_t *dbg = NULL;)
49 * Creates an TEMPLATE Add.
51 * @param env The transformation environment
52 * @param op1 first operator
53 * @param op2 second operator
54 * @return the created TEMPLATE Add node
56 static ir_node *gen_Add(TEMPLATE_transform_env_t *env, ir_node *op1, ir_node *op2)
58 return new_bd_TEMPLATE_Add(env->dbg, env->block, op1, op2, env->mode);
64 * Creates an TEMPLATE Mul.
66 * @param dbg firm node dbg
67 * @param block the block the new node should belong to
68 * @param op1 first operator
69 * @param op2 second operator
70 * @param mode node mode
71 * @return the created TEMPLATE Mul node
73 static ir_node *gen_Mul(TEMPLATE_transform_env_t *env, ir_node *op1, ir_node *op2)
75 if (mode_is_float(env->mode)) {
76 return new_bd_TEMPLATE_fMul(env->dbg, env->block, op1, op2, env->mode);
78 return new_bd_TEMPLATE_Mul(env->dbg, env->block, op1, op2, env->mode);
85 * Creates an TEMPLATE And.
87 * @param dbg firm node dbg
88 * @param block the block the new node should belong to
89 * @param op1 first operator
90 * @param op2 second operator
91 * @param mode node mode
92 * @return the created TEMPLATE And node
94 static ir_node *gen_And(TEMPLATE_transform_env_t *env, ir_node *op1, ir_node *op2)
96 return new_bd_TEMPLATE_And(env->dbg, env->block, op1, op2, env->mode);
102 * Creates an TEMPLATE Or.
104 * @param dbg firm node dbg
105 * @param block the block the new node should belong to
106 * @param op1 first operator
107 * @param op2 second operator
108 * @param mode node mode
109 * @return the created TEMPLATE Or node
111 static ir_node *gen_Or(TEMPLATE_transform_env_t *env, ir_node *op1, ir_node *op2)
113 return new_bd_TEMPLATE_Or(env->dbg, env->block, op1, op2, env->mode);
119 * Creates an TEMPLATE Eor.
121 * @param dbg firm node dbg
122 * @param block the block the new node should belong to
123 * @param op1 first operator
124 * @param op2 second operator
125 * @param mode node mode
126 * @return the created TEMPLATE Eor node
128 static ir_node *gen_Eor(TEMPLATE_transform_env_t *env, ir_node *op1, ir_node *op2)
130 return new_bd_TEMPLATE_Eor(env->dbg, env->block, op1, op2, env->mode);
136 * Creates an TEMPLATE Sub.
138 * @param dbg firm node dbg
139 * @param block the block the new node should belong to
140 * @param op1 first operator
141 * @param op2 second operator
142 * @param mode node mode
143 * @return the created TEMPLATE Sub node
145 static ir_node *gen_Sub(TEMPLATE_transform_env_t *env, ir_node *op1, ir_node *op2)
147 if (mode_is_float(env->mode)) {
148 return new_bd_TEMPLATE_fSub(env->dbg, env->block, op1, op2, env->mode);
150 return new_bd_TEMPLATE_Sub(env->dbg, env->block, op1, op2, env->mode);
157 * Creates an TEMPLATE floating Div.
159 * @param dbg firm node dbg
160 * @param block the block the new node should belong to
161 * @param op1 first operator
162 * @param op2 second operator
163 * @param mode node mode
164 * @return the created TEMPLATE fDiv node
166 static ir_node *gen_Quot(TEMPLATE_transform_env_t *env, ir_node *op1, ir_node *op2)
168 return new_bd_TEMPLATE_fDiv(env->dbg, env->block, op1, op2, env->mode);
174 * Creates an TEMPLATE Shl.
176 * @param dbg firm node dbg
177 * @param block the block the new node should belong to
178 * @param op1 first operator
179 * @param op2 second operator
180 * @param mode node mode
181 * @return the created TEMPLATE Shl node
183 static ir_node *gen_Shl(TEMPLATE_transform_env_t *env, ir_node *op1, ir_node *op2)
185 return new_bd_TEMPLATE_Shl(env->dbg, env->block, op1, op2, env->mode);
191 * Creates an TEMPLATE Shr.
193 * @param dbg firm node dbg
194 * @param block the block the new node should belong to
195 * @param op1 first operator
196 * @param op2 second operator
197 * @param mode node mode
198 * @return the created TEMPLATE Shr node
200 static ir_node *gen_Shr(TEMPLATE_transform_env_t *env, ir_node *op1, ir_node *op2)
202 return new_bd_TEMPLATE_Shr(env->dbg, env->block, op1, op2, env->mode);
208 * Transforms a Minus node.
210 * @param mod the debug module
211 * @param block the block the new node should belong to
212 * @param node the ir Minus node
214 * @param mode node mode
215 * @return the created TEMPLATE Minus node
217 static ir_node *gen_Minus(TEMPLATE_transform_env_t *env, ir_node *op)
219 if (mode_is_float(env->mode)) {
220 return new_bd_TEMPLATE_fMinus(env->dbg, env->block, op, env->mode);
222 return new_bd_TEMPLATE_Minus(env->dbg, env->block, op, env->mode);
228 * Transforms a Not node.
230 * @param mod the debug module
231 * @param block the block the new node should belong to
232 * @param node the ir Not node
234 * @param mode node mode
235 * @return the created TEMPLATE Not node
237 static ir_node *gen_Not(TEMPLATE_transform_env_t *env, ir_node *op)
239 return new_bd_TEMPLATE_Not(env->dbg, env->block, op, env->mode);
247 * @param mod the debug module
248 * @param block the block the new node should belong to
249 * @param node the ir Load node
250 * @param mode node mode
251 * @return the created TEMPLATE Load node
253 static ir_node *gen_Load(TEMPLATE_transform_env_t *env)
255 ir_node *node = env->irn;
257 if (mode_is_float(env->mode)) {
258 return new_bd_TEMPLATE_fLoad(env->dbg, env->block, get_Load_ptr(node), get_Load_mem(node), env->mode);
260 return new_bd_TEMPLATE_Load(env->dbg, env->block, get_Load_ptr(node), get_Load_mem(node), env->mode);
266 * Transforms a Store.
268 * @param mod the debug module
269 * @param block the block the new node should belong to
270 * @param node the ir Store node
271 * @param mode node mode
272 * @return the created TEMPLATE Store node
274 static ir_node *gen_Store(TEMPLATE_transform_env_t *env)
276 ir_node *node = env->irn;
278 if (mode_is_float(env->mode)) {
279 return new_bd_TEMPLATE_fStore(env->dbg, env->block, get_Store_ptr(node), get_Store_value(node), get_Store_mem(node), env->mode);
281 return new_bd_TEMPLATE_Store(env->dbg, env->block, get_Store_ptr(node), get_Store_value(node), get_Store_mem(node), env->mode);
284 static ir_node *gen_Jmp(TEMPLATE_transform_env_t *env)
286 return new_bd_TEMPLATE_Jmp(env->dbg, env->block);
293 * Transforms the given firm node (and maybe some other related nodes)
294 * into one or more assembler nodes.
296 * @param node the firm node
297 * @param env the debug module
299 void TEMPLATE_transform_node(ir_node *node, void *env)
301 ir_opcode code = get_irn_opcode(node);
302 ir_node *asm_node = NULL;
303 TEMPLATE_transform_env_t tenv;
309 tenv.block = get_nodes_block(node);
310 tenv.dbg = get_irn_dbg_info(node);
311 tenv.irg = current_ir_graph;
313 tenv.mode = get_irn_mode(node);
315 #define UNOP(a) case iro_##a: asm_node = gen_##a(&tenv, get_##a##_op(node)); break
316 #define BINOP(a) case iro_##a: asm_node = gen_##a(&tenv, get_##a##_left(node), get_##a##_right(node)); break
317 #define GEN(a) case iro_##a: asm_node = gen_##a(&tenv); break
318 #define IGN(a) case iro_##a: break
319 #define BAD(a) case iro_##a: goto bad
321 DBG((dbg, LEVEL_1, "check %+F ... ", node));
343 /* TODO: implement these nodes */
359 /* You probably don't need to handle the following nodes */
391 fprintf(stderr, "Not implemented: %s\n", get_irn_opname(node));
396 exchange(node, asm_node);
397 DB((dbg, LEVEL_1, "created node %+F[%p]\n", asm_node, asm_node));
399 DB((dbg, LEVEL_1, "ignored\n"));
403 void TEMPLATE_init_transform(void)
405 FIRM_DBG_REGISTER(dbg, "firm.be.TEMPLATE.transform");