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