@@ -258,10 +258,8 @@ typedef struct basicblock_ {
258
258
int b_iused ;
259
259
/* length of instruction array (b_instr) */
260
260
int b_ialloc ;
261
- /* Number of predecssors that a block has. */
261
+ /* Number of predecessors that a block has. */
262
262
int b_predecessors ;
263
- /* Number of predecssors that a block has as an exception handler. */
264
- int b_except_predecessors ;
265
263
/* depth of stack upon entry of block, computed by stackdepth() */
266
264
int b_startdepth ;
267
265
/* instruction offset for block, computed by assemble_jump_offsets() */
@@ -270,6 +268,8 @@ typedef struct basicblock_ {
270
268
unsigned b_preserve_lasti : 1 ;
271
269
/* Used by compiler passes to mark whether they have visited a basic block. */
272
270
unsigned b_visited : 1 ;
271
+ /* b_except_handler is used by the cold-detection algorithm to mark exception targets */
272
+ unsigned b_except_handler : 1 ;
273
273
/* b_cold is true if this block is not perf critical (like an exception handler) */
274
274
unsigned b_cold : 1 ;
275
275
/* b_warm is used by the cold-detection algorithm to mark blocks which are definitely not cold */
@@ -7296,6 +7296,25 @@ label_exception_targets(basicblock *entryblock) {
7296
7296
return -1 ;
7297
7297
}
7298
7298
7299
+
7300
+ static int
7301
+ mark_except_handlers (basicblock * entryblock ) {
7302
+ #ifndef NDEBUG
7303
+ for (basicblock * b = entryblock ; b != NULL ; b = b -> b_next ) {
7304
+ assert (!b -> b_except_handler );
7305
+ }
7306
+ #endif
7307
+ for (basicblock * b = entryblock ; b != NULL ; b = b -> b_next ) {
7308
+ for (int i = 0 ; i < b -> b_iused ; i ++ ) {
7309
+ struct instr * instr = & b -> b_instr [i ];
7310
+ if (is_block_push (instr )) {
7311
+ instr -> i_target -> b_except_handler = 1 ;
7312
+ }
7313
+ }
7314
+ }
7315
+ return 0 ;
7316
+ }
7317
+
7299
7318
static int
7300
7319
mark_warm (basicblock * entryblock ) {
7301
7320
basicblock * * stack = make_cfg_traversal_stack (entryblock );
@@ -7308,7 +7327,7 @@ mark_warm(basicblock *entryblock) {
7308
7327
entryblock -> b_visited = 1 ;
7309
7328
while (sp > stack ) {
7310
7329
basicblock * b = * (-- sp );
7311
- assert (!b -> b_except_predecessors );
7330
+ assert (!b -> b_except_handler );
7312
7331
b -> b_warm = 1 ;
7313
7332
basicblock * next = b -> b_next ;
7314
7333
if (next && BB_HAS_FALLTHROUGH (b ) && !next -> b_visited ) {
@@ -7343,8 +7362,7 @@ mark_cold(basicblock *entryblock) {
7343
7362
7344
7363
basicblock * * sp = stack ;
7345
7364
for (basicblock * b = entryblock ; b != NULL ; b = b -> b_next ) {
7346
- if (b -> b_except_predecessors ) {
7347
- assert (b -> b_except_predecessors == b -> b_predecessors );
7365
+ if (b -> b_except_handler ) {
7348
7366
assert (!b -> b_warm );
7349
7367
* sp ++ = b ;
7350
7368
b -> b_visited = 1 ;
@@ -8257,8 +8275,8 @@ static void
8257
8275
dump_basicblock (const basicblock * b )
8258
8276
{
8259
8277
const char * b_return = basicblock_returns (b ) ? "return " : "" ;
8260
- fprintf (stderr , "%d: [%d %d %d %p] used: %d, depth: %d, offset: %d %s\n" ,
8261
- b -> b_label , b -> b_cold , b -> b_warm , BB_NO_FALLTHROUGH (b ), b , b -> b_iused ,
8278
+ fprintf (stderr , "%d: [EH= %d CLD= %d WRM=%d NO_FT= %d %p] used: %d, depth: %d, offset: %d %s\n" ,
8279
+ b -> b_label , b -> b_except_handler , b -> b_cold , b -> b_warm , BB_NO_FALLTHROUGH (b ), b , b -> b_iused ,
8262
8280
b -> b_startdepth , b -> b_offset , b_return );
8263
8281
if (b -> b_instr ) {
8264
8282
int i ;
@@ -8616,6 +8634,12 @@ assemble(struct compiler *c, int addNone)
8616
8634
if (calculate_jump_targets (g -> g_entryblock )) {
8617
8635
goto error ;
8618
8636
}
8637
+ if (mark_except_handlers (g -> g_entryblock ) < 0 ) {
8638
+ goto error ;
8639
+ }
8640
+ if (label_exception_targets (g -> g_entryblock )) {
8641
+ goto error ;
8642
+ }
8619
8643
if (optimize_cfg (g , consts , c -> c_const_cache )) {
8620
8644
goto error ;
8621
8645
}
@@ -8634,9 +8658,6 @@ assemble(struct compiler *c, int addNone)
8634
8658
}
8635
8659
/* TO DO -- For 3.12, make sure that `maxdepth <= MAX_ALLOWED_STACK_USE` */
8636
8660
8637
- if (label_exception_targets (g -> g_entryblock )) {
8638
- goto error ;
8639
- }
8640
8661
convert_exception_handlers_to_nops (g -> g_entryblock );
8641
8662
8642
8663
if (push_cold_blocks_to_end (g , code_flags ) < 0 ) {
@@ -9353,11 +9374,6 @@ mark_reachable(basicblock *entryblock) {
9353
9374
* sp ++ = target ;
9354
9375
}
9355
9376
target -> b_predecessors ++ ;
9356
- if (is_block_push (instr )) {
9357
- target -> b_except_predecessors ++ ;
9358
- }
9359
- assert (target -> b_except_predecessors == 0 ||
9360
- target -> b_except_predecessors == target -> b_predecessors );
9361
9377
}
9362
9378
}
9363
9379
}
0 commit comments