[pypy-svn] r65717 - in pypy/branch/pyjitpl5-experiments/pypy: config jit/backend jit/backend/llvm jit/backend/llvm/test

arigo at codespeak.net arigo at codespeak.net
Wed Jun 10 12:28:52 CEST 2009


Author: arigo
Date: Wed Jun 10 12:28:51 2009
New Revision: 65717

Modified:
   pypy/branch/pyjitpl5-experiments/pypy/config/translationoption.py
   pypy/branch/pyjitpl5-experiments/pypy/jit/backend/detect_cpu.py
   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/jit/backend/llvm/test/test_1st.py
Log:
Clean up the CallDescr class, avoiding building ty_xxx values
when calldescrof() is called.  Other minor clean-ups.


Modified: pypy/branch/pyjitpl5-experiments/pypy/config/translationoption.py
==============================================================================
--- pypy/branch/pyjitpl5-experiments/pypy/config/translationoption.py	(original)
+++ pypy/branch/pyjitpl5-experiments/pypy/config/translationoption.py	Wed Jun 10 12:28:51 2009
@@ -116,7 +116,7 @@
                suggests=[("translation.gc", "boehm"),         # for now
                          ("translation.list_comprehension_operations", True)]),
     ChoiceOption("jit_backend", "choose the backend for the JIT",
-                 ["auto", "minimal", "x86"],
+                 ["auto", "minimal", "x86", "llvm"],
                  default="auto", cmdline="--jit-backend"),
 
     # misc

Modified: pypy/branch/pyjitpl5-experiments/pypy/jit/backend/detect_cpu.py
==============================================================================
--- pypy/branch/pyjitpl5-experiments/pypy/jit/backend/detect_cpu.py	(original)
+++ pypy/branch/pyjitpl5-experiments/pypy/jit/backend/detect_cpu.py	Wed Jun 10 12:28:51 2009
@@ -49,6 +49,8 @@
         from pypy.jit.backend.minimal.runner import LLtypeCPU as CPU
     elif backend_name == 'cli':
         from pypy.jit.backend.cli.runner import CliCPU as CPU
+    elif backend_name == 'llvm':
+        from pypy.jit.backend.llvm.runner import LLVMCPU as CPU
     else:
         raise ProcessorAutodetectError, "unsupported cpu '%s'" % backend_name
     return CPU

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 12:28:51 2009
@@ -84,6 +84,7 @@
 
     def done_generating_function(self):
         llvm_rffi.LLVMDisposeBuilder(self.builder)
+        llvm_rffi.LLVMDumpValue(self.compiling_func)   # xxx for debugging
         #
         func_addr = llvm_rffi.LLVM_EE_getPointerToFunction(self.cpu.ee,
                                                            self.compiling_func)
@@ -516,32 +517,28 @@
     def generate_CALL(self, op):
         calldescr = op.descr
         assert isinstance(calldescr, CallDescr)
+        ty_function_ptr = self.cpu.get_calldescr_ty_function_ptr(calldescr)
         v = op.args[0]
         if isinstance(v, Const):
-            func = self.cpu._make_const(v.getint(), calldescr.ty_function_ptr)
+            func = self.cpu._make_const(v.getint(), ty_function_ptr)
         else:
             func = self.getintarg(v)
             func = llvm_rffi.LLVMBuildIntToPtr(self.builder,
                                                func,
-                                               calldescr.ty_function_ptr, "")
+                                               ty_function_ptr, "")
         nb_args = len(op.args) - 1
         arglist = lltype.malloc(rffi.CArray(llvm_rffi.LLVMValueRef), nb_args,
                                 flavor='raw')
         for i in range(nb_args):
             v = op.args[1 + i]
-            if v.type == INT:
-                value_ref = self.getintarg(v)
-            else:
-                value_ref = self.getptrarg(v)
+            index = calldescr.args_indices[i]
+            getarg = self.cpu.getarg_by_index[index]
+            value_ref = getarg(self, v)
             arglist[i] = value_ref
         res = llvm_rffi.LLVMBuildCall(self.builder,
                                       func, arglist, nb_args, "")
         lltype.free(arglist, flavor='raw')
         if op.result is not None:
-            if calldescr.result_mask >= 0:
-                mask = self.cpu._make_const_int(calldescr.result_mask)
-                res = llvm_rffi.LLVMBuildAnd(self.builder,
-                                             res, mask, "")
             self.vars[op.result] = res
 
     generate_CALL_PURE = generate_CALL

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 12:28:51 2009
@@ -148,6 +148,7 @@
 LLVMVoidType = llexternal('LLVMVoidType', [], LLVMTypeRef)
 
 LLVMTypeOf = llexternal('LLVMTypeOf', [LLVMValueRef], LLVMTypeRef)
+LLVMDumpValue = llexternal('LLVMDumpValue', [LLVMValueRef], lltype.Void)
 LLVMConstNull = llexternal('LLVMConstNull', [LLVMTypeRef], LLVMValueRef)
 LLVMConstInt = llexternal('LLVMConstInt', [LLVMTypeRef,     # type
                                            rffi.ULONGLONG,  # value

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 12:28:51 2009
@@ -251,7 +251,6 @@
         from pypy.jit.backend.llvm.compile import LLVMJITCompiler
         compiler = LLVMJITCompiler(self, loop)
         compiler.compile()
-        llvm_rffi.LLVMDumpModule(self.module)   # xxx for debugging
 
     def _ensure_in_args(self, count):
         while len(self.in_out_args) < count:
@@ -281,14 +280,6 @@
         llvmconstptr = llvm_rffi.LLVMConstIntToPtr(llvmconstint, ty_result)
         return llvmconstptr
 
-    def _lltype2llvmtype(self, TYPE):
-        if TYPE is lltype.Void:
-            return self.ty_void
-        elif isinstance(TYPE, lltype.Ptr) and TYPE.TO._gckind == 'gc':
-            return self.ty_char_ptr
-        else:
-            return self.ty_int
-
     def _get_var_type(self, v):
         if v.type == INT:
             return self.ty_int
@@ -410,35 +401,43 @@
         return self._arraydescrs[itemsize_index]
 
     def calldescrof(self, FUNC, ARGS, RESULT):
-        try:
-            return self._descr_caches['call', ARGS, RESULT]
-        except KeyError:
-            pass
-        #
-        param_types = lltype.malloc(rffi.CArray(llvm_rffi.LLVMTypeRef),
-                                    len(ARGS), flavor='raw')
-        for i in range(len(ARGS)):
-            param_types[i] = self._lltype2llvmtype(ARGS[i])
-        ty_func = llvm_rffi.LLVMFunctionType(self._lltype2llvmtype(RESULT),
-                                             param_types, len(ARGS), 0)
-        lltype.free(param_types, flavor='raw')
-        ty_funcptr = llvm_rffi.LLVMPointerType(ty_func, 0)
-        #
+        args_indices = [self._get_size_index(ARG) for ARG in ARGS]
         if RESULT is lltype.Void:
-            result_mask = 0
-        elif isinstance(RESULT, lltype.Ptr) and RESULT.TO._gckind == 'gc':
-            result_mask = -2
+            res_index = -1
         else:
-            result_size = symbolic.get_size(RESULT,
-                                            self.translate_support_code)
-            if result_size < self.size_of_int:
-                result_mask = (1 << (result_size*8)) - 1
-            else:
-                result_mask = -1
-        descr = CallDescr(ty_funcptr, result_mask)
-        self._descr_caches['call', ARGS, RESULT] = descr
+            res_index = self._get_size_index(RESULT)
+        #
+        key = ('call', tuple(args_indices), res_index)
+        try:
+            descr = self._descr_caches[key]
+        except KeyError:
+            descr = CallDescr(args_indices, res_index)
+            self._descr_caches[key] = descr
         return descr
 
+    def get_calldescr_ty_function_ptr(self, calldescr):
+        if not calldescr.ty_function_ptr:
+            #
+            args_indices = calldescr.args_indices
+            param_types = lltype.malloc(rffi.CArray(llvm_rffi.LLVMTypeRef),
+                                        len(args_indices), flavor='raw')
+            for i in range(len(args_indices)):
+                param_types[i] = self.types_by_index[args_indices[i]]
+            #
+            res_index = calldescr.res_index
+            if res_index < 0:
+                ty_result = self.ty_void
+            else:
+                ty_result = self.types_by_index[res_index]
+            #
+            ty_func = llvm_rffi.LLVMFunctionType(ty_result, param_types,
+                                                 len(args_indices), 0)
+            lltype.free(param_types, flavor='raw')
+            ty_funcptr = llvm_rffi.LLVMPointerType(ty_func, 0)
+            calldescr.ty_function_ptr = ty_funcptr
+            #
+        return calldescr.ty_function_ptr
+
     # ------------------------------
     # do_xxx methods
 
@@ -652,14 +651,15 @@
 
     def do_call(self, args, calldescr):
         assert isinstance(calldescr, CallDescr)
-        num_args = len(args) - 1
-        ptr = (calldescr.result_mask == -2)
+        num_args = len(calldescr.args_indices)
+        assert num_args == len(args) - 1
+        ptr = (calldescr.res_index == self.SIZE_GCPTR)
         loop = self._get_loop_for_call(num_args, calldescr, ptr)
         history.set_future_values(self, args)
         self.execute_operations(loop)
         # Note: if an exception is set, the rest of the code does a bit of
         # nonsense but nothing wrong (the return value should be ignored)
-        if calldescr.result_mask == 0:
+        if calldescr.res_index < 0:
             return None
         elif ptr:
             return BoxPtr(self.get_latest_value_ptr(0))
@@ -695,12 +695,13 @@
 
 class CallDescr(AbstractDescr):
     ty_function_ptr = lltype.nullptr(llvm_rffi.LLVMTypeRef.TO)
-    result_mask = -1
+    args_indices = [0]   # dummy value to make annotation happy
+    res_index = 0
     _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
+    def __init__(self, args_indices, res_index):
+        self.args_indices = args_indices
+        self.res_index = res_index
 
 # ____________________________________________________________
 

Modified: pypy/branch/pyjitpl5-experiments/pypy/jit/backend/llvm/test/test_1st.py
==============================================================================
--- pypy/branch/pyjitpl5-experiments/pypy/jit/backend/llvm/test/test_1st.py	(original)
+++ pypy/branch/pyjitpl5-experiments/pypy/jit/backend/llvm/test/test_1st.py	Wed Jun 10 12:28:51 2009
@@ -99,3 +99,12 @@
     cpu.set_future_value_int(1, 60)
     cpu.execute_operations(loop2)
     assert cpu.get_latest_value_int(0) == 1443    # should see the change
+
+def test_descrof():
+    cpu = LLVMCPU(None)
+    # just to check that we can call them before setup_once():
+    from pypy.rpython.lltypesystem import lltype, rclass
+    cpu.sizeof(rclass.OBJECT)
+    cpu.fielddescrof(rclass.OBJECT, 'typeptr')
+    cpu.arraydescrof(lltype.GcArray(lltype.Signed))
+    cpu.calldescrof(lltype.FuncType([], lltype.Signed), (), lltype.Signed)



More information about the Pypy-commit mailing list