2 * Register mapping for firm nodes. Stolen from bearch_firm :)
11 #include "ia32_map_regs.h"
12 #include "ia32_new_nodes.h"
15 /* Mapping to store registers in firm nodes */
17 struct ia32_irn_reg_assoc {
19 const arch_register_t *reg;
22 int ia32_cmp_irn_reg_assoc(const void *a, const void *b, size_t len) {
23 const struct ia32_irn_reg_assoc *x = a;
24 const struct ia32_irn_reg_assoc *y = b;
26 return !(x->irn == y->irn);
29 static struct ia32_irn_reg_assoc *get_irn_reg_assoc(const ir_node *irn, set *reg_set) {
30 struct ia32_irn_reg_assoc templ;
37 return set_insert(reg_set, &templ, sizeof(templ), hash);
40 void ia32_set_firm_reg(ir_node *irn, const arch_register_t *reg, set *reg_set) {
41 struct ia32_irn_reg_assoc *assoc = get_irn_reg_assoc(irn, reg_set);
45 const arch_register_t *ia32_get_firm_reg(const ir_node *irn, set *reg_set) {
46 struct ia32_irn_reg_assoc *assoc = get_irn_reg_assoc(irn, reg_set);
52 /* Mapping to store proj numbers for registers */
54 struct ia32_reg_projnum_assoc {
55 const arch_register_t *reg;
59 int ia32_cmp_reg_projnum_assoc(const void *a, const void *b, size_t len) {
60 const struct ia32_reg_projnum_assoc *x = a;
61 const struct ia32_reg_projnum_assoc *y = b;
63 return !(x->reg == y->reg);
66 static struct ia32_reg_projnum_assoc *get_reg_projnum_assoc(const arch_register_t *reg, set *reg_set) {
67 struct ia32_reg_projnum_assoc templ;
74 return set_insert(reg_set, &templ, sizeof(templ), hash);
77 void ia32_set_reg_projnum(const arch_register_t *reg, long proj_num, set *reg_set) {
78 struct ia32_reg_projnum_assoc *assoc = get_reg_projnum_assoc(reg, reg_set);
79 assoc->proj_num = proj_num;
82 long ia32_get_reg_projnum(const arch_register_t *reg, set *reg_set) {
83 struct ia32_reg_projnum_assoc *assoc = get_reg_projnum_assoc(reg, reg_set);
84 return assoc->proj_num;
90 * Translates the projnum into a "real" argument position for register
91 * requirements dependend on the predecessor.
93 long ia32_translate_proj_pos(const ir_node *proj) {
95 ir_node *pred = get_Proj_pred(proj);
96 long nr = get_Proj_proj(proj);
98 if (is_ia32_Load(pred)) {
99 if (nr == pn_Load_res)
101 assert(0 && "unsupported Proj(Load) number");
103 else if (is_ia32_Store(pred)) {
106 else if (is_ia32_CondJmp(pred) || is_ia32_CondJmp_i(pred)) {
109 else if (is_ia32_SwitchJmp(pred)) {
112 else if (is_ia32_Cltd(pred) || is_ia32_Mul(pred)) {
118 else if (is_ia32_DivMod(pred)) {
119 if (nr == pn_DivMod_res_div || pn_Div_res)
121 if (nr == pn_DivMod_res_mod || pn_Mod_res)
124 else if (is_ia32_Call(pred)) {
127 else if (get_irn_mode(proj) == mode_X && nr == pn_Start_X_initial_exec) {
130 else if (is_Proj(pred)) {
131 // return nr + translate_proj_pos(pred);
132 first = get_Proj_pred(pred);
134 if (is_ia32_Call(first))
137 assert(0 && "unsupported proj-pos translation Proj(Proj)");
140 else if (get_irn_opcode(pred) == iro_Start) {
144 // assert(0 && "unsupported Proj(X)");