Commit 50e74b3c authored by John Zhang's avatar John Zhang

fix: InteriorPtr doesn't work because rtyper translates it down to Ptr....

fix: InteriorPtr doesn't work because rtyper translates it down to Ptr. Therefore iref type translation is done by using hints to opaque type hack.
Added translation support for converting RPython list struct/array to meta-circular array. Implemented compiler intrinsic llops 'mu_meta_barebuf2cstriref' and 'mu_meta_lst2metacarr' in ll2mu.
Small tests for the meta-circular binding seems okay.
parent 312f3b54
This diff is collapsed.
......@@ -2,33 +2,60 @@ from rpython.rlib.rmu import holstein_meta as rmu
from rpython.translator.interactive import Translation
from rpython.translator.mu.tool.textgraph import print_graph
from rpython.translator.mu.test.test_mutyper import graph_of
from rpython.translator.mu import mutype
from rpython.rtyper.lltypesystem import lltype
def test_str2metacstr():
t = Translation(rmu.str2metacstr, [str], backend='mu')
# t.backendopt(mallocs=True, inline=True)
t.mutype()
t.backendopt(mallocs=True, inline=True)
g = graph_of(rmu.str2metacstr, t)
t.mutype()
print_graph(g)
assert [op.opname for op in g.startblock.operations[-3:-1]] == ['mu_getiref', 'mu_getvarpartiref']
assert isinstance(g.startblock.operations[-3].result.concretetype, mutype.MuIRef)
def test_lst2metaarr():
def f(lst):
return rmu.lst2metacarr(rmu.MuID, lst)
t = Translation(f, [[rmu.MuID]], backend='mu')
t.annotate()
g = graph_of(f, t)
t.backendopt(mallocs=True, inline=True)
t.mutype()
print_graph(g)
t.compile_mu() # passes the Mu static checker
assert [op.opname for op in g.startblock.operations[:-1]] == \
['mu_getiref',
'mu_getfieldiref',
'mu_load',
'mu_getiref',
'mu_getvarpartiref',
'mu_shiftiref']
def test_type_translation():
def main(argv):
bldr = rmu.MuIRBuilder()
# i8 = bldr.gen_sym("@i8")
# bldr.new_type_int(i8, 8)
# stt = bldr.gen_sym("@stt")
# bldr.new_type_struct(stt, [i8], 1)
i8 = bldr.gen_sym("@i8")
bldr.new_type_int(i8, 8)
stt = bldr.gen_sym("@stt")
bldr.new_type_struct(stt, [i8])
bldr.load()
return 0
t = Translation(main, None, backend='mu')
t.annotate()
# t.view()
t.rtype()
t.view()
# t.mutype()
# t.view()
t.backendopt(mallocs=True, inline=True)
g = graph_of(main, t)
g.view()
print_graph(g)
t.mutype()
g.view()
print_graph(g)
def test_compile_calls():
......
......@@ -603,6 +603,9 @@ LL_OPERATIONS = {
# entry point hacks
'mu_thread_exit': LLOp(),
'mu_threadlocalref_init': LLOp(),
# hacks for meta-circular ir building instructions
'mu_meta_barebuf2cstriref': LLOp(),
'mu_meta_lst2carr': LLOp(),
}
# ***** Run test_lloperation after changes. *****
......
......@@ -1571,6 +1571,42 @@ class LL2MuMapper:
def map_op_mu_sizedescr2tid(self, llop):
sd = llop.args[0]
# ----------------
# Meta-circular bundle building API binding support (rmu.*_meta)
def map_op_mu_meta_barebuf2cstriref(self, llop):
# check if arg is ref<hybrid<int<8>>>
Ref = llop.args[0].concretetype
assert isinstance(Ref, mutype.MuRef)
Hyb = Ref.TO
assert isinstance(Hyb, mutype.MuHybrid)
assert len(Hyb._names) == 1 # fixed part empty
assert Hyb._var_field_type() is mutype.MU_INT8
ops = []
iref = varof(mutype.MuIRef(Hyb))
ops.append(self.gen_mu_getiref(llop.args[0], iref))
ops.append(self.gen_mu_getvarpartiref(iref, llop.result))
return ops
def map_op_mu_meta_lst2carr(self, llop):
LIST = llop.args[0].concretetype.TO
if isinstance(LIST, mutype.MuStruct):
REFARR = getattr(LIST, 'items', None)
assert isinstance(REFARR, mutype.MuRef)
assert isinstance(REFARR.TO, mutype.MuHybrid)
refarr = varof(REFARR)
ops = self.map_op(SpaceOperation('getfield', [llop.args[0], Constant('items', mutype.MU_VOID)], refarr))
else:
assert isinstance(LIST, mutype.MuHybrid)
ops = []
refarr = llop.args[0]
iref_itm, _ops = self._getarrayitemiref(refarr, Constant(mutype.mu_int64(0), mutype.MU_INT64))
assert iref_itm.concretetype == llop.result.concretetype
_ops[-1].result = llop.result
ops.extend(_ops)
return ops
# -----------------------------------------------------------------------------
# helper functions for constructing muops
def gen_mu_binop(self, optr, opnd1, opnd2, res=None, status=None, status_results=None, excclause=None):
......@@ -1948,4 +1984,19 @@ _lldebugop_c_externfncs = {
'debug_forked': c_debug_forked,
'debug_flush': c_debug_flush,
'have_debug_prints': c_have_debug_prints
}
\ No newline at end of file
}
# conversion functions that can be called without supplying a LL2MuMapper instance
def ll2mu_type(LLT):
ll2mu = LL2MuMapper()
MuT = ll2mu.map_type(LLT)
ll2mu.resolve_ptr_types()
return MuT
def ll2mu_value(llv):
ll2mu = LL2MuMapper()
muv = ll2mu.map_value(llv)
ll2mu.resolve_ptr_values()
return muv
......@@ -202,6 +202,8 @@ class MuTyper:
'mu_setgcidhash',
'mu_thread_exit',
'mu_threadlocalref_init',
'mu_meta_barebuf2cstriref',
'mu_meta_lst2carr',
))
llop.args = [self.specialise_arg(arg) for arg in llop.args]
......
......@@ -694,3 +694,37 @@ def test_cast_pointer_pin():
ll2mu.resolve_ptr_types()
muops = ll2mu.map_op(llop)
assert [op.opname for op in muops] == ['mu_comminst', 'mu_convop']
def test_map_op_mu_meta_barebuf2cstriref():
ll2mu = LL2MuMapper()
llop = SpaceOperation('mu_meta_barebuf2cstriref',
[varof(mutype.MuRef(mutype.MuHybrid('dummy', ('varpart', mutype.MU_INT8))))],
varof(mutype.META_CSTR))
muops = ll2mu.map_op(llop)
assert [op.opname for op in muops] == ['mu_getiref', 'mu_getvarpartiref']
def test_map_op_mu_meta_lst2carr():
ll2mu = LL2MuMapper()
ELM_LLT = lltype.Signed
ARR_LLT = lltype.GcArray(lltype.Signed)
LIST_LLT = lltype.GcStruct('list', ('length', lltype.Signed), ('items', lltype.Ptr(ARR_LLT)))
ELM_MuT = ll2mu.map_type(ELM_LLT)
ARR_MuT = ll2mu.map_type(ARR_LLT)
LIST_MuT = ll2mu.map_type(LIST_LLT)
ll2mu.resolve_ptr_types()
# array case
res = varof(mutype.MuIRef(ELM_MuT))
llop = SpaceOperation('mu_meta_lst2carr', [varof(mutype.MuRef(ARR_MuT))], res)
muops = ll2mu.map_op(llop)
assert [op.opname for op in muops] == ['mu_getiref', 'mu_getvarpartiref', 'mu_shiftiref']
assert muops[-1].result is res
# struct list case
llop = SpaceOperation('mu_meta_lst2carr', [varof(mutype.MuRef(LIST_MuT))], res)
muops = ll2mu.map_op(llop)
assert [op.opname for op in muops] == ['mu_getiref', 'mu_getfieldiref', 'mu_load',
'mu_getiref', 'mu_getvarpartiref', 'mu_shiftiref']
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