Author: Armin Rigo <[email protected]>
Branch: op_malloc_gc
Changeset: r50629:9d09995aae35
Date: 2011-12-17 16:30 +0100
http://bitbucket.org/pypy/pypy/changeset/9d09995aae35/

Log:    Finish test_rewrite.TestFramework.

diff --git a/pypy/jit/backend/llsupport/gc.py b/pypy/jit/backend/llsupport/gc.py
--- a/pypy/jit/backend/llsupport/gc.py
+++ b/pypy/jit/backend/llsupport/gc.py
@@ -679,18 +679,19 @@
     def _make_functions(self):
         llop1 = self.llop1
 
-        def malloc_nursery(size):
+        def malloc_nursery_slowpath(size):
             """Allocate 'size' null bytes out of the nursery.
-            Note that the fast path is typically inlined by the backend.
-            """
+            Note that the fast path is typically inlined by the backend."""
             type_id = rffi.cast(llgroup.HALFWORD, 0)    # missing here
             return llop1.do_malloc_fixedsize_clear(llmemory.GCREF,
                                                    type_id, size,
                                                    False, False, False)
-        self.generate_function('malloc_nursery', malloc_nursery,
+        self.generate_function('malloc_nursery', malloc_nursery_slowpath,
                                [lltype.Signed])
 
         def malloc_array(itemsize, tid, num_elem):
+            """Allocate an array with a variable-size num_elem.
+            Only works for standard arrays."""
             type_id = llop.extract_ushort(llgroup.HALFWORD, tid)
             check_typeid(type_id)
             return llop1.do_malloc_varsize_clear(
@@ -700,6 +701,28 @@
         self.generate_function('malloc_array', malloc_array,
                                [lltype.Signed] * 3)
 
+        def malloc_str(length):
+            return llop1.do_malloc_varsize_clear(
+                llmemory.GCREF,
+                str_type_id, length, str_basesize, str_itemsize,
+                str_ofs_length)
+        self.generate_function('malloc_str', malloc_str,
+                               [lltype.Signed])
+
+        def malloc_unicode(length):
+            return llop1.do_malloc_varsize_clear(
+                llmemory.GCREF,
+                unicode_type_id, length, unicode_basesize, unicode_itemsize,
+                unicode_ofs_length)
+        self.generate_function('malloc_unicode', malloc_unicode,
+                               [lltype.Signed])
+
+        # Rarely called: allocate a fixed-size amount of bytes, but
+        # not in the nursery, because it is too big.  Implemented like
+        # malloc_nursery_slowpath() above.
+        self.generate_function('malloc_fixedsize', malloc_nursery_slowpath,
+                               [lltype.Signed])
+
 ##        # make the fixed malloc function, with one argument
 ##        def malloc_gc_fixed(size):
 ##            type_id = rffi.cast(llgroup.HALFWORD, 0)    # missing here
diff --git a/pypy/jit/backend/llsupport/rewrite.py 
b/pypy/jit/backend/llsupport/rewrite.py
--- a/pypy/jit/backend/llsupport/rewrite.py
+++ b/pypy/jit/backend/llsupport/rewrite.py
@@ -125,7 +125,15 @@
             self.gen_initialize_tid(op.result, tid)
             self.gen_initialize_len(op.result, v_length, arraylen_descr)
         else:
-            self.gen_malloc_array(item_size, tid, v_length, op.result)
+            opnum = op.getopnum()
+            if opnum == rop.NEW_ARRAY:
+                self.gen_malloc_array(item_size, tid, v_length, op.result)
+            elif opnum == rop.NEWSTR:
+                self.gen_malloc_str(v_length, op.result)
+            elif opnum == rop.NEWUNICODE:
+                self.gen_malloc_unicode(v_length, op.result)
+            else:
+                raise NotImplementedError(op.getopname())
 
     # ----------
 
@@ -159,6 +167,16 @@
                                   ConstInt(tid),
                                   v_num_elem], v_result)
 
+    def gen_malloc_str(self, v_num_elem, v_result):
+        """Generate a CALL_MALLOC_GC(malloc_str_fn, ...)."""
+        self._gen_call_malloc_gc([self.gc_ll_descr.c_malloc_str_fn,
+                                  v_num_elem], v_result)
+
+    def gen_malloc_unicode(self, v_num_elem, v_result):
+        """Generate a CALL_MALLOC_GC(malloc_unicode_fn, ...)."""
+        self._gen_call_malloc_gc([self.gc_ll_descr.c_malloc_unicode_fn,
+                                  v_num_elem], v_result)
+
     def gen_malloc_nursery(self, size, v_result):
         """Try to generate or update a CALL_MALLOC_NURSERY.
         If that fails, generate a plain CALL_MALLOC_GC instead.
diff --git a/pypy/jit/backend/llsupport/test/test_rewrite.py 
b/pypy/jit/backend/llsupport/test/test_rewrite.py
--- a/pypy/jit/backend/llsupport/test/test_rewrite.py
+++ b/pypy/jit/backend/llsupport/test/test_rewrite.py
@@ -332,7 +332,8 @@
             jump()
         """, """
             []
-            p0 = malloc_gc(%(bdescr.get_base_size(False) + 100)d, 0, 0)
+            p0 = call_malloc_gc(ConstClass(malloc_fixedsize), \
+                                %(bdescr.get_base_size(False) + 100)d)
             setfield_gc(p0, 8765, descr=tiddescr)
             setfield_gc(p0, 100, descr=blendescr)
             jump()
@@ -348,13 +349,15 @@
             jump()
         """, """
             []
-            p0 = malloc_nursery(%(2 * (bdescr.get_base_size(False) + 104))d)
+            p0 = call_malloc_nursery(ConstClass(malloc_nursery), \
+                              %(2 * (bdescr.get_base_size(False) + 104))d)
             setfield_gc(p0, 8765, descr=tiddescr)
             setfield_gc(p0, 101, descr=blendescr)
             p1 = int_add(p0, %(bdescr.get_base_size(False) + 104)d)
             setfield_gc(p1, 8765, descr=tiddescr)
             setfield_gc(p1, 102, descr=blendescr)
-            p2 = malloc_nursery(%(bdescr.get_base_size(False) + 104)d)
+            p2 = call_malloc_nursery(ConstClass(malloc_nursery), \
+                              %(bdescr.get_base_size(False) + 104)d)
             setfield_gc(p2, 8765, descr=tiddescr)
             setfield_gc(p2, 103, descr=blendescr)
             jump()
@@ -367,7 +370,8 @@
             jump()
         """, """
             [p1]
-            p0 = malloc_nursery(104)      # rounded up
+            p0 = call_malloc_nursery(ConstClass(malloc_nursery), \
+                                     104)      # rounded up
             setfield_gc(p0, 9315, descr=tiddescr)
             setfield_gc(p0, ConstClass(o_vtable), descr=vtable_descr)
             jump()
@@ -381,7 +385,7 @@
             jump()
         """, """
             [p1]
-            p0 = malloc_gc(102, 0, 0)
+            p0 = call_malloc_gc(ConstClass(malloc_fixedsize), 102)
             setfield_gc(p0, 9315, descr=tiddescr)
             setfield_gc(p0, ConstClass(o_vtable), descr=vtable_descr)
             jump()
@@ -393,18 +397,19 @@
             p0 = newstr(14)
             p1 = newunicode(10)
             p2 = newunicode(i2)
+            p3 = newstr(i2)
             jump()
         """, """
             [i2]
-            p0 = malloc_nursery(%(str_basesize + 16 * str_itemsize + \
+            p0 = call_malloc_nursery(ConstClass(malloc_nursery),     \
+                                %(str_basesize + 16 * str_itemsize + \
                                   unicode_basesize + 10 * unicode_itemsize)d)
             setfield_gc(p0, %(str_type_id)d, descr=tiddescr)
             setfield_gc(p0, 14, descr=strlendescr)
             p1 = int_add(p0, %(str_basesize + 16 * str_itemsize)d)
             setfield_gc(p1, %(unicode_type_id)d, descr=tiddescr)
             setfield_gc(p1, 10, descr=unicodelendescr)
-            p2 = malloc_gc(%(unicode_basesize)d, i2, %(unicode_itemsize)d)
-            setfield_gc(p2, %(unicode_type_id)d, descr=tiddescr)
-            setfield_gc(p2, i2, descr=unicodelendescr)
+            p2 = call_malloc_gc(ConstClass(malloc_unicode), i2)
+            p3 = call_malloc_gc(ConstClass(malloc_str), i2)
             jump()
         """)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to