Author: Maciej Fijalkowski <[email protected]>
Branch: jitframe-on-heap
Changeset: r61178:9ea48f1df7ad
Date: 2013-02-13 20:09 +0200
http://bitbucket.org/pypy/pypy/changeset/9ea48f1df7ad/
Log: move two copies of slightly different code into one place
diff --git a/rpython/jit/backend/arm/locations.py
b/rpython/jit/backend/arm/locations.py
--- a/rpython/jit/backend/arm/locations.py
+++ b/rpython/jit/backend/arm/locations.py
@@ -24,6 +24,8 @@
def as_key(self):
raise NotImplementedError
+ def get_position(self):
+ raise NotImplementedError # only for stack
class RegisterLocation(AssemblerLocation):
_immutable_ = True
@@ -122,6 +124,9 @@
def location_code(self):
return 'b'
+ def get_position(self):
+ return self.position
+
def assembler(self):
return repr(self)
diff --git a/rpython/jit/backend/arm/opassembler.py
b/rpython/jit/backend/arm/opassembler.py
--- a/rpython/jit/backend/arm/opassembler.py
+++ b/rpython/jit/backend/arm/opassembler.py
@@ -21,59 +21,31 @@
from rpython.jit.backend.arm.jump import remap_frame_layout
from rpython.jit.backend.arm.regalloc import TempInt, TempPtr
from rpython.jit.backend.arm.locations import imm
-from rpython.jit.backend.llsupport import symbolic, jitframe
+from rpython.jit.backend.llsupport import symbolic
from rpython.jit.backend.llsupport.gcmap import allocate_gcmap
from rpython.jit.backend.llsupport.descr import InteriorFieldDescr
+from rpython.jit.backend.llsupport.assembler import GuardToken
from rpython.jit.metainterp.history import (Box, AbstractFailDescr,
INT, FLOAT, REF)
from rpython.jit.metainterp.history import JitCellToken, TargetToken
from rpython.jit.metainterp.resoperation import rop
from rpython.rlib.objectmodel import we_are_translated
from rpython.rlib import rgc
-from rpython.rtyper.lltypesystem import rstr, rffi, lltype, llmemory
-from rpython.rlib.rarithmetic import r_uint
+from rpython.rtyper.lltypesystem import rstr, rffi, lltype
from rpython.rtyper.annlowlevel import cast_instance_to_gcref
NO_FORCE_INDEX = -1
-class GuardToken(object):
- def __init__(self, gcmap, faildescr, failargs, fail_locs, offset, exc,
- frame_depth, fcond=c.AL, is_guard_not_invalidated=False,
- is_guard_not_forced=False):
- assert isinstance(exc, bool)
- self.faildescr = faildescr
- self.failargs = failargs
- self.fail_locs = fail_locs
- self.offset = offset
- self.gcmap = self.compute_gcmap(gcmap, failargs,
- fail_locs, frame_depth)
- self.exc = exc
- self.is_guard_not_invalidated = is_guard_not_invalidated
- self.is_guard_not_forced = is_guard_not_forced
+class ArmGuardToken(GuardToken):
+ def __init__(self, cpu, gcmap, faildescr, failargs, fail_locs,
+ offset, exc, frame_depth, is_guard_not_invalidated=False,
+ is_guard_not_forced=False, fcond=c.AL):
+ GuardToken.__init__(self, cpu, gcmap, faildescr, failargs, fail_locs,
+ offset, exc, frame_depth, is_guard_not_invalidated,
+ is_guard_not_forced)
self.fcond = fcond
- def compute_gcmap(self, gcmap, failargs, fail_locs, frame_depth):
- # note that regalloc has a very similar compute, but
- # one that does iteration over all bindings, so slightly different,
- # eh
- input_i = 0
- for i in range(len(failargs)):
- arg = failargs[i]
- if arg is None:
- continue
- loc = fail_locs[input_i]
- input_i += 1
- if arg.type == REF:
- loc = fail_locs[i]
- if loc.is_reg():
- val = loc.value
- else:
- assert loc.is_stack()
- val = JITFRAME_FIXED_SIZE + loc.value
- gcmap[val // WORD // 8] |= r_uint(1) << (val % (WORD * 8))
- return gcmap
-
class ResOpAssembler(object):
@@ -237,7 +209,7 @@
else:
self.mc.BKPT()
gcmap = allocate_gcmap(self, arglocs[0].value, JITFRAME_FIXED_SIZE)
- self.pending_guards.append(GuardToken(gcmap,
+ self.pending_guards.append(ArmGuardToken(self.cpu, gcmap,
descr,
failargs=op.getfailargs(),
fail_locs=arglocs[1:],
diff --git a/rpython/jit/backend/llsupport/assembler.py
b/rpython/jit/backend/llsupport/assembler.py
new file mode 100644
--- /dev/null
+++ b/rpython/jit/backend/llsupport/assembler.py
@@ -0,0 +1,41 @@
+
+from rpython.rlib.rarithmetic import r_uint
+from rpython.jit.backend.llsupport.symbolic import WORD
+from rpython.jit.metainterp.history import REF
+
+class GuardToken(object):
+ def __init__(self, cpu, gcmap, faildescr, failargs, fail_locs, exc,
+ frame_depth, is_guard_not_invalidated, is_guard_not_forced):
+ self.cpu = cpu
+ self.faildescr = faildescr
+ self.failargs = failargs
+ self.fail_locs = fail_locs
+ self.gcmap = self.compute_gcmap(gcmap, failargs,
+ fail_locs, frame_depth)
+ self.exc = exc
+ self.is_guard_not_invalidated = is_guard_not_invalidated
+ self.is_guard_not_forced = is_guard_not_forced
+
+ def compute_gcmap(self, gcmap, failargs, fail_locs, frame_depth):
+ # note that regalloc has a very similar compute, but
+ # one that does iteration over all bindings, so slightly different,
+ # eh
+ input_i = 0
+ for i in range(len(failargs)):
+ arg = failargs[i]
+ if arg is None:
+ continue
+ loc = fail_locs[input_i]
+ input_i += 1
+ if arg.type == REF:
+ loc = fail_locs[i]
+ if loc.is_reg():
+ val = self.cpu.gpr_reg_mgr_cls.all_reg_indexes[loc.value]
+ else:
+ val = loc.get_position() + self.cpu.JITFRAME_FIXED_SIZE
+ gcmap[val // WORD // 8] |= r_uint(1) << (val % (WORD * 8))
+ return gcmap
+
+class BaseAssembler(object):
+ """ Base class for Assembler generator in real backends
+ """
diff --git a/rpython/jit/backend/x86/assembler.py
b/rpython/jit/backend/x86/assembler.py
--- a/rpython/jit/backend/x86/assembler.py
+++ b/rpython/jit/backend/x86/assembler.py
@@ -1,6 +1,7 @@
import sys, os
from rpython.jit.backend.llsupport import symbolic, jitframe
+from rpython.jit.backend.llsupport.assembler import GuardToken, BaseAssembler
from rpython.jit.backend.llsupport.asmmemmgr import MachineDataBlockWrapper
from rpython.jit.backend.llsupport.gcmap import allocate_gcmap
from rpython.jit.metainterp.history import Const, Box, BoxInt, ConstInt
@@ -42,46 +43,12 @@
def align_stack_words(words):
return (words + CALL_ALIGN - 1) & ~(CALL_ALIGN-1)
-
-class GuardToken(object):
- def __init__(self, gcmap, faildescr, failargs, fail_locs, exc,
- frame_depth, is_guard_not_invalidated, is_guard_not_forced):
- self.faildescr = faildescr
- self.failargs = failargs
- self.fail_locs = fail_locs
- self.gcmap = self.compute_gcmap(gcmap, failargs,
- fail_locs, frame_depth)
- self.exc = exc
- self.is_guard_not_invalidated = is_guard_not_invalidated
- self.is_guard_not_forced = is_guard_not_forced
-
- def compute_gcmap(self, gcmap, failargs, fail_locs, frame_depth):
- # note that regalloc has a very similar compute, but
- # one that does iteration over all bindings, so slightly different,
- # eh
- input_i = 0
- for i in range(len(failargs)):
- arg = failargs[i]
- if arg is None:
- continue
- loc = fail_locs[input_i]
- input_i += 1
- if arg.type == REF:
- loc = fail_locs[i]
- if isinstance(loc, RegLoc):
- val = gpr_reg_mgr_cls.all_reg_indexes[loc.value]
- else:
- assert isinstance(loc, StackLoc)
- val = loc.position + JITFRAME_FIXED_SIZE
- gcmap[val // WORD // 8] |= r_uint(1) << (val % (WORD * 8))
- return gcmap
-
DEBUG_COUNTER = lltype.Struct('DEBUG_COUNTER', ('i', lltype.Signed),
('type', lltype.Char), # 'b'ridge, 'l'abel or
# 'e'ntry point
('number', lltype.Signed))
-class Assembler386(object):
+class Assembler386(BaseAssembler):
_regalloc = None
_output_loop_log = None
@@ -1886,7 +1853,7 @@
is_guard_not_invalidated = guard_opnum == rop.GUARD_NOT_INVALIDATED
is_guard_not_forced = guard_opnum == rop.GUARD_NOT_FORCED
gcmap = allocate_gcmap(self, frame_depth, JITFRAME_FIXED_SIZE)
- return GuardToken(gcmap, faildescr, failargs,
+ return GuardToken(self.cpu, gcmap, faildescr, failargs,
fail_locs, exc, frame_depth,
is_guard_not_invalidated, is_guard_not_forced)
diff --git a/rpython/jit/backend/x86/regloc.py
b/rpython/jit/backend/x86/regloc.py
--- a/rpython/jit/backend/x86/regloc.py
+++ b/rpython/jit/backend/x86/regloc.py
@@ -42,6 +42,15 @@
def find_unused_reg(self): return eax
+ def is_stack(self):
+ return False
+
+ def is_reg(self):
+ return False
+
+ def get_position(self):
+ raise NotImplementedError # only for stack
+
class RawStackLoc(AssemblerLocation):
""" The same as stack location, but does not know it's position.
Mostly usable for raw frame access
@@ -70,6 +79,9 @@
def add_offset(self, ofs):
return RawStackLoc(self.value + ofs)
+ def is_stack(self):
+ return True
+
class RawEspLoc(AssemblerLocation):
""" Esp-based location
"""
@@ -113,6 +125,9 @@
# One of INT, REF, FLOAT
self.type = type
+ def get_position(self):
+ return self.position
+
class RegLoc(AssemblerLocation):
_immutable_ = True
def __init__(self, regnum, is_xmm):
@@ -154,6 +169,9 @@
def is_float(self):
return self.is_xmm
+ def is_reg(self):
+ return True
+
class ImmediateAssemblerLocation(AssemblerLocation):
_immutable_ = True
diff --git a/rpython/jit/backend/x86/runner.py
b/rpython/jit/backend/x86/runner.py
--- a/rpython/jit/backend/x86/runner.py
+++ b/rpython/jit/backend/x86/runner.py
@@ -1,18 +1,13 @@
import py
from rpython.rlib.unroll import unrolling_iterable
from rpython.rtyper.lltypesystem import lltype, llmemory, rffi
-from rpython.rtyper.lltypesystem.lloperation import llop
from rpython.rtyper.llinterp import LLInterpreter
-from rpython.rlib.objectmodel import specialize
from rpython.rlib.jit_hooks import LOOP_RUN_CONTAINER
from rpython.jit.metainterp import history
from rpython.jit.backend.x86.assembler import Assembler386
-from rpython.jit.backend.x86.arch import IS_X86_32, JITFRAME_FIXED_SIZE
from rpython.jit.backend.x86.profagent import ProfileAgent
from rpython.jit.backend.llsupport.llmodel import AbstractLLCPU
-from rpython.jit.backend.llsupport import jitframe
from rpython.jit.backend.x86 import regloc
-from rpython.jit.backend.llsupport.symbolic import WORD
import sys
@@ -29,6 +24,8 @@
dont_keepalive_stuff = False # for tests
with_threads = False
+ from rpython.jit.backend.x86.arch import JITFRAME_FIXED_SIZE
+
def __init__(self, rtyper, stats, opts=None, translate_support_code=False,
gcdescr=None):
AbstractLLCPU.__init__(self, rtyper, stats, opts,
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit