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 amd64 FIRM)
23 * @version $Id: amd64_transform.c 26673 2009-10-01 16:43:13Z matze $
28 #include "irgraph_t.h"
37 #include "../benode.h"
38 #include "../betranshlp.h"
39 #include "bearch_amd64_t.h"
41 #include "amd64_nodes_attr.h"
42 #include "amd64_transform.h"
43 #include "amd64_new_nodes.h"
45 #include "gen_amd64_regalloc_if.h"
47 DEBUG_ONLY(static firm_dbg_module_t *dbg = NULL;)
49 /** holds the current code generator during transformation */
50 static amd64_code_gen_t *env_cg;
52 /* Some support functions: */
55 * Create a DAG constructing a given Const.
57 * @param irn a Firm const
59 static ir_node *create_const_graph(ir_node *irn, ir_node *block)
61 tarval *tv = get_Const_tarval(irn);
62 ir_mode *mode = get_tarval_mode(tv);
63 dbg_info *dbgi = get_irn_dbg_info(irn);
66 if (mode_is_reference(mode)) {
67 /* AMD64 is 64bit, so we can safely convert a reference tarval into Iu */
68 assert(get_mode_size_bits(mode) == get_mode_size_bits(mode_Iu));
69 tv = tarval_convert_to(tv, mode_Iu);
72 value = get_tarval_long(tv);
73 printf ("TEST GENERATE %d\n", value);
75 return new_bd_amd64_Immediate(dbgi, block, value);
78 /* Op transformers: */
81 * Transforms a Const node.
83 * @return The transformed ARM node.
85 static ir_node *gen_Const(ir_node *node) {
86 ir_node *block = be_transform_node(get_nodes_block(node));
87 ir_mode *mode = get_irn_mode(node);
90 ir_node *res = create_const_graph(node, block);
91 be_dep_on_frame (res);
96 /* Boilerplate code for transformation: */
98 static void amd64_pretransform_node(void)
100 amd64_code_gen_t *cg = env_cg;
104 static void set_transformer(ir_op *op, be_transform_func amd64_transform_func)
106 op->ops.generic = (op_func)amd64_transform_func;
109 static void amd64_register_transformers(void)
111 clear_irp_opcodes_generic_func();
113 set_transformer(op_Const, gen_Const);
117 void amd64_transform_graph(amd64_code_gen_t *cg)
119 amd64_register_transformers();
121 be_transform_graph(cg->birg, amd64_pretransform_node);
124 void amd64_init_transform(void)
126 FIRM_DBG_REGISTER(dbg, "firm.be.amd64.transform");