Permalink
Browse files

timeout in allocator for programs w/ too many vars

also added some tests and tweaked makefile
  • Loading branch information...
cantora committed Sep 28, 2012
1 parent 23a8b4e commit fe46865893e762badd6c4d3aa517bdcafc60df2a
Showing with 2,061 additions and 9 deletions.
  1. +6 −0 README
  2. +4 −1 makefile
  3. +20 −4 pyc
  4. +28 −4 pyc_reg_allocator.py
  5. +2 −0 student_tests/Symphony_test_tempvar4.in
  6. +2,000 −0 student_tests/Symphony_test_tempvar4.py
  7. +1 −0 test/super_easy.in
View
6 README
@@ -5,3 +5,9 @@ to compile on 64 bit:
-on ubuntu:
sudo apt-get install gcc-multilib libc6-i386 libc6-dev-i386
+
+BAD TESTS:
+ Everest_Testy.py no input file?
+ starcroce_test0.py undefined var
+ wonder_test02.py undefined var
+
View
@@ -1,7 +1,10 @@
TMPDIR := /tmp/pyc
SRCS = $(filter-out ./parsetab.py, $(wildcard ./*.py) )
-TESTS = $(wildcard ./grader_tests/*.py) #$(wildcard ./test/*.py)
+TESTS = $(wildcard ./grader_tests/*.py) \
+ $(filter-out %stack_test.py, $(wildcard ./test/*.py) ) \
+ $(wildcard ./student_tests/*.py)
+
.PHONY: pkg
pkg: hw.zip
View
24 pyc
@@ -10,6 +10,7 @@ import pyc_asm_nodes
from pyc_log import *
import os.path
+import time
def opt_parser():
parser = argparse.ArgumentParser(description='compile python to x86 assembly.')
@@ -57,6 +58,7 @@ def run(options):
log( lambda : repr(as_tree))
log( lambda : pyc_ast.str(as_tree))
+ t0 = time.time()
ss_list = pyc_ast.to_ss_list(as_tree)
log("se list: ")
log(lambda : "\n".join([repr(ss) for ss in ss_list]) )
@@ -66,17 +68,31 @@ def run(options):
asm_list = reduce(lambda a,b: a + b, asm_list, [])
log( lambda : "\n".join([repr(n) for n in asm_list]) )
-
+ t_flatten = time.time()
+ #print "flatten time: %d" % (t_flatten - t0)
+
more_alloc_needed = 1
adjusted_asm_list = asm_list
symtbl = pyc_reg_allocator.SymTable()
+ alloc_timeout = 10
while more_alloc_needed:
log("analyze asm nodes and assign memory locations")
+ t0 = time.time()
live_list, graph = pyc_var_analyzer.interference_graph(adjusted_asm_list)
-
- pyc_reg_allocator.alloc(live_list, graph, symtbl)
-
+ t_graph = time.time()
+ #print "graph time: %d" % (t_graph - t0)
+
+ t0 = time.time()
+ pyc_reg_allocator.alloc(live_list, graph, symtbl, alloc_timeout)
+ t_alloc = time.time()
+ #print "alloc time: %d" % (t_alloc - t0)
+
+ #we only want to restrict the time of the first pass
+ #because the subsequent passes may have vars which need
+ #registers
+ alloc_timeout = 0
+
log( lambda : "mem allocation offsets:\n\t%s" % str(symtbl) )
(more_alloc_needed, adjusted_asm_list) = pyc_reg_allocator.adjust(adjusted_asm_list, symtbl)
View
@@ -1,8 +1,10 @@
from pyc_var_analyzer import IntfGraph
from pyc_log import *
from pyc_asm_nodes import *
+
import random
import copy
+import time
reg_index_map = {}
for i in range(0, len(Register.registers) ):
@@ -51,8 +53,11 @@ def swap_map(self, node, loc):
def get(self, node):
return self.mem_map.get(node, None)
+ def high_index(self):
+ return max(self.mem_map.values())
+
def stack(self):
- return (max(self.mem_map.values()) - 6)*4 + 4
+ return (self.high_index() - 6)*4 + 4
#throws key error if the arg isnt mapped
def __getitem__(self, arg):
@@ -83,12 +88,13 @@ def __getitem__(self, arg):
"""
class Allocator:
- def __init__(self, live_list, graph, symtbl):
+ def __init__(self, live_list, graph, symtbl, timeout=0):
self.live_list = live_list
self.graph = graph
self.symtbl = symtbl
self.symtbl.boot_reg_dwellers()
self.constraints = {}
+ self.timeout = timeout
reg_nodes = [Register(x) for x in Register.registers]
self.todo = set(self.graph.keys()) - set(self.symtbl.mem_map.keys()) - set(reg_nodes)
@@ -151,19 +157,37 @@ def next(self):
return sorted_items[0][0]
+ def throw_the_rest_on_the_stack(self):
+ i = self.symtbl.high_index() + 1
+ for node in self.todo:
+ if node.needs_reg and i > (len(Register.registers) - 1):
+ raise Exception("%s needs a reg!" % repr(node))
+
+ self.symtbl.map(node, i)
+ i = i+1
+
+ self.constraints.clear()
+ self.todo.clear()
+
def run(self):
+ t0 = time.time()
+
while len(self.todo) > 0:
log("todo: %s" % repr(self.todo))
log("constraints: %s" % repr(self.constraints) )
self.allocate_mem(self.next())
+ if self.timeout > 0 and (time.time() - t0) > self.timeout:
+ self.throw_the_rest_on_the_stack()
+ break
+
return self.symtbl
-def alloc(live_list, graph, symtbl):
- al = Allocator(live_list, graph, symtbl)
+def alloc(live_list, graph, symtbl, timeout=0):
+ al = Allocator(live_list, graph, symtbl, timeout)
return al.run()
@@ -0,0 +1,2 @@
+1000
+707
Oops, something went wrong.

0 comments on commit fe46865

Please sign in to comment.