X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Fmini%2Fabcremoval.c;h=8a9349d293d1467718f93e1796c44f2b8c005307;hb=7f23a0c1f3b357cea793f429b52a918f45157855;hp=0e84305fa7b2a973dacef3119d3676ebb18456e4;hpb=9e1f34dd2d7be45b2a3a6b1c133a4a1de8c3d864;p=mono.git diff --git a/mono/mini/abcremoval.c b/mono/mini/abcremoval.c index 0e84305fa7b..8a9349d293d 100644 --- a/mono/mini/abcremoval.c +++ b/mono/mini/abcremoval.c @@ -14,6 +14,8 @@ #include #include +#include + #ifndef DISABLE_JIT #include "abcremoval.h" @@ -314,6 +316,13 @@ get_relation_from_ins (MonoVariableRelationsEvaluationArea *area, MonoInst *ins, value->type = MONO_VARIABLE_SUMMARIZED_VALUE; value->value.variable.variable = ins->sreg1; value->value.variable.delta = 0; + area->defs [ins->dreg] = ins; + break; + case OP_LDADDR: + /* The result is non-null */ + result->relation = MONO_GT_RELATION; + value->type = MONO_CONSTANT_SUMMARIZED_VALUE; + value->value.constant.value = 0; break; /* FIXME: Add more opcodes */ @@ -997,6 +1006,34 @@ remove_abc_from_inst (MonoInst *ins, MonoVariableRelationsEvaluationArea *area) } } +static gboolean +eval_non_null (MonoVariableRelationsEvaluationArea *area, int reg) +{ + MonoRelationsEvaluationContext *context = &(area->contexts [reg]); + + clean_contexts (area->contexts, area->cfg->next_vreg); + evaluate_relation_with_target_variable (area, reg, reg, NULL); + + return context->ranges.zero.lower > 0; +} + +static void +add_non_null (MonoVariableRelationsEvaluationArea *area, MonoCompile *cfg, int reg, + GSList **check_relations) +{ + MonoAdditionalVariableRelation *rel; + + rel = mono_mempool_alloc0 (cfg->mempool, sizeof (MonoAdditionalVariableRelation)); + rel->variable = reg; + rel->relation.relation = MONO_GT_RELATION; + rel->relation.related_value.type = MONO_CONSTANT_SUMMARIZED_VALUE; + rel->relation.related_value.value.constant.value = 0; + + apply_change_to_evaluation_area (area, rel); + + *check_relations = g_slist_append_mempool (cfg->mempool, *check_relations, rel); +} + /* * Process a BB removing bounds checks from array accesses. * It does the following (in sequence): @@ -1087,28 +1124,57 @@ process_block (MonoCompile *cfg, MonoBasicBlock *bb, MonoVariableRelationsEvalua } if (ins->opcode == OP_CHECK_THIS) { - MonoRelationsEvaluationContext *context = &(area->contexts [ins->sreg1]); - - clean_contexts (area->contexts, area->cfg->next_vreg); - evaluate_relation_with_target_variable (area, ins->sreg1, ins->sreg1, NULL); - - if (context->ranges.zero.lower > 0) { + if (eval_non_null (area, ins->sreg1)) { if (REPORT_ABC_REMOVAL) printf ("ARRAY-ACCESS: removed check_this instruction.\n"); NULLIFY_INS (ins); } } - if (ins->opcode == OP_NOT_NULL) { - rel = mono_mempool_alloc0 (cfg->mempool, sizeof (MonoAdditionalVariableRelation)); - rel->variable = ins->sreg1; - rel->relation.relation = MONO_GT_RELATION; - rel->relation.related_value.type = MONO_CONSTANT_SUMMARIZED_VALUE; - rel->relation.related_value.value.constant.value = 0; + if (ins->opcode == OP_NOT_NULL) + add_non_null (area, cfg, ins->sreg1, &check_relations); - apply_change_to_evaluation_area (area, rel); - - check_relations = g_slist_append_mempool (cfg->mempool, check_relations, rel); + /* + * FIXME: abcrem equates an array with its length, + * so a = new int [100] implies a != null, but a = new int [0] doesn't. + */ + /* + * Eliminate MONO_INST_FAULT flags if possible. + */ + if (COMPILE_LLVM (cfg) && (ins->opcode == OP_LDLEN || + ins->opcode == OP_BOUNDS_CHECK || + ins->opcode == OP_STRLEN || + (MONO_IS_LOAD_MEMBASE (ins) && (ins->flags & MONO_INST_FAULT)) || + (MONO_IS_STORE_MEMBASE (ins) && (ins->flags & MONO_INST_FAULT)))) { + int reg; + + if (MONO_IS_STORE_MEMBASE (ins)) + reg = ins->inst_destbasereg; + else if (MONO_IS_LOAD_MEMBASE (ins)) + reg = ins->inst_basereg; + else + reg = ins->sreg1; + + /* + * This doesn't work because LLVM can move the non-faulting loads before the faulting + * ones (test_0_llvm_moving_faulting_loads ()). + * So only do it if we know the load cannot be moved before the instruction which ensures it is not + * null (i.e. the def of its sreg). + */ + if (area->defs [reg] && area->defs [reg]->opcode == OP_NEWARR) { + if (REPORT_ABC_REMOVAL) + printf ("ARRAY-ACCESS: removed MONO_INST_FAULT flag.\n"); + ins->flags &= ~MONO_INST_FAULT; + } + /* + if (eval_non_null (area, reg)) { + if (REPORT_ABC_REMOVAL) + printf ("ARRAY-ACCESS: removed MONO_INST_FAULT flag.\n"); + ins->flags &= ~MONO_INST_FAULT; + } else { + add_non_null (area, cfg, reg, &check_relations); + } + */ } } @@ -1203,12 +1269,14 @@ mono_perform_abc_removal (MonoCompile *cfg) mono_mempool_alloc (cfg->mempool, sizeof (MonoRelationsEvaluationContext) * (cfg->next_vreg)); area.variable_value_kind = (MonoIntegerValueKind *) mono_mempool_alloc (cfg->mempool, sizeof (MonoIntegerValueKind) * (cfg->next_vreg)); + area.defs = mono_mempool_alloc (cfg->mempool, sizeof (MonoInst*) * cfg->next_vreg); for (i = 0; i < cfg->next_vreg; i++) { area.variable_value_kind [i] = MONO_UNKNOWN_INTEGER_VALUE; area.relations [i].relation = MONO_EQ_RELATION; area.relations [i].relation_is_static_definition = TRUE; MAKE_VALUE_ANY (area.relations [i].related_value); area.relations [i].next = NULL; + area.defs [i] = NULL; } for (bb = cfg->bb_entry; bb; bb = bb->next_bb) {