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