2008-01-24 Zoltan Varga <vargaz@gmail.com>
+ * mini.h *.c: Change cfg->vars to contain the MonoMethodVar entries directly
+ instead of though a pointer to save an indirection when accessing elements of
+ the array.
+
* mini.h (MONO_IS_COND_BRANCH_OP): Move these macros here from mini.c. Fix
some typos.
(NOT_IMPLEMENTED): New helper macro.
area.relations [i].relation = MONO_EQ_RELATION;
area.relations [i].relation_is_static_definition = TRUE;
area.relations [i].next = NULL;
- if (cfg->vars [i]->def != NULL) {
- MonoInst *value = get_variable_value_from_store_instruction (cfg->vars [i]->def, i);
+ if (MONO_VARINFO (cfg, i)->def != NULL) {
+ MonoInst *value = get_variable_value_from_store_instruction (MONO_VARINFO (cfg, i)->def, i);
if (value != NULL) {
gboolean is_array_type;
MonoIntegerValueKind effective_value_kind;
int num = cfg->num_varinfo;
if ((num + 1) >= cfg->varinfo_count) {
+ int orig_count = cfg->varinfo_count;
cfg->varinfo_count = (cfg->varinfo_count + 2) * 2;
cfg->varinfo = (MonoInst **)g_realloc (cfg->varinfo, sizeof (MonoInst*) * cfg->varinfo_count);
- cfg->vars = (MonoMethodVar **)g_realloc (cfg->vars, sizeof (MonoMethodVar*) * cfg->varinfo_count);
+ cfg->vars = (MonoMethodVar *)g_realloc (cfg->vars, sizeof (MonoMethodVar) * cfg->varinfo_count);
+ memset (&cfg->vars [orig_count], 0, (cfg->varinfo_count - orig_count) * sizeof (MonoMethodVar));
}
/*g_print ("created temp %d of type 0x%x\n", num, type->type);*/
cfg->varinfo [num] = inst;
- cfg->vars [num] = mono_mempool_alloc0 (cfg->mempool, sizeof (MonoMethodVar));
- MONO_INIT_VARINFO (cfg->vars [num], num);
+ MONO_INIT_VARINFO (&cfg->vars [num], num);
cfg->num_varinfo++;
if (cfg->verbose_level > 2)
};
#undef OPDEF
-#define MONO_VARINFO(cfg,varnum) ((cfg)->vars [varnum])
+#define MONO_VARINFO(cfg,varnum) (&(cfg)->vars [varnum])
#define MONO_INST_NEW(cfg,dest,op) do { \
(dest) = mono_mempool_alloc0 ((cfg)->mempool, sizeof (MonoInst)); \
MonoMethod *method;
MonoMemPool *mempool;
MonoInst **varinfo;
- MonoMethodVar **vars;
+ MonoMethodVar *vars;
MonoInst *ret;
MonoBasicBlock *bb_entry;
MonoBasicBlock *bb_exit;
inst->inst_i0 = new_var;
#ifdef USE_ORIGINAL_VARS
- cfg->vars [new_var->inst_c0]->reg = idx;
+ MONO_VARINFO (cfg, new_var->inst_c0)->reg = idx;
#endif
stack [idx] = new_var;
(inst->inst_i0->opcode == OP_LOCAL || inst->inst_i0->opcode == OP_ARG)) {
MonoInst *new_var;
int idx = inst->inst_i0->inst_c0;
- MonoMethodVar *mv = cfg->vars [idx];
+ MonoMethodVar *mv = MONO_VARINFO (cfg, idx);
if (mv->reg != -1 && mv->reg != mv->idx) {
for (j = 0; j < bb->in_count; j++) {
MonoBasicBlock *pred = bb->in_bb [j];
int idx = phi->inst_phi_args [j + 1];
- MonoMethodVar *mv = cfg->vars [idx];
+ MonoMethodVar *mv = MONO_VARINFO (cfg, idx);
if (mv->reg != -1 && mv->reg != mv->idx) {
//printf ("PHICOPY %d %d -> %d\n", idx, mv->reg, inst->inst_i0->inst_c0);
}
for (i = 0; i < cfg->num_varinfo; ++i) {
- cfg->vars [i]->reg = -1;
+ MONO_VARINFO (cfg, i)->reg = -1;
if (!is_live [i]) {
cfg->varinfo [i]->flags |= MONO_INST_IS_DEAD;
}
if ((inst->ssa_op == MONO_SSA_STORE) &&
(inst->inst_i0->opcode == OP_LOCAL /*|| inst->inst_i0->opcode == OP_ARG */)) {
idx = inst->inst_i0->inst_c0;
- info = cfg->vars [idx];
+ info = MONO_VARINFO (cfg, idx);
//printf ("%d defined in BB%d %p\n", idx, bb->block_num, root);
if (info->def) {
g_warning ("more than one definition of variable %d in %s", idx,
for (i = inst->inst_i1->inst_phi_args [0]; i > 0; i--) {
MonoVarUsageInfo *ui = mono_mempool_alloc (cfg->mempool, sizeof (MonoVarUsageInfo));
idx = inst->inst_i1->inst_phi_args [i];
- info = cfg->vars [idx];
+ info = MONO_VARINFO (cfg, idx);
//printf ("FOUND %d\n", idx);
ui->bb = bb;
ui->inst = root;
(inst->inst_i0->opcode == OP_LOCAL || inst->inst_i0->opcode == OP_ARG)) {
MonoVarUsageInfo *ui = mono_mempool_alloc (cfg->mempool, sizeof (MonoVarUsageInfo));
idx = inst->inst_i0->inst_c0;
- info = cfg->vars [idx];
+ info = MONO_VARINFO (cfg, idx);
//printf ("FOUND %d\n", idx);
ui->bb = bb;
ui->inst = root;
MONO_BB_FOR_EACH_INS (bb, inst) {
if (inst->ssa_op == MONO_SSA_STORE && inst->inst_i0->opcode == OP_LOCAL &&
!IS_CALL (inst->inst_i1->opcode) && inst->inst_i1->opcode != OP_PHI && !inst->flags) {
- i1 = cfg->vars [inst->inst_i0->inst_c0];
+ i1 = MONO_VARINFO (cfg, inst->inst_i0->inst_c0);
/* fixme: compiling mcs does not work when I enable this */
#if 0
g_list_length (i1->uses) == 1 &&
inst->opcode == next->opcode &&
inst->inst_i0->type == next->inst_i0->type) {
- i2 = cfg->vars [next->inst_i0->inst_c0];
+ i2 = MONO_VARINFO (cfg, next->inst_i0->inst_c0);
//printf ("ELIM. COPY in BB%d %s\n", bb->block_num, mono_method_full_name (cfg->method, TRUE));
inst->inst_i0 = next->inst_i0;
i2->def = inst;
}
} else if (inst->ssa_op == MONO_SSA_STORE &&
(inst->inst_i0->opcode == OP_LOCAL || inst->inst_i0->opcode == OP_ARG)) {
- MonoMethodVar *info = cfg->vars [inst->inst_i0->inst_c0];
+ MonoMethodVar *info = MONO_VARINFO (cfg, inst->inst_i0->inst_c0);
MonoInst *i1 = inst->inst_i1;
int res;
int j;
for (j = 1; j <= i1->inst_phi_args [0]; j++) {
- MonoMethodVar *mv = cfg->vars [i1->inst_phi_args [j]];
+ MonoMethodVar *mv = MONO_VARINFO (cfg, i1->inst_phi_args [j]);
MonoInst *src = mv->def;
if (mv->def_bb && !(mv->def_bb->flags & BB_REACHABLE)) {
memset (carray, 0, sizeof (MonoInst *) * cfg->num_varinfo);
for (i = 0; i < cfg->num_varinfo; i++) {
- MonoMethodVar *info = cfg->vars [i];
+ MonoMethodVar *info = MONO_VARINFO (cfg, i);
if (!info->def)
info->cpstate = 2;
}
/* fixme: we should update usage infos during cprop, instead of computing it again */
cfg->comp_done &= ~MONO_COMP_SSA_DEF_USE;
for (i = 0; i < cfg->num_varinfo; i++) {
- MonoMethodVar *info = cfg->vars [i];
+ MonoMethodVar *info = MONO_VARINFO (cfg, i);
info->def = NULL;
info->uses = NULL;
}
work_list = NULL;
for (i = 0; i < cfg->num_varinfo; i++) {
- MonoMethodVar *info = cfg->vars [i];
+ MonoMethodVar *info = MONO_VARINFO (cfg, i);
work_list = g_list_prepend (work_list, info);
//if ((info->def != NULL) && (info->def->inst_i1->opcode != OP_PHI)) printf ("SSA DEADCE TOTAL LOCAL\n");
if (i1->opcode == OP_PHI) {
int j;
for (j = i1->inst_phi_args [0]; j > 0; j--) {
- MonoMethodVar *u = cfg->vars [i1->inst_phi_args [j]];
+ MonoMethodVar *u = MONO_VARINFO (cfg, i1->inst_phi_args [j]);
add_to_dce_worklist (cfg, info, u, &work_list);
}
} else if (i1->ssa_op == MONO_SSA_LOAD &&
(i1->inst_i0->opcode == OP_LOCAL || i1->inst_i0->opcode == OP_ARG)) {
- MonoMethodVar *u = cfg->vars [i1->inst_i0->inst_c0];
+ MonoMethodVar *u = MONO_VARINFO (cfg, i1->inst_i0->inst_c0);
add_to_dce_worklist (cfg, info, u, &work_list);
}
//if (i1->opcode != OP_PHI) printf ("SSA DEADCE DEAD LOCAL\n");
continue;
for (i = 0; i < cfg->num_varinfo; i++) {
- MonoMethodVar *info = cfg->vars [i];
+ MonoMethodVar *info = MONO_VARINFO (cfg, i);
if (info->def && info->def->ssa_op == MONO_SSA_STORE &&
info->def->inst_i0->opcode == OP_LOCAL && g_list_find (lp, info->def_bb)) {
result->left_argument = expression->left_argument;
} else {
result->left_argument.type = MONO_SSAPRE_EXPRESSION_ARGUMENT_ORIGINAL_VARIABLE;
- original_variable = cfg->vars [expression->left_argument.argument.ssa_variable]->reg;
+ original_variable = MONO_VARINFO (cfg, expression->left_argument.argument.ssa_variable)->reg;
if (original_variable >= 0) {
result->left_argument.argument.original_variable = original_variable;
} else {
result->right_argument = expression->right_argument;
} else {
result->right_argument.type = MONO_SSAPRE_EXPRESSION_ARGUMENT_ORIGINAL_VARIABLE;
- original_variable = cfg->vars [expression->right_argument.argument.ssa_variable]->reg;
+ original_variable = MONO_VARINFO (cfg, expression->right_argument.argument.ssa_variable)->reg;
if (original_variable >= 0) {
result->right_argument.argument.original_variable = original_variable;
} else {
* Given a variable index, checks if it is a phi definition
* (it assumes the "area" is visible).
*/
-#define IS_PHI_DEFINITION(v) is_phi_definition (area->cfg->vars [v]->def)
+#define IS_PHI_DEFINITION(v) is_phi_definition (MONO_VARINFO (area->cfg, v)->def)
/*
* Given a variable index, checks if it is a phi definition.
*/
static int*
get_phi_definition (MonoCompile *cfg, gssize variable) {
- MonoInst *definition = cfg->vars [variable]->def;
+ MonoInst *definition = MONO_VARINFO (cfg, variable)->def;
if (is_phi_definition (definition) && (definition->inst_left->inst_c0 == variable)) {
return definition->inst_right->inst_phi_args;
} else {
*/
static MonoSsapreBBInfo*
get_bb_info_of_definition (MonoSsapreWorkArea *area, gssize variable) {
- MonoBasicBlock *def_bb = area->cfg->vars [variable]->def_bb;
+ MonoBasicBlock *def_bb = MONO_VARINFO (area->cfg, variable)->def_bb;
if (def_bb != NULL) {
return area->bb_infos_in_cfg_dfn_order [def_bb->dfn];
} else {
if ((current_inst->inst_left->opcode == OP_LOCAL) || (current_inst->inst_left->opcode == OP_ARG)) {
int variable_index = current_inst->inst_left->inst_c0;
- if (area->cfg->vars [variable_index]->def_bb == NULL) {
+ if (MONO_VARINFO (area->cfg, variable_index)->def_bb == NULL) {
if (area->cfg->verbose_level >= 4) {
printf ("SSAPRE WARNING: variable %d has no definition, fixing.\n", variable_index);
}
- area->cfg->vars [variable_index]->def_bb = bb_info->bb;
+ MONO_VARINFO (area->cfg, variable_index)->def_bb = bb_info->bb;
}
}
break;
int* phi_definition = get_phi_definition (area->cfg, variable);
if (phi_definition != NULL) {
- int definition_bb = area->cfg->vars [variable]->def_bb->dfn;
+ int definition_bb = MONO_VARINFO (area->cfg, variable)->def_bb->dfn;
if (! mono_bitset_test (phi_bbs, definition_bb)) {
int i;
mono_bitset_set (phi_bbs, definition_bb);
if (original_variable_index == BOTTOM_REDUNDANCY_CLASS) {
original_variable_index = new_var->inst_c0;
}
- area->cfg->vars [new_var->inst_c0]->reg = original_variable_index;
- area->cfg->vars [new_var->inst_c0]->def_bb = current_bb->bb;
+ MONO_VARINFO (area->cfg, new_var->inst_c0)->reg = original_variable_index;
+ MONO_VARINFO (area->cfg, new_var->inst_c0)->def_bb = current_bb->bb;
} else {
current_bb->phi_variable_index = BOTTOM_REDUNDANCY_CLASS;
}
if (original_variable_index == BOTTOM_REDUNDANCY_CLASS) {
original_variable_index = new_var->inst_c0;
}
- area->cfg->vars [new_var->inst_c0]->reg = original_variable_index;
- area->cfg->vars [new_var->inst_c0]->def_bb = current_bb->bb;
+ MONO_VARINFO (area->cfg, new_var->inst_c0)->reg = original_variable_index;
+ MONO_VARINFO (area->cfg, new_var->inst_c0)->def_bb = current_bb->bb;
} else {
current_expression->variable_index = BOTTOM_REDUNDANCY_CLASS;
}
if (original_variable_index == BOTTOM_REDUNDANCY_CLASS) {
original_variable_index = new_var->inst_c0;
}
- area->cfg->vars [new_var->inst_c0]->reg = original_variable_index;
- area->cfg->vars [new_var->inst_c0]->def_bb = current_bb->bb;
+ MONO_VARINFO (area->cfg, new_var->inst_c0)->reg = original_variable_index;
+ MONO_VARINFO (area->cfg, new_var->inst_c0)->def_bb = current_bb->bb;
} else {
current_bb->phi_argument_variable_index = BOTTOM_REDUNDANCY_CLASS;
}
int in_bb;
NEW_INST (phi, OP_PHI);
- phi->inst_c0 = area->cfg->vars [current_bb->phi_variable_index]->reg;
+ phi->inst_c0 = MONO_VARINFO (area->cfg, current_bb->phi_variable_index)->reg;
phi->inst_phi_args = mono_mempool_alloc (area->cfg->mempool, (sizeof (int) * ((current_bb->in_count) + 1)));
phi->inst_phi_args [0] = current_bb->in_count;
for (in_bb = 0; in_bb < current_bb->in_count; in_bb++) {
MONO_INST_LIST_ADD (&store->node,
¤t_bb->bb->ins_list);
}
- area->cfg->vars [current_bb->phi_variable_index]->def = store;
+ MONO_VARINFO (area->cfg, current_bb->phi_variable_index)->def = store;
current_bb->phi_insertion_point = store;
area->added_phis ++;
MONO_INST_LIST_ADD (&store->node,
¤t_bb->bb->ins_list);
}
- area->cfg->vars [current_expression->variable_index]->def = store;
+ MONO_VARINFO (area->cfg, current_expression->variable_index)->def = store;
mono_compile_make_var_load (area->cfg, current_expression->occurrence, current_expression->variable_index);
if (current_expression->father_in_tree != NULL) {
handle_father_expression (area, current_expression, store);
inserted_expression = create_expression (area, &expression_description, &prototype_occurrence);
store = mono_compile_create_var_store (area->cfg, current_bb->phi_argument_variable_index, inserted_expression);
- area->cfg->vars [current_bb->phi_argument_variable_index]->def = store;
+ MONO_VARINFO (area->cfg, current_bb->phi_argument_variable_index)->def = store;
MONO_INST_LIST_INIT (&store->node);
mono_add_ins_to_end (current_bb->bb, store);