big refactoring of arch_XXX functions
[libfirm] / ir / be / amd64 / amd64_new_nodes.c
1 /*
2  * Copyright (C) 1995-2011 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
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.
10  *
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.
14  *
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
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @brief   This file implements the creation of the achitecture specific firm
23  *          opcodes and the coresponding node constructors for the amd64
24  *          assembler irg.
25  * @version $Id: amd64_new_nodes.c 26673 2009-10-01 16:43:13Z matze $
26  */
27 #include "config.h"
28
29 #include <stdlib.h>
30
31 #include "irprog_t.h"
32 #include "irgraph_t.h"
33 #include "irnode_t.h"
34 #include "irmode_t.h"
35 #include "ircons_t.h"
36 #include "iropt_t.h"
37 #include "irop.h"
38 #include "irprintf.h"
39 #include "xmalloc.h"
40
41 #include "../bearch.h"
42
43 #include "amd64_nodes_attr.h"
44 #include "amd64_new_nodes.h"
45 #include "gen_amd64_regalloc_if.h"
46
47 void set_amd64_ls_mode(ir_node *node, ir_mode *mode)
48 {
49   amd64_attr_t *attr = get_amd64_attr(node);
50   attr->ls_mode = mode;
51 }
52
53 /**
54  * Dumper interface for dumping amd64 nodes in vcg.
55  * @param F        the output file
56  * @param n        the node to dump
57  * @param reason   indicates which kind of information should be dumped
58  */
59 static void amd64_dump_node(FILE *F, ir_node *n, dump_reason_t reason)
60 {
61         ir_mode *mode = NULL;
62
63         switch (reason) {
64         case dump_node_opcode_txt:
65                 fprintf(F, "%s", get_irn_opname(n));
66                 break;
67
68         case dump_node_mode_txt:
69                 mode = get_irn_mode(n);
70
71                 if (mode) {
72                         fprintf(F, "[%s]", get_mode_name(mode));
73                 } else {
74                         fprintf(F, "[?NOMODE?]");
75                 }
76                 break;
77
78         case dump_node_nodeattr_txt:
79
80                 /* TODO: dump some attributes which should show up */
81                 /* in node name in dump (e.g. consts or the like)  */
82
83                 break;
84
85         case dump_node_info_txt:
86                 arch_dump_reqs_and_registers(F, n);
87                 break;
88         }
89 }
90
91 const amd64_attr_t *get_amd64_attr_const(const ir_node *node)
92 {
93         assert(is_amd64_irn(node) && "need amd64 node to get attributes");
94         return (const amd64_attr_t *)get_irn_generic_attr_const(node);
95 }
96
97 amd64_attr_t *get_amd64_attr(ir_node *node)
98 {
99         assert(is_amd64_irn(node) && "need amd64 node to get attributes");
100         return (amd64_attr_t *)get_irn_generic_attr(node);
101 }
102
103 const amd64_SymConst_attr_t *get_amd64_SymConst_attr_const(const ir_node *node)
104 {
105         const amd64_SymConst_attr_t *attr
106                 = (const amd64_SymConst_attr_t*)get_irn_generic_attr_const(node);
107         return attr;
108 }
109
110 amd64_SymConst_attr_t *get_amd64_SymConst_attr(ir_node *node)
111 {
112         amd64_SymConst_attr_t *attr
113                 = (amd64_SymConst_attr_t*)get_irn_generic_attr(node);
114         return attr;
115 }
116
117 /**
118  * Initializes the nodes attributes.
119  */
120 static void init_amd64_attributes(ir_node *node, arch_irn_flags_t flags,
121                               const arch_register_req_t **in_reqs,
122                               const be_execution_unit_t ***execution_units,
123                               int n_res)
124 {
125         ir_graph        *irg  = get_irn_irg(node);
126         struct obstack  *obst = get_irg_obstack(irg);
127         amd64_attr_t *attr    = get_amd64_attr(node);
128
129         backend_info_t  *info;
130         (void) execution_units;
131
132         arch_set_irn_flags(node, flags);
133         arch_set_irn_register_reqs_in(node, in_reqs);
134
135         info            = be_get_info(node);
136         info->out_infos = NEW_ARR_D(reg_out_info_t, obst, n_res);
137         memset(info->out_infos, 0, n_res * sizeof(info->out_infos[0]));
138
139         attr->data.ins_permuted = 0;
140         attr->data.cmp_unsigned = 0;
141         attr->ext.relation      = ir_relation_false;
142         attr->ext.imm_value     = 0;
143 }
144
145 /**
146  * Initialize SymConst attributes.
147  */
148 static void init_amd64_SymConst_attributes(ir_node *node, ir_entity *entity)
149 {
150         amd64_SymConst_attr_t *attr = get_amd64_SymConst_attr(node);
151         attr->entity    = entity;
152         attr->fp_offset = 0;
153 }
154
155 /** Compare node attributes for SymConst. */
156 static int cmp_amd64_attr_SymConst(const ir_node *a, const ir_node *b)
157 {
158         const amd64_SymConst_attr_t *attr_a = get_amd64_SymConst_attr_const(a);
159         const amd64_SymConst_attr_t *attr_b = get_amd64_SymConst_attr_const(b);
160
161         if (attr_a->entity != attr_b->entity
162             || attr_a->fp_offset != attr_b->fp_offset)
163                 return 1;
164
165         return 0;
166 }
167
168 /** Compare common amd64 node attributes. */
169 static int cmp_amd64_attr(const ir_node *a, const ir_node *b)
170 {
171         const amd64_attr_t *attr_a = get_amd64_attr_const(a);
172         const amd64_attr_t *attr_b = get_amd64_attr_const(b);
173
174         return attr_a->ext.imm_value != attr_b->ext.imm_value;
175 }
176
177 /** copies the AMD64 attributes of a node. */
178 static void amd64_copy_attr(ir_graph *irg, const ir_node *old_node,
179                           ir_node *new_node)
180 {
181         struct obstack   *obst       = get_irg_obstack(irg);
182         const amd64_attr_t *attr_old = get_amd64_attr_const(old_node);
183         amd64_attr_t     *attr_new   = get_amd64_attr(new_node);
184         backend_info_t   *old_info   = be_get_info(old_node);
185         backend_info_t   *new_info   = be_get_info(new_node);
186
187         /* copy the attributes */
188         memcpy(attr_new, attr_old, get_op_attr_size(get_irn_op(old_node)));
189
190         /* copy out flags */
191         new_info->flags = old_info->flags;
192         new_info->out_infos =
193                 DUP_ARR_D(reg_out_info_t, obst, old_info->out_infos);
194         new_info->in_reqs = old_info->in_reqs;
195 }
196
197 /* Include the generated constructor functions */
198 #include "gen_amd64_new_nodes.c.inl"