a0d85924ff237288e07ec57ad4b8d898a28e37b0
[libfirm] / ir / be / amd64 / amd64_new_nodes.c
1 /*
2  * Copyright (C) 1995-2008 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 "irvrfy_t.h"
39 #include "irprintf.h"
40 #include "xmalloc.h"
41
42 #include "../bearch.h"
43
44 #include "amd64_nodes_attr.h"
45 #include "amd64_new_nodes.h"
46 #include "gen_amd64_regalloc_if.h"
47
48 /**
49  * Dumper interface for dumping amd64 nodes in vcg.
50  * @param n        the node to dump
51  * @param F        the output file
52  * @param reason   indicates which kind of information should be dumped
53  * @return 0 on success or != 0 on failure
54  */
55 static int amd64_dump_node(ir_node *n, FILE *F, dump_reason_t reason)
56 {
57         ir_mode *mode = NULL;
58
59         switch (reason) {
60         case dump_node_opcode_txt:
61                 fprintf(F, "%s", get_irn_opname(n));
62                 break;
63
64         case dump_node_mode_txt:
65                 mode = get_irn_mode(n);
66
67                 if (mode) {
68                         fprintf(F, "[%s]", get_mode_name(mode));
69                 } else {
70                         fprintf(F, "[?NOMODE?]");
71                 }
72                 break;
73
74         case dump_node_nodeattr_txt:
75
76                 /* TODO: dump some attributes which should show up */
77                 /* in node name in dump (e.g. consts or the like)  */
78
79                 break;
80
81         case dump_node_info_txt:
82                 arch_dump_reqs_and_registers(F, n);
83                 break;
84         }
85
86         return 0;
87 }
88
89 const amd64_attr_t *get_amd64_attr_const(const ir_node *node)
90 {
91         assert(is_amd64_irn(node) && "need amd64 node to get attributes");
92         return (const amd64_attr_t *)get_irn_generic_attr_const(node);
93 }
94
95 amd64_attr_t *get_amd64_attr(ir_node *node)
96 {
97         assert(is_amd64_irn(node) && "need amd64 node to get attributes");
98         return (amd64_attr_t *)get_irn_generic_attr(node);
99 }
100
101 static const amd64_immediate_attr_t *get_amd64_immediate_attr_const(const ir_node *node)
102 {
103         const amd64_attr_t           *attr     = get_amd64_attr_const(node);
104         const amd64_immediate_attr_t *imm_attr = CONST_CAST_AMD64_ATTR(amd64_immediate_attr_t, attr);
105
106         return imm_attr;
107 }
108
109 /*
110 static amd64_immediate_attr_t *get_amd64_immediate_attr(ir_node *node)
111 {
112         amd64_attr_t           *attr     = get_amd64_attr(node);
113         amd64_immediate_attr_t *imm_attr = CAST_AMD64_ATTR(amd64_immediate_attr_t, attr);
114
115         return imm_attr;
116 }
117 */
118
119
120 /**
121  * Returns the argument register requirements of a amd64 node.
122  */
123 const arch_register_req_t **get_amd64_in_req_all(const ir_node *node)
124 {
125         const amd64_attr_t *attr = get_amd64_attr_const(node);
126         return attr->in_req;
127 }
128
129 /**
130  * Returns the argument register requirement at position pos of an amd64 node.
131  */
132 const arch_register_req_t *get_amd64_in_req(const ir_node *node, int pos)
133 {
134         const amd64_attr_t *attr = get_amd64_attr_const(node);
135         return attr->in_req[pos];
136 }
137
138 /**
139  * Sets the IN register requirements at position pos.
140  */
141 void set_amd64_req_in(ir_node *node, const arch_register_req_t *req, int pos)
142 {
143         amd64_attr_t *attr  = get_amd64_attr(node);
144         attr->in_req[pos] = req;
145 }
146
147 /**
148  * Initializes the nodes attributes.
149  */
150 static void init_amd64_attributes(ir_node *node, arch_irn_flags_t flags,
151                               const arch_register_req_t **in_reqs,
152                               const be_execution_unit_t ***execution_units,
153                               int n_res)
154 {
155         ir_graph        *irg  = get_irn_irg(node);
156         struct obstack  *obst = get_irg_obstack(irg);
157         amd64_attr_t *attr = get_amd64_attr(node);
158         backend_info_t  *info;
159         (void) execution_units;
160
161         arch_irn_set_flags(node, flags);
162         attr->in_req  = in_reqs;
163
164         info            = be_get_info(node);
165         info->out_infos = NEW_ARR_D(reg_out_info_t, obst, n_res);
166         memset(info->out_infos, 0, n_res * sizeof(info->out_infos[0]));
167 }
168
169 /**
170  * Initialize immediate attributes.
171  */
172 static void init_amd64_immediate_attributes(ir_node *node, unsigned imm_value)
173 {
174         amd64_immediate_attr_t *attr = get_irn_generic_attr (node);
175         attr->imm_value = imm_value;
176 }
177
178 /** Compare node attributes for Immediates. */
179 static int cmp_amd64_attr_immediate(ir_node *a, ir_node *b)
180 {
181         const amd64_immediate_attr_t *attr_a = get_amd64_immediate_attr_const(a);
182         const amd64_immediate_attr_t *attr_b = get_amd64_immediate_attr_const(b);
183
184         if (attr_a->imm_value != attr_b->imm_value)
185                 return 1;
186
187         return 0;
188 }
189
190 static int cmp_amd64_attr(ir_node *a, ir_node *b)
191 {
192         const amd64_attr_t *attr_a = get_amd64_attr_const(a);
193         const amd64_attr_t *attr_b = get_amd64_attr_const(b);
194         (void) attr_a;
195         (void) attr_b;
196
197         return 0;
198 }
199
200 /* Include the generated constructor functions */
201 #include "gen_amd64_new_nodes.c.inl"