[pypy-svn] r65676 - in pypy/branch/pyjitpl5-experiments/pypy/jit/backend: llvm test
arigo at codespeak.net
arigo at codespeak.net
Mon Jun 8 22:00:47 CEST 2009
Author: arigo
Date: Mon Jun 8 22:00:46 2009
New Revision: 65676
Modified:
pypy/branch/pyjitpl5-experiments/pypy/jit/backend/llvm/compile.py
pypy/branch/pyjitpl5-experiments/pypy/jit/backend/llvm/runner.py
pypy/branch/pyjitpl5-experiments/pypy/jit/backend/test/runner_test.py
Log:
NEW_ARRAY.
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 Mon Jun 8 22:00:46 2009
@@ -586,16 +586,20 @@
self.getptrarg(op.args[0]),
self.cpu.const_null_charptr, "")
- def _generate_len(self, op, ty, const_index_length):
+ def _generate_len_gep(self, array_ref, ty, const_index_length):
array = llvm_rffi.LLVMBuildBitCast(self.builder,
- self.getptrarg(op.args[0]),
- ty, "")
+ array_ref, ty, "")
indices = lltype.malloc(rffi.CArray(llvm_rffi.LLVMValueRef), 2,
flavor='raw')
indices[0] = self.cpu.const_zero
indices[1] = const_index_length
loc = llvm_rffi.LLVMBuildGEP(self.builder, array, indices, 2, "")
lltype.free(indices, flavor='raw')
+ return loc
+
+ def _generate_len(self, op, ty, const_index_length):
+ loc = self._generate_len_gep(self.getptrarg(op.args[0]),
+ ty, const_index_length)
self.vars[op.result] = llvm_rffi.LLVMBuildLoad(self.builder, loc, "")
def generate_ARRAYLEN_GC(self, op):
@@ -668,17 +672,21 @@
value_ref = self.getunichararg(op.args[2])
llvm_rffi.LLVMBuildStore(self.builder, value_ref, loc, "")
- def generate_NEW(self, op):
- sizedescr = op.descr
- assert isinstance(sizedescr, SizeDescr)
+ def _generate_new(self, size_ref):
malloc_func = self.cpu._make_const(self.cpu.malloc_fn_ptr,
self.cpu.ty_malloc_fn)
arglist = lltype.malloc(rffi.CArray(llvm_rffi.LLVMValueRef), 1,
flavor='raw')
- arglist[0] = self.cpu._make_const_int(sizedescr.size)
+ arglist[0] = size_ref
res = llvm_rffi.LLVMBuildCall(self.builder, malloc_func,
arglist, 1, "")
lltype.free(arglist, flavor='raw')
+ return res
+
+ def generate_NEW(self, op):
+ sizedescr = op.descr
+ assert isinstance(sizedescr, SizeDescr)
+ res = self._generate_new(self.cpu._make_const_int(sizedescr.size))
self.vars[op.result] = res
def generate_NEW_WITH_VTABLE(self, op):
@@ -687,6 +695,21 @@
value_ref = self.getintarg(op.args[0])
llvm_rffi.LLVMBuildStore(self.builder, value_ref, loc, "")
+ def generate_NEW_ARRAY(self, op):
+ arraydescr = op.descr
+ assert isinstance(arraydescr, ArrayDescr)
+ length_ref = self.getintarg(op.args[0])
+ size_ref = llvm_rffi.LLVMBuildMul(
+ self.builder, length_ref,
+ self.cpu._make_const_int(arraydescr.itemsize), "")
+ res = self._generate_new(size_ref)
+ loc = self._generate_len_gep(res, arraydescr.ty_array_ptr,
+ self.cpu.const_array_index_length)
+ llvm_rffi.LLVMBuildStore(self.builder,
+ length_ref,
+ loc, "")
+ self.vars[op.result] = res
+
# ____________________________________________________________
class MissingOperation(Exception):
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 Mon Jun 8 22:00:46 2009
@@ -32,10 +32,14 @@
self.fail_ops = []
self.in_out_args = []
self._descr_caches = {
- ('array', self.SIZE_GCPTR): ArrayDescr(self.SIZE_GCPTR),
- ('array', self.SIZE_INT): ArrayDescr(self.SIZE_INT),
- ('array', self.SIZE_CHAR): ArrayDescr(self.SIZE_CHAR),
- ('array', self.SIZE_UNICHAR): ArrayDescr(self.SIZE_UNICHAR),
+ ('array', self.SIZE_GCPTR):
+ ArrayDescr(llmemory.GCREF, self.SIZE_GCPTR),
+ ('array', self.SIZE_INT):
+ ArrayDescr(lltype.Signed, self.SIZE_INT),
+ ('array', self.SIZE_CHAR):
+ ArrayDescr(lltype.Char, self.SIZE_CHAR),
+ ('array', self.SIZE_UNICHAR):
+ ArrayDescr(lltype.UniChar, self.SIZE_UNICHAR),
}
self.fielddescr_vtable = self.fielddescrof(rclass.OBJECT, 'typeptr')
if sys.maxint == 2147483647:
@@ -472,7 +476,8 @@
self.size_index = size_index # index in cpu.types_by_index
class ArrayDescr(AbstractDescr):
- def __init__(self, itemsize_index):
+ def __init__(self, TYPE, itemsize_index):
+ self.itemsize = llmemory.sizeof(TYPE)
self.itemsize_index = itemsize_index # index in cpu.types_by_index
self.ty_array_ptr = lltype.nullptr(llvm_rffi.LLVMTypeRef.TO)
# ^^^ set by setup_once()
Modified: pypy/branch/pyjitpl5-experiments/pypy/jit/backend/test/runner_test.py
==============================================================================
--- pypy/branch/pyjitpl5-experiments/pypy/jit/backend/test/runner_test.py (original)
+++ pypy/branch/pyjitpl5-experiments/pypy/jit/backend/test/runner_test.py Mon Jun 8 22:00:46 2009
@@ -596,6 +596,17 @@
t = lltype.cast_opaque_ptr(lltype.Ptr(self.T), t_box.value)
assert s.parent.parent.typeptr == t.parent.parent.typeptr
+ def test_new_array(self):
+ A = lltype.GcArray(lltype.Signed)
+ arraydescr = self.cpu.arraydescrof(A)
+ r1 = self.execute_operation(rop.NEW_ARRAY, [BoxInt(342)],
+ 'ptr', descr=arraydescr)
+ r2 = self.execute_operation(rop.NEW_ARRAY, [BoxInt(342)],
+ 'ptr', descr=arraydescr)
+ assert r1.value != r2.value
+ a = lltype.cast_opaque_ptr(lltype.Ptr(A), r1.value)
+ assert len(a) == 342
+
class OOtypeBackendTest(BaseBackendTest):
More information about the Pypy-commit
mailing list