#include "../arch/archop.h" /* we need this for Min and Max nodes */
#include "ia32_transform.h"
#include "ia32_new_nodes.h"
+#include "ia32_map_regs.h"
#include "gen_ia32_regalloc_if.h"
extern ir_op *get_op_Mulh(void);
-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 const ia32_register_req_t **current_gpreg_param_req;
-static const ia32_register_req_t **current_fpreg_param_req;
-
-/* this is the order of the assigned registers usesd 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
-};
-
-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
-};
-
-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
-};
-
-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
-};
-
-/* this is a struct to minimize the number of parameters
- passed to each gen_xxx function */
-typedef struct _transform_env_t {
- const arch_env_t *arch_env; /**<< The arch_env */
- firm_dbg_module_t *mod; /**<< The firm debugger */
- dbg_info *dbg; /**<< The node debug info */
- ir_graph *irg; /**<< The irg, the node should be created in */
- ir_node *block; /**<< The block, the node should belong to */
- ir_node *irn; /**<< The irn, to be transformed */
- ir_mode *mode; /**<< The mode of the irn */
-} transform_env_t;
/****************************************************************************************************
* @param mode node mode
* @return the created ia23 Add_i node
*/
-static ir_node *gen_imm_Add(transform_env_t *env, ir_node *expr_op, ir_node *const_op) {
+static ir_node *gen_imm_Add(ia32_transform_env_t *env, ir_node *expr_op, ir_node *const_op) {
ir_node *new_op;
tarval *tv = get_ia32_Immop_tarval(const_op);
int normal_add = 0;
* @param mode node mode
* @return the created ia32 Add node
*/
-static ir_node *gen_Add(transform_env_t *env, ir_node *op1, ir_node *op2) {
+static ir_node *gen_Add(ia32_transform_env_t *env, ir_node *op1, ir_node *op2) {
ir_node *shli_op;
ir_node *expr_op;
ir_node *new_op;
int normal_add = 0;
- firm_dbg_module_t *mod = env->mod;
- dbg_info *dbg = env->dbg;
- ir_mode *mode = env->mode;
- ir_graph *irg = env->irg;
- ir_node *block = env->block;
+ dbg_info *dbg = env->dbg;
+ ir_mode *mode = env->mode;
+ ir_graph *irg = env->irg;
+ ir_node *block = env->block;
if (mode_is_float(mode)) {
return new_rd_ia32_fAdd(dbg, irg, block, op1, op2, mode);
* @param mul_flav flavour_Mul/Mulh
* @return The ready-to-go Mul node
*/
-ir_node *generate_Mul(transform_env_t *env, ir_node *op1, ir_node *op2, op_flavour_t mul_flav, int is_imm_op) {
+ir_node *generate_Mul(ia32_transform_env_t *env, ir_node *op1, ir_node *op2, op_flavour_t mul_flav, int is_imm_op) {
ir_node *in_keep[1], *res;
long pn_good, pn_bad;
dbg_info *dbg = env->dbg;
/* create the mul */
if (is_imm_op) {
mul = new_rd_ia32_Mul_i(dbg, irg, block, op1, mode_T);
- set_ia32_Immop_attr(res, op2);
+ set_ia32_Immop_attr(mul, op2);
}
else {
mul = new_rd_ia32_Mul(dbg, irg, block, op1, op2, mode_T);
* @param mode node mode
* @return the created ia23 Mul_i node
*/
-static ir_node *gen_imm_Mul(transform_env_t *env, ir_node *expr_op, ir_node *const_op) {
+static ir_node *gen_imm_Mul(ia32_transform_env_t *env, ir_node *expr_op, ir_node *const_op) {
/* Mul with immediate only possible with int, so we don't need to check for float */
return generate_Mul(env, expr_op, const_op, flavour_Mul, 1);
}
* @param mode node mode
* @return the created ia32 Mul node
*/
-ir_node *gen_Mul(transform_env_t *env, ir_node *op1, ir_node *op2) {
+ir_node *gen_Mul(ia32_transform_env_t *env, ir_node *op1, ir_node *op2) {
if (mode_is_float(env->mode)) {
return new_rd_ia32_fMul(env->dbg, env->irg, env->block, op1, op2, env->mode);
}
* @param mode node mode
* @return the created ia23 Mulh_i node
*/
-static ir_node *gen_imm_Mulh(transform_env_t *env, ir_node *expr_op, ir_node *const_op) {
+static ir_node *gen_imm_Mulh(ia32_transform_env_t *env, ir_node *expr_op, ir_node *const_op) {
return generate_Mul(env, expr_op, const_op, flavour_Mulh, 1);
}
* @param mode node mode
* @return the created ia32 Mulh node
*/
-static ir_node *gen_Mulh(transform_env_t *env, ir_node *op1, ir_node *op2) {
+static ir_node *gen_Mulh(ia32_transform_env_t *env, ir_node *op1, ir_node *op2) {
return generate_Mul(env, op1, op2, flavour_Mulh, 0);
}
* @param mode node mode
* @return the created ia23 And_i node
*/
-static ir_node *gen_imm_And(transform_env_t *env, ir_node *expr_op, ir_node *const_op) {
+static ir_node *gen_imm_And(ia32_transform_env_t *env, ir_node *expr_op, ir_node *const_op) {
return new_rd_ia32_And_i(env->dbg, env->irg, env->block, expr_op, env->mode);
}
* @param mode node mode
* @return the created ia32 And node
*/
-static ir_node *gen_And(transform_env_t *env, ir_node *op1, ir_node *op2) {
+static ir_node *gen_And(ia32_transform_env_t *env, ir_node *op1, ir_node *op2) {
return new_rd_ia32_And(env->dbg, env->irg, env->block, op1, op2, env->mode);
}
* @param mode node mode
* @return the created ia23 Or_i node
*/
-static ir_node *gen_imm_Or(transform_env_t *env, ir_node *expr_op, ir_node *const_op) {
+static ir_node *gen_imm_Or(ia32_transform_env_t *env, ir_node *expr_op, ir_node *const_op) {
return new_rd_ia32_Or_i(env->dbg, env->irg, env->block, expr_op, env->mode);
}
* @param mode node mode
* @return the created ia32 Or node
*/
-static ir_node *gen_Or(transform_env_t *env, ir_node *op1, ir_node *op2) {
+static ir_node *gen_Or(ia32_transform_env_t *env, ir_node *op1, ir_node *op2) {
return new_rd_ia32_Or(env->dbg, env->irg, env->block, op1, op2, env->mode);
}
* @param mode node mode
* @return the created ia23 Eor_i node
*/
-static ir_node *gen_imm_Eor(transform_env_t *env, ir_node *expr_op, ir_node *const_op) {
+static ir_node *gen_imm_Eor(ia32_transform_env_t *env, ir_node *expr_op, ir_node *const_op) {
return new_rd_ia32_Eor_i(env->dbg, env->irg, env->block, expr_op, env->mode);
}
* @param mode node mode
* @return the created ia32 Eor node
*/
-static ir_node *gen_Eor(transform_env_t *env, ir_node *op1, ir_node *op2) {
+static ir_node *gen_Eor(ia32_transform_env_t *env, ir_node *op1, ir_node *op2) {
return new_rd_ia32_Eor(env->dbg, env->irg, env->block, op1, op2, env->mode);
}
* @param mode node mode
* @return the created ia23 Max node
*/
-static ir_node *gen_Max(transform_env_t *env, ir_node *op1, ir_node *op2) {
+static ir_node *gen_Max(ia32_transform_env_t *env, ir_node *op1, ir_node *op2) {
return new_rd_ia32_Max(env->dbg, env->irg, env->block, op1, op2, env->mode);
}
* @param mode node mode
* @return the created ia23 Min node
*/
-static ir_node *gen_Min(transform_env_t *env, ir_node *op1, ir_node *op2) {
+static ir_node *gen_Min(ia32_transform_env_t *env, ir_node *op1, ir_node *op2) {
return new_rd_ia32_Min(env->dbg, env->irg, env->block, op1, op2, env->mode);
}
* @param mode node mode
* @return the created ia23 Sub_i node
*/
-static ir_node *gen_imm_Sub(transform_env_t *env, ir_node *expr_op, ir_node *const_op) {
+static ir_node *gen_imm_Sub(ia32_transform_env_t *env, ir_node *expr_op, ir_node *const_op) {
ir_node *new_op;
tarval *tv = get_ia32_Immop_tarval(const_op);
int normal_sub = 0;
* @param mode node mode
* @return the created ia32 Sub node
*/
-static ir_node *gen_Sub(transform_env_t *env, ir_node *op1, ir_node *op2) {
+static ir_node *gen_Sub(ia32_transform_env_t *env, ir_node *op1, ir_node *op2) {
if (mode_is_float(env->mode)) {
return new_rd_ia32_fSub(env->dbg, env->irg, env->block, op1, op2, env->mode);
}
* @param dm_flav flavour_Div/Mod/DivMod
* @return The created ia32 DivMod node
*/
-static ir_node *generate_DivMod(transform_env_t *env, ir_node *dividend, ir_node *divisor, op_flavour_t dm_flav) {
+static ir_node *generate_DivMod(ia32_transform_env_t *env, ir_node *dividend, ir_node *divisor, op_flavour_t dm_flav) {
ir_node *res, *proj;
ir_node *edx_node, *cltd;
ir_node *in_keep[1];
/**
* Wrapper for generate_DivMod. Sets flavour_Mod.
*/
-static ir_node *gen_Mod(transform_env_t *env, ir_node *op1, ir_node *op2) {
+static ir_node *gen_Mod(ia32_transform_env_t *env, ir_node *op1, ir_node *op2) {
return generate_DivMod(env, op1, op2, flavour_Mod);
}
/**
* Wrapper for generate_DivMod. Sets flavour_Div.
*/
-static ir_node *gen_Div(transform_env_t *env, ir_node *op1, ir_node *op2) {
+static ir_node *gen_Div(ia32_transform_env_t *env, ir_node *op1, ir_node *op2) {
return generate_DivMod(env, op1, op2, flavour_Div);
}
/**
* Wrapper for generate_DivMod. Sets flavour_DivMod.
*/
-static ir_node *gen_DivMod(transform_env_t *env, ir_node *op1, ir_node *op2) {
+static ir_node *gen_DivMod(ia32_transform_env_t *env, ir_node *op1, ir_node *op2) {
return generate_DivMod(env, op1, op2, flavour_DivMod);
}
* @param mode node mode
* @return the created ia32 fDiv node
*/
-static ir_node *gen_Quot(transform_env_t *env, ir_node *op1, ir_node *op2) {
+static ir_node *gen_Quot(ia32_transform_env_t *env, ir_node *op1, ir_node *op2) {
return new_rd_ia32_fDiv(env->dbg, env->irg, env->block, op1, op2, env->mode);
}
* @param mode node mode
* @return the created ia23 Shl_i node
*/
-static ir_node *gen_imm_Shl(transform_env_t *env, ir_node *expr_op, ir_node *const_op) {
+static ir_node *gen_imm_Shl(ia32_transform_env_t *env, ir_node *expr_op, ir_node *const_op) {
return new_rd_ia32_Shl_i(env->dbg, env->irg, env->block, expr_op, env->mode);
}
* @param mode node mode
* @return the created ia32 Shl node
*/
-static ir_node *gen_Shl(transform_env_t *env, ir_node *op1, ir_node *op2) {
+static ir_node *gen_Shl(ia32_transform_env_t *env, ir_node *op1, ir_node *op2) {
return new_rd_ia32_Shl(env->dbg, env->irg, env->block, op1, op2, env->mode);
}
* @param mode node mode
* @return the created ia23 Shr_i node
*/
-static ir_node *gen_imm_Shr(transform_env_t *env, ir_node *expr_op, ir_node *const_op) {
+static ir_node *gen_imm_Shr(ia32_transform_env_t *env, ir_node *expr_op, ir_node *const_op) {
return new_rd_ia32_Shr_i(env->dbg, env->irg, env->block, expr_op, env->mode);
}
* @param mode node mode
* @return the created ia32 Shr node
*/
-static ir_node *gen_Shr(transform_env_t *env, ir_node *op1, ir_node *op2) {
+static ir_node *gen_Shr(ia32_transform_env_t *env, ir_node *op1, ir_node *op2) {
return new_rd_ia32_Shr(env->dbg, env->irg, env->block, op1, op2, env->mode);
}
* @param mode node mode
* @return the created ia23 Shrs_i node
*/
-static ir_node *gen_imm_Shrs(transform_env_t *env, ir_node *expr_op, ir_node *const_op) {
+static ir_node *gen_imm_Shrs(ia32_transform_env_t *env, ir_node *expr_op, ir_node *const_op) {
return new_rd_ia32_Shrs_i(env->dbg, env->irg, env->block, expr_op, env->mode);
}
* @param mode node mode
* @return the created ia32 Shrs node
*/
-static ir_node *gen_Shrs(transform_env_t *env, ir_node *op1, ir_node *op2) {
+static ir_node *gen_Shrs(ia32_transform_env_t *env, ir_node *op1, ir_node *op2) {
return new_rd_ia32_Shrs(env->dbg, env->irg, env->block, op1, op2, env->mode);
}
* @param mode node mode
* @return the created ia32 RotL node
*/
-static ir_node *gen_RotL(transform_env_t *env, ir_node *op1, ir_node *op2) {
+static ir_node *gen_RotL(ia32_transform_env_t *env, ir_node *op1, ir_node *op2) {
return new_rd_ia32_RotL(env->dbg, env->irg, env->block, op1, op2, env->mode);
}
* @param mode node mode
* @return the created ia32 RotR node
*/
-static ir_node *gen_RotR(transform_env_t *env, ir_node *op1, ir_node *op2) {
+static ir_node *gen_RotR(ia32_transform_env_t *env, ir_node *op1, ir_node *op2) {
return new_rd_ia32_RotR(env->dbg, env->irg, env->block, op1, op2, env->mode);
}
* @param mode node mode
* @return the created ia32 RotL node
*/
-static ir_node *gen_imm_Rot(transform_env_t *env, ir_node *expr_op, ir_node *const_op) {
+static ir_node *gen_imm_Rot(ia32_transform_env_t *env, ir_node *expr_op, ir_node *const_op) {
return new_rd_ia32_RotL_i(env->dbg, env->irg, env->block, expr_op, env->mode);
}
* @param mode node mode
* @return the created ia32 RotL or RotR node
*/
-static ir_node *gen_Rot(transform_env_t *env, ir_node *op1, ir_node *op2) {
+static ir_node *gen_Rot(ia32_transform_env_t *env, ir_node *op1, ir_node *op2) {
ir_node *rotate = NULL;
/* Firm has only Rot (which is a RotL), so we are looking for a right (op2)
* @param com flag if op is commutative
* @return the created assembler node
*/
-static ir_node *gen_arith_Op(transform_env_t *env, ir_node *op1, ir_node *op2, int com) {
+static ir_node *gen_arith_Op(ia32_transform_env_t *env, ir_node *op1, ir_node *op2, int com) {
firm_dbg_module_t *mod = env->mod;
- dbg_info *dbg = env->dbg;
ir_node *node = env->irn;
ir_node *imm_op = NULL;
ir_node *expr_op = NULL;
* @param mode node mode
* @return the created ia32 Minus node
*/
-static ir_node *gen_Minus(transform_env_t *env, ir_node *op) {
+static ir_node *gen_Minus(ia32_transform_env_t *env, ir_node *op) {
if (is_ia32_Minus(op) || is_ia32_fMinus(op)) {
DBG((env->mod, LEVEL_1, "optimizing --(e) to e ..."));
return get_irn_n(op, 0);
* @param mode node mode
* @return the created ia32 Conv node
*/
-static ir_node *gen_Conv(transform_env_t *env, ir_node *op) {
+static ir_node *gen_Conv(ia32_transform_env_t *env, ir_node *op) {
return new_rd_ia32_Conv(env->dbg, env->irg, env->block, op, env->mode);
}
* @param mode node mode
* @return the created ia32 Not node
*/
-static ir_node *gen_Not(transform_env_t *env, ir_node *op) {
+static ir_node *gen_Not(ia32_transform_env_t *env, ir_node *op) {
return new_rd_ia32_Not(env->dbg, env->irg, env->block, op, env->mode);
}
* @param mode node mode
* @return the created ia32 Abs node
*/
-static ir_node *gen_Abs(transform_env_t *env, ir_node *op) {
- ir_node *res, *p_eax, *p_edx;
- firm_dbg_module_t *mod = env->mod;
- dbg_info *dbg = env->dbg;
- ir_mode *mode = env->mode;
- ir_graph *irg = env->irg;
- ir_node *block = env->block;
+static ir_node *gen_Abs(ia32_transform_env_t *env, ir_node *op) {
+ ir_node *res, *p_eax, *p_edx;
+ dbg_info *dbg = env->dbg;
+ ir_mode *mode = env->mode;
+ ir_graph *irg = env->irg;
+ ir_node *block = env->block;
res = new_rd_ia32_Cltd(dbg, irg, block, op, mode_T);
p_eax = new_rd_Proj(dbg, irg, block, res, mode, pn_EAX);
* @param mode node mode
* @return the created ia32 Load node
*/
-static ir_node *gen_Load(transform_env_t *env) {
+static ir_node *gen_Load(ia32_transform_env_t *env) {
ir_node *node = env->irn;
if (mode_is_float(env->mode)) {
* @param mode node mode
* @return the created ia32 Store node
*/
-ir_node *gen_Store(transform_env_t *env) {
+ir_node *gen_Store(ia32_transform_env_t *env) {
ir_node *node = env->irn;
if (mode_is_float(env->mode)) {
-/**
- * Check all parameters and determine the maximum number of parameters
- * to pass in gp regs resp. in fp regs.
- */
-static void get_n_regparam_class(int n, ir_node **param, int *n_int, int *n_float) {
- int i;
-
- for (i = 0; i < n; i++) {
- if (mode_is_int(get_irn_mode(param[i])))
- *n_int = *n_int + 1;
- else if (mode_is_float(get_irn_mode(param[i])))
- *n_float = *n_float + 1;
-
- /* test for maximum */
- if (*n_int == maxnum_gpreg_args)
- break;
-
- if (*n_float == maxnum_fpreg_args)
- break;
- }
-}
-
/**
* Transforms a Call and its arguments corresponding to the calling convention.
*
* @param dummy mode doesn't matter
* @return the created ia32 Call node
*/
-static ir_node *gen_Call(transform_env_t *env) {
+static ir_node *gen_Call(ia32_transform_env_t *env) {
const ia32_register_req_t **in_req;
ir_node **in;
ir_node *new_call, *sync;
- ir_mode *mode;
- int i, j, n_new_call_in;
+ int i, j, n_new_call_in, ignore = 0;
asmop_attr *attr;
- firm_dbg_module_t *mod = env->mod;
dbg_info *dbg = env->dbg;
ir_graph *irg = env->irg;
ir_node *block = env->block;
ir_node *call_Mem = get_Call_mem(call);
unsigned cc = get_method_calling_convention(get_Call_type(call));
int n = get_Call_n_params(call);
- int n_gpregparam = 0;
- int n_fpregparam = 0;
- int cur_gp_idx = 0;
- int cur_fp_idx = 0;
int stack_idx = 0;
- int done = 0;
+ int biggest_n = -1;
if (cc & cc_reg_param)
- get_n_regparam_class(n, param, &n_gpregparam, &n_fpregparam);
+ biggest_n = ia32_get_n_regparam_class(n, param, &ignore, &ignore);
+
+ /* remember: biggest_n = x means we can pass (x + 1) parameters in register */
/* do we need to pass arguments on stack? */
- if (n - n_gpregparam - n_fpregparam > 0)
- stack_param = calloc(n - n_gpregparam - n_fpregparam, sizeof(ir_node *));
+ if (biggest_n + 1 < n)
+ stack_param = calloc(n - biggest_n - 1, sizeof(ir_node *));
/* we need at least one in, either for the stack params or the call_Mem */
- n_new_call_in = 1 + n_gpregparam + n_fpregparam;
-
- current_gpreg_param_req = gpreg_param_req_std;
- current_fpreg_param_req = fpreg_param_req_std;
-
- if (cc & cc_this_call) {
- current_gpreg_param_req = gpreg_param_req_this;
- current_fpreg_param_req = fpreg_param_req_this;
- }
+ n_new_call_in = biggest_n + 2;
/* the call has one IN for all stack parameter and one IN for each reg param */
in = calloc(n_new_call_in, sizeof(ir_node *));
in_req = calloc(n_new_call_in, sizeof(arch_register_req_t *));
- /* loop over all parameters and determine whether its a int or float register parameter */
- for (i = 0; i < n && !done && (cc & cc_reg_param); i++) {
- mode = get_irn_mode(param[i]);
-
- if (mode_is_int(mode) && cur_gp_idx < maxnum_gpreg_args) {
- /* param can be passed in general purpose register and we have some registers left */
- in[cur_gp_idx + cur_fp_idx] = param[i];
- in_req[cur_gp_idx] = current_gpreg_param_req[cur_gp_idx];
- cur_gp_idx++;
- }
- else if (mode_is_float(mode) && 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");
- in[cur_gp_idx + cur_fp_idx] = param[i];
- in_req[cur_fp_idx] = current_gpreg_param_req[cur_fp_idx];
- cur_fp_idx++;
- }
-
- /* maximum number of register parameters in one class reached? */
- if (cur_gp_idx >= maxnum_gpreg_args || cur_fp_idx >= maxnum_fpreg_args) {
- done = 1;
- }
+ /* loop over all parameters and set the register requirements */
+ for (i = 0; i <= biggest_n && (cc & cc_reg_param); i++) {
+ in_req[i] = ia32_get_RegParam_req(n, param, i, cc);
}
stack_idx = i;
}
if (stack_param) {
- sync = new_r_Sync(irg, block, n - n_gpregparam - n_fpregparam, stack_param);
+ sync = new_r_Sync(irg, block, n - biggest_n - 1, stack_param);
in[n_new_call_in - 1] = sync;
}
else {
/* set register requirements for in and out */
attr = get_ia32_attr(new_call);
attr->in_req = in_req;
- attr->out_req = calloc(1, sizeof(ia32_register_req_t *));
+ attr->out_req = calloc(2, sizeof(ia32_register_req_t *));
attr->out_req[0] = &ia32_default_req_ia32_general_purpose_eax;
- attr->slots = calloc(1, sizeof(arch_register_t *));
+ attr->out_req[1] = &ia32_default_req_ia32_general_purpose_edx;
+ attr->slots = calloc(2, sizeof(arch_register_t *));
/* stack parameter has no OUT register */
attr->in_req[n_new_call_in - 1] = &ia32_default_req_none;
-/**
- * creates a unique ident by adding a number to a tag
- *
- * @param tag the tag string, must contain a %d if a number
- * should be added
- */
-static ident *unique_id(const char *tag)
-{
- static unsigned id = 0;
- char str[256];
-
- snprintf(str, sizeof(str), tag, ++id);
- return new_id_from_str(str);
-}
-
-/**
- * Transforms a SymConst.
- *
- * @param mod the debug module
- * @param block the block the new node should belong to
- * @param node the ir SymConst node
- * @param mode mode of the SymConst
- * @return the created ia32 Const node
- */
-static ir_node *gen_SymConst(transform_env_t *env) {
- ir_node *cnst;
- firm_dbg_module_t *mod = env->mod;
- dbg_info *dbg = env->dbg;
- ir_mode *mode = env->mode;
- ir_graph *irg = env->irg;
- ir_node *block = env->block;
-
- if (mode_is_float(mode)) {
- cnst = new_rd_ia32_fConst(dbg, irg, block, mode);
-
- }
- else {
- cnst = new_rd_ia32_Const(dbg, irg, block, mode);
- }
-
- set_ia32_Const_attr(cnst, env->irn);
- return cnst;
-}
-
-/**
- * Transforms a Const.
- *
- * @param mod the debug module
- * @param block the block the new node should belong to
- * @param node the ir Const node
- * @param mode mode of the Const
- * @return the created ia32 Const node
- */
-static ir_node *gen_Const(transform_env_t *env) {
- ir_node *cnst;
- entity *ent;
- type *tp;
- symconst_symbol sym;
- firm_dbg_module_t *mod = env->mod;
- dbg_info *dbg = env->dbg;
- ir_mode *mode = env->mode;
- ir_graph *irg = env->irg;
- ir_node *block = env->block;
- ir_node *node = env->irn;
-
- if (mode_is_float(mode)) {
- tp = get_Const_type(node);
- if (tp == firm_unknown_type) {
- tp = new_type_primitive(unique_id("tp_ia32_float_%u"), mode);
- }
-
- ent = new_entity(get_glob_type(), unique_id("ia32FloatCnst_%u"), tp);
-
- set_entity_ld_ident(ent, get_entity_ident(ent));
- set_entity_visibility(ent, visibility_local);
- set_entity_variability(ent, variability_constant);
- set_entity_allocation(ent, allocation_static);
-
- set_atomic_ent_value(ent, node);
-
- sym.entity_p = ent;
-
- cnst = new_rd_SymConst(dbg, irg, block, sym, symconst_addr_ent);
- env->irn = cnst;
- cnst = gen_SymConst(env);
- }
- else {
- cnst = new_rd_ia32_Const(dbg, irg, block, mode);
- set_ia32_Const_attr(cnst, node);
- }
-
- return cnst;
-}
-
-
-
/**
* Transforms a Cond -> Proj[b] -> Cmp into a CondJmp or CondJmp_i
*
* @param mode mode of the Cond
* @return The transformed node.
*/
-static ir_node *gen_Cond(transform_env_t *env) {
- firm_dbg_module_t *mod = env->mod;
+static ir_node *gen_Cond(ia32_transform_env_t *env) {
dbg_info *dbg = env->dbg;
- ir_mode *mode = env->mode;
ir_graph *irg = env->irg;
ir_node *block = env->block;
ir_node *node = env->irn;
* @param start the Start node
* @return Should be always NULL
*/
-static ir_node *gen_Proj_Start(transform_env_t *env, ir_node *proj, ir_node *start) {
+static ir_node *gen_Proj_Start(ia32_transform_env_t *env, ir_node *proj, ir_node *start) {
+ const ia32_register_req_t *temp_req;
const ir_edge_t *edge;
ir_node *succ, *irn;
ir_node **projargs;
unsigned cc;
ir_node *proj_M = get_irg_initial_mem(current_ir_graph);
entity *irg_ent = get_irg_entity(current_ir_graph);
- type *tp = get_entity_type(irg_ent);
- int cur_gp_idx = 0;
- int cur_fp_idx = 0;
- int stack_idx = 0;
- int done = 0;
- firm_dbg_module_t *mod = env->mod;
- dbg_info *dbg = env->dbg;
+ ir_type *tp = get_entity_type(irg_ent);
+ int cur_pn = 0;
ir_graph *irg = env->irg;
ir_node *block = env->block;
be variadic or one argument is not used. */
n = get_irn_n_edges(proj);
+ /* Allocate memory for all non variadic parameters in advance to be on the save side */
+ env->cg->reg_param_req = calloc(get_method_n_params(tp), sizeof(ia32_register_req_t *));
+
/* we are done here when there are no parameters */
if (n < 1)
break;
cc = get_method_calling_convention(tp);
- /* get the correct order in case of 'this' call */
- current_gpreg_param_req = gpreg_param_req_std;
- current_fpreg_param_req = fpreg_param_req_std;
- if (cc & cc_this_call) {
- current_gpreg_param_req = gpreg_param_req_this;
- current_fpreg_param_req = fpreg_param_req_this;
- }
-
/* loop over all parameters and check whether its a int or float */
- for (i = 0; i < n && !done && (cc & cc_reg_param); i++) {
- mode = get_irn_mode(projargs[i]);
-
- if (mode_is_int(mode) && cur_gp_idx < maxnum_gpreg_args) {
- /* parameter got passed in general purpose register */
- irn = new_rd_ia32_RegParam(get_irn_dbg_info(proj), irg, block, proj, mode);
- set_ia32_pncode(irn, get_Proj_proj(projargs[i]));
- set_ia32_req_out(irn, current_gpreg_param_req[cur_gp_idx], 0);
- cur_gp_idx++;
+ for (i = 0; i < n; i++) {
+ mode = get_irn_mode(projargs[i]);
+ cur_pn = get_Proj_proj(projargs[i]);
+
+ if (cc & cc_reg_param) {
+ temp_req = ia32_get_RegParam_req(n, projargs, cur_pn, cc);
}
- else if (mode_is_float(mode) && cur_fp_idx < maxnum_fpreg_args) {
- /* parameter got passed in floating point register*/
- irn = new_rd_ia32_RegParam(get_irn_dbg_info(proj), irg, block, proj, mode);
- set_ia32_pncode(irn, get_Proj_proj(projargs[i]));
- set_ia32_req_out(irn, current_fpreg_param_req[cur_fp_idx], 0);
- cur_fp_idx++;
+ else {
+ temp_req = NULL;
}
- /* kill the old "Proj Arg" and replace with the new Arg */
- exchange(projargs[i], irn);
-
- if (cur_gp_idx >= maxnum_gpreg_args || cur_fp_idx >= maxnum_fpreg_args) {
- stack_idx = i;
- done = 1;
+ if (temp_req) {
+ /* passed in register */
+ env->cg->reg_param_req[cur_pn] = temp_req;
}
- }
-
- /* create all remaining stack parameters */
- for (i = stack_idx; i < n; i++) {
- mode = get_irn_mode(projargs[i]);
-
- if (mode_is_float(mode))
- irn = new_rd_ia32_fStackParam(get_irn_dbg_info(projargs[i]), irg, block, proj_M, mode);
- else
- irn = new_rd_ia32_StackParam(get_irn_dbg_info(projargs[i]), irg, block, proj_M, mode);
+ else {
+ /* passed on stack */
+ if (mode_is_float(mode))
+ irn = new_rd_ia32_fStackParam(get_irn_dbg_info(projargs[i]), irg, block, proj_M, mode);
+ else
+ irn = new_rd_ia32_StackParam(get_irn_dbg_info(projargs[i]), irg, block, proj_M, mode);
- set_ia32_pncode(irn, get_Proj_proj(projargs[i]));
+ set_ia32_pncode(irn, cur_pn);
- /* kill the old "Proj Arg" and replace with the new stack param */
- exchange(projargs[i], irn);
+ /* kill the old "Proj Arg" and replace with the new stack param */
+ exchange(projargs[i], irn);
+ }
}
free(projargs);
break;
+ case pn_Start_P_frame_base:
case pn_Start_X_initial_exec:
case pn_Start_M:
- case pn_Start_P_frame_base:
case pn_Start_P_globals:
case pn_Start_P_value_arg_base:
break;
* @param mode mode of the Proj
* @return The transformed node.
*/
-static ir_node *gen_Proj(transform_env_t *env) {
+static ir_node *gen_Proj(ia32_transform_env_t *env) {
ir_node *new_node = NULL;
ir_node *pred = get_Proj_pred(env->irn);
ia32_code_gen_t *cgenv = (ia32_code_gen_t *)env;
opcode code = get_irn_opcode(node);
ir_node *asm_node = NULL;
- transform_env_t tenv;
+ ia32_transform_env_t tenv;
if (is_Block(node))
return;
tenv.irn = node;
tenv.mod = cgenv->mod;
tenv.mode = get_irn_mode(node);
+ tenv.cg = cgenv;
#define UNOP(a) case iro_##a: asm_node = gen_##a(&tenv, get_##a##_op(node)); break
#define BINOP(a) case iro_##a: asm_node = gen_##a(&tenv, get_##a##_left(node), get_##a##_right(node)); break
GEN(Load);
GEN(Store);
GEN(Call);
- GEN(Const);
- GEN(SymConst);
GEN(Cond);
GEN(Proj);
IGN(IJmp);
IGN(Break);
IGN(Cmp);
+ IGN(Unknown);
+ /* constant transformation happens earlier */
+ IGN(Const);
+ IGN(SymConst);
+ BAD(Alloc);
BAD(Raise);
BAD(Sel);
BAD(InstOf);
BAD(Cast);
- BAD(Alloc);
BAD(Free);
BAD(Sync);
BAD(Tuple);
BAD(Id);
BAD(Bad);
BAD(Confirm);
- BAD(Unknown);
BAD(Filter);
BAD(CallBegin);
BAD(EndReg);