[pypy-svn] r74459 - in pypy/branch/blackhole-improvement/pypy/jit: codewriter codewriter/test metainterp metainterp/test
arigo at codespeak.net
arigo at codespeak.net
Mon May 10 12:50:09 CEST 2010
Author: arigo
Date: Mon May 10 12:50:07 2010
New Revision: 74459
Modified:
pypy/branch/blackhole-improvement/pypy/jit/codewriter/assembler.py
pypy/branch/blackhole-improvement/pypy/jit/codewriter/call.py
pypy/branch/blackhole-improvement/pypy/jit/codewriter/codewriter.py
pypy/branch/blackhole-improvement/pypy/jit/codewriter/jitcode.py
pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_call.py
pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_codewriter.py
pypy/branch/blackhole-improvement/pypy/jit/metainterp/blackhole.py
pypy/branch/blackhole-improvement/pypy/jit/metainterp/test/test_basic.py
pypy/branch/blackhole-improvement/pypy/jit/metainterp/warmspot.py
Log:
Have test_basic.test_direct_call() half-passing again.
Modified: pypy/branch/blackhole-improvement/pypy/jit/codewriter/assembler.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/codewriter/assembler.py (original)
+++ pypy/branch/blackhole-improvement/pypy/jit/codewriter/assembler.py Mon May 10 12:50:07 2010
@@ -43,6 +43,7 @@
self.switchdictdescrs = []
self.count_regs = dict.fromkeys(KINDS, 0)
self.liveness = {}
+ self.startpoints = set()
def emit_reg(self, reg):
if reg.index >= self.count_regs[reg.kind]:
@@ -147,6 +148,7 @@
key = opname + '/' + ''.join(argcodes)
num = self.insns.setdefault(key, len(self.insns))
self.code[startposition] = chr(num)
+ self.startpoints.add(startposition)
def get_liveness_info(self, insn, kind):
lives = [chr(reg.index) for reg in insn[1:] if reg.kind == kind]
@@ -182,4 +184,5 @@
self.count_regs['ref'],
self.count_regs['float'],
liveness=self.liveness,
- assembler=self)
+ assembler=self,
+ startpoints=self.startpoints)
Modified: pypy/branch/blackhole-improvement/pypy/jit/codewriter/call.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/codewriter/call.py (original)
+++ pypy/branch/blackhole-improvement/pypy/jit/codewriter/call.py Mon May 10 12:50:07 2010
@@ -4,23 +4,25 @@
#
from pypy.jit.codewriter import support
-from pypy.translator.simplify import get_funcobj
from pypy.jit.codewriter.jitcode import JitCode
+from pypy.translator.simplify import get_funcobj, get_functype
+from pypy.rpython.lltypesystem import lltype, llmemory
class CallControl(object):
- def __init__(self, rtyper=None, portal_graph=None):
- self.rtyper = rtyper
+ def __init__(self, cpu=None, portal_graph=None):
+ self.cpu = cpu
self.portal_graph = portal_graph
self.jitcodes = {} # map {graph: jitcode}
self.unfinished_graphs = [] # list of graphs with pending jitcodes
- if rtyper is not None:
+ if cpu is not None:
from pypy.jit.metainterp.effectinfo import VirtualizableAnalyzer
from pypy.translator.backendopt.canraise import RaiseAnalyzer
from pypy.translator.backendopt.writeanalyze import \
ReadWriteAnalyzer
- translator = rtyper.annotator.translator
+ self.rtyper = cpu.rtyper
+ translator = self.rtyper.annotator.translator
self.raise_analyzer = RaiseAnalyzer(translator)
self.readwrite_analyzer = ReadWriteAnalyzer(translator)
self.virtualizable_analyzer = VirtualizableAnalyzer(translator)
@@ -135,7 +137,21 @@
try:
return self.jitcodes[graph]
except KeyError:
- jitcode = JitCode(graph.name, called_from=called_from)
+ fnaddr, calldescr = self.get_jitcode_calldescr(graph)
+ jitcode = JitCode(graph.name, fnaddr, calldescr,
+ called_from=called_from)
self.jitcodes[graph] = jitcode
self.unfinished_graphs.append(graph)
return jitcode
+
+ def get_jitcode_calldescr(self, graph):
+ fnptr = self.rtyper.getcallable(graph)
+ FUNC = get_functype(lltype.typeOf(fnptr))
+ if self.rtyper.type_system.name == 'ootypesystem':
+ XXX
+ else:
+ fnaddr = llmemory.cast_ptr_to_adr(fnptr)
+ NON_VOID_ARGS = [ARG for ARG in FUNC.ARGS if ARG is not lltype.Void]
+ calldescr = self.cpu.calldescrof(FUNC, tuple(NON_VOID_ARGS),
+ FUNC.RESULT)
+ return (fnaddr, calldescr)
Modified: pypy/branch/blackhole-improvement/pypy/jit/codewriter/codewriter.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/codewriter/codewriter.py (original)
+++ pypy/branch/blackhole-improvement/pypy/jit/codewriter/codewriter.py Mon May 10 12:50:07 2010
@@ -60,7 +60,8 @@
self.assembler.assemble(ssarepr, jitcode)
def make_jitcodes(self, maingraph, policy, verbose=False):
- self.callcontrol = CallControl(self.cpu.rtyper, maingraph)
+ self.portal_graph = maingraph
+ self.callcontrol = CallControl(self.cpu, maingraph)
self.callcontrol.find_all_graphs(policy)
mainjitcode = self.callcontrol.get_jitcode(maingraph)
for graph, jitcode in self.callcontrol.enum_pending_graphs():
Modified: pypy/branch/blackhole-improvement/pypy/jit/codewriter/jitcode.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/codewriter/jitcode.py (original)
+++ pypy/branch/blackhole-improvement/pypy/jit/codewriter/jitcode.py Mon May 10 12:50:07 2010
@@ -1,5 +1,6 @@
from pypy.jit.metainterp.history import AbstractDescr
from pypy.rlib.objectmodel import we_are_translated
+from pypy.rpython.lltypesystem import llmemory
class JitCode(AbstractDescr):
@@ -15,7 +16,7 @@
def setup(self, code='', constants_i=[], constants_r=[], constants_f=[],
num_regs_i=256, num_regs_r=256, num_regs_f=256,
- liveness=None, assembler=None):
+ liveness=None, assembler=None, startpoints=None):
self.code = code
# if the following lists are empty, use a single shared empty list
self.constants_i = constants_i or self._empty_i
@@ -27,6 +28,10 @@
(num_regs_f << 0))
self.liveness = liveness
self._assembler = assembler # debugging
+ self._startpoints = startpoints # debugging
+
+ def get_fnaddr_as_int(self):
+ return llmemory.cast_adr_to_int(self.fnaddr)
def num_regs_i(self):
return self.num_regs_encoded >> 18
Modified: pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_call.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_call.py (original)
+++ pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_call.py Mon May 10 12:50:07 2010
@@ -137,7 +137,8 @@
# ____________________________________________________________
def test_get_jitcode():
- cc = CallControl()
+ from pypy.jit.codewriter.test.test_codewriter import FakeCPU
+ cc = CallControl(FakeCPU())
class somegraph:
name = "foo"
jitcode = cc.get_jitcode(somegraph)
Modified: pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_codewriter.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_codewriter.py (original)
+++ pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_codewriter.py Mon May 10 12:50:07 2010
@@ -1,9 +1,21 @@
import py
from pypy.jit.codewriter.codewriter import CodeWriter
from pypy.jit.codewriter import support
+from pypy.rpython.lltypesystem import lltype, llmemory
+
+class FakeRTyper:
+ class annotator:
+ translator = None
+ class type_system:
+ name = 'lltypesystem'
+ def getcallable(self, graph):
+ F = lltype.FuncType([], lltype.Signed)
+ return lltype.functionptr(F, 'bar')
class FakeCPU:
- rtyper = None
+ rtyper = FakeRTyper()
+ def calldescrof(self, FUNC, ARGS, RESULT):
+ return ('calldescr', FUNC, ARGS, RESULT)
class FakePolicy:
def look_inside_graph(self, graph):
@@ -51,6 +63,8 @@
assert jitcode.name == 'fff'
assert jitcode2.name == 'ggg'
assert 'ggg' in jitcode._dump
+ assert lltype.typeOf(jitcode2.fnaddr) == llmemory.Address
+ assert jitcode2.calldescr[0] == 'calldescr'
def test_integration():
from pypy.jit.metainterp.blackhole import BlackholeInterpBuilder
Modified: pypy/branch/blackhole-improvement/pypy/jit/metainterp/blackhole.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/metainterp/blackhole.py (original)
+++ pypy/branch/blackhole-improvement/pypy/jit/metainterp/blackhole.py Mon May 10 12:50:07 2010
@@ -5,7 +5,7 @@
from pypy.rpython.lltypesystem import lltype, llmemory, rclass
from pypy.rpython.lltypesystem.lloperation import llop
from pypy.rpython.llinterp import LLException
-from pypy.jit.codewriter.jitcode import SwitchDictDescr
+from pypy.jit.codewriter.jitcode import JitCode, SwitchDictDescr
def arguments(*argtypes, **kwds):
@@ -80,6 +80,10 @@
#
def dispatch_loop(self, code, position):
while True:
+ if not we_are_translated():
+ assert position in self._current_jitcode._startpoints, (
+ "the current position %d is in the middle of "
+ "an instruction!" % position)
opcode = ord(code[position])
position += 1
for i, func in all_funcs:
@@ -148,11 +152,13 @@
value = self.cpu
elif argtype == 'pc':
value = position
- elif argtype == 'd':
+ elif argtype == 'd' or argtype == 'j':
assert argcodes[next_argcode] == 'd'
next_argcode = next_argcode + 1
index = ord(code[position]) | (ord(code[position+1])<<8)
value = self.descrs[index]
+ if argtype == 'j':
+ assert isinstance(value, JitCode)
position += 2
else:
raise AssertionError("bad argtype: %r" % (argtype,))
@@ -262,6 +268,8 @@
self.registers_f[index] = value
def run(self, jitcode, position):
+ if not we_are_translated():
+ self._current_jitcode = jitcode
self.copy_constants(self.registers_i, jitcode.constants_i)
self.copy_constants(self.registers_r, jitcode.constants_r)
self.copy_constants(self.registers_f, jitcode.constants_f)
@@ -751,6 +759,16 @@
def bhimpl_residual_call_irf_v(cpu, func, calldescr,args_i,args_r,args_f):
cpu.bh_call_v(func, calldescr, args_i, args_r, args_f)
+ @arguments("cpu", "j", "R", returns="i")
+ def bhimpl_inline_call_r_i(cpu, jitcode, args_r):
+ return cpu.bh_call_i(jitcode.get_fnaddr_as_int(), jitcode.calldescr,
+ None, args_r, None)
+
+ @arguments("cpu", "j", "I", "R", returns="i")
+ def bhimpl_inline_call_ir_i(cpu, jitcode, args_i, args_r):
+ return cpu.bh_call_i(jitcode.get_fnaddr_as_int(), jitcode.calldescr,
+ args_i, args_r, None)
+
@arguments("cpu", "d", "i", returns="r")
def bhimpl_new_array(cpu, arraydescr, length):
return cpu.bh_new_array(arraydescr, length)
Modified: pypy/branch/blackhole-improvement/pypy/jit/metainterp/test/test_basic.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/metainterp/test/test_basic.py (original)
+++ pypy/branch/blackhole-improvement/pypy/jit/metainterp/test/test_basic.py Mon May 10 12:50:07 2010
@@ -5,7 +5,7 @@
from pypy.jit.metainterp.warmspot import ll_meta_interp, get_stats
from pypy.jit.backend.llgraph import runner
from pypy.jit.metainterp import pyjitpl, history
-from pypy.jit.metainterp.policy import JitPolicy, StopAtXPolicy
+from pypy.jit.codewriter.policy import JitPolicy, StopAtXPolicy
from pypy import conftest
from pypy.rlib.rarithmetic import ovfcheck
from pypy.jit.metainterp.typesystem import LLTypeHelper, OOTypeHelper
@@ -21,7 +21,7 @@
stats = history.Stats()
cpu = CPUClass(rtyper, stats, None, False)
cw = codewriter.CodeWriter(cpu)
- mainjitcode = cw.make_jitcodes(graphs[0], verbose=True)
+ mainjitcode = cw.make_jitcodes(graphs[0], JitPolicy(), verbose=True)
return cw, mainjitcode
def _run_with_blackhole(cw, mainjitcode, args):
Modified: pypy/branch/blackhole-improvement/pypy/jit/metainterp/warmspot.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/metainterp/warmspot.py (original)
+++ pypy/branch/blackhole-improvement/pypy/jit/metainterp/warmspot.py Mon May 10 12:50:07 2010
@@ -18,10 +18,10 @@
from pypy.jit.metainterp import history, pyjitpl, gc
from pypy.jit.metainterp.pyjitpl import MetaInterpStaticData, MetaInterp
-from pypy.jit.metainterp.policy import JitPolicy
from pypy.jit.metainterp.typesystem import LLTypeHelper, OOTypeHelper
from pypy.jit.metainterp.jitprof import Profiler, EmptyProfiler
from pypy.jit.codewriter import support
+from pypy.jit.codewriter.policy import JitPolicy
from pypy.rlib.jit import DEBUG_STEPS, DEBUG_DETAILED, DEBUG_OFF, DEBUG_PROFILE
# ____________________________________________________________
More information about the Pypy-commit
mailing list