added ir/opt include
[libfirm] / ir / be / mips / mips_map_regs.c
1 /**
2  * Register mapping for firm nodes. Stolen from bearch_firm :)
3  * $Id$
4  */
5 #ifdef HAVE_CONFIG_H
6 #include "config.h"
7 #endif
8
9 #include <stdlib.h>
10
11 #include "mips_map_regs.h"
12 #include "mips_new_nodes.h"
13
14 /* Mapping to store registers in firm nodes */
15
16 struct mips_irn_reg_assoc {
17         const ir_node *irn;
18         const arch_register_t *reg;
19 };
20
21 int mips_cmp_irn_reg_assoc(const void *a, const void *b, size_t len) {
22         const struct mips_irn_reg_assoc *x = a;
23         const struct mips_irn_reg_assoc *y = b;
24
25         return x->irn != y->irn;
26 }
27
28 static struct mips_irn_reg_assoc *get_irn_reg_assoc(const ir_node *irn, set *reg_set) {
29         struct mips_irn_reg_assoc templ;
30         unsigned int hash;
31
32         templ.irn = irn;
33         templ.reg = NULL;
34         hash = HASH_PTR(irn);
35
36         return set_insert(reg_set, &templ, sizeof(templ), hash);
37 }
38
39 void mips_set_firm_reg(ir_node *irn, const arch_register_t *reg, set *reg_set) {
40         struct mips_irn_reg_assoc *assoc = get_irn_reg_assoc(irn, reg_set);
41         assoc->reg = reg;
42 }
43
44 const arch_register_t *mips_get_firm_reg(const ir_node *irn, set *reg_set) {
45         struct mips_irn_reg_assoc *assoc = get_irn_reg_assoc(irn, reg_set);
46         return assoc->reg;
47 }
48
49 /**
50  * Translates the projnum into a "real" argument position for register
51  * requirements dependend on the predecessor.
52  */
53 long mips_translate_proj_pos(const ir_node *proj) {
54         return get_Proj_proj(proj);
55 }