X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fbe%2Fia32%2Fia32_map_regs.c;h=49110979b11f8bab8e98520d74523e4692bdbd6f;hb=ffb3cd49207934dfff98359a6fc6e05231384fa6;hp=1173cedb7d5c1b8a4004ba1fe1e6dd26f790e73d;hpb=3b1a4ee674e9522acfd95b6d49c91f86f9b97d32;p=libfirm diff --git a/ir/be/ia32/ia32_map_regs.c b/ir/be/ia32/ia32_map_regs.c index 1173cedb7..49110979b 100644 --- a/ir/be/ia32/ia32_map_regs.c +++ b/ir/be/ia32/ia32_map_regs.c @@ -1,63 +1,78 @@ +/* + * 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$ */ -#ifdef HAVE_CONFIG_H #include "config.h" -#endif #include +#include "pmap.h" +#include "error.h" + #include "ia32_map_regs.h" #include "ia32_new_nodes.h" +#include "ia32_architecture.h" #include "gen_ia32_regalloc_if.h" +#include "bearch_ia32_t.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 */ +#define MAXNUM_GPREG_ARGS 3 +#define MAXNUM_SSE_ARGS 8 -/* this is the order of the assigned registers usesd for parameter passing */ +/* this is the order of the assigned registers used for parameter passing */ -const ia32_register_req_t *gpreg_param_req_std[] = { - &ia32_default_req_ia32_general_purpose_eax, - &ia32_default_req_ia32_general_purpose_ecx, - &ia32_default_req_ia32_general_purpose_edx, - &ia32_default_req_ia32_general_purpose_ebx, - &ia32_default_req_ia32_general_purpose_edi, - &ia32_default_req_ia32_general_purpose_esi +static const arch_register_t *gpreg_param_reg_fastcall[] = { + &ia32_gp_regs[REG_ECX], + &ia32_gp_regs[REG_EDX], + NULL }; -const ia32_register_req_t *gpreg_param_req_this[] = { - &ia32_default_req_ia32_general_purpose_ecx, - &ia32_default_req_ia32_general_purpose_eax, - &ia32_default_req_ia32_general_purpose_edx, - &ia32_default_req_ia32_general_purpose_ebx, - &ia32_default_req_ia32_general_purpose_edi, - &ia32_default_req_ia32_general_purpose_esi +static const arch_register_t *gpreg_param_reg_regparam[] = { + &ia32_gp_regs[REG_EAX], + &ia32_gp_regs[REG_EDX], + &ia32_gp_regs[REG_ECX] }; -const ia32_register_req_t *fpreg_param_req_std[] = { - &ia32_default_req_ia32_floating_point_xmm0, - &ia32_default_req_ia32_floating_point_xmm1, - &ia32_default_req_ia32_floating_point_xmm2, - &ia32_default_req_ia32_floating_point_xmm3, - &ia32_default_req_ia32_floating_point_xmm4, - &ia32_default_req_ia32_floating_point_xmm5, - &ia32_default_req_ia32_floating_point_xmm6, - &ia32_default_req_ia32_floating_point_xmm7 +static const arch_register_t *gpreg_param_reg_this[] = { + &ia32_gp_regs[REG_ECX], + NULL, + NULL }; -const ia32_register_req_t *fpreg_param_req_this[] = { - NULL, /* in case of a "this" pointer, the first parameter must not be a float */ - &ia32_default_req_ia32_floating_point_xmm0, - &ia32_default_req_ia32_floating_point_xmm1, - &ia32_default_req_ia32_floating_point_xmm2, - &ia32_default_req_ia32_floating_point_xmm3, - &ia32_default_req_ia32_floating_point_xmm4, - &ia32_default_req_ia32_floating_point_xmm5, - &ia32_default_req_ia32_floating_point_xmm6, - &ia32_default_req_ia32_floating_point_xmm7 +static const arch_register_t *fpreg_sse_param_reg_std[] = { + &ia32_xmm_regs[REG_XMM0], + &ia32_xmm_regs[REG_XMM1], + &ia32_xmm_regs[REG_XMM2], + &ia32_xmm_regs[REG_XMM3], + &ia32_xmm_regs[REG_XMM4], + &ia32_xmm_regs[REG_XMM5], + &ia32_xmm_regs[REG_XMM6], + &ia32_xmm_regs[REG_XMM7] }; +static const arch_register_t *fpreg_sse_param_reg_this[] = { + NULL, /* in case of a "this" pointer, the first parameter must not be a float */ +}; /* Mapping to store registers in firm nodes */ @@ -70,6 +85,7 @@ struct ia32_irn_reg_assoc { int ia32_cmp_irn_reg_assoc(const void *a, const void *b, size_t len) { const struct ia32_irn_reg_assoc *x = a; const struct ia32_irn_reg_assoc *y = b; + (void) len; return x->irn != y->irn; } @@ -80,7 +96,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 = hash_irn(irn); return set_insert(reg_set, &templ, sizeof(templ), hash); } @@ -95,195 +111,83 @@ const arch_register_t *ia32_get_firm_reg(const ir_node *irn, set *reg_set) { return assoc->reg; } - - -/* Mapping to store proj numbers for registers */ - -struct ia32_reg_projnum_assoc { - const arch_register_t *reg; - long proj_num; -}; - -int ia32_cmp_reg_projnum_assoc(const void *a, const void *b, size_t len) { - const struct ia32_reg_projnum_assoc *x = a; - const struct ia32_reg_projnum_assoc *y = b; - - return !(x->reg == y->reg); -} - -static struct ia32_reg_projnum_assoc *get_reg_projnum_assoc(const arch_register_t *reg, set *reg_set) { - struct ia32_reg_projnum_assoc templ; - unsigned int hash; - - templ.reg = reg; - templ.proj_num = -1; - hash = HASH_PTR(reg); - - return set_insert(reg_set, &templ, sizeof(templ), hash); +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"); } -void ia32_set_reg_projnum(const arch_register_t *reg, long proj_num, set *reg_set) { - struct ia32_reg_projnum_assoc *assoc = get_reg_projnum_assoc(reg, reg_set); - assoc->proj_num = proj_num; +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"); } -long ia32_get_reg_projnum(const arch_register_t *reg, set *reg_set) { - struct ia32_reg_projnum_assoc *assoc = get_reg_projnum_assoc(reg, reg_set); - return assoc->proj_num; +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); - -/** - * 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 parameter list - * @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_node **params, int *n_int, int *n_float) { - int i, finished = 0; - - for (i = 0; i < n && !finished; i++) { - if (mode_is_int(get_irn_mode(params[i]))) { - *n_int = *n_int + 1; - } - else if (mode_is_float(get_irn_mode(params[i]))) { - *n_float = *n_float + 1; - } - else { - finished = 1; - } - - /* test for maximum */ - if (*n_int == maxnum_gpreg_args || *n_float == maxnum_fpreg_args) { - finished = 1; - } + //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 i - 1; + return e->value; } - /** - * Returns the register requirements for parameter nr. - * - * @param n The number of parameters - * @param modes The parameter list - * @param nr The number of the parameter to return the requirements for - * @param cc The calling convention - * @return The register requirements + * Returns the register for parameter nr. */ -const ia32_register_req_t *ia32_get_RegParam_req(int n, ir_node **params, long nr, unsigned cc) { - const ia32_register_req_t **current_gpreg_param_req; - const ia32_register_req_t **current_fpreg_param_req; - const ia32_register_req_t *param_req = 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, params, &n_gpregparam, &n_fpregparam); - - /* Check if parameter #nr is in range for passing in register */ - if (nr <= biggest_n) { - current_gpreg_param_req = gpreg_param_req_std; - current_fpreg_param_req = fpreg_param_req_std; +const arch_register_t *ia32_get_RegParam_reg(unsigned cc, size_t nr, + const ir_mode *mode) +{ + if (! (cc & cc_reg_param)) + return NULL; + + if (mode_is_float(mode)) { + if (!ia32_cg_config.use_sse2 || (cc & cc_fpreg_param) == 0) + return NULL; + if (nr >= MAXNUM_SSE_ARGS) + return NULL; if (cc & cc_this_call) { - current_gpreg_param_req = gpreg_param_req_this; - current_fpreg_param_req = fpreg_param_req_this; + return fpreg_sse_param_reg_this[nr]; } + return fpreg_sse_param_reg_std[nr]; + } else if (mode_is_int(mode) || mode_is_reference(mode)) { + unsigned num_regparam; - /* 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(get_irn_mode(params[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(get_irn_mode(params[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_req[cur_fp_idx] && "'this' pointer cannot be passed as float"); - cur_fp_idx++; - } - } + if (get_mode_size_bits(mode) > 32) + return NULL; - /* now: i == nr, that's the parameter requirement we want */ - if (mode_is_int(get_irn_mode(params[i])) && cur_gp_idx < maxnum_gpreg_args) { - /* parameter #nr can be passed in general purpose register */ - param_req = current_gpreg_param_req[i]; - } - else if (mode_is_float(get_irn_mode(params[i])) && cur_fp_idx < maxnum_fpreg_args) { - /* parameter #nr can be passed in floating point register */ - param_req = current_fpreg_param_req[i]; + if (nr >= MAXNUM_GPREG_ARGS) + return NULL; + + if (cc & cc_this_call) { + return gpreg_param_reg_this[nr]; } - else { - assert(0 && "This should not happen!"); + num_regparam = cc & ~cc_bits; + if (num_regparam == 0) { + /* default fastcall */ + return gpreg_param_reg_fastcall[nr]; } + if (nr < num_regparam) + return gpreg_param_reg_regparam[nr]; + return NULL; } - return param_req; -} - - - -/** - * 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 *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)) { - 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(0 && "unsupported Proj(X)"); - return nr; + panic("unknown argument mode"); }