X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Fmini%2Fssa.c;h=cb100267ef706a6c3608f7b09e12f5dcb92e1cfb;hb=b2cf10659d74681988ad53c18f368c007990d829;hp=95bea3006eef32939c9fbfd145f62f5b754c3816;hpb=28f473c41df72b278eaf9784c29c2b8fa2cbe06a;p=mono.git diff --git a/mono/mini/ssa.c b/mono/mini/ssa.c index 95bea3006ee..cb100267ef7 100644 --- a/mono/mini/ssa.c +++ b/mono/mini/ssa.c @@ -6,6 +6,7 @@ * * (C) 2003 Ximian, Inc. * Copyright 2011 Xamarin, Inc (http://www.xamarin.com) + * Licensed under the MIT license. See LICENSE file in the project root for full license information. */ #include #include @@ -141,7 +142,7 @@ static inline void record_use (MonoCompile *cfg, MonoInst *var, MonoBasicBlock *bb, MonoInst *ins) { MonoMethodVar *info; - MonoVarUsageInfo *ui = mono_mempool_alloc (cfg->mempool, sizeof (MonoVarUsageInfo)); + MonoVarUsageInfo *ui = (MonoVarUsageInfo *)mono_mempool_alloc (cfg->mempool, sizeof (MonoVarUsageInfo)); info = MONO_VARINFO (cfg, var->inst_c0); @@ -352,7 +353,7 @@ mono_ssa_compute (MonoCompile *cfg) mono_compile_dominator_info (cfg, MONO_COMP_DOM | MONO_COMP_IDOM | MONO_COMP_DFRONTIER); bitsize = mono_bitset_alloc_size (cfg->num_bblocks, 0); - buf = buf_start = g_malloc0 (mono_bitset_alloc_size (cfg->num_bblocks, 0) * cfg->num_varinfo); + buf = buf_start = (guint8 *)g_malloc0 (mono_bitset_alloc_size (cfg->num_bblocks, 0) * cfg->num_varinfo); for (i = 0; i < cfg->num_varinfo; ++i) { vinfo [i].def_in = mono_bitset_mem_new (buf, cfg->num_bblocks, 0); @@ -434,7 +435,7 @@ mono_ssa_compute (MonoCompile *cfg) else ins->klass = var->klass; - ins->inst_phi_args = mono_mempool_alloc0 (cfg->mempool, sizeof (int) * (cfg->bblocks [idx]->in_count + 1)); + ins->inst_phi_args = (int *)mono_mempool_alloc0 (cfg->mempool, sizeof (int) * (cfg->bblocks [idx]->in_count + 1)); ins->inst_phi_args [0] = cfg->bblocks [idx]->in_count; /* For debugging */ @@ -457,7 +458,7 @@ mono_ssa_compute (MonoCompile *cfg) /* Renaming phase */ - stack = alloca (sizeof (MonoInst *) * cfg->num_varinfo); + stack = (MonoInst **)alloca (sizeof (MonoInst *) * cfg->num_varinfo); memset (stack, 0, sizeof (MonoInst *) * cfg->num_varinfo); lvreg_stack = g_new0 (guint32, cfg->next_vreg); @@ -477,6 +478,73 @@ mono_ssa_compute (MonoCompile *cfg) cfg->comp_done |= MONO_COMP_SSA; } +/* + * mono_ssa_remove_gsharedvt: + * + * Same as mono_ssa_remove, but only remove phi nodes for gsharedvt variables. + */ +void +mono_ssa_remove_gsharedvt (MonoCompile *cfg) +{ + MonoInst *ins, *var, *move; + int i, j, first; + + /* + * When compiling gsharedvt code, we need to get rid of the VPHI instructions, + * since they cannot be handled later in the llvm backend. + */ + g_assert (cfg->comp_done & MONO_COMP_SSA); + + for (i = 0; i < cfg->num_bblocks; ++i) { + MonoBasicBlock *bb = cfg->bblocks [i]; + + if (cfg->verbose_level >= 4) + printf ("\nREMOVE SSA %d:\n", bb->block_num); + + for (ins = bb->code; ins; ins = ins->next) { + if (!(MONO_IS_PHI (ins) && ins->opcode == OP_VPHI && mini_is_gsharedvt_variable_type (&ins->klass->byval_arg))) + continue; + + g_assert (ins->inst_phi_args [0] == bb->in_count); + var = get_vreg_to_inst (cfg, ins->dreg); + + /* Check for PHI nodes where all the inputs are the same */ + first = ins->inst_phi_args [1]; + + for (j = 1; j < bb->in_count; ++j) + if (first != ins->inst_phi_args [j + 1]) + break; + + if ((bb->in_count > 1) && (j == bb->in_count)) { + ins->opcode = op_phi_to_move (ins->opcode); + if (ins->opcode == OP_VMOVE) + g_assert (ins->klass); + ins->sreg1 = first; + } else { + for (j = 0; j < bb->in_count; j++) { + MonoBasicBlock *pred = bb->in_bb [j]; + int sreg = ins->inst_phi_args [j + 1]; + + if (cfg->verbose_level >= 4) + printf ("\tADD R%d <- R%d in BB%d\n", var->dreg, sreg, pred->block_num); + if (var->dreg != sreg) { + MONO_INST_NEW (cfg, move, op_phi_to_move (ins->opcode)); + if (move->opcode == OP_VMOVE) { + g_assert (ins->klass); + move->klass = ins->klass; + } + move->dreg = var->dreg; + move->sreg1 = sreg; + mono_add_ins_to_end (pred, move); + } + } + + NULLIFY_INS (ins); + } + } + } +} + void mono_ssa_remove (MonoCompile *cfg) { @@ -937,7 +1005,7 @@ visit_inst (MonoCompile *cfg, MonoBasicBlock *bb, MonoInst *ins, GList **cvars, if (MONO_IS_JUMP_TABLE (ins)) { int i; - MonoJumpInfoBBTable *table = MONO_JUMP_TABLE_FROM_INS (ins); + MonoJumpInfoBBTable *table = (MonoJumpInfoBBTable *)MONO_JUMP_TABLE_FROM_INS (ins); if (!ins->next || ins->next->opcode != OP_PADD) { /* The PADD was optimized away */ @@ -973,7 +1041,7 @@ visit_inst (MonoCompile *cfg, MonoBasicBlock *bb, MonoInst *ins, GList **cvars, if (ins->opcode == OP_SWITCH) { int i; - MonoJumpInfoBBTable *table = ins->inst_p0; + MonoJumpInfoBBTable *table = (MonoJumpInfoBBTable *)ins->inst_p0; for (i = 0; i < table->table_size; i++) if (table->table [i]) @@ -1049,7 +1117,7 @@ fold_ins (MonoCompile *cfg, MonoBasicBlock *bb, MonoInst *ins, MonoInst **carray if (MONO_IS_JUMP_TABLE (ins)) { int i; - MonoJumpInfoBBTable *table = MONO_JUMP_TABLE_FROM_INS (ins); + MonoJumpInfoBBTable *table = (MonoJumpInfoBBTable *)MONO_JUMP_TABLE_FROM_INS (ins); if (!ins->next || ins->next->opcode != OP_PADD) { /* The PADD was optimized away */