|
14 | 14 | /* SCCP (Sparse Conditional Constant Propagation) optimization */ |
15 | 15 | #include "opt-sccp.c" |
16 | 16 |
|
| 17 | +/* Configuration constants - replace magic numbers */ |
| 18 | +#define PHI_WORKLIST_SIZE 64 |
| 19 | +#define DCE_WORKLIST_SIZE 2048 |
| 20 | + |
17 | 21 | /* cfront does not accept structure as an argument, pass pointer */ |
18 | 22 | void bb_forward_traversal(bb_traversal_args_t *args) |
19 | 23 | { |
@@ -606,12 +610,17 @@ void solve_phi_insertion(void) |
606 | 610 | for (symbol_t *sym = func->global_sym_list.head; sym; sym = sym->next) { |
607 | 611 | var_t *var = sym->var; |
608 | 612 |
|
609 | | - basic_block_t *work_list[64]; |
| 613 | + basic_block_t *work_list[PHI_WORKLIST_SIZE]; |
610 | 614 | int work_list_idx = 0; |
611 | 615 |
|
612 | 616 | for (ref_block_t *ref = var->ref_block_list.head; ref; |
613 | | - ref = ref->next) |
| 617 | + ref = ref->next) { |
| 618 | + if (work_list_idx >= PHI_WORKLIST_SIZE - 1) { |
| 619 | + printf("Error: PHI worklist overflow\n"); |
| 620 | + abort(); |
| 621 | + } |
614 | 622 | work_list[work_list_idx++] = ref->bb; |
| 623 | + } |
615 | 624 |
|
616 | 625 | for (int i = 0; i < work_list_idx; i++) { |
617 | 626 | basic_block_t *bb = work_list[i]; |
@@ -656,8 +665,13 @@ void solve_phi_insertion(void) |
656 | 665 | break; |
657 | 666 | } |
658 | 667 | } |
659 | | - if (!found) |
| 668 | + if (!found) { |
| 669 | + if (work_list_idx >= PHI_WORKLIST_SIZE - 1) { |
| 670 | + printf("Error: PHI worklist overflow\n"); |
| 671 | + abort(); |
| 672 | + } |
660 | 673 | work_list[work_list_idx++] = df; |
| 674 | + } |
661 | 675 | } |
662 | 676 | } |
663 | 677 | } |
@@ -1515,14 +1529,14 @@ int dce_init_mark(insn_t *insn, insn_t *work_list[], int work_list_idx) |
1515 | 1529 | /* Dead Code Elimination (DCE) */ |
1516 | 1530 | void dce_insn(basic_block_t *bb) |
1517 | 1531 | { |
1518 | | - insn_t *work_list[2048]; |
| 1532 | + insn_t *work_list[DCE_WORKLIST_SIZE]; |
1519 | 1533 | int work_list_idx = 0; |
1520 | 1534 |
|
1521 | 1535 | /* initially analyze current bb*/ |
1522 | 1536 | for (insn_t *insn = bb->insn_list.head; insn; insn = insn->next) { |
1523 | 1537 | int mark_num = dce_init_mark(insn, work_list, work_list_idx); |
1524 | 1538 | work_list_idx += mark_num; |
1525 | | - if (work_list_idx > 2048 - 1) { |
| 1539 | + if (work_list_idx > DCE_WORKLIST_SIZE - 1) { |
1526 | 1540 | printf("size of work_list in DCE is not enough\n"); |
1527 | 1541 | abort(); |
1528 | 1542 | } |
|
0 commit comments