Commit ca4fb56d authored by John Zhang's avatar John Zhang

some refactoring

parent e520ccac
...@@ -247,7 +247,8 @@ class MuDatabase: ...@@ -247,7 +247,8 @@ class MuDatabase:
# graphs # graphs
for g in self.tlc.graphs: for g in self.tlc.graphs:
graph_name = '@' + g.name g.name = man.get_graph_name(g)
graph_name = g.name
self.mu_name_map[g] = graph_name self.mu_name_map[g] = graph_name
for i, blk in enumerate(g.iterblocks()): for i, blk in enumerate(g.iterblocks()):
blk_name = '%(graph_name)s.blk%(i)d' % locals() blk_name = '%(graph_name)s.blk%(i)d' % locals()
...@@ -342,6 +343,7 @@ class MuNameManager: ...@@ -342,6 +343,7 @@ class MuNameManager:
} }
self._assigned_names = set() self._assigned_names = set()
self._conflict_ctr = {} self._conflict_ctr = {}
self.graph_name_dic = {}
# verbose struct name? # verbose struct name?
from rpython.config.translationoption import get_translation_config from rpython.config.translationoption import get_translation_config
...@@ -453,3 +455,19 @@ class MuNameManager: ...@@ -453,3 +455,19 @@ class MuNameManager:
name = 'extfnc_' + const.value._name name = 'extfnc_' + const.value._name
return '@' + name return '@' + name
def get_graph_name(self, g):
name = g.name if '.' in g.name else g.name.split('__')[0]
name = re.sub(r'[^0-9a-zA-Z_-]', '_', name) # replace illegal characters in names
name_dic = self.graph_name_dic
if name not in name_dic:
ctr = 0
name_dic[name] = ([g], ctr)
else:
gs, ctr = name_dic[name]
if g not in gs:
gs.append(g)
ctr += 1
name_dic[name] = (gs, ctr)
return "@%s_%d" % (name, ctr)
...@@ -35,14 +35,27 @@ class MuTyper: ...@@ -35,14 +35,27 @@ class MuTyper:
self.ll2mu.set_threadlocal_struct_type(self.TLStt) self.ll2mu.set_threadlocal_struct_type(self.TLStt)
def prepare_all(self): def prepare_all(self):
self.graphs = prepare(self.tlc.graphs, self.tlc.entry_point_graph) if hasattr(self.tlc, 'entry_point_graph'):
# Task 1: prune and remove inlined graphs
n0 = len(self.tlc.graphs)
graphs = graph_closure(self.tlc.entry_point_graph)
log.prune("%d -> %d graphs" % (n0, len(graphs)))
else:
graphs = self.tlc.graphs
for g in graphs:
prepare(g)
self.graphs = graphs
def specialise_all(self): def specialise_all(self):
if not hasattr(self, 'graphs'): if not hasattr(self, 'graphs'):
raise AttributeError("don't have graphs. Run prepare_all() first.") raise AttributeError("don't have graphs. Run prepare_all() first.")
for g in self.ll2mu.llhelper_graphs: for g in self.ll2mu.llhelper_graphs:
self.graphs = self.graphs.union(prepare([g], g)) _gs = graph_closure(g)
for _g in _gs:
prepare(_g)
self.graphs = self.graphs.union(_gs)
log.specialise_all('specialising graphs...') log.specialise_all('specialising graphs...')
mdb.restart() mdb.restart()
...@@ -63,9 +76,13 @@ class MuTyper: ...@@ -63,9 +76,13 @@ class MuTyper:
arg_llts = map(lambda arg: arg.concretetype, g.startblock.inputargs) arg_llts = map(lambda arg: arg.concretetype, g.startblock.inputargs)
g.sig = mutype.MuFuncSig([self.ll2mu.map_type(arg_t) for arg_t in arg_llts], g.sig = mutype.MuFuncSig([self.ll2mu.map_type(arg_t) for arg_t in arg_llts],
[self.ll2mu.map_type(ret_llt)] if ret_llt != lltype.Void else []) [self.ll2mu.map_type(ret_llt)] if ret_llt != lltype.Void else [])
for blk in g.iterblocks(): for blk in g.iterblocks():
self.specialise_block(blk) self.specialise_block(blk)
if (len(g.sig.ARGS) == 1 and g.sig.ARGS[0] == mutype.MU_VOID):
raise AssertionError("input arg can not have type void")
remove_unaryops(g, ['same_as', 'likely']) remove_unaryops(g, ['same_as', 'likely'])
def specialise_block(self, blk): def specialise_block(self, blk):
...@@ -215,7 +232,8 @@ class MuTyper: ...@@ -215,7 +232,8 @@ class MuTyper:
muops = [] muops = []
muops.extend(self.extract_load_gcell(llop.args)) muops.extend(self.extract_load_gcell(llop.args))
muops.extend(self.ll2mu.map_op(llop)) muops.extend(self.ll2mu.map_op(llop
))
return muops return muops
def extract_load_gcell(self, args): def extract_load_gcell(self, args):
...@@ -318,7 +336,7 @@ def graph_closure(g_entry): ...@@ -318,7 +336,7 @@ def graph_closure(g_entry):
return graph_closure return graph_closure
def prepare(graphs, entry_graph): def prepare(g):
def _keep_arg(arg, opname=''): def _keep_arg(arg, opname=''):
from rpython.rtyper.lltypesystem.lloperation import LL_OPERATIONS from rpython.rtyper.lltypesystem.lloperation import LL_OPERATIONS
_OPS_ALLOW_LLTYPE_ARGS = [] _OPS_ALLOW_LLTYPE_ARGS = []
...@@ -341,30 +359,6 @@ def prepare(graphs, entry_graph): ...@@ -341,30 +359,6 @@ def prepare(graphs, entry_graph):
# log.keep_arg("Throwing argument %(arg)r from operation %(opname)s" % locals()) # log.keep_arg("Throwing argument %(arg)r from operation %(opname)s" % locals())
return False return False
name_dic = {}
def rename(g):
""" reassign graph names (shorter names more readable) """
name = g.name if '.' in g.name else g.name.split('__')[0]
name = re.sub(r'[^0-9a-zA-Z_-]', '_', name) # replace illegal characters in names
if name not in name_dic:
ctr = 0
name_dic[name] = ([g], ctr)
else:
gs, ctr = name_dic[name]
if g not in gs:
gs.append(g)
ctr += 1
name_dic[name] = (gs, ctr)
g.name = "%s_%d" % (name, ctr)
# Task 1: prune and remove inlined graphs
n0 = len(graphs)
graphs = graph_closure(entry_graph)
log.prune("%d -> %d graphs" % (n0, len(graphs)))
for g in graphs:
rename(g)
for blk in list(g.iterblocks()) + [g.returnblock]: # force include return block, in case always throwing exceptions for blk in list(g.iterblocks()) + [g.returnblock]: # force include return block, in case always throwing exceptions
# Task 2: Remove Void args and parameters in inputargs, operations and links # Task 2: Remove Void args and parameters in inputargs, operations and links
blk.inputargs = [arg for arg in blk.inputargs if arg.concretetype != lltype.Void] blk.inputargs = [arg for arg in blk.inputargs if arg.concretetype != lltype.Void]
...@@ -385,5 +379,3 @@ def prepare(graphs, entry_graph): ...@@ -385,5 +379,3 @@ def prepare(graphs, entry_graph):
_v = Variable('dummy') _v = Variable('dummy')
_v.concretetype = blk.inputargs[i].concretetype _v.concretetype = blk.inputargs[i].concretetype
blk.inputargs[i] = _v blk.inputargs[i] = _v
return graphs
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment