@@ -143,6 +143,7 @@ arena_t *arena_init(int initial_capacity)
143
143
abort ();
144
144
}
145
145
arena -> head = arena_block_create (initial_capacity );
146
+ arena -> total_bytes = initial_capacity ;
146
147
return arena ;
147
148
}
148
149
@@ -171,6 +172,7 @@ void *arena_alloc(arena_t *arena, int size)
171
172
arena_block_t * new_block = arena_block_create (new_capacity );
172
173
new_block -> next = arena -> head ;
173
174
arena -> head = new_block ;
175
+ arena -> total_bytes += new_capacity ;
174
176
}
175
177
176
178
void * ptr = arena -> head -> memory + arena -> head -> offset ;
@@ -198,16 +200,8 @@ void *arena_calloc(arena_t *arena, int n, int size)
198
200
int total = n * size ;
199
201
void * ptr = arena_alloc (arena , total );
200
202
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 );
211
205
212
206
return ptr ;
213
207
}
@@ -1099,11 +1093,11 @@ void global_init(void)
1099
1093
1100
1094
MACROS_MAP = hashmap_create (MAX_ALIASES );
1101
1095
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 */
1107
1101
PH2_IR_FLATTEN = malloc (MAX_IR_INSTR * sizeof (ph2_ir_t * ));
1108
1102
SOURCE = strbuf_create (MAX_SOURCE );
1109
1103
FUNC_MAP = hashmap_create (DEFAULT_FUNCS_SIZE );
0 commit comments