summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2021-07-17 08:10:33 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2021-07-17 19:51:24 +0900
commit4dda97502b0fd0f58931d14dff9c1da07634995d (patch)
tree954aeb4b8274353e08e9455e1e12217ae0d15bfa
parent3401396a16f0cc53cc9a2908b9891bdec9ce3888 (diff)
downloadmruby-4dda97502b0fd0f58931d14dff9c1da07634995d.tar.gz
mruby-4dda97502b0fd0f58931d14dff9c1da07634995d.zip
codegen.c: optimize `OP_SETUPVAR` after `OP_MOVE`.
-rw-r--r--mrbgems/mruby-compiler/core/codegen.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/mrbgems/mruby-compiler/core/codegen.c b/mrbgems/mruby-compiler/core/codegen.c
index f3d6d2d25..2a95a79ad 100644
--- a/mrbgems/mruby-compiler/core/codegen.c
+++ b/mrbgems/mruby-compiler/core/codegen.c
@@ -516,6 +516,20 @@ gen_getupvar(codegen_scope *s, uint16_t dst, mrb_sym id)
}
static void
+gen_setupvar(codegen_scope *s, uint16_t dst, mrb_sym id)
+{
+ int idx;
+ int lv = search_upvar(s, id, &idx);
+
+ struct mrb_insn_data data = mrb_last_insn(s);
+ if (!no_peephole(s) && data.insn == OP_MOVE && data.a == dst) {
+ dst = data.b;
+ s->pc = s->lastpc;
+ }
+ genop_3(s, OP_SETUPVAR, dst, idx, lv);
+}
+
+static void
gen_return(codegen_scope *s, uint8_t op, uint16_t src)
{
if (no_peephole(s)) {
@@ -1311,8 +1325,7 @@ gen_assignment(codegen_scope *s, node *tree, int sp, int val)
break;
}
else { /* upvar */
- int lv = search_upvar(s, nsym(tree), &idx);
- genop_3(s, OP_SETUPVAR, sp, idx, lv);
+ gen_setupvar(s, sp, nsym(tree));
}
break;
case NODE_NVAR: