X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fbe%2Fia32%2Fia32_map_regs.c;h=8c94426462c4ebe0e0ae780c37759276b0eeb418;hb=9c9aa4c39f524635f26bb014bd4a83013a304166;hp=c6efb8d4d9aeea14aa004da0ec9bf38ce5cba858;hpb=2c177f2fc2df0c30eee7125c7437da967dda48a8;p=libfirm diff --git a/ir/be/ia32/ia32_map_regs.c b/ir/be/ia32/ia32_map_regs.c index c6efb8d4d..8c9442646 100644 --- a/ir/be/ia32/ia32_map_regs.c +++ b/ir/be/ia32/ia32_map_regs.c @@ -1,6 +1,27 @@ +/* + * Copyright (C) 1995-2007 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$ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -9,13 +30,16 @@ #include #include "pmap.h" +#include "error.h" #include "ia32_map_regs.h" #include "ia32_new_nodes.h" #include "gen_ia32_regalloc_if.h" +#include "bearch_ia32_t.h" +#include "../benodesets.h" static int maxnum_gpreg_args = 3; /* maximum number of int arguments passed in registers; default 3 */ -static int maxnum_fpreg_args = 5; /* maximum number of float arguments passed in registers; default 5 */ +static int maxnum_sse_args = 5; /* maximum number of float arguments passed in registers; default 5 */ /* this is the order of the assigned registers usesd for parameter passing */ @@ -37,7 +61,7 @@ const arch_register_t *gpreg_param_reg_this[] = { &ia32_gp_regs[REG_ESI] }; -const arch_register_t *fpreg_param_reg_std[] = { +const arch_register_t *fpreg_sse_param_reg_std[] = { &ia32_xmm_regs[REG_XMM0], &ia32_xmm_regs[REG_XMM1], &ia32_xmm_regs[REG_XMM2], @@ -48,7 +72,7 @@ const arch_register_t *fpreg_param_reg_std[] = { &ia32_xmm_regs[REG_XMM7] }; -const arch_register_t *fpreg_param_reg_this[] = { +const arch_register_t *fpreg_sse_param_reg_this[] = { NULL, /* in case of a "this" pointer, the first parameter must not be a float */ &ia32_xmm_regs[REG_XMM0], &ia32_xmm_regs[REG_XMM1], @@ -82,7 +106,7 @@ static struct ia32_irn_reg_assoc *get_irn_reg_assoc(const ir_node *irn, set *reg templ.irn = irn; templ.reg = NULL; - hash = HASH_PTR(irn); + hash = nodeset_hash(irn); return set_insert(reg_set, &templ, sizeof(templ), hash); } @@ -115,10 +139,21 @@ void ia32_build_8bit_reg_map(pmap *reg_map) { pmap_insert(reg_map, &ia32_gp_regs[REG_EDX], "dl"); } -char *ia32_get_mapped_reg_name(pmap *reg_map, const arch_register_t *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); - assert(e && "missing map init?"); + //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; + } return e->value; } @@ -126,37 +161,34 @@ char *ia32_get_mapped_reg_name(pmap *reg_map, const arch_register_t *reg) { /** * Check all parameters and determine the maximum number of parameters * to pass in gp regs resp. in fp regs. - * - * @param n The number of parameters - * @param modes The list of the parameter modes - * @param n_int Holds the number of int parameters to be passed in regs after the call - * @param n_float Holds the number of float parameters to be passed in regs after the call - * @return The number of the last parameter to be passed in register */ -int ia32_get_n_regparam_class(int n, ir_mode **modes, int *n_int, int *n_float) { - int i, finished = 0; - - *n_int = 0; - *n_float = 0; +int ia32_get_n_regparam_class(ia32_code_gen_t *cg, int n, ir_mode **modes) +{ + int i; + int max_fp_regs; + int n_int = 0; + int n_float = 0; + + if(USE_SSE2(cg)) { + max_fp_regs = maxnum_sse_args; + } else { + max_fp_regs = 0; + } - for (i = 0; i < n && !finished; i++) { + for (i = 0; i < n; i++) { if (mode_is_int(modes[i]) || mode_is_reference(modes[i])) { - *n_int = *n_int + 1; - } - else if (mode_is_float(modes[i])) { - *n_float = *n_float + 1; - } - else { - finished = 1; + ++n_int; + } else if (mode_is_float(modes[i])) { + ++n_float; + } else { + panic("Unknown parameter mode encountered"); } - /* test for maximum */ - if (*n_int == maxnum_gpreg_args || *n_float == maxnum_fpreg_args) { - finished = 1; - } + if (n_int >= maxnum_gpreg_args || n_float >= max_fp_regs) + break; } - return i - 1; + return i; } @@ -169,110 +201,24 @@ int ia32_get_n_regparam_class(int n, ir_mode **modes, int *n_int, int *n_float) * @param cc The calling convention * @return The register */ -const arch_register_t *ia32_get_RegParam_reg(int n, ir_mode **modes, long nr, unsigned cc) { - const arch_register_t **current_gpreg_param_reg; - const arch_register_t **current_fpreg_param_reg; - const arch_register_t *param_reg = NULL; - int n_gpregparam = 0; - int n_fpregparam = 0; - int i, done = 0; - int cur_gp_idx = 0; - int cur_fp_idx = 0; - int biggest_n = ia32_get_n_regparam_class(n, modes, &n_gpregparam, &n_fpregparam); - - /* Check if parameter #nr is in range for passing in register */ - if (nr <= biggest_n) { - current_gpreg_param_reg = gpreg_param_reg_std; - current_fpreg_param_reg = fpreg_param_reg_std; - - if (cc & cc_this_call) { - current_gpreg_param_reg = gpreg_param_reg_this; - current_fpreg_param_reg = fpreg_param_reg_this; - } - - /* loop over all parameters and determine whether its a int or float register parameter */ - for (i = 0; i < nr && !done && (cc & cc_reg_param); i++) { - if ((mode_is_int(modes[i]) || mode_is_reference(modes[i])) && cur_gp_idx < maxnum_gpreg_args) { - /* param can be passed in general purpose register and we have some registers left */ - cur_gp_idx++; - } - else if (mode_is_float(modes[i]) && cur_fp_idx < maxnum_fpreg_args) { - /* param can be passed in floating point register and we have some registers left */ - assert(current_gpreg_param_reg[cur_fp_idx] && "'this' pointer cannot be passed as float"); - cur_fp_idx++; - } - } - - /* now: i == nr, that's the parameter requirement we want */ - if ((mode_is_int(modes[i]) || mode_is_reference(modes[i])) && cur_gp_idx < maxnum_gpreg_args) { - /* parameter #nr can be passed in general purpose register */ - param_reg = current_gpreg_param_reg[i]; - } - else if (mode_is_float(modes[i]) && cur_fp_idx < maxnum_fpreg_args) { - /* parameter #nr can be passed in floating point register */ - param_reg = current_fpreg_param_reg[i]; - } - else { - assert(0 && "This should not happen!"); +const arch_register_t *ia32_get_RegParam_reg(ia32_code_gen_t *cg, unsigned cc, + unsigned nr, ir_mode *mode) +{ + if(mode_is_float(mode)) { + if(!USE_SSE2(cg)) + return NULL; + assert(nr < maxnum_sse_args); + if(cc & cc_this_call) { + return fpreg_sse_param_reg_this[nr]; } + return fpreg_sse_param_reg_std[nr]; } - return param_reg; -} - + assert(mode_is_int(mode) || mode_is_reference(mode)); - -/** - * Translates the projnum into a "real" argument position for register - * requirements dependend on the predecessor. - */ -long ia32_translate_proj_pos(const ir_node *proj) { - ir_node *pred = get_Proj_pred(proj); - long nr = get_Proj_proj(proj); - - if (is_ia32_Ld(pred)) { - if (nr == pn_Load_res || nr == 0) - return 0; - assert(0 && "unsupported Proj(Load) number"); - } - else if (is_ia32_St(pred)) { - return 0; + if(cc & cc_this_call) { + assert(nr < maxnum_gpreg_args); + return gpreg_param_reg_this[nr]; } - else if (is_ia32_CondJmp(pred)) { - return 0; - } - else if (is_ia32_SwitchJmp(pred)) { - return 0; - } - else if (is_ia32_Cdq(pred) || is_ia32_Mulh(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) - return 0; - if (nr == pn_DivMod_res_mod) - return 1; - assert(0 && "unsupported DivMod"); - } - else if (is_ia32_fDiv(pred)) { - if (nr == pn_Quot_res) - return 0; - else - assert(0 && "there should be no more Projs for a fDiv"); - } - else if (get_irn_mode(proj) == mode_X && nr == pn_Start_X_initial_exec) { - return 0; - } - else if (is_Proj(pred)) { - return nr; - } - else if (get_irn_opcode(pred) == iro_Start) { - return nr; - } - -// assert(0 && "unsupported Proj(X)"); - return nr; + return gpreg_param_reg_std[nr]; }