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