@@ -143,6 +143,7 @@ arena_t *arena_init(int initial_capacity)
143143 abort ();
144144 }
145145 arena -> head = arena_block_create (initial_capacity );
146+ arena -> total_bytes = initial_capacity ;
146147 return arena ;
147148}
148149
@@ -171,6 +172,7 @@ void *arena_alloc(arena_t *arena, int size)
171172 arena_block_t * new_block = arena_block_create (new_capacity );
172173 new_block -> next = arena -> head ;
173174 arena -> head = new_block ;
175+ arena -> total_bytes += new_capacity ;
174176 }
175177
176178 void * ptr = arena -> head -> memory + arena -> head -> offset ;
@@ -198,16 +200,8 @@ void *arena_calloc(arena_t *arena, int n, int size)
198200 int total = n * size ;
199201 void * ptr = arena_alloc (arena , total );
200202
201- int * w_ptr = ptr ;
202- int w_count = total >> 2 ;
203- int b_index = w_count << 2 ;
204-
205- for (int i = 0 ; i < w_count ; ++ i )
206- w_ptr [i ] = 0 ;
207-
208- char * b_ptr = ptr ;
209- while (b_index < total )
210- b_ptr [b_index ++ ] = 0 ;
203+ /* Use memset for better performance */
204+ memset (ptr , 0 , total );
211205
212206 return ptr ;
213207}
@@ -1099,11 +1093,11 @@ void global_init(void)
10991093
11001094 MACROS_MAP = hashmap_create (MAX_ALIASES );
11011095 TYPES = malloc (MAX_TYPES * sizeof (type_t ));
1102- BLOCK_ARENA = arena_init (DEFAULT_ARENA_SIZE );
1103- INSN_ARENA = arena_init (DEFAULT_ARENA_SIZE );
1104- BB_ARENA = arena_init (DEFAULT_ARENA_SIZE );
1105- HASHMAP_ARENA = arena_init (DEFAULT_ARENA_SIZE );
1106- GENERAL_ARENA = arena_init (DEFAULT_ARENA_SIZE );
1096+ BLOCK_ARENA = arena_init (DEFAULT_ARENA_SIZE ); /* Variables/blocks */
1097+ INSN_ARENA = arena_init (LARGE_ARENA_SIZE ); /* Instructions - high usage */
1098+ BB_ARENA = arena_init (SMALL_ARENA_SIZE ); /* Basic blocks - low usage */
1099+ HASHMAP_ARENA = arena_init (DEFAULT_ARENA_SIZE ); /* Hash nodes */
1100+ GENERAL_ARENA = arena_init (SMALL_ARENA_SIZE ); /* Misc - low usage */
11071101 PH2_IR_FLATTEN = malloc (MAX_IR_INSTR * sizeof (ph2_ir_t * ));
11081102 SOURCE = strbuf_create (MAX_SOURCE );
11091103 FUNC_MAP = hashmap_create (DEFAULT_FUNCS_SIZE );
0 commit comments