Merge pull request #2338 from BogdanovKirill/httpwritefix3
[mono.git] / mono / mini / branch-opts.c
index 904db01827de6ce2c8e14f08931843f1cce7cccb..aeb11a0ff0e7ab327bac24441a82e0854a51cec2 100644 (file)
@@ -85,7 +85,7 @@ mono_branch_optimize_exception_target (MonoCompile *cfg, MonoBasicBlock *bb, con
                                                MONO_INST_NEW (cfg, jump, OP_BR);
 
                                                /* Allocate memory for our branch target */
-                                               jump->inst_i1 = mono_mempool_alloc0 (cfg->mempool, sizeof (MonoInst));
+                                               jump->inst_i1 = (MonoInst *)mono_mempool_alloc0 (cfg->mempool, sizeof (MonoInst));
                                                jump->inst_true_bb = targetbb;
 
                                                if (cfg->verbose_level > 2) 
@@ -626,7 +626,7 @@ mono_if_conversion (MonoCompile *cfg)
         * optimize_branches () since the IR is already optimized.
         */
        for (bb = cfg->bb_entry; bb; bb = bb->next_bb) {
-               MonoBasicBlock *bb1, *bb2, *true_bb, *false_bb, *next_bb;
+               MonoBasicBlock *bb1, *bb2, *next_bb;
                MonoInst *branch1, *branch2, *compare1, *ins, *next;
 
                /* Look for the IR code generated from if (<var> < 0 || v > <limit>)
@@ -657,8 +657,6 @@ mono_if_conversion (MonoCompile *cfg)
                if (!(branch1 && ((branch1->opcode == OP_IBLT) || (branch1->opcode == OP_LBLT)) && (branch1->inst_false_bb == next_bb)))
                        continue;
 
-               true_bb = branch1->inst_true_bb;
-
                /* Check second branch */
                branch2 = mono_bb_last_inst (next_bb, filter);
                if (!branch2)
@@ -666,9 +664,9 @@ mono_if_conversion (MonoCompile *cfg)
 
                /* mcs sometimes generates inverted branches */
                if (((branch2->opcode == OP_IBGT) || (branch2->opcode == OP_LBGT)) && branch2->inst_true_bb == branch1->inst_true_bb)
-                       false_bb = branch2->inst_false_bb;
+                       ;
                else if (((branch2->opcode == OP_IBLE) || (branch2->opcode == OP_LBLE)) && branch2->inst_false_bb == branch1->inst_true_bb)
-                       false_bb = branch2->inst_true_bb;
+                       ;
                else
                        continue;
 
@@ -853,7 +851,7 @@ replace_out_block_in_code (MonoBasicBlock *bb, MonoBasicBlock *orig, MonoBasicBl
                                        ins->inst_false_bb = repl;
                        } else 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);
                                for (i = 0; i < table->table_size; i++ ) {
                                        if (table->table [i] == orig)
                                                table->table [i] = repl;
@@ -997,7 +995,7 @@ mono_merge_basic_blocks (MonoCompile *cfg, MonoBasicBlock *bb, MonoBasicBlock *b
                for (inst = bb->code; inst != NULL; inst = inst->next) {
                        if (MONO_IS_JUMP_TABLE (inst)) {
                                int i;
-                               MonoJumpInfoBBTable *table = MONO_JUMP_TABLE_FROM_INS (inst);
+                               MonoJumpInfoBBTable *table = (MonoJumpInfoBBTable *)MONO_JUMP_TABLE_FROM_INS (inst);
                                for (i = 0; i < table->table_size; i++ ) {
                                        /* Might be already NULL from a previous merge */
                                        if (table->table [i])
@@ -1139,7 +1137,7 @@ mono_remove_critical_edges (MonoCompile *cfg)
                                 * overwrite the sreg1 of the ins.
                                 */
                                if ((in_bb->out_count > 1) || (in_bb->out_count == 1 && in_bb->last_ins && in_bb->last_ins->opcode == OP_BR_REG)) {
-                                       MonoBasicBlock *new_bb = mono_mempool_alloc0 ((cfg)->mempool, sizeof (MonoBasicBlock));
+                                       MonoBasicBlock *new_bb = (MonoBasicBlock *)mono_mempool_alloc0 ((cfg)->mempool, sizeof (MonoBasicBlock));
                                        new_bb->block_num = cfg->num_bblocks++;
 //                                     new_bb->real_offset = bb->real_offset;
                                        new_bb->region = bb->region;
@@ -1163,7 +1161,7 @@ mono_remove_critical_edges (MonoCompile *cfg)
                                                        /* We cannot add any inst to the entry BB, so we must */
                                                        /* put a new BB in the middle to hold the OP_BR */
                                                        MonoInst *jump;
-                                                       MonoBasicBlock *new_bb_after_entry = mono_mempool_alloc0 ((cfg)->mempool, sizeof (MonoBasicBlock));
+                                                       MonoBasicBlock *new_bb_after_entry = (MonoBasicBlock *)mono_mempool_alloc0 ((cfg)->mempool, sizeof (MonoBasicBlock));
                                                        new_bb_after_entry->block_num = cfg->num_bblocks++;
 //                                                     new_bb_after_entry->real_offset = bb->real_offset;
                                                        new_bb_after_entry->region = bb->region;
@@ -1192,10 +1190,10 @@ mono_remove_critical_edges (MonoCompile *cfg)
                                        previous_bb = new_bb;
                                        
                                        /* Setup in_bb and out_bb */
-                                       new_bb->in_bb = mono_mempool_alloc ((cfg)->mempool, sizeof (MonoBasicBlock*));
+                                       new_bb->in_bb = (MonoBasicBlock **)mono_mempool_alloc ((cfg)->mempool, sizeof (MonoBasicBlock*));
                                        new_bb->in_bb [0] = in_bb;
                                        new_bb->in_count = 1;
-                                       new_bb->out_bb = mono_mempool_alloc ((cfg)->mempool, sizeof (MonoBasicBlock*));
+                                       new_bb->out_bb = (MonoBasicBlock **)mono_mempool_alloc ((cfg)->mempool, sizeof (MonoBasicBlock*));
                                        new_bb->out_bb [0] = bb;
                                        new_bb->out_count = 1;
                                        
@@ -1240,7 +1238,7 @@ mono_remove_critical_edges (MonoCompile *cfg)
 void
 mono_optimize_branches (MonoCompile *cfg)
 {
-       int i, changed = FALSE;
+       int i, count = 0, changed = FALSE;
        MonoBasicBlock *bb, *bbn;
        guint32 niterations;
        MonoInst *bbn_first_inst;
@@ -1263,6 +1261,11 @@ mono_optimize_branches (MonoCompile *cfg)
 
                /* we skip the entry block (exit is handled specially instead ) */
                for (previous_bb = cfg->bb_entry, bb = cfg->bb_entry->next_bb; bb; previous_bb = bb, bb = bb->next_bb) {
+                       count ++;
+                       if (count == 1000) {
+                               mono_threads_safepoint ();
+                               count = 0;
+                       }
                        /* dont touch code inside exception clauses */
                        if (bb->region != -1)
                                continue;