From 5749658633632313f40ae9173335ee839d27e5c7 Mon Sep 17 00:00:00 2001 From: Cassie Jones Date: Mon, 2 Mar 2020 16:07:40 +0100 Subject: [PATCH] Avoid redundant loads in capture generation When generating the SSA form for captures, the previous code generated loads of all the variables that existed. This worked correctly for some cases, but since it skipped the system in trans_expr that forwards loads, it would sometimes generate loads to SSA variables that could just be directly referenced instead, which would end up causing loads from stack slots that were never written to due to optimizations. Using trans_expr on the captured variable instead of generating loads directly lets us reuse that capture logic, and it ends up making the code simpler :D --- .gitignore | 2 ++ src/trans.rs | 11 +---------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 5aa569a..e0acd43 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ /target a.out +*.s +!rt/*.s diff --git a/src/trans.rs b/src/trans.rs index c518197..2a30492 100644 --- a/src/trans.rs +++ b/src/trans.rs @@ -150,16 +150,7 @@ fn trans_expr( let ssa = func.fresh_ssa(); let upvars = upvars .iter() - .map(|var| { - let ssa = func.fresh_ssa(); - let resolved = env - .resolve(var) - .ok_or_else(|| format!("Unable to resolve variable {:?}", var))?; - let load = Code::Load(resolved); - func.block.insert(ssa, load); - func.order.push(ssa); - Ok(ssa) - }) + .map(|&var| trans_expr(prog, env, func, &Ast::Var(var))) .collect::>()?; func.block.insert( ssa, -- 2.43.2