Skip to content

Commit

Permalink
Moved phase 2 RCE into a separate function
Browse files Browse the repository at this point in the history
  • Loading branch information
AjayBrahmakshatriya committed May 24, 2024
1 parent b09810e commit 15a2c33
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions src/blocks/rce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,26 +303,32 @@ 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

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);
Expand All @@ -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);
}

}

0 comments on commit 15a2c33

Please sign in to comment.