[pypy-svn] r65712 - in pypy/branch/pyjitpl5-experiments/pypy: jit/backend/llvm jit/backend/llvm/test rpython/lltypesystem

arigo at codespeak.net arigo at codespeak.net
Wed Jun 10 10:24:06 CEST 2009


Author: arigo
Date: Wed Jun 10 10:24:05 2009
New Revision: 65712

Added:
   pypy/branch/pyjitpl5-experiments/pypy/jit/backend/llvm/test/test_zrpy_gc.py   (contents, props changed)
Removed:
   pypy/branch/pyjitpl5-experiments/pypy/jit/backend/llvm/test/test_zrpy_basic.py
Modified:
   pypy/branch/pyjitpl5-experiments/pypy/jit/backend/llvm/compile.py
   pypy/branch/pyjitpl5-experiments/pypy/jit/backend/llvm/llvm_rffi.py
   pypy/branch/pyjitpl5-experiments/pypy/jit/backend/llvm/runner.py
   pypy/branch/pyjitpl5-experiments/pypy/rpython/lltypesystem/ll2ctypes.py
Log:
In-progress: trying to translate the llvm backend.


Modified: pypy/branch/pyjitpl5-experiments/pypy/jit/backend/llvm/compile.py
==============================================================================
--- pypy/branch/pyjitpl5-experiments/pypy/jit/backend/llvm/compile.py	(original)
+++ pypy/branch/pyjitpl5-experiments/pypy/jit/backend/llvm/compile.py	Wed Jun 10 10:24:05 2009
@@ -318,8 +318,8 @@
                                           self.cpu.const_zero,
                                           "")
         else:
-            # value_ref: ty_int
-            res = LLVMBuildNot(self.builder, value_ref, "")
+            # value_ref: ty_bit
+            res = llvm_rffi.LLVMBuildNot(self.builder, value_ref, "")
         self.vars[op.result] = res
 
     def generate_INT_ADD_OVF(self, op):

Modified: pypy/branch/pyjitpl5-experiments/pypy/jit/backend/llvm/llvm_rffi.py
==============================================================================
--- pypy/branch/pyjitpl5-experiments/pypy/jit/backend/llvm/llvm_rffi.py	(original)
+++ pypy/branch/pyjitpl5-experiments/pypy/jit/backend/llvm/llvm_rffi.py	Wed Jun 10 10:24:05 2009
@@ -14,6 +14,8 @@
 libname = os.path.join(dirname, 'pypy_cache_llvm.so')
 cname = os.path.join(os.path.dirname(__file__), 'demo1.c')
 cppname = os.path.join(os.path.dirname(__file__), 'demo2.cpp')
+o1name = os.path.join(dirname, 'demo1.o')
+o2name = os.path.join(dirname, 'demo2.o')
 
 if (not os.path.isfile(libname) or
         os.path.getmtime(cname) > os.path.getmtime(libname) or
@@ -29,18 +31,25 @@
         if err:
             raise Exception("gcc command failed")
 
-    o1name = os.path.join(dirname, 'demo1.o')
-    o2name = os.path.join(dirname, 'demo2.o')
     do("g++ -g -c '%s' -o '%s' `%s --cppflags`" % (cname, o1name, llvm_config))
     do("g++ -g -c '%s' -o '%s' `%s --cppflags`" % (cppname, o2name, llvm_config))
     do("g++ -g -shared '%s' '%s' -o '%s'" % (o1name, o2name, libname) +
        " `%s --cflags --ldflags --libs jit engine`" % llvm_config)
 
-compilation_info = ExternalCompilationInfo(
+ctypes_compilation_info = ExternalCompilationInfo(
     library_dirs = [dirname],
     libraries    = ['pypy_cache_llvm'],
 )
 
+compilation_info = ExternalCompilationInfo.from_linker_flags(
+    os.popen("%s --ldflags --libs jit engine" % llvm_config, 'r').read())
+
+compilation_info = compilation_info.merge(ExternalCompilationInfo(
+    link_extra = [o1name, o2name],
+    ))
+
+compilation_info._with_ctypes = ctypes_compilation_info
+
 _teardown = None
 
 def set_teardown_function(fn):

Modified: pypy/branch/pyjitpl5-experiments/pypy/jit/backend/llvm/runner.py
==============================================================================
--- pypy/branch/pyjitpl5-experiments/pypy/jit/backend/llvm/runner.py	(original)
+++ pypy/branch/pyjitpl5-experiments/pypy/jit/backend/llvm/runner.py	Wed Jun 10 10:24:05 2009
@@ -5,7 +5,6 @@
 from pypy.rlib import runicode
 from pypy.jit.metainterp.history import AbstractDescr, INT
 from pypy.jit.metainterp.history import BoxInt, BoxPtr
-from pypy.jit.backend import model
 from pypy.jit.backend.llvm import llvm_rffi
 from pypy.jit.metainterp import history
 from pypy.jit.metainterp.resoperation import rop, ResOperation
@@ -14,7 +13,7 @@
 history.TreeLoop._llvm_compiled_index = -1
 
 
-class LLVMCPU(model.AbstractCPU):
+class LLVMCPU(object):
     is_oo = False
     RAW_VALUE = rffi.CFixedArray(rffi.ULONGLONG, 1)
     SIGNED_VALUE = rffi.CFixedArray(lltype.Signed, 1)
@@ -358,6 +357,7 @@
 
     @staticmethod
     def cast_int_to_adr(x):
+        assert x == 0 or x > (1<<20) or x < (-1<<20)
         if we_are_translated():
             return rffi.cast(llmemory.Address, x)
         else:
@@ -694,10 +694,13 @@
         # ^^^ set by setup_once()
 
 class CallDescr(AbstractDescr):
+    ty_function_ptr = lltype.nullptr(llvm_rffi.LLVMTypeRef.TO)
+    result_mask = -1
+    _generated_mp = None
+    #
     def __init__(self, ty_function_ptr, result_mask):
         self.ty_function_ptr = ty_function_ptr
         self.result_mask = result_mask     # -2 to mark a ptr result
-        self._generated_mp = None
 
 # ____________________________________________________________
 

Added: pypy/branch/pyjitpl5-experiments/pypy/jit/backend/llvm/test/test_zrpy_gc.py
==============================================================================
--- (empty file)
+++ pypy/branch/pyjitpl5-experiments/pypy/jit/backend/llvm/test/test_zrpy_gc.py	Wed Jun 10 10:24:05 2009
@@ -0,0 +1,79 @@
+"""
+This is a test that translates a complete JIT to C and runs it.  It is
+not testing much, expect that it basically works.  What it *is* testing,
+however, is the correct handling of GC, i.e. if objects are freed as
+soon as possible (at least in a simple case).
+"""
+import weakref
+import py
+py.test.skip("in-progress")
+from pypy.rlib import rgc
+from pypy.rlib.jit import JitDriver
+from pypy.jit.backend.llvm.runner import LLVMCPU
+
+
+class X(object):
+    next = None
+
+def get_test(main):
+    main._dont_inline_ = True
+
+    def g(n):
+        x = X()
+        x.foo = 2
+        main(n, x)
+        x.foo = 5
+        return weakref.ref(x)
+    g._dont_inline_ = True
+
+    def entrypoint(args):
+        r_list = []
+        for i in range(20):
+            r = g(2000)
+            r_list.append(r)
+            rgc.collect()
+        rgc.collect(); rgc.collect()
+        freed = 0
+        for r in r_list:
+            if r() is None:
+                freed += 1
+        print freed
+        return 0
+
+    return entrypoint
+
+
+def compile_and_run(f, gc, **kwds):
+    from pypy.annotation.listdef import s_list_of_strings
+    from pypy.translator.translator import TranslationContext
+    from pypy.jit.metainterp.warmspot import apply_jit
+    from pypy.translator.c import genc
+    #
+    t = TranslationContext()
+    t.config.translation.gc = gc
+    t.config.translation.gcconfig.debugprint = True
+    for name, value in kwds.items():
+        setattr(t.config.translation, name, value)
+    t.buildannotator().build_types(f, [s_list_of_strings])
+    t.buildrtyper().specialize()
+    if kwds['jit']:
+        apply_jit(t, CPUClass=LLVMCPU)
+    cbuilder = genc.CStandaloneBuilder(t, f, t.config)
+    cbuilder.generate_source()
+    cbuilder.compile()
+    #
+    data = cbuilder.cmdexec('')
+    return data.strip()
+
+
+def test_compile_boehm():
+    myjitdriver = JitDriver(greens = [], reds = ['n', 'x'])
+    def main(n, x):
+        while n > 0:
+            myjitdriver.can_enter_jit(n=n, x=x)
+            myjitdriver.jit_merge_point(n=n, x=x)
+            y = X()
+            y.foo = x.foo
+            n -= y.foo
+    res = compile_and_run(get_test(main), "boehm", jit=True)
+    assert int(res) >= 16

Modified: pypy/branch/pyjitpl5-experiments/pypy/rpython/lltypesystem/ll2ctypes.py
==============================================================================
--- pypy/branch/pyjitpl5-experiments/pypy/rpython/lltypesystem/ll2ctypes.py	(original)
+++ pypy/branch/pyjitpl5-experiments/pypy/rpython/lltypesystem/ll2ctypes.py	Wed Jun 10 10:24:05 2009
@@ -819,11 +819,14 @@
     
     old_eci = funcptr._obj.compilation_info
     funcname = funcptr._obj._name
-    try:
-        eci = _eci_cache[old_eci]
-    except KeyError:
-        eci = old_eci.compile_shared_lib()
-        _eci_cache[old_eci] = eci
+    if hasattr(old_eci, '_with_ctypes'):
+        eci = old_eci._with_ctypes
+    else:
+        try:
+            eci = _eci_cache[old_eci]
+        except KeyError:
+            eci = old_eci.compile_shared_lib()
+            _eci_cache[old_eci] = eci
 
     libraries = list(eci.libraries + eci.frameworks)
 



More information about the Pypy-commit mailing list