+/*
+ * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
+ *
+ * This file is part of libFirm.
+ *
+ * This file may be distributed and/or modified under the terms of the
+ * GNU General Public License version 2 as published by the Free Software
+ * Foundation and appearing in the file LICENSE.GPL included in the
+ * packaging of this file.
+ *
+ * Licensees holding valid libFirm Professional Edition licenses may use
+ * this file in accordance with the libFirm Commercial License.
+ * Agreement provided with the Software.
+ *
+ * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+ * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE.
+ */
+
/**
- * Register mapping for firm nodes. Stolen from bearch_firm :)
- * $Id$
+ * @file
+ * @brief Register param constraints and some other register handling tools.
+ * @author Christian Wuerdig
+ * @version $Id$
*/
+#include "config.h"
#include <stdlib.h>
+#include "pmap.h"
+#include "error.h"
+
#include "ia32_map_regs.h"
#include "ia32_new_nodes.h"
-
-struct irn_reg_assoc {
- const ir_node *irn;
- const arch_register_t *reg;
-};
-
-int cmp_irn_reg_assoc(const void *a, const void *b, size_t len) {
- const struct irn_reg_assoc *x = a;
- const struct irn_reg_assoc *y = b;
-
- return !(x->irn == y->irn);
+#include "ia32_architecture.h"
+#include "gen_ia32_regalloc_if.h"
+#include "bearch_ia32_t.h"
+
+/* this is the order of the assigned registers used for parameter passing */
+
+
+void ia32_build_16bit_reg_map(pmap *reg_map) {
+ pmap_insert(reg_map, &ia32_gp_regs[REG_EAX], "ax");
+ pmap_insert(reg_map, &ia32_gp_regs[REG_EBX], "bx");
+ pmap_insert(reg_map, &ia32_gp_regs[REG_ECX], "cx");
+ pmap_insert(reg_map, &ia32_gp_regs[REG_EDX], "dx");
+ pmap_insert(reg_map, &ia32_gp_regs[REG_ESI], "si");
+ pmap_insert(reg_map, &ia32_gp_regs[REG_EDI], "di");
+ pmap_insert(reg_map, &ia32_gp_regs[REG_EBP], "bp");
+ pmap_insert(reg_map, &ia32_gp_regs[REG_ESP], "sp");
}
-static struct irn_reg_assoc *get_irn_reg_assoc(const ir_node *irn, set *reg_set) {
- struct irn_reg_assoc templ;
- unsigned int hash;
-
- templ.irn = irn;
- templ.reg = NULL;
- hash = HASH_PTR(irn);
-
- return set_insert(reg_set, &templ, sizeof(templ), hash);
-}
-
-void ia32_set_firm_reg(const arch_irn_ops_t *self, ir_node *irn,
- const arch_register_t *reg, set *reg_set)
-{
- struct irn_reg_assoc *assoc = get_irn_reg_assoc(irn, reg_set);
- assoc->reg = reg;
+void ia32_build_8bit_reg_map(pmap *reg_map) {
+ pmap_insert(reg_map, &ia32_gp_regs[REG_EAX], "al");
+ pmap_insert(reg_map, &ia32_gp_regs[REG_EBX], "bl");
+ pmap_insert(reg_map, &ia32_gp_regs[REG_ECX], "cl");
+ pmap_insert(reg_map, &ia32_gp_regs[REG_EDX], "dl");
}
-const arch_register_t *ia32_get_firm_reg(const arch_irn_ops_t *self,
- const ir_node *irn, set *reg_set)
-{
- struct irn_reg_assoc *assoc = get_irn_reg_assoc(irn, reg_set);
- return assoc->reg;
+void ia32_build_8bit_reg_map_high(pmap *reg_map) {
+ pmap_insert(reg_map, &ia32_gp_regs[REG_EAX], "ah");
+ pmap_insert(reg_map, &ia32_gp_regs[REG_EBX], "bh");
+ pmap_insert(reg_map, &ia32_gp_regs[REG_ECX], "ch");
+ pmap_insert(reg_map, &ia32_gp_regs[REG_EDX], "dh");
}
+const char *ia32_get_mapped_reg_name(pmap *reg_map, const arch_register_t *reg) {
+ pmap_entry *e = pmap_find(reg_map, (void *)reg);
-/**
- * Translates the projnum into a "real" argument position for register
- * requirements dependend on the predecessor.
- */
-long translate_proj_pos(const ir_node *proj) {
- ir_node *first;
- ir_node *pred = get_Proj_pred(proj);
- long nr = get_Proj_proj(proj);
-
- if (is_ia32_Load(pred)) {
- if (nr == pn_Load_res)
- return 0;
- assert(0 && "unsupported Proj(Load) number");
- }
- else if (is_ia32_Store(pred)) {
- return 0;
- }
- else if (is_ia32_CondJmp(pred) || is_ia32_CondJmp_i(pred)) {
- return 0;
- }
- else if (is_ia32_SwitchJmp(pred)) {
- return 0;
- }
- else if (is_ia32_Cltd(pred) || is_ia32_Mul(pred)) {
- if (nr == pn_EAX)
- return 0;
- if (nr == pn_EDX)
- return 1;
- }
- else if (is_ia32_DivMod(pred)) {
- if (nr == pn_DivMod_res_div || pn_Div_res)
- return 0;
- if (nr == pn_DivMod_res_mod || pn_Mod_res)
- return 1;
- }
- else if (is_ia32_Call(pred)) {
- return 0;
- }
- else if (get_irn_mode(proj) == mode_X && nr == pn_Start_X_initial_exec) {
- return 0;
- }
- else if (is_Proj(pred)) {
-// return nr + translate_proj_pos(pred);
- first = get_Proj_pred(pred);
-
- if (is_ia32_Call(first))
- return 0;
-
- assert(0 && "unsupported proj-pos translation Proj(Proj)");
- return -1;
- }
- else if (get_irn_opcode(pred) == iro_Start) {
- return nr;
+ //assert(e && "missing map init?");
+ if (! e) {
+ printf("FIXME: ia32map_regs.c:122: returning fake register name for ia32 with 32 register\n");
+ return reg->name;
}
-// assert(0 && "unsupported Proj(X)");
- return nr;
+ return e->value;
}