[pypy-svn] r65614 - in pypy/branch/pyjitpl5-experiments/pypy/jit/backend/llvm: . test
arigo at codespeak.net
arigo at codespeak.net
Sat Jun 6 13:01:56 CEST 2009
Author: arigo
Date: Sat Jun 6 13:01:55 2009
New Revision: 65614
Modified:
pypy/branch/pyjitpl5-experiments/pypy/jit/backend/llvm/runner.py
pypy/branch/pyjitpl5-experiments/pypy/jit/backend/llvm/test/test_runner.py
Log:
Finish the refactoring, and add a test that goes twice through the
loop in execute_operations().
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 Sat Jun 6 13:01:55 2009
@@ -277,12 +277,19 @@
incoming.append(self.getintarg(op.args[i]))
llvm_rffi.LLVMBuildBr(self.builder, self.bb_start)
else:
- xxx
+ index = op.jump_target._llvm_compiled_index
+ assert index >= 0
+ self._generate_fail(op.args, index)
def generate_FAIL(self, op):
- self.cpu._ensure_out_args(len(op.args))
- for i in range(len(op.args)):
- value_ref = self.vars[op.args[i]]
+ i = len(self.cpu.fail_ops)
+ self.cpu.fail_ops.append(op)
+ self._generate_fail(op.args, ~i)
+
+ def _generate_fail(self, args, index):
+ self.cpu._ensure_out_args(len(args))
+ for i in range(len(args)):
+ value_ref = self.vars[args[i]]
ty = llvm_rffi.LLVMTypeOf(value_ref)
typtr = llvm_rffi.LLVMPointerType(ty, 0)
addr_as_signed = rffi.cast(lltype.Signed, self.cpu.in_out_args[i])
@@ -290,9 +297,7 @@
llvmconstptr = llvm_rffi.LLVMConstIntToPtr(llvmconstint, typtr)
llvm_rffi.LLVMBuildStore(self.builder, value_ref,
llvmconstptr)
- i = len(self.cpu.fail_ops)
- self.cpu.fail_ops.append(op)
- llvm_rffi.LLVMBuildRet(self.builder, self._make_const_int(~i))
+ llvm_rffi.LLVMBuildRet(self.builder, self._make_const_int(index))
# ____________________________________________________________
Modified: pypy/branch/pyjitpl5-experiments/pypy/jit/backend/llvm/test/test_runner.py
==============================================================================
--- pypy/branch/pyjitpl5-experiments/pypy/jit/backend/llvm/test/test_runner.py (original)
+++ pypy/branch/pyjitpl5-experiments/pypy/jit/backend/llvm/test/test_runner.py Sat Jun 6 13:01:55 2009
@@ -55,3 +55,47 @@
cpu.set_future_value_int(2, 0)
cpu.execute_operations(loop)
assert cpu.get_latest_value_int(0) == 3*(2**29)
+
+def test_loop_2():
+ cpu = LLVMCPU(None)
+ cpu.setup_once()
+ #
+ v1 = BoxInt(); v2 = BoxInt()
+ loop1 = TreeLoop('loop1')
+ loop1.inputargs = [v1]
+ loop1.operations = [
+ ResOperation(rop.INT_ADD, [ConstInt(1), v1], v2),
+ ResOperation(rop.FAIL, [v2], None),
+ ]
+ cpu.compile_operations(loop1)
+ #
+ cpu.set_future_value_int(0, 123)
+ cpu.execute_operations(loop1)
+ assert cpu.get_latest_value_int(0) == 124
+ #
+ v3 = BoxInt(); v4 = BoxInt(); v5 = BoxInt()
+ loop2 = TreeLoop('loop2')
+ loop2.inputargs = [v3, v4]
+ loop2.operations = [
+ ResOperation(rop.INT_SUB, [v3, v4], v5),
+ ResOperation(rop.JUMP, [v5], None),
+ ]
+ loop2.operations[-1].jump_target = loop1
+ cpu.compile_operations(loop2)
+ #
+ cpu.set_future_value_int(0, 1500)
+ cpu.set_future_value_int(1, 60)
+ cpu.execute_operations(loop2)
+ assert cpu.get_latest_value_int(0) == 1441
+ #
+ # Now try to change the definition of loop1...
+ loop1.operations = [
+ ResOperation(rop.INT_ADD, [ConstInt(3), v1], v2),
+ ResOperation(rop.FAIL, [v2], None),
+ ]
+ cpu.compile_operations(loop1)
+ #
+ cpu.set_future_value_int(0, 1500)
+ cpu.set_future_value_int(1, 60)
+ cpu.execute_operations(loop2)
+ assert cpu.get_latest_value_int(0) == 1443 # should see the change
More information about the Pypy-commit
mailing list