From 15a2c33bea2e9cfc42075cd13280e3785d724857 Mon Sep 17 00:00:00 2001 From: Ajay Brahmakshatriya Date: Fri, 24 May 2024 16:53:47 -0400 Subject: [PATCH] Moved phase 2 RCE into a separate function --- src/blocks/rce.cpp | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/src/blocks/rce.cpp b/src/blocks/rce.cpp index 7465fe6..45a1095 100644 --- a/src/blocks/rce.cpp +++ b/src/blocks/rce.cpp @@ -303,17 +303,15 @@ class decl_deleter: public block_visitor { } }; -static void rce_phase1(block::Ptr ast) { - // gather general statistics first - usage_counter counter; - ast->accept(&counter); - +static void rce_phase1(block::Ptr ast, const usage_counter& counter) { // Phase 1 RCE phase1_visitor p1v; p1v.usage_count = counter.usage_count; p1v.address_taken_vars = counter.address_taken_vars; ast->accept(&p1v); +} +static void rce_phase2(block::Ptr ast, const usage_counter& counter) { // Phase 2 RCE // Since Phase 2 RCE only uses address_taken // we don't need to run usage_counter again @@ -321,8 +319,16 @@ static void rce_phase1(block::Ptr ast) { phase2_visitor p2v; p2v.address_taken_vars = counter.address_taken_vars; ast->accept(&p2v); +} + +void eliminate_redundant_vars(block::Ptr ast) { + // gather general statistics first + usage_counter counter; + ast->accept(&counter); + + rce_phase1(ast, counter); + rce_phase2(ast, counter); - // Perform a second usage count before cleanup usage_counter counter2; ast->accept(&counter2); @@ -332,17 +338,4 @@ static void rce_phase1(block::Ptr ast) { ast->accept(&deleter); } -static void rce_phase2(block::Ptr ast) { - // phase 2 also needs usage information - // for filtering out variables that have their address taken - - usage_counter counter; - ast->accept(&counter); -} - -void eliminate_redundant_vars(block::Ptr ast) { - rce_phase1(ast); - rce_phase2(ast); -} - }