From fb1b3e086903b0474e14d901f7cc82113f192bdd Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Mon, 5 Jun 2023 11:03:44 +0900 Subject: [PATCH] [qfcc] Use ud- and du-chains for block live analysis The ud- and du-chains include known side-effects of the instructions and thus depict a more accurate view of what operands an instruction uses or defines. Fixes the arraylife2 test. --- tools/qfcc/source/flow.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/tools/qfcc/source/flow.c b/tools/qfcc/source/flow.c index 8749e69db..e0d33346c 100644 --- a/tools/qfcc/source/flow.c +++ b/tools/qfcc/source/flow.c @@ -1237,12 +1237,30 @@ flow_live_vars (flowgraph_t *graph) // first, calculate use and def for each block, and initialize the in and // out sets. + set_t *node_statements = set_new (); for (i = 0; i < graph->num_nodes; i++) { node = graph->nodes[i]; use = set_new (); def = set_new (); + set_empty (node_statements); for (st = node->sblock->statements; st; st = st->next) { - flow_analyze_statement (st, stuse, stdef, 0, 0); + set_add (node_statements, st->number); + } + for (st = node->sblock->statements; st; st = st->next) { + set_empty (stuse); + set_empty (stdef); + for (int i = 0; i < st->num_use; i++) { + udchain_t ud = graph->func->ud_chains[st->first_use + i]; + if (!set_is_member (node_statements, ud.defst)) { + set_add (stuse, ud.var); + } + } + for (int i = 0; i < st->num_def; i++) { + udchain_t du = graph->func->du_chains[st->first_def + i]; + if (!set_is_member (node_statements, du.usest)) { + set_add (stdef, du.var); + } + } live_set_use (stuse, use, def); live_set_def (stdef, use, def); } @@ -1251,6 +1269,7 @@ flow_live_vars (flowgraph_t *graph) node->live_vars.in = set_new (); node->live_vars.out = set_new (); } + set_delete (node_statements); // create in for the exit dummy block using the global vars used by the // function use = set_new ();