[前][次][番号順一覧][スレッド一覧]

ruby-changes:63491

From: wanabe <ko1@a...>
Date: Sat, 31 Oct 2020 11:58:48 +0900 (JST)
Subject: [ruby-changes:63491] 4f8d9b0db8 (master): Revert "Use adjusted sp on `iseq_set_sequence()`" and "Delay `remove_unreachable_chunk()` after `iseq_set_sequence()`"

https://git.ruby-lang.org/ruby.git/commit/?id=4f8d9b0db8

From 4f8d9b0db84c42c8d37f75de885de1c0a5cb542c Mon Sep 17 00:00:00 2001
From: wanabe <s.wanabe@g...>
Date: Sat, 31 Oct 2020 11:53:20 +0900
Subject: Revert "Use adjusted sp on `iseq_set_sequence()`" and "Delay
 `remove_unreachable_chunk()` after `iseq_set_sequence()`"

This reverts commit 3685ed7303fc08bf68cd3cc8d11e22a8ce63a067 and 5dc107b03f5cf32656a5308574b90458486c633c.
Because of some CI failures https://github.com/ruby/ruby/pull/3404#issuecomment-719868313.

diff --git a/compile.c b/compile.c
index fea4a60..bf2c4f8 100644
--- a/compile.c
+++ b/compile.c
@@ -478,7 +478,6 @@ static int iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *anchor, const NODE *n https://github.com/ruby/ruby/blob/trunk/compile.c#L478
 static int iseq_setup(rb_iseq_t *iseq, LINK_ANCHOR *const anchor);
 static int iseq_setup_insn(rb_iseq_t *iseq, LINK_ANCHOR *const anchor);
 static int iseq_optimize(rb_iseq_t *iseq, LINK_ANCHOR *const anchor);
-static int iseq_optimize_after_set_sequence(rb_iseq_t *iseq, LINK_ANCHOR *const anchor);
 static int iseq_insns_unification(rb_iseq_t *iseq, LINK_ANCHOR *const anchor);
 
 static int iseq_set_local_table(rb_iseq_t *iseq, const ID *tbl);
@@ -1468,7 +1467,6 @@ iseq_setup(rb_iseq_t *iseq, LINK_ANCHOR *const anchor) https://github.com/ruby/ruby/blob/trunk/compile.c#L1467
 
     debugs("[compile step 4.1 (iseq_set_sequence)]\n");
     if (!iseq_set_sequence(iseq, anchor)) return COMPILE_NG;
-    iseq_optimize_after_set_sequence(iseq, anchor);
     if (compile_debug > 5)
 	dump_disasm_list(FIRST_ELEMENT(anchor));
 
@@ -2270,14 +2268,16 @@ iseq_set_sequence(rb_iseq_t *iseq, LINK_ANCHOR *const anchor) https://github.com/ruby/ruby/blob/trunk/compile.c#L2268
 	    }
 	  case ISEQ_ELEMENT_ADJUST:
 	    {
-                ADJUST *adjust = (ADJUST *)list;
-                int orig_sp = sp;
-                sp = adjust->label ? adjust->label->sp : 0;
-                if (adjust->line_no != -1 && orig_sp - sp > 0) {
-                    if (orig_sp - sp > 1) code_index++; /* 1 operand */
-                    code_index++; /* insn */
-                    insn_num++;
-                }
+		ADJUST *adjust = (ADJUST *)list;
+		if (adjust->line_no != -1) {
+		    int orig_sp = sp;
+		    sp = adjust->label ? adjust->label->sp : 0;
+		    if (orig_sp - sp > 0) {
+			if (orig_sp - sp > 1) code_index++; /* 1 operand */
+			code_index++; /* insn */
+			insn_num++;
+		    }
+		}
 		break;
 	    }
 	  default: break;
@@ -2856,20 +2856,6 @@ ci_argc_set(const rb_iseq_t *iseq, const struct rb_callinfo *ci, int argc) https://github.com/ruby/ruby/blob/trunk/compile.c#L2856
 }
 
 static int
-iseq_peephole_optimize_after_set_sequence(rb_iseq_t *iseq, LINK_ELEMENT *list)
-{
-    INSN *const iobj = (INSN *)list;
-
-    optimize_checktype(iseq, iobj);
-
-    if (IS_INSN_ID(iobj, jump) || IS_INSN_ID(iobj, leave)) {
-        remove_unreachable_chunk(iseq, iobj->link.next);
-    }
-
-    return COMPILE_OK;
-}
-
-static int
 iseq_peephole_optimize(rb_iseq_t *iseq, LINK_ELEMENT *list, const int do_tailcallopt)
 {
     INSN *const iobj = (INSN *)list;
@@ -2907,6 +2893,7 @@ iseq_peephole_optimize(rb_iseq_t *iseq, LINK_ELEMENT *list, const int do_tailcal https://github.com/ruby/ruby/blob/trunk/compile.c#L2893
 	     *      LABEL2 directly
 	     */
 	    replace_destination(iobj, diobj);
+	    remove_unreachable_chunk(iseq, iobj->link.next);
 	    goto again;
 	}
         else if (IS_INSN_ID(diobj, leave)) {
@@ -2980,6 +2967,9 @@ iseq_peephole_optimize(rb_iseq_t *iseq, LINK_ELEMENT *list, const int do_tailcal https://github.com/ruby/ruby/blob/trunk/compile.c#L2967
 		ELEM_REPLACE(&piobj->link, &popiobj->link);
 	    }
 	}
+	if (remove_unreachable_chunk(iseq, iobj->link.next)) {
+	    goto again;
+	}
     }
 
     /*
@@ -3012,6 +3002,10 @@ iseq_peephole_optimize(rb_iseq_t *iseq, LINK_ELEMENT *list, const int do_tailcal https://github.com/ruby/ruby/blob/trunk/compile.c#L3002
 	}
     }
 
+    if (IS_INSN_ID(iobj, leave)) {
+	remove_unreachable_chunk(iseq, iobj->link.next);
+    }
+
     if (IS_INSN_ID(iobj, branchif) ||
 	IS_INSN_ID(iobj, branchnil) ||
 	IS_INSN_ID(iobj, branchunless)) {
@@ -3548,25 +3542,6 @@ iseq_optimize(rb_iseq_t *iseq, LINK_ANCHOR *const anchor) https://github.com/ruby/ruby/blob/trunk/compile.c#L3542
     return COMPILE_OK;
 }
 
-static int
-iseq_optimize_after_set_sequence(rb_iseq_t *iseq, LINK_ANCHOR *const anchor)
-{
-    LINK_ELEMENT *list;
-    const int do_peepholeopt = ISEQ_COMPILE_DATA(iseq)->option->peephole_optimization;
-
-    list = FIRST_ELEMENT(anchor);
-
-    while (list) {
-	if (IS_INSN(list)) {
-	    if (do_peepholeopt) {
-		iseq_peephole_optimize_after_set_sequence(iseq, list);
-	    }
-	}
-	list = list->next;
-    }
-    return COMPILE_OK;
-}
-
 #if OPT_INSTRUCTIONS_UNIFICATION
 static INSN *
 new_unified_insn(rb_iseq_t *iseq,
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]