@@ -532,8 +532,8 @@ dfs_visit (TransformData *td)
532
532
{
533
533
int dfs_index = 0 ;
534
534
int next_stack_index = 0 ;
535
- td -> bblocks = (InterpBasicBlock * * )mono_mempool_alloc0 (td -> mempool , sizeof (InterpBasicBlock * ) * td -> bb_count );
536
- InterpBasicBlock * * stack = (InterpBasicBlock * * )mono_mempool_alloc0 ( td -> mempool , sizeof (InterpBasicBlock * ) * td -> bb_count );
535
+ td -> bblocks = (InterpBasicBlock * * )mono_mempool_alloc0 (td -> opt_mempool , sizeof (InterpBasicBlock * ) * td -> bb_count );
536
+ InterpBasicBlock * * stack = (InterpBasicBlock * * )g_malloc0 ( sizeof (InterpBasicBlock * ) * td -> bb_count );
537
537
538
538
g_assert (!td -> entry_bb -> in_count );
539
539
stack [next_stack_index ++ ] = td -> entry_bb ;
@@ -558,6 +558,7 @@ dfs_visit (TransformData *td)
558
558
}
559
559
}
560
560
561
+ g_free (stack );
561
562
return dfs_index ;
562
563
}
563
564
@@ -622,7 +623,7 @@ is_bblock_ssa_cfg (TransformData *td, InterpBasicBlock *bb)
622
623
static void
623
624
interp_compute_dominators (TransformData * td )
624
625
{
625
- InterpBasicBlock * * idoms = (InterpBasicBlock * * )mono_mempool_alloc0 (td -> mempool , sizeof (InterpBasicBlock * ) * td -> bblocks_count );
626
+ InterpBasicBlock * * idoms = (InterpBasicBlock * * )mono_mempool_alloc0 (td -> opt_mempool , sizeof (InterpBasicBlock * ) * td -> bblocks_count );
626
627
627
628
idoms [0 ] = td -> entry_bb ;
628
629
gboolean changed = TRUE;
@@ -698,7 +699,7 @@ static void
698
699
interp_compute_dominance_frontier (TransformData * td )
699
700
{
700
701
int bitsize = mono_bitset_alloc_size (td -> bblocks_count , 0 );
701
- char * mem = (char * )mono_mempool_alloc0 (td -> mempool , bitsize * td -> bblocks_count );
702
+ char * mem = (char * )mono_mempool_alloc0 (td -> opt_mempool , bitsize * td -> bblocks_count );
702
703
703
704
for (int i = 0 ; i < td -> bblocks_count ; i ++ ) {
704
705
td -> bblocks [i ]-> dfrontier = mono_bitset_mem_new (mem , td -> bblocks_count , 0 );
@@ -975,7 +976,7 @@ static void
975
976
compute_gen_kill_sets (TransformData * td )
976
977
{
977
978
int bitsize = mono_bitset_alloc_size (td -> renamable_vars_size , 0 );
978
- char * mem = (char * )mono_mempool_alloc0 (td -> mempool , bitsize * td -> bblocks_count * 4 );
979
+ char * mem = (char * )mono_mempool_alloc0 (td -> opt_mempool , bitsize * td -> bblocks_count * 4 );
979
980
980
981
for (int i = 0 ; i < td -> bblocks_count ; i ++ ) {
981
982
InterpBasicBlock * bb = td -> bblocks [i ];
@@ -1094,7 +1095,7 @@ bb_insert_phi (TransformData *td, InterpBasicBlock *bb, int var)
1094
1095
g_print ("BB%d NEW_PHI %d\n" , bb -> index , var );
1095
1096
1096
1097
phi -> dreg = var ;
1097
- phi -> info .args = (int * )mono_mempool_alloc (td -> mempool , (bb -> in_count + 1 ) * sizeof (int ));
1098
+ phi -> info .args = (int * )mono_mempool_alloc (td -> opt_mempool , (bb -> in_count + 1 ) * sizeof (int ));
1098
1099
int i ;
1099
1100
for (i = 0 ; i < bb -> in_count ; i ++ )
1100
1101
phi -> info .args [i ] = var ;
@@ -1109,7 +1110,7 @@ bb_insert_dead_phi (TransformData *td, InterpBasicBlock *bb, int var)
1109
1110
bitset = bb -> first_ins -> info .dead_phi_vars ;
1110
1111
} else {
1111
1112
InterpInst * phi = interp_insert_ins_bb (td , bb , NULL , MINT_DEAD_PHI );
1112
- gpointer mem = mono_mempool_alloc0 (td -> mempool , mono_bitset_alloc_size (td -> renamable_vars_size , 0 ));
1113
+ gpointer mem = mono_mempool_alloc0 (td -> opt_mempool , mono_bitset_alloc_size (td -> renamable_vars_size , 0 ));
1113
1114
phi -> info .dead_phi_vars = bitset = mono_bitset_mem_new (mem , td -> renamable_vars_size , 0 );
1114
1115
}
1115
1116
int ext_index = td -> vars [var ].ext_index ;
@@ -1322,7 +1323,7 @@ rename_vars_in_bb_start (TransformData *td, InterpBasicBlock *bb)
1322
1323
if (renamed_var != -1 ) {
1323
1324
g_assert (td -> vars [renamed_var ].renamed_ssa_fixed );
1324
1325
int renamed_var_ext = td -> vars [renamed_var ].ext_index ;
1325
- InterpLivenessPosition * liveness_ptr = (InterpLivenessPosition * )mono_mempool_alloc (td -> mempool , sizeof (InterpLivenessPosition ));
1326
+ InterpLivenessPosition * liveness_ptr = (InterpLivenessPosition * )mono_mempool_alloc (td -> opt_mempool , sizeof (InterpLivenessPosition ));
1326
1327
* liveness_ptr = current_liveness ;
1327
1328
td -> renamed_fixed_vars [renamed_var_ext ].live_limit_bblocks = g_slist_prepend (td -> renamed_fixed_vars [renamed_var_ext ].live_limit_bblocks , liveness_ptr );
1328
1329
}
@@ -1347,7 +1348,7 @@ rename_vars_in_bb_end (TransformData *td, InterpBasicBlock *bb)
1347
1348
g_assert (td -> vars [renamed_var ].renamed_ssa_fixed );
1348
1349
int renamed_var_ext = td -> vars [renamed_var ].ext_index ;
1349
1350
if (!td -> renamed_fixed_vars [renamed_var_ext ].live_out_bblocks ) {
1350
- gpointer mem = mono_mempool_alloc0 (td -> mempool , mono_bitset_alloc_size (td -> bblocks_count , 0 ));
1351
+ gpointer mem = mono_mempool_alloc0 (td -> opt_mempool , mono_bitset_alloc_size (td -> bblocks_count , 0 ));
1351
1352
td -> renamed_fixed_vars [renamed_var_ext ].live_out_bblocks = mono_bitset_mem_new (mem , td -> bblocks_count , 0 );
1352
1353
}
1353
1354
@@ -1386,8 +1387,8 @@ static void
1386
1387
rename_vars (TransformData * td )
1387
1388
{
1388
1389
int next_stack_index = 0 ;
1389
- InterpBasicBlock * * stack = (InterpBasicBlock * * )mono_mempool_alloc0 ( td -> mempool , sizeof (InterpBasicBlock * ) * td -> bblocks_count );
1390
- gboolean * bb_status = (gboolean * )mono_mempool_alloc0 ( td -> mempool , sizeof (InterpBasicBlock * ) * td -> bblocks_count );
1390
+ InterpBasicBlock * * stack = (InterpBasicBlock * * )g_malloc0 ( sizeof (InterpBasicBlock * ) * td -> bblocks_count );
1391
+ gboolean * bb_status = (gboolean * )g_malloc0 ( sizeof (InterpBasicBlock * ) * td -> bblocks_count );
1391
1392
1392
1393
stack [next_stack_index ++ ] = td -> entry_bb ;
1393
1394
@@ -1414,6 +1415,9 @@ rename_vars (TransformData *td)
1414
1415
}
1415
1416
}
1416
1417
1418
+ g_free (stack );
1419
+ g_free (bb_status );
1420
+
1417
1421
if (td -> verbose_level ) {
1418
1422
g_print ("\nFIXED SSA VARS LIVENESS LIMIT:\n" );
1419
1423
for (unsigned int i = 0 ; i < td -> renamed_fixed_vars_size ; i ++ ) {
@@ -1718,7 +1722,7 @@ interp_link_bblocks (TransformData *td, InterpBasicBlock *from, InterpBasicBlock
1718
1722
static void
1719
1723
interp_mark_reachable_bblocks (TransformData * td )
1720
1724
{
1721
- InterpBasicBlock * * queue = mono_mempool_alloc0 ( td -> mempool , td -> bb_count * sizeof (InterpBasicBlock * ));
1725
+ InterpBasicBlock * * queue = g_malloc0 ( td -> bb_count * sizeof (InterpBasicBlock * ));
1722
1726
InterpBasicBlock * current ;
1723
1727
int cur_index = 0 ;
1724
1728
int next_position = 0 ;
@@ -1761,6 +1765,8 @@ interp_mark_reachable_bblocks (TransformData *td)
1761
1765
if (needs_retry )
1762
1766
goto retry ;
1763
1767
}
1768
+
1769
+ g_free (queue );
1764
1770
}
1765
1771
1766
1772
/**
@@ -2714,7 +2720,7 @@ interp_cprop (TransformData *td)
2714
2720
// FIXME
2715
2721
// There is no need to zero, if we pay attention to phi args vars. They
2716
2722
// can be used before the definition.
2717
- td -> var_values = (InterpVarValue * ) mono_mempool_alloc0 ( td -> mempool , td -> vars_size * sizeof (InterpVarValue ));
2723
+ td -> var_values = (InterpVarValue * ) g_malloc0 ( td -> vars_size * sizeof (InterpVarValue ));
2718
2724
2719
2725
// Traverse in dfs order. This guarantees that we always reach the definition first before the
2720
2726
// use of the var. Exception is only for phi nodes, where we don't care about the definition
@@ -3790,8 +3796,7 @@ interp_prepare_no_ssa_opt (TransformData *td)
3790
3796
td -> vars [i ].has_indirects = (td -> vars [i ].indirects > 0 ) ? TRUE : FALSE;
3791
3797
}
3792
3798
3793
- if (!td -> bblocks )
3794
- td -> bblocks = (InterpBasicBlock * * )mono_mempool_alloc0 (td -> mempool , sizeof (InterpBasicBlock * ) * td -> bb_count );
3799
+ td -> bblocks = (InterpBasicBlock * * )mono_mempool_alloc0 (td -> opt_mempool , sizeof (InterpBasicBlock * ) * td -> bb_count );
3795
3800
3796
3801
int i = 0 ;
3797
3802
for (InterpBasicBlock * bb = td -> entry_bb ; bb != NULL ; bb = bb -> next_bb ) {
@@ -3861,6 +3866,14 @@ interp_optimize_code (TransformData *td)
3861
3866
g_print ("Huge method. SSA disabled for first iteration\n" );
3862
3867
}
3863
3868
optimization_retry :
3869
+ if (td -> opt_mempool != NULL )
3870
+ mono_mempool_destroy (td -> opt_mempool );
3871
+ if (td -> var_values != NULL ) {
3872
+ g_free (td -> var_values );
3873
+ td -> var_values = NULL ;
3874
+ }
3875
+ td -> opt_mempool = mono_mempool_new ();
3876
+
3864
3877
td -> need_optimization_retry = FALSE;
3865
3878
3866
3879
if (td -> disable_ssa )
@@ -3897,6 +3910,8 @@ interp_optimize_code (TransformData *td)
3897
3910
goto optimization_retry ;
3898
3911
}
3899
3912
3913
+ mono_mempool_destroy (td -> opt_mempool );
3914
+
3900
3915
if (td -> verbose_level ) {
3901
3916
g_print ("\nOptimized IR:\n" );
3902
3917
mono_interp_print_td_code (td );
0 commit comments