Permalink
Browse files

Incorporate the big "max stack size" patch.

Finally, we (semi-) accurately calculate how much Converge stack size each
function needs and use only that. Doing this allows the JIT to speed things
up considerably. At the moment, the calculation is, in some places,
approximate; with luck, it should be conservative (i.e. it might request more
space is needed), so it might be a bit slower but, hopefully, it won't cause
programs to crash. Time will tell.

Programs need to be recompiled after this patch, as the compiler statically
calculates the stack size of each function. Fortunately we can do this in a
backwards compatible way (i.e. code compiled with this version of the
compiler is backwards compatible with the old VM), as we're able to make use
of spare bits in the FUNC_DEFN instruction. Running code compiled using the
old compiler will give undefined results.
  • Loading branch information...
ltratt committed Oct 31, 2011
1 parent 5c0d819 commit 565046160d2d66ff1752589dcecde3acd730de70
Showing with 282 additions and 115 deletions.
  1. +237 −92 compiler/Compiler/Code_Gen.cv
  2. +7 −1 compiler/Compiler/Targets/Sixty_Four_Bit.cv
  3. +5 −5 pypyvm/Builtins.py
  4. +3 −2 pypyvm/Bytecode.py
  5. +19 −6 pypyvm/README
  6. +1 −1 pypyvm/Target.py
  7. +10 −8 pypyvm/VM.py

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -397,7 +397,7 @@ class Instr_Func_Defn(Instruction):
func to_bytecode(self):
return b_8_1(INSTR_FUNC_DEFN, self.is_bound)
return b_8_1_23(INSTR_FUNC_DEFN, self.is_bound, self.max_stack_size)
@@ -993,6 +993,12 @@ func b_8_1(b_8, b_1):
func b_8_1_23(b_8, b_1, b_2):
return b_8.or(b_1.lsl(8).or(b_2.lsl(9)))
func b_8_8(b1_8, b2_8):
return b1_8.or(b2_8.lsl(8))
View
@@ -164,7 +164,7 @@ def get_slot_raw(self, vm, n):
return self.instance_of
if o is None:
print o, n
#print o, n
raise Exception("XXX")
return o
@@ -471,17 +471,17 @@ def new_bc_con_module(vm, bc, name, id_, src_path, imps, tlvars_map, num_consts)
#
class Con_Func(Con_Boxed_Object):
__slots__ = ("name", "is_bound", "pc", "num_params", "num_vars", "container_closure")
_immutable_fields_ = ("name", "is_bound", "pc", "num_params", "num_vars", "container_closure")
__slots__ = ("name", "is_bound", "pc", "max_stack_size", "num_vars", "container_closure")
_immutable_fields_ = ("name", "is_bound", "pc", "max_stack_size", "num_vars", "container_closure")
def __init__(self, vm, name, is_bound, pc, num_params, num_vars, container, container_closure):
def __init__(self, vm, name, is_bound, pc, max_stack_size, num_vars, container, container_closure):
Con_Boxed_Object.__init__(self, vm, vm.get_builtin(BUILTIN_FUNC_CLASS))
self.name = name
self.is_bound = is_bound
self.pc = pc
self.num_params = num_params
self.max_stack_size = max_stack_size
self.num_vars = num_vars
self.container_closure = container_closure
View
@@ -106,8 +106,9 @@ def add_mod(vm, bc, mod_off):
mod = new_bc_con_module(vm, mod_bc, name, id_, src_path, imps, tlvars_map, num_consts)
init_func_off = read_word(mod_bc, BC_MOD_INSTRUCTIONS)
pc = BC_PC(mod, init_func_off)
mod.init_func = Con_Func(vm, Con_String(vm, "$$init$$"), False, pc, 0, num_vars, mod, \
None)
max_stack_size = 64 # XXX!
mod.init_func = Con_Func(vm, Con_String(vm, "$$init$$"), False, pc, max_stack_size, num_vars, \
mod, None)
vm.set_mod(mod)
View
@@ -1,8 +1,9 @@
This directory contains an experimental PyPy VM for Converge. At least
initially, this is meant to be 100% backwards compatible with the C Converge
VM. Currently it is extremely incomplete and can only run toy examples. It
is likely that this VM will change rapidly as a better understanding of the
best way to do this is gained.
This directory contains an experimental RPython VM for Converge. This is
backwards compatible with the C Converge VM (i.e. programs which run on this
VM will run on the C Converge VM) but programs do need to be recompiled for
this VM. Currently it is extremely incomplete and can only run toy examples.
It is likely that this VM will change rapidly as a better understanding of
the best way to do this is gained.
You first need to download the PyPy source distribution from
<http://pypy.org/download.html> (note that you do not need to build PyPy -
@@ -25,4 +26,16 @@ Or translate it using PyPy:
$ python $PYPY_SRC/pypy/translator/goal/translate.py --continuation --opt=0 main.py
$ ./main-c <converge binary file>
All optimisation levels up to and including --opt=jit should work.
All optimisation levels up to and including --opt=jit should work.
You then need to recompile the base Converge system to make sure the bytecode
is compatible with this VM:
$ cd <top level Converge directory>
$ gmake clean
$ gmake
To compile and run an example file, one can then do e.g.:
$ convergec -m t.cv
$ ./main-c t
View
@@ -182,7 +182,7 @@ def unpack_is_assigned(instr2):
@elidable_promote()
def unpack_func_defn(instr):
return (instr & 0x00000100) >> 8
return ((instr & 0x00000100) >> 8, (instr & 0x7ffffe00) >> 9)
@elidable_promote()
def unpack_list(instr):
View
@@ -566,15 +566,15 @@ def _instr_fail_now(self, instr, cf):
def _instr_func_defn(self, instr, cf):
is_bound = Target.unpack_func_defn(instr)
is_bound, max_stack_size = Target.unpack_func_defn(instr)
np_o = self._cf_stack_pop(cf)
assert isinstance(np_o, Builtins.Con_Int)
nv_o = self._cf_stack_pop(cf)
assert isinstance(nv_o, Builtins.Con_Int)
name = self._cf_stack_pop(cf)
new_pc = BC_PC(cf.pc.mod, cf.bc_off + 2 * Target.INTSIZE)
container = cf.func.get_slot(self, "container")
f = Builtins.Con_Func(self, name, is_bound, new_pc, np_o.v, nv_o.v, \
f = Builtins.Con_Func(self, name, is_bound, new_pc, max_stack_size, nv_o.v, \
container, cf.closure)
self._cf_stack_push(cf, f)
cf.bc_off += Target.INTSIZE
@@ -810,7 +810,12 @@ def _add_continuation_frame(self, func, nargs, resumable=False):
else:
closure = [[None] * func.num_vars]
cf = Stack_Continuation_Frame(func, pc, nargs, bc_off, closure, resumable)
if func.max_stack_size > nargs:
max_stack_size = func.max_stack_size
else:
max_stack_size = nargs
cf = Stack_Continuation_Frame(func, pc, max_stack_size, nargs, bc_off, closure, resumable)
self.cf_stack.append(cf)
return cf
@@ -916,11 +921,8 @@ class Stack_Continuation_Frame(Con_Thingy):
"closure", "ct", "ffp", "gfp", "xfp", "resumable", "returned")
_immutable_fields_ = ("stack", "ff_cache", "func", "closure", "pc", "nargs", "resumable")
def __init__(self, func, pc, nargs, bc_off, closure, resumable):
if isinstance(pc, BC_PC):
self.stack = [None] * 32
else:
self.stack = [None] * nargs
def __init__(self, func, pc, max_stack_size, nargs, bc_off, closure, resumable):
self.stack = [None] * max_stack_size
debug.make_sure_not_resized(self.stack)
self.func = func
self.pc = pc

0 comments on commit 5650461

Please sign in to comment.