Commits

Mark Shannon committed 5f4ef19 Draft

Eliminate redundant stores to frame in generators for DOC

  • Participants
  • Parent commits 2498ce0

Comments (0)

Files changed (1)

File Python/trace_D_O_C.c

     Py_CLEAR(LOCAL(index));
     v = POP();
     store_to_local(x, opt->top_frame, index, v);
+    /* Write-through if a generator frame */
+    if (opt->top_frame->code != Py_None &&
+        ((PyCodeObject *)opt->top_frame->code)->co_flags & CO_GENERATOR) {
+        assert(opt->top_frame->allocated);
+        assert(opt->top_frame->locals[index] && opt->top_frame->locals[index] != REAL_VALUE);
+        Py_INCREF(opt->top_frame->locals[index]);
+        materialise(x, opt->top_frame->locals[index]);
+        x->next->store_fast(x->next, i);
+    }
     SHOW_STACK();
     SHOW_FRAME();
 }
         make_stack_deferred(x, STACK_DEPTH());
     v = POP();
     v = MAKE_DEFERRED(x, v);
-    f = new_frame(0);
-    Py_INCREF(Py_None);
-    f->code = Py_None;
+    f = new_frame(code->co_nlocals);
+    Py_INCREF(code);
+    f->code = (PyObject *)code;
     Py_INCREF(Py_None);
     f->globals = Py_None;
     f->builtins = Py_None;
 
 static void leave_gen_frame(HotPyOptimiser *x)
 {
-    int i;
     HotPy_DOC *opt = (HotPy_DOC *)x;
     assert (opt->top_frame->allocated);
-    /* Ensure all values are materialised */
-    for (i = 0; i < opt->top_frame->lcount; i++) {
-        PyObject *l = opt->top_frame->locals[i];
-        if (l && l != REAL_VALUE) {
-            materialise(x, l);
-            x->next->store_fast(x->next, i);
-            opt->top_frame->locals[i] = NULL;
-        }
-    }
     materialise_stack_top(x, STACK_DEPTH());
     if (opt->top_frame->lasti >= 0)
         x->next->set_lasti(x->next, opt->top_frame->lasti);
         for (i = 0; i < n; i++)
             PUSH(real_value());
         Py_INCREF(Py_None);
-        opt->top_frame->code = Py_None;
-        Py_INCREF(Py_None);
+        opt->top_frame->code = (PyObject *)f->f_code;
+        Py_INCREF(f->f_code);
         opt->top_frame->globals = Py_None;
         opt->top_frame->builtins = Py_None;
         opt->top_frame->allocated = 1;