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_t.h"
38 #include "bearch_TEMPLATE_t.h"
40 #include "TEMPLATE_nodes_attr.h"
42 #include "TEMPLATE_transform.h"
43 #include "TEMPLATE_new_nodes.h"
44 #include "TEMPLATE_map_regs.h"
46 #include "gen_TEMPLATE_regalloc_if.h"
48 extern ir_op *get_op_Mulh(void);
52 /****************************************************************************************************
54 * | | | | / _| | | (_)
55 * _ __ ___ __| | ___ | |_ _ __ __ _ _ __ ___| |_ ___ _ __ _ __ ___ __ _| |_ _ ___ _ __
56 * | '_ \ / _ \ / _` |/ _ \ | __| '__/ _` | '_ \/ __| _/ _ \| '__| '_ ` _ \ / _` | __| |/ _ \| '_ \
57 * | | | | (_) | (_| | __/ | |_| | | (_| | | | \__ \ || (_) | | | | | | | | (_| | |_| | (_) | | | |
58 * |_| |_|\___/ \__,_|\___| \__|_| \__,_|_| |_|___/_| \___/|_| |_| |_| |_|\__,_|\__|_|\___/|_| |_|
60 ****************************************************************************************************/
63 * Creates an TEMPLATE Add.
65 * @param env The transformation environment
66 * @param op1 first operator
67 * @param op2 second operator
68 * @return the created TEMPLATE Add node
70 static ir_node *gen_Add(TEMPLATE_transform_env_t *env, ir_node *op1, ir_node *op2) {
71 return new_bd_TEMPLATE_Add(env->dbg, env->block, op1, op2, env->mode);
77 * Creates an TEMPLATE Mul.
79 * @param dbg firm node dbg
80 * @param block the block the new node should belong to
81 * @param op1 first operator
82 * @param op2 second operator
83 * @param mode node mode
84 * @return the created TEMPLATE Mul node
86 static ir_node *gen_Mul(TEMPLATE_transform_env_t *env, ir_node *op1, ir_node *op2) {
87 if (mode_is_float(env->mode)) {
88 return new_bd_TEMPLATE_fMul(env->dbg, env->block, op1, op2, env->mode);
91 return new_bd_TEMPLATE_Mul(env->dbg, env->block, op1, op2, env->mode);
98 * Creates an TEMPLATE And.
100 * @param dbg firm node dbg
101 * @param block the block the new node should belong to
102 * @param op1 first operator
103 * @param op2 second operator
104 * @param mode node mode
105 * @return the created TEMPLATE And node
107 static ir_node *gen_And(TEMPLATE_transform_env_t *env, ir_node *op1, ir_node *op2) {
108 return new_bd_TEMPLATE_And(env->dbg, env->block, op1, op2, env->mode);
114 * Creates an TEMPLATE Or.
116 * @param dbg firm node dbg
117 * @param block the block the new node should belong to
118 * @param op1 first operator
119 * @param op2 second operator
120 * @param mode node mode
121 * @return the created TEMPLATE Or node
123 static ir_node *gen_Or(TEMPLATE_transform_env_t *env, ir_node *op1, ir_node *op2) {
124 return new_bd_TEMPLATE_Or(env->dbg, env->block, op1, op2, env->mode);
130 * Creates an TEMPLATE Eor.
132 * @param dbg firm node dbg
133 * @param block the block the new node should belong to
134 * @param op1 first operator
135 * @param op2 second operator
136 * @param mode node mode
137 * @return the created TEMPLATE Eor node
139 static ir_node *gen_Eor(TEMPLATE_transform_env_t *env, ir_node *op1, ir_node *op2) {
140 return new_bd_TEMPLATE_Eor(env->dbg, env->block, op1, op2, env->mode);
146 * Creates an TEMPLATE Sub.
148 * @param dbg firm node dbg
149 * @param block the block the new node should belong to
150 * @param op1 first operator
151 * @param op2 second operator
152 * @param mode node mode
153 * @return the created TEMPLATE Sub node
155 static ir_node *gen_Sub(TEMPLATE_transform_env_t *env, ir_node *op1, ir_node *op2) {
156 if (mode_is_float(env->mode)) {
157 return new_bd_TEMPLATE_fSub(env->dbg, env->block, op1, op2, env->mode);
160 return new_bd_TEMPLATE_Sub(env->dbg, env->block, op1, op2, env->mode);
167 * Creates an TEMPLATE floating Div.
169 * @param dbg firm node dbg
170 * @param block the block the new node should belong to
171 * @param op1 first operator
172 * @param op2 second operator
173 * @param mode node mode
174 * @return the created TEMPLATE fDiv node
176 static ir_node *gen_Quot(TEMPLATE_transform_env_t *env, ir_node *op1, ir_node *op2) {
177 return new_bd_TEMPLATE_fDiv(env->dbg, env->block, op1, op2, env->mode);
183 * Creates an TEMPLATE Shl.
185 * @param dbg firm node dbg
186 * @param block the block the new node should belong to
187 * @param op1 first operator
188 * @param op2 second operator
189 * @param mode node mode
190 * @return the created TEMPLATE Shl node
192 static ir_node *gen_Shl(TEMPLATE_transform_env_t *env, ir_node *op1, ir_node *op2) {
193 return new_bd_TEMPLATE_Shl(env->dbg, env->block, op1, op2, env->mode);
199 * Creates an TEMPLATE Shr.
201 * @param dbg firm node dbg
202 * @param block the block the new node should belong to
203 * @param op1 first operator
204 * @param op2 second operator
205 * @param mode node mode
206 * @return the created TEMPLATE Shr node
208 static ir_node *gen_Shr(TEMPLATE_transform_env_t *env, ir_node *op1, ir_node *op2) {
209 return new_bd_TEMPLATE_Shr(env->dbg, env->block, op1, op2, env->mode);
215 * Transforms a Minus node.
217 * @param mod the debug module
218 * @param block the block the new node should belong to
219 * @param node the ir Minus node
221 * @param mode node mode
222 * @return the created TEMPLATE Minus node
224 static ir_node *gen_Minus(TEMPLATE_transform_env_t *env, ir_node *op) {
225 if (mode_is_float(env->mode)) {
226 return new_bd_TEMPLATE_fMinus(env->dbg, env->block, op, env->mode);
228 return new_bd_TEMPLATE_Minus(env->dbg, env->block, op, env->mode);
234 * Transforms a Not node.
236 * @param mod the debug module
237 * @param block the block the new node should belong to
238 * @param node the ir Not node
240 * @param mode node mode
241 * @return the created TEMPLATE Not node
243 static ir_node *gen_Not(TEMPLATE_transform_env_t *env, ir_node *op) {
244 return new_bd_TEMPLATE_Not(env->dbg, env->block, op, env->mode);
252 * @param mod the debug module
253 * @param block the block the new node should belong to
254 * @param node the ir Load node
255 * @param mode node mode
256 * @return the created TEMPLATE Load node
258 static ir_node *gen_Load(TEMPLATE_transform_env_t *env) {
259 ir_node *node = env->irn;
261 if (mode_is_float(env->mode)) {
262 return new_bd_TEMPLATE_fLoad(env->dbg, env->block, get_Load_ptr(node), get_Load_mem(node), env->mode);
264 return new_bd_TEMPLATE_Load(env->dbg, env->block, get_Load_ptr(node), get_Load_mem(node), env->mode);
270 * Transforms a Store.
272 * @param mod the debug module
273 * @param block the block the new node should belong to
274 * @param node the ir Store node
275 * @param mode node mode
276 * @return the created TEMPLATE Store node
278 static ir_node *gen_Store(TEMPLATE_transform_env_t *env) {
279 ir_node *node = env->irn;
281 if (mode_is_float(env->mode)) {
282 return new_bd_TEMPLATE_fStore(env->dbg, env->block, get_Store_ptr(node), get_Store_value(node), get_Store_mem(node), env->mode);
284 return new_bd_TEMPLATE_Store(env->dbg, env->block, get_Store_ptr(node), get_Store_value(node), get_Store_mem(node), env->mode);
289 /*********************************************************
292 * _ __ ___ __ _ _ _ __ __| |_ __ ___ _____ _ __
293 * | '_ ` _ \ / _` | | '_ \ / _` | '__| \ \ / / _ \ '__|
294 * | | | | | | (_| | | | | | | (_| | | | |\ V / __/ |
295 * |_| |_| |_|\__,_|_|_| |_| \__,_|_| |_| \_/ \___|_|
297 *********************************************************/
302 * Transforms the given firm node (and maybe some other related nodes)
303 * into one or more assembler nodes.
305 * @param node the firm node
306 * @param env the debug module
308 void TEMPLATE_transform_node(ir_node *node, void *env) {
310 TEMPLATE_code_gen_t *cgenv = (TEMPLATE_code_gen_t *)env;
312 ir_opcode code = get_irn_opcode(node);
313 ir_node *asm_node = NULL;
314 TEMPLATE_transform_env_t tenv;
320 tenv.block = get_nodes_block(node);
321 tenv.dbg = get_irn_dbg_info(node);
322 tenv.irg = current_ir_graph;
325 tenv.mod = cgenv->mod;
327 tenv.mode = get_irn_mode(node);
329 #define UNOP(a) case iro_##a: asm_node = gen_##a(&tenv, get_##a##_op(node)); break
330 #define BINOP(a) case iro_##a: asm_node = gen_##a(&tenv, get_##a##_left(node), get_##a##_right(node)); break
331 #define GEN(a) case iro_##a: asm_node = gen_##a(&tenv); break
332 #define IGN(a) case iro_##a: break
333 #define BAD(a) case iro_##a: goto bad
335 DBG((tenv.mod, LEVEL_1, "check %+F ... ", node));
356 /* TODO: implement these nodes */
371 /* You probably don't need to handle the following nodes */
402 if (get_irn_op(node) == get_op_Max() ||
403 get_irn_op(node) == get_op_Min() ||
406 /* TODO: implement */
411 fprintf(stderr, "Not implemented: %s\n", get_irn_opname(node));
416 exchange(node, asm_node);
417 DB((tenv.mod, LEVEL_1, "created node %+F[%p]\n", asm_node, asm_node));
420 DB((tenv.mod, LEVEL_1, "ignored\n"));