WARNING! Access to this system is limited to authorised users only.
Unauthorised users may be subject to prosecution.
Unauthorised access to this system is a criminal offence under Australian law (Federal Crimes Act 1914 Part VIA)
It is a criminal offence to:
(1) Obtain access to data without authority. -Penalty 2 years imprisonment.
(2) Damage, delete, alter or insert data without authority. -Penalty 10 years imprisonment.
User activity is monitored and recorded. Anyone using this system expressly consents to such monitoring and recording.

To protect your data, the CISO officer has suggested users to enable 2FA as soon as possible.
Currently 2.2% of users enabled 2FA.

Commit ca4fb56d authored by John Zhang's avatar John Zhang
Browse files

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,49 +359,23 @@ def prepare(graphs, entry_graph): ...@@ -341,49 +359,23 @@ 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 = {} for blk in list(g.iterblocks()) + [g.returnblock]: # force include return block, in case always throwing exceptions
def rename(g): # Task 2: Remove Void args and parameters in inputargs, operations and links
""" reassign graph names (shorter names more readable) """ blk.inputargs = [arg for arg in blk.inputargs if arg.concretetype != lltype.Void]
name = g.name if '.' in g.name else g.name.split('__')[0] for lnk in blk.exits:
name = re.sub(r'[^0-9a-zA-Z_-]', '_', name) # replace illegal characters in names lnk.args = [arg for arg in lnk.args if arg.concretetype != lltype.Void]
if name not in name_dic: for op in blk.operations:
ctr = 0 op.args = [arg for arg in op.args if _keep_arg(arg, op.opname)]
name_dic[name] = ([g], ctr)
else: if op.opname in ('force_cast', 'cast_primitive'):
gs, ctr = name_dic[name] # HACK: save original arg and result types to discern signedness.
if g not in gs: op._src_llt = op.args[0].concretetype
gs.append(g) op._res_llt = op.result.concretetype
ctr += 1
name_dic[name] = (gs, ctr) # replace constants with dummy variables in inputargs --> they shouldn't appear there
g.name = "%s_%d" % (name, ctr) idx_cnsts = filter(lambda _i: isinstance(blk.inputargs[_i], Constant), range(len(blk.inputargs)))
if len(idx_cnsts) > 0:
# Task 1: prune and remove inlined graphs for i in idx_cnsts:
n0 = len(graphs) _v = Variable('dummy')
graphs = graph_closure(entry_graph) _v.concretetype = blk.inputargs[i].concretetype
log.prune("%d -> %d graphs" % (n0, len(graphs))) blk.inputargs[i] = _v
for g in graphs:
rename(g)
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
blk.inputargs = [arg for arg in blk.inputargs if arg.concretetype != lltype.Void]
for lnk in blk.exits:
lnk.args = [arg for arg in lnk.args if arg.concretetype != lltype.Void]
for op in blk.operations:
op.args = [arg for arg in op.args if _keep_arg(arg, op.opname)]
if op.opname in ('force_cast', 'cast_primitive'):
# HACK: save original arg and result types to discern signedness.
op._src_llt = op.args[0].concretetype
op._res_llt = op.result.concretetype
# replace constants with dummy variables in inputargs --> they shouldn't appear there
idx_cnsts = filter(lambda _i: isinstance(blk.inputargs[_i], Constant), range(len(blk.inputargs)))
if len(idx_cnsts) > 0:
for i in idx_cnsts:
_v = Variable('dummy')
_v.concretetype = blk.inputargs[i].concretetype
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