...
 
Commits (5)
This diff is collapsed.
......@@ -534,7 +534,9 @@ class Bookkeeper(object):
results = []
for desc in pbc.descriptions:
results.append(desc.pycall(whence, args, s_previous_result, op))
logger.info('pbc_call.results = %s' % results)
s_result = unionof(*results)
logger.info('pbc_call.s_result = %s' % s_result)
return s_result
def emulate_pbc_call(self, unique_key, pbc, args_s, replace=[], callback=None):
......
......@@ -223,7 +223,8 @@ class FunctionDesc(Desc):
def buildgraph(self, alt_name=None, builder=None):
translator = self.bookkeeper.annotator.translator
# logger.info("buildgraph for %s" % self.name)
logger.info("buildgraph for %s" % self.name)
# assert self.name != 'll_arraycopy'
if builder:
graph = builder(translator, self.pyobj)
else:
......@@ -319,29 +320,49 @@ class FunctionDesc(Desc):
return self.specializer(self, inputcells)
def pycall(self, whence, args, s_previous_result, op=None):
# assert self.name != 'll_math_isfinite'
logger.info('pycall( \n%s, \n%s,\n %s,\n %s,\n %s)' % (self, whence, args, s_previous_result, op))
inputcells = self.parse_arguments(args)
logger.info('pycall.inputcells = %s' % inputcells)
result = self.specialize(inputcells, op)
logger.info('pycall.result = \n%s \n%s\n' % (result, type(result)))
if isinstance(result, FunctionGraph):
graph = result # common case
logger.info('graph.func.func_code: \n %s' % graph.func.func_code)
# # RTMU
# self.create_rtmu_copies(graph)
annotator = self.bookkeeper.annotator
# if that graph has a different signature, we need to re-parse
# the arguments.
# recreate the args object because inputcells may have been changed
new_args = args.unmatch_signature(self.signature, inputcells)
logger.info('pycall.new_args: %s' % new_args)
inputcells = self.parse_arguments(new_args, graph)
logger.info('pycall.inputcells: %s' % inputcells)
result = annotator.recursivecall(graph, whence, inputcells)
logger.info('pycall.result.rec: %s' % result)
signature = getattr(self.pyobj, '_signature_', None)
# logger.info('pycall.sig: %s' % signature)
if signature:
sigresult = enforce_signature_return(self, signature[1], result)
if sigresult is not None:
annotator.addpendingblock(
graph, graph.returnblock, [sigresult])
result = sigresult
logger.info('pycall.result.final = %s' % result)
# Some specializations may break the invariant of returning
# annotations that are always more general than the previous time.
# We restore it here:
from rpython.annotator.model import unionof
result = unionof(result, s_previous_result)
logger.info('pycall.result.unionof: %s' % result)
return result
def get_graph(self, args, op):
......
......@@ -8,8 +8,12 @@ from rpython.flowspace.model import checkgraph
from rpython.flowspace.operation import op
from rpython.annotator import model as annmodel
from rpython.flowspace.argument import Signature
from rpython.tool.ansi_print import AnsiLogger
logger = AnsiLogger('ann.specialize')
def flatten_star_args(funcdesc, args_s):
logger.info('flatten_star_args( \n%s, \n%s' % (funcdesc, args_s))
argnames, vararg, kwarg = funcdesc.signature
assert not kwarg, "functions with ** arguments are not supported"
if vararg:
......@@ -50,13 +54,16 @@ def flatten_star_args(funcdesc, args_s):
return graph
key = ('star', nb_extra_args)
logger.info('flatten_star_args.returning:\n%s,\n%s, \n%s' % (flattened_s, key, builder))
return flattened_s, key, builder
else:
logger.info('flatten_star_args.2ndreturn: %s' % args_s)
return args_s, None, None
def default_specialize(funcdesc, args_s):
# first flatten the *args
logger.info('default_specialize( \n%s, \n%s)' % (funcdesc, args_s))
args_s, key, builder = flatten_star_args(funcdesc, args_s)
# two versions: a regular one and one for instances with 'access_directly'
jit_look_inside = getattr(funcdesc.pyobj, '_jit_look_inside_', True)
......@@ -80,6 +87,7 @@ def default_specialize(funcdesc, args_s):
graph = funcdesc.cachedgraph(key, builder=builder)
if access_directly:
graph.access_directly = True
logger.info('default_specialize.returning: %s' % graph)
return graph
class AccessDirect(object):
......@@ -236,6 +244,7 @@ class MemoTable(object):
return make_helper(firstarg, stmt, {})
entrypoint = make_subhelper(args_so_far = ())
self.graph = annotator.translator.buildflowgraph(entrypoint)
self.graph.defaults = self.funcdesc.defaults
......
......@@ -22,11 +22,14 @@ from rpython.annotator.binaryop import _dict_can_only_throw_nothing
from rpython.annotator.classdesc import ClassDesc, is_primitive_type, BuiltinTypeDesc
from rpython.annotator.model import AnnotatorError
from rpython.annotator.argument import simple_args, complex_args
from rpython.tool.ansi_print import AnsiLogger
UNARY_OPERATIONS = set([oper.opname for oper in op.__dict__.values()
if oper.dispatch == 1])
UNARY_OPERATIONS.remove('contains')
logger = AnsiLogger('unaryop')
@op.type.register(SomeObject)
def type_SomeObject(annotator, v_arg):
......@@ -113,8 +116,11 @@ def contains_number(annotator, number, element):
@op.simple_call.register(SomeObject)
def simple_call_SomeObject(annotator, func, *args):
logger.info('simple_call_SomeObject(..., %s, %s)' % (func, args))
s_func = annotator.annotation(func)
logger.info('s_func = %s' % s_func)
argspec = simple_args([annotator.annotation(arg) for arg in args])
logger.info('argspec = %s' % argspec)
return s_func.call(argspec)
@op.call_args.register_transform(SomeObject)
......
# from rpython.dev.dev_CD.radar_frame import *
import math
def calc_distance_3d(ac1, ac2):
dx = ac2.x - ac1.x
dy = ac2.y - ac1.y
dz = ac2.z - ac1.z
return math.sqrt((dx*dx)+(dy*dy)+(dz*dz))
def check_rdr_frame(rf):
ap1 = rf[0]
ap2 = rf[1]
res = calc_distance_3d(ap1, ap2)
return res
from rpython.rlib.rrtmu.rtzebu import os_exit
from rpython.dev.dev_CD.radar_frame import AirCraft, FrameElement
from rpython.dev.dev_CD.detector import *
from rpython.rlib.rrtmu.ll_mem import init_rtmu_mem, new_scope, enter_scope, exit_area
def main_region():
# create a new parent region and enter it as the allocation context
# pt_region = new_region(4*1024*1024)
# enter_region(pt_region)
init_rtmu_mem()
pt_region = new_scope(4*1024*1024)
enter_scope(pt_region)
ac1 = AirCraft('air_1')
ac2 = AirCraft('air_2')
re1 = FrameElement(ac1, 10.0, 20.22, 30.33)
re2 = FrameElement(ac2, 10.0, 20.22, 65.33)
rf1 = []
rf1.append(re1)
rf1.append(re2)
res = check_rdr_frame(rf1)
if 34.0 < res < 36.0:
res_i = 35
else:
res_i = 1
# exit_region()
exit_area()
# delete_region(pt_region)
os_exit(res_i)
class AirCraft:
def __init__(self, call_sign='aircraft'):
self.call_sign = call_sign
class FrameElement:
def __init__(self, aircraft, x_dim, y_dim, z_dim):
self.aircraft = aircraft
self.x = x_dim
self.y = y_dim
self.z = z_dim
# class RadarFrame:
# def __init__(self):
# self.elements = []
#
# def append(self, element):
# self.elements.append(element)
from rpython.rlib.rrtmu import rtzebu
from rpython.rtyper.lltypesystem import lltype
from rpython.rlib.rrtmu.ll_mem import rtmu_emm_alloc, rtmu_heap_alloc
class Ty1:
i = 0
def __init__(self, ii):
self.i = ii
class Ty2:
j = 0
k = 0
def __init__(self, ii, jj):
self.j = ii
self.k = jj
def alloc_type(ty, *args):
pass
# r = lltype.malloc(ty, flavor='raw')
# return str(ty)
# return ty(*args)
def test_alloc_type():
i1 = Ty1(122)
i2 = Ty2(1, 3)
# str1 = alloc_type(Ty1, 123)
# str2 = alloc_type(Ty2, 234)
str1 = rtmu_emm_alloc(Ty1)
str2 = rtmu_emm_alloc(Ty2)
return str1
# return len(str1) + len(str2)
from rpython.rlib.rrtmu.ll_mem import new_scope, enter_scope
class Ty:
def __init__(self, ii):
self.i = ii
g1 = Ty(123)
g2 = Ty(312)
def test_globals():
l1 = Ty(256)
scp = new_scope(1024)
enter_scope(scp)
l2 = Ty(6656)
return l1.i + g1.i + g2.i + l2.i
......@@ -163,7 +163,7 @@ class Link(object):
class Block(object):
__slots__ = """inputargs operations exitswitch
exits blockcolor mu_excparam""".split()
exits blockcolor mu_excparam muops is_processed""".split()
def __init__(self, inputargs):
self.inputargs = list(inputargs) # mixed list of variable/const XXX
......@@ -266,7 +266,7 @@ class Block(object):
class Variable(object):
__slots__ = ["_name", "_nr", "annotation", "concretetype", "rtmu_tag"]
__slots__ = ["_name", "_nr", "annotation", "concretetype", "rtmu_tag", "is_untraced"]
dummyname = 'v'
namesdict = {dummyname: (dummyname, 0)}
......@@ -288,6 +288,7 @@ class Variable(object):
def __init__(self, name=None):
self.rtmu_tag = 0
self.is_untraced = False
self._name = self.dummyname
self._nr = -1
self.annotation = None
......@@ -340,6 +341,9 @@ class Variable(object):
def replace(self, mapping):
return mapping.get(self, self)
def deepcopy(self):
return self.copy()
class Constant(Hashable):
__slots__ = ["concretetype", 'rtmu_tag']
......@@ -372,6 +376,10 @@ class Constant(Hashable):
def replace(self, mapping):
return self
def deepcopy(self):
res = Constant(self.value, self.concretetype)
return res
class FSException(object):
def __init__(self, w_type, w_value):
......@@ -451,6 +459,19 @@ class SpaceOperation(object):
newresult = self.result.replace(mapping)
return type(self)(self.opname, newargs, newresult, self.offset)
def deepcopy(self):
from copy import copy, deepcopy
res = SpaceOperation(
deepcopy(self.opname),
map(lambda x: x.deepcopy(), self.args),
self.result.deepcopy(),
self.offset
)
return res
class Atom(object):
def __init__(self, name):
self.__name__ = name # make save_global happy
......
......@@ -1468,7 +1468,7 @@ class MuIRBuilder:
def new_ealloc(self, id, result_id, allocty, exc_clause=MU_NO_ID):
self._bldr.c_new_ealloc(self._bldr, id, result_id, allocty, exc_clause)
def new_eallochyrid(self, id, result_id, allocty, lenty, length, exc_clause=MU_NO_ID):
def new_eallochybrid(self, id, result_id, allocty, lenty, length, exc_clause=MU_NO_ID):
self._bldr.c_new_eallochybrid(
self._bldr, id, result_id, allocty, lenty, length, exc_clause)
......@@ -1486,7 +1486,7 @@ class MuIRBuilder:
self._bldr.c_new_ralloc(
self._bldr, id, result_id, allocty, reg, exc_clause)
def new_rallochyrid(self, id, result_id, allocty, lenty, length, reg, exc_clause=MU_NO_ID):
def new_rallochybrid(self, id, result_id, allocty, lenty, length, reg, exc_clause=MU_NO_ID):
self._bldr.c_new_rallochybrid(
self._bldr, id, result_id, allocty, lenty, length, reg, exc_clause)
......
from rpython.rlib.rrtmu.rtzebu import new_region, enter_region, delete_region, exit_region
RTMU_MEM_OPS = {
"rtmu_region_alloc",
"rtmu_emm_alloc",
"rtmu_heap_alloc",
"rtmu_region_alloc_hybrid",
"rtmu_emm_alloc_hybrid",
"rtmu_heap_alloc_hybrid",
}
RTMU_HEAP = 0
RTMU_EMM = 1
RTMU_REGIONS = 2
class RegContainer:
__slots__ = "regref"
def __init__(self, rr):
self.regref = rr
def get(self):
return self.regref
# _fake_heap = RegContainer(new_region(1))
# _fake_emm = RegContainer(new_region(1))
class MemGlobals:
__slots__ = ("area_stack", "current_area", "__a1", "__a2", "_fake_heap", "_fake_emm")
def __init__(self):
# self._fake_heap = new_region(1)
# self._fake_emm = new_region(1)
# self.current_area = self._fake_heap
# self.area_stack = [self.current_area]
self.area_stack = []
# self.current_area = _fake_heap.get()
# class MemContext:
# __slots__ = "mm_globals"
#
# def __init__(self, mmg):
# self.mm_globals = mmg
#
# def get_globals(self):
# return self.mm_globals
mm_global = MemGlobals()
# mm_context = MemContext()
def new_scope(size):
scp = new_region(size)
return scp
# TODO not thread safe
def enter_scope(scp):
global mm_global
mm_global.area_stack.insert(0, RegContainer(mm_global.current_area))
mm_global.current_area = scp
# area_stack.append(scp)
def enter_heap():
global mm_global
mm_global.area_stack.insert(0, RegContainer(mm_global.current_area))
mm_global.current_area = mm_global._fake_heap
# area_stack.append(_fake_heap)
# area_stack.insert(0, _fake_heap)
def exit_area():
global mm_global
mm_global.current_area = mm_global.area_stack.pop().get()
# current_area = area_stack[0]
def rtmu_heap_alloc(ty):
pass
def rtmu_emm_alloc(ty):
pass
def rtmu_region_alloc(ty, reg):
pass
def rtmu_heap_alloc_hybrid(ty, v_s):
pass
def rtmu_emm_alloc_hybrid(ty, v_s):
pass
def rtmu_region_alloc_hybrid(ty, v_s, reg):
pass
# def rtmu_allocate(ty):
# global mm_global
# if mm_global.current_area == _fake_heap.get():
# return rtmu_heap_alloc(ty)
# elif mm_global.current_area == _fake_emm.get():
# return rtmu_emm_alloc(ty)
# else:
# reg = mm_global.current_area
# return rtmu_region_alloc(ty, reg)
#
#
# def rtmu_allocate_varsize(ty, v_s):
# global mm_global
# if mm_global.current_area == _fake_heap:
# return rtmu_heap_alloc_hybrid(ty, v_s)
# elif mm_global.current_area == _fake_emm:
# return rtmu_emm_alloc_hybrid(ty, v_s)
# else:
# reg = mm_global.current_area
# return rtmu_region_alloc_hybrid(ty, v_s, reg)
def init_rtmu_mem():
global mm_global
mm_global._fake_heap = new_region(1)
mm_global._fake_emm = new_region(1)
mm_global.current_area = mm_global._fake_heap
mm_global.area_stack = [RegContainer(mm_global.current_area)]
mm_global.__a1 = __get_current_area()
mm_global.__a2 = __get_current_scope()
# mm_global.__a1 = rtmu_allocate(RegContainer)
# mm_global.__a2 = rtmu_allocate(MemGlobals)
# mm_global.__ah1 = rtmu_allocate_varsize(RegContainer, 1)
# mm_global.__ah2 = rtmu_allocate_varsize(MemGlobals, 1)
def __get_current_area():
global mm_global
if mm_global.current_area == mm_global._fake_heap:
return RTMU_HEAP
elif mm_global.current_area == mm_global._fake_emm:
return RTMU_EMM
else:
return RTMU_REGIONS
def __get_current_scope():
global mm_global
return mm_global.current_area
# mm_global.__gca = __get_current_area()
# mm_global.__gcs = __get_current_scope()
new_scope._dont_inline_ = True
enter_scope._dont_inline_ = True
enter_heap._dont_inline_ = True
exit_area._dont_inline_ = True
init_rtmu_mem._dont_inline_ = True
rtmu_region_alloc._dont_inline_ = True
rtmu_heap_alloc._dont_inline_ = True
rtmu_emm_alloc._dont_inline_ = True
__get_current_area._dont_inline_ = True
__get_current_scope._dont_inline_ = True
......@@ -6,6 +6,11 @@ from rpython.tool.ansi_print import AnsiLogger
logger = AnsiLogger('rtzebu.py')
class LifeTimeError(Exception):
"""Exception class for storing untraced objects to heap"""
pass
c_exit = rffi.llexternal('exit', [rffi.INT], lltype.Void, _nowrapper=True)
RTMU_OP_NAMES = {
......@@ -46,7 +51,13 @@ RTMU_NOP_NAMES = {
"PIFutex___init__",
# "_fake_entry",
"do_something_realy_non_trivial",
"do_something_non_trivial"
"do_something_non_trivial",
'll_str__InstanceR_rpython_rlib_rrtmu_r_rpython_rlib_rrtmu_rtzebu_RegionPtr',
'll_str__InstanceR_rpython_rlib_rrtmu_r_rpython_rlib_rrtmu_rtzebu_PIFutexPtr',
'll_str__InstanceR_rpython_rlib_rrtmu_r_rpython_rlib_rrtmu_rtzebu_TimerPtr',
'll_str__InstanceR_rpython_rlib_rrtmu_r_rpython_rlib_rrtmu_rtzebu_AttrPtr',
'll_str__InstanceR_rpython_rlib_rrtmu_r_rpython_rlib_rrtmu_rtzebu_ThreadPtr',
# 'init_rtmu_mem',
}
RTMU_TRD_NAMES = {
......@@ -69,24 +80,33 @@ RTMU_METHOD_NAMES = {
}
NO_COPY_LIST = {
"memo_",
"copy_string_to_raw",
"scoped_nonmovingbuffer",
"free_nonmovingbuffer",
"write",
"validate_fd",
"get_nonmovingbuffer",
"_errno_",
"setraw",
"getraw",
"rpython_print_newline",
"rpython_print_item",
"get_saved_errno",
"dtoa",
"format_number",
"str2charp",
"time",
# "memo_",
# "copy_string_to_raw",
# "scoped_nonmovingbuffer",
# "free_nonmovingbuffer",
# "write",
# "validate_fd",
# "get_nonmovingbuffer",
# "_errno_",
# "setraw",
# "getraw",
# "rpython_print_newline",
# "rpython_print_item",
# "get_saved_errno",
# "dtoa",
# "format_number",
# "str2charp",
# "time",
# "_get_raw_buf",
# "isconstant",
# "ll_join_strs",
# "ll_math_pow",
}
RTMU_NOID_OP = {
"mu_dec_global",
}
#########################################
# new RT_RPYTHON types
# on top of RTMu
......@@ -250,7 +270,7 @@ def exit_emm():
def enter_region(reg):
res = do_something_realy_non_trivial('enter_region')
res = do_something_realy_non_trivial('enter_region_%s' % reg)
def exit_region():
......@@ -531,9 +551,21 @@ def get_rg_id_bin(_rg):
return bin(idi)
def get_rtmu_copy(g, cid):
for gg in g.rtmu_graphs:
if get_rg_id(gg) == cid:
return gg
# def get_rtmu_copy(g, cid):
# for gg in g.rtmu_graphs:
# gid = get_rg_id(gg)
# logger.info('cid: %d, gid: %d' %(cid, gid))
# if gid == cid:
# return gg
#
# return None
def is_nocopy_graph(g):
return name_starts_with(g.name, RTMU_OP_NAMES) or name_starts_with(g.name, RTMU_NOP_NAMES) or \
name_starts_with(g.name, RTMU_TRD_NAMES)
def must_ignore_graph(g):
return g.name in RTMU_NOP_NAMES
return None
......@@ -598,9 +598,12 @@ LL_OPERATIONS = {
'mu_comminst': LLOp(),
'mu_newrtthread': LLOp(),
'mu_newregion': LLOp(),
'mu_dec_global': LLOp(),
'mu_deleteregion': LLOp(),
'mu_ralloc': LLOp(),
'mu_rallochybrid': LLOp(),
'mu_ealloc': LLOp(),
'mu_eallochybrid': LLOp(),
'mu_exitthread': LLOp(),
'mu_yield': LLOp(),
'mu_newfutex': LLOp(),
......
......@@ -90,8 +90,10 @@ def safe_equal(x, y, TLS=TLS):
class frozendict(dict):
def __hash__(self):
# logger.info('frozendict.__hash__.type: %s' % self)
items = self.items()
items.sort()
# logger.info('frozendict.__hash__.items: %s' % items)
return hash(tuple(items))
......
......@@ -214,6 +214,10 @@ class RPythonTyper(object):
if block not in self.already_seen]
if not pending:
break
# RTMU
# pending = self.annotate_pending_rtmu(pending)
# shuffle blocks a bit
if self.seed:
import random
......@@ -228,14 +232,19 @@ class RPythonTyper(object):
previous_percentage = 0
# specialize all blocks in the 'pending' list
for block in pending:
logger.info('specializing block: %s, of graph: %s' % (block, self.annotator.annotated[block].name))
tracking(block)
blockcount += 1
try:
self.specialize_block(block)
except (KeyError, AttributeError) as er:
logger.WARNING('specialize_more_blocks: removing graph %s' % self.annotator.annotated[block].name)
self.annotator.translator.graphs.remove(self.annotator.annotated[block])
self.annotator.annotated.pop(block)
# try:
self.specialize_block(block)
# except (KeyError, AttributeError, LookupError, TyperError) as er:
# logger.WARNING('specialize_more_blocks: removing graph %s' % self.annotator.annotated[block].name)
# self.annotator.translator.graphs.remove(self.annotator.annotated[block])
# self.annotator.annotated.pop(block)
# except Exception as err:
# logger.WARNING('exception %s\n when specializing block %s of graph %s'
# % (err.message, block, self.annotator.annotated[block].name))
# raise err
self.already_seen[block] = True
# progress bar
......@@ -334,7 +343,7 @@ class RPythonTyper(object):
varmapping[v] = v # records existing Variables
for hop in self.highlevelops(block, newops):
# logger.info('HOP detected: %s' % hop.__str__())
logger.info('HOP detected: %s' % hop)
try:
hop.setup() # this is called from here to catch TyperErrors...
self.translate_hl_to_ll(hop, varmapping)
......@@ -465,7 +474,8 @@ class RPythonTyper(object):
yield HighLevelOp(self, block.operations[-1], exclinks, llops)
def translate_hl_to_ll(self, hop, varmapping):
#self.log.translating(hop.spaceop.opname, hop.args_s)
# self.log.translating(hop.spaceop.opname, hop.args_s)
# self.log.info('op: %s\n args: %s' % (hop.spaceop.opname, hop.args_s))
resultvar = hop.dispatch()
if hop.exceptionlinks and hop.llops.llop_raising_exceptions is None:
raise TyperError("the graph catches %s, but the rtyper did not "
......@@ -656,13 +666,13 @@ class HighLevelOp(object):
self.llops = llops
def setup(self):
# logger.info("HLO.setup op is: %s" % self.spaceop.opname)
logger.info("HLO.setup op is: %s" % self.spaceop.opname)
rtyper = self.rtyper
spaceop = self.spaceop
self.args_v = list(spaceop.args)
self.args_s = [rtyper.binding(a) for a in spaceop.args]
# logger.info("self.args_s = %s" % self.args_s.__str__())
# logger.info('spaceop.result = %s' % spaceop.result.__str__())
logger.info("self.args_s = %s" % self.args_s)
logger.info('spaceop.result = %s' % spaceop.result)
self.s_result = rtyper.binding(spaceop.result)
self.args_r = [rtyper.getrepr(s_a) for s_a in self.args_s]
self.r_result = rtyper.getrepr(self.s_result)
......@@ -686,6 +696,7 @@ class HighLevelOp(object):
opname = self.spaceop.opname
translate_meth = getattr(rtyper, 'translate_op_' + opname,
rtyper.default_translate_operation)
logger.info('hop.dispatch.translate_meth: %s' % translate_meth)
return translate_meth(self)
def inputarg(self, converted_to, arg):
......
This diff is collapsed.
......@@ -9,6 +9,7 @@ DEFAULTS = {
'translation.verbose': True,
}
class Translation(object):
def __init__(self, entry_point, argtypes=None, **kwds):
......
......@@ -57,7 +57,7 @@ class MuDatabase:
def collect_global_defs(self):
# collect global definitions in graphs
for graph in self.graphs:
# log.info("*** GRAPH: %s ***" % graph.name)
log.info("*** GRAPH: %s ***" % graph.name)
self._add_type(graph.sig)
for blk in graph.iterblocks():
......@@ -67,9 +67,12 @@ class MuDatabase:
self._add_type(blk.mu_excparam.concretetype)
for op in blk.operations:
# log.info("collecting types for op: %s" %op.opname)
log.info("collecting types for op: %s" % op.opname)
for a in op.args:
self._add_type(a.concretetype)
if hasattr(a, 'concretetype'):
self._add_type(a.concretetype)
else:
log.WARNING('OP: %s, arg: %s has no concretetype' % (op, a))
# log.info("added type: %s" % a.concretetype)
if isinstance(a, Constant):
self._collect_constant(a)
......@@ -99,22 +102,31 @@ class MuDatabase:
self.heap_NULL_constant_map[T] = c
def _collect_constant(self, c):
log.info('_collect_contant: %s' % c)
log.info('_collect_contant.type: %s' % c.concretetype)
if isinstance(c.concretetype, mutype.MuNumber):
self.consts.add(c)
elif isinstance(c.concretetype, mutype.MuGlobalCell):
log.info('_collect_contant.added to consts')
elif isinstance(c.concretetype, mutype.MuGlobalCell) or isinstance(c.concretetype, mutype.RTMuType):
self.gcells.add(c)
log.info('_collect_contant.added to gcells')
elif isinstance(c.concretetype, mutype.MuReferenceType) and c.value._is_null():
self.consts.add(c)
log.info('_collect_contant.added to consts')
elif isinstance(c.concretetype, mutype.MuUFuncPtr):
self.extern_fncs.add(c)
log.info('_collect_contant.added to extern_funcs')
elif isinstance(c.concretetype, mutype.MuFuncRef):
self.funcref_consts.add(c)
log.info('_collect_contant.added to funcref_consts')
def _add_type(self, T):
# try:
# log.info("_add_type: %s" % T.__str__())
# except TypeError:
# log.info("_add_type: can't print as string")
try:
log.info("_add_type: %s" % T)
log.info("_add_type.type: %s" % type(T))
# log.info("_add_type.self.types.type: %s" % type(self.types))
except TypeError:
log.info("_add_type: can't print as string")
assert isinstance(T, mutype.MuType)
......@@ -475,7 +487,7 @@ class MuNameManager:
self._counter['gcl'] += 1
elif isinstance(const.concretetype, mutype.MuReferenceType) and const.value._is_null():
name = 'NULL_%s' % self.get_type_name(const.concretetype)[1:]
elif isinstance(const.concretetype, mutype.MuNumber):
elif isinstance(const.concretetype, mutype.MuNumber) or isinstance(const.concretetype, mutype.RTMuType):
name = '%(hex)s_%(type)s' % {'hex': mutype.hex_repr(const.value),
'type': self.get_type_name(const.concretetype)[1:]}
elif isinstance(const.concretetype, mutype.MuUFuncPtr):
......
......@@ -7,7 +7,9 @@ from rpython.rtyper.llannotation import lltype_to_annotation
from rpython.rtyper.lltypesystem import lltype
from rpython.rtyper.lltypesystem.lltype import _ptr
from rpython.translator.backendopt.all import backend_optimizations
from rpython.tool.ansi_print import AnsiLogger
logger = AnsiLogger('exctran')
class MuExceptionTransformer:
def __init__(self, translator):
......@@ -97,6 +99,7 @@ class MuExceptionTransformer:
def transform_all(self):
for g in self.graphs:
logger.info('transform_all.graph: %s' % g)
self.exctran(g)
def exctran(self, g):
......
......@@ -252,7 +252,7 @@ class MuBundleGen:
self.log.gen_types("declaring %d types..." % len(self.db.types))
for T in self.db.types:
_id = self._id_of(T)
# self.log.info('id: %d, type: %s' % (_id, T))
self.log.info('id: %d, type: %s' % (_id, T))
if isinstance(T, mutype.MuIntType):
self.bdr.new_type_int(_id, T.BITS)
elif T == mutype.MU_FLOAT:
......@@ -357,6 +357,7 @@ class MuBundleGen:
count = 0
total = len(self.db.graphs)
for g in self.db.graphs:
self.log.info('generating graph: %s' % g.name)
count += 1
sys.stderr.write("\033[0F\033[K")
......@@ -371,16 +372,21 @@ class MuBundleGen:
for blk in g.iterblocks():
op_ids = []
# self.log.info('-- bb with %d ops' % len(blk.operations))
self.log.info('-- bb with %d ops' % len(blk.operations))
for op in filter(lambda op: op.opname.startswith('mu_'), blk.operations):
# self.log.info("--__ bb op to gen: %s" % (op.opname))
_id = self.bdr.gen_sym()
# if hasattr(_id, 'idx'):
# self.log.info("--__-- gen sym %s" % (_id.idx))
op_ids.append(_id)
mtd = getattr(self, '_genop_' + op.opname)
# self.log.info("--__ calling mtd %s" % mtd)
mtd(op, _id)
self.log.info("--__ bb op to gen: %s" % op)
from rpython.rlib.rrtmu.rtzebu import RTMU_NOID_OP
if op.opname in RTMU_NOID_OP:
mtd = getattr(self, '_genop_' + op.opname)
mtd(op)
else:
_id = self.bdr.gen_sym()
# if hasattr(_id, 'idx'):
# self.log.info("--__-- gen sym %s" % (_id.idx))
op_ids.append(_id)
mtd = getattr(self, '_genop_' + op.opname)
self.log.info("--__ calling mtd %s" % mtd)
mtd(op, _id)
# self.log.info("-- going to build bb")
self.bdr.new_bb(self._id_of(blk),
self._ids_of(blk.inputargs),
......@@ -642,6 +648,9 @@ class MuBundleGen:
def _genop_mu_newregion(self, op, op_id):
self.bdr.new_newregion(op_id, self._id_of(op.result), self._id_of(op.args[0]))
def _genop_mu_dec_global(self, op):
self.bdr.new_global_cell(self._id_of(op.args[0]), self._id_of(op.args[1]))
def _genop_mu_deleteregion(self, op, op_id):
self.bdr.new_deleteregion(op_id, self._id_of(op.args[0]))
......@@ -651,7 +660,7 @@ class MuBundleGen:
def _genop_mu_rallochybrid(self, op, op_id):
self.bdr.new_rallochybrid(op_id,
self._id_of(op.result),
self._id_of(op.args[0]),
self._id_of(op.args[0].value),
self._id_of(op.args[1].concretetype),
self._id_of(op.args[1]),
self._id_of(op.args[2])
......@@ -709,22 +718,32 @@ class MuBundleGen:
def _id_of(self, entity):
# look up id of the entity, if non-existent, call gen_sym
_id = "something"
# _id = "something"
try:
_id = self.idmap[entity]
except KeyError as err:
# self.log.info("genmu._id_of KeyError")
# self.log.info("idmap length = %d" % len(self.idmap))
# self.log.info("mu_name_map length = %d" % len(self.db.mu_name_map))
# self.log.info("mu_name_map[entity] = %s" % self.db.mu_name_map[entity].__str__())
self.log.info('_id_of: %s' % entity)
self.log.info('entity.mutype: %s' % type(entity))
# self.log.info('entity in self.idmap? %s' % entity in self.idmap)
self.log.info("genmu._id_of exception: %s" % err)
self.log.info("idmap length = %d" % len(self.idmap))
self.log.info("mu_name_map length = %d" % len(self.db.mu_name_map))
# self.log.info("\n\nself.idmap = %s" % self.idmap)
# self.log.info("\n\nmu_name_map = %s" % self.db.mu_name_map)
#
# for key in self.idmap:
# self.log.info("KEY:")
# self.log.info("%s" % key.__str__())
# self.log.info("id:")
# self.log.info("%s" % self.idmap[key].__str__())
raise err
for key in self.idmap:
# self.log.info("KEY:\n")
# self.log.info("%s\n" % key)
# self.log.info('key.mutype: %s' % type(key))
if key == entity:
self.log.WARNING("KEY == entity is %s" % (key == entity))
_id = self.idmap[key]
# self.log.info("id: %s\n" % self.idmap[key])
# _id = self.idmap[key]
# self.log.info('self.idmap[entity] = %s' % self.idmap[entity])
# raise err
assert _id
......
......@@ -96,7 +96,7 @@ def mu_offsetOf(mutype, fld):
if isinstance(mutype, MuArray):
of = mutype.OF
logger.info('mu_offsetOf.arr.of = %s' % of.__str__())
# logger.info('mu_offsetOf.arr.of = %s' % of.__str__())
return _alignUp(mu_sizeOf(of), mu_alignOf(of)) * fld
if isinstance(mutype, MuHybrid):
......
This diff is collapsed.
......@@ -5,6 +5,10 @@ from rpython.rlib import rarithmetic
from rpython.rtyper.lltypesystem import lltype, rffi
import weakref
from rpython.tool.ansi_print import AnsiLogger
logger = AnsiLogger("mutype.py")
def _setup_consistent_methods(cls):
tmpcls, mtds = cls._template
for mtd in mtds:
......@@ -59,17 +63,23 @@ class MuType(object):
# NB. the __cached_hash should neither be used nor updated
# if we enter with hash_level > 0, because the computed
# __hash__ can be different in this situation.
# logger.info('MuType.__hash__ for %s' % self)
# logger.info('MuType.__hash__.__class__: for %s' % self.__class__)
hash_level = 0
try:
hash_level = TLS.nested_hash_level
# logger.info('MuType.__hash__.hash_level: %d' % hash_level)
if hash_level == 0:
# logger.info('MuType.__hash__.__cached_hash: %d' % self.__cached_hash)
return self.__cached_hash
except AttributeError:
pass
if hash_level >= 3:
# logger.info('MuType.__hash__.hash_level_bound: %d' % hash_level)
return 0
items = self.__dict__.items()
items.sort()
# logger.info('MuType.__hash__.items: %s' % items)
TLS.nested_hash_level = hash_level + 1
try:
result = hash((self.__class__,) + tuple(items))
......@@ -101,14 +111,21 @@ _setup_consistent_methods(MuPrimitive)
class RTMuType(MuPrimitive):
_val_type = property(lambda self: _rtmutype)
def __init__(self, name):
MuPrimitive.__init__(self, name, None)
class _rtmutype(object):
pass
class MuRegionRef(RTMuType):
__slots__ = ("_obj", "_TYPE")
_symbol = '@reg'
_val_type = property(lambda self: _muregref)
def __init(self, name, _obj=None):
RTMuType.__init__(self, name)
......@@ -116,22 +133,40 @@ class MuRegionRef(RTMuType):
self._TYPE = MuRegionRef
def _null(self):
return MuRegionRef("REGREF_NULL")
return _muregref(self, None)
class _muregref(_rtmutype):
def __init__(self, TYPE, _obj):
self._TYPE = TYPE
self._obj = _obj
def _is_null(self):
return self._obj is None
class MuFutexRef(RTMuType):
__slots__ = ("_obj", "_TYPE")
_symbol = '@ftx'
_val_type = property(lambda self: _mufutexref)
def __init(self, name, _obj=None):
RTMuType.__init__(self, name)
self._obj = _obj
self._TYPE = MuFutexRef
# self._obj = _obj
# self._TYPE = MuFutexRef
def _null(self):
nl = MuFutexRef("FUTREF_NULL")
nl._TYPE = MU_FUTEXREF
return nl
return _mufutexref(self, None)
# def _is_null(self):
# return self._obj is None
class _mufutexref(_rtmutype):
def __init__(self, TYPE, _obj):
self._TYPE = TYPE
self._obj = _obj
def _is_null(self):
return self._obj is None
......@@ -140,16 +175,25 @@ class MuFutexRef(RTMuType):
class MuAttrRef(RTMuType):
__slots__ = ("_obj", "_TYPE")
_symbol = '@atr'
_val_type = property(lambda self: _muattrref)
def __init(self, name, _obj=None):
RTMuType.__init__(self, name)
self._obj = _obj
self._TYPE = MuAttrRef
# self._obj = _obj
# self._TYPE = MuAttrRef
def _null(self):
nl = MuAttrRef("ATTREF_NULL")
nl._TYPE = MuAttrRef
return nl
return _muattrref(self, None)
# def _is_null(self):
# return self._obj is None
class _muattrref(_rtmutype):
def __init__(self, TYPE, _obj):
self._TYPE = TYPE
self._obj = _obj
def _is_null(self):
return self._obj is None
......@@ -158,6 +202,7 @@ class MuAttrRef(RTMuType):
class MuTimerRef(RTMuType):
__slots__ = ("_obj", "_TYPE")
_symbol = '@tmr'
_val_type = property(lambda self: _mutimerref)
def __init(self, name, _obj=None):
RTMuType.__init__(self, name)
......@@ -165,7 +210,17 @@ class MuTimerRef(RTMuType):
self._TYPE = MuTimerRef
def _null(self):
return MuTimerRef("TMRREF_NULL")
return _mutimerref(self, None)
class _mutimerref(_rtmutype):
def __init__(self, TYPE, _obj):
self._TYPE = TYPE
self._obj = _obj
def _is_null(self):
return self._obj is None
class MuThreadRef(RTMuType):
......@@ -246,7 +301,7 @@ class MuFloatType(MuNumber):
def hex_repr(val):
MuT = mutypeOf(val)
assert isinstance(MuT, MuNumber)
assert isinstance(MuT, (MuNumber, RTMuType))
if isinstance(MuT, MuIntType):
return hex(val)[:-1]
if isinstance(MuT, MuFloatType):
......@@ -1226,7 +1281,7 @@ class _muuptr(_muobject_reference):
return _getobjfield(self._root_ref._obj, self._offsets)
def _setobj(self, value):
logger.info('_setobj.value = %s, _T = %s, mutype(self) = %s' % (value, self._T, mutypeOf(self)))
# logger.info('_setobj.value = %s, _T = %s, mutype(self) = %s' % (value, self._T, mutypeOf(self)))
if mutypeOf(value) != self._T:
raise TypeError("storing %s of type %s to %s" %
(value, mutypeOf(value), mutypeOf(self)))
......@@ -1394,10 +1449,15 @@ _prim_val_type_map = {
type(None): MU_VOID
}
from rpython.tool.ansi_print import AnsiLogger
# RTMU
_rtmu_val_type_map = {
MuRegionRef: MU_REGIONREF,
MuTimerRef: MU_TIMERREF,
MuFutexRef: MU_FUTEXREF,
MuAttrRef: MU_ATTRREF
}
logger = AnsiLogger("mutype.py"
"")
def mutypeOf(val):
# logger.info("mutypeOf: %s" % val.__str__())
try:
......@@ -1407,6 +1467,9 @@ def mutypeOf(val):
# logger.info("no _TYPE, tp is: %s" % tp.__name__)
if tp in _prim_val_type_map:
return _prim_val_type_map[tp]
# RTMU
if tp in _rtmu_val_type_map:
return _rtmu_val_type_map[tp]
raise TypeError("mutypeOf(%r object)" % (tp.__name__,))
......@@ -1422,7 +1485,7 @@ def new(T):
o = _muarray(T)
elif isinstance(T, MuNumber):
o = T._defl()
elif isinstance(T, MuReferenceType):
elif isinstance(T, MuReferenceType) or isinstance(T, RTMuType):
o = T._null()
else:
raise TypeError("do know how to new %s" % T)
......
This diff is collapsed.
......@@ -49,16 +49,20 @@ class TranslationContext(object):
# return 0
if (self.rtyper is not None or \
self.doing_entry_func is True or \
graph.name in rtzebu.RTMU_OP_NAMES or \
name_starts_with(graph.name, rtzebu.RTMU_OP_NAMES) or \
name_starts_with(graph.name, rtzebu.RTMU_NOP_NAMES) or \
name_starts_with(graph.name, rtzebu.RTMU_TRD_NAMES)) or \
name_starts_with(graph.name, rtzebu.NO_COPY_LIST) or \
is_rpython_internal(graph):
if self.doing_entry_func:
log.info('entry_functiom, returning zero')
self.doing_entry_func = False
return 0
# elif self.rtyper:
# log.info('already has rtyper, returning zero')
# return 0
elif (graph.name in rtzebu.RTMU_OP_NAMES or name_starts_with(graph.name, rtzebu.RTMU_OP_NAMES) or
name_starts_with(graph.name, rtzebu.RTMU_NOP_NAMES) or
name_starts_with(graph.name, rtzebu.RTMU_TRD_NAMES)) or \
name_starts_with(graph.name, rtzebu.NO_COPY_LIST):
# or is_rpython_internal(graph):
log.info('name in one of the rtzebu no-copy lists')
return 0
# log.info('graph: %s' % graph.name)
......@@ -81,64 +85,6 @@ class TranslationContext(object):
else:
return res
# rtmu-specific function.
# Makes `num` copies of `graph_orig` to be added to the main graph list.
# Copies are marked with `is_rtmu_copy` attribute.
# They also keep a ref to the original graph.
# The `func_orig` argument is required to preserve the independence of graph copies.
def get_rtmu_func_graphs(self, graph_orig, func_orig, num):
gl = []
for i in range(num):
func_copy = self.deepcopy_func(func_orig, '_' + str(i) + '_rtmu_untraced__')
graph_copy = build_flow(func_copy)
simplify.simplify_graph(graph_copy)
graph_copy.is_rtmu_copy = True
graph_copy.graph_orig = graph_orig
gl.append(graph_copy)
return gl
@staticmethod
def deepcopy_func(func, last_name):
import functools
# from rpython.rlib.rrtmu.rtzebu import deepcopy_func
#
# log.info("func_name = %s" % func.func_name)
# log.info("last_name = %s" % last_name)
#
# return deepcopy_func(func, last_name)
# assert isinstance(func, types.FunctionType)
# from copy import deepcopy
# from rpython.tool.sourcetools import newcode_withfilename
# code_copy = newcode_withfilename(func.func_code, func.func_code.co_filename)
fcopy = types.FunctionType(func.func_code,
func.func_globals.copy(),
func.func_name,
func.func_defaults,
func.func_closure)
fcopy = functools.update_wrapper(fcopy, func)
fcopy.func_name = func.func_name + last_name
# def deepcopy_dict(dct):
# new_dict = dict()
# for idx in dct:
# new_dict[deepcopy(idx)] = deepcopy(dct[idx])
#
# return new_dict
# if hasattr(func, "__dict__") and len(func.__dict__) > 0:
# # log.info("Func Dict: %s" % func.__dict__.__str__())
# # fcopy.__dict__ = deepcopy(func.__dict__, memo=dict)
# # fcopy.__dict__ = deepcopy_dict(func.__dict__)
# fcopy.__dict__ = func.__dict__.copy()
# return func
return fcopy
def buildflowgraph(self, func, mute_dot=False):
"""Get the flow graph for a function."""
# log.info("buildflowgraph for func: %s" % func.__str__())
......@@ -152,27 +98,29 @@ class TranslationContext(object):
if self.config.translation.verbose:
log(nice_repr_for_func(func))
func_orig = self.deepcopy_func(func, '_copy')
# func_orig = self.deepcopy_func(func, '_copy')
graph = build_flow(func)
simplify.simplify_graph(graph)
# log.info('buildflow for graph: %s' % graph.name)
_num_of_copies = self.get_num_of_copies(graph)
log.info('built and simplified flow for graph: %s' % graph.name)
log.info('graph.func_code: \n %s' % graph.func.func_code)
# _num_of_copies = self.get_num_of_copies(graph)
# log.info('num of copies: %d' % _num_of_copies)
if _num_of_copies is 0:
# del func_orig
pass
else:
gl = self.get_rtmu_func_graphs(graph, func_orig, _num_of_copies)
# log(nice_repr_for_func(func))
graph.has_rtmu_copy = True
graph.rtmu_graphs = gl
self.graphs.extend(gl)
#
# if _num_of_copies is 0:
# # del func_orig
# pass
# else:
# gl = self.get_rtmu_func_graphs(graph, func_orig, _num_of_copies)
# graph.has_rtmu_copy = True
# graph.rtmu_graphs = gl
# self.graphs.extend(gl)
if self.config.translation.list_comprehension_operations:
simplify.detect_list_comprehension(graph)
log.info('buildflowgraph, graph name after list comprehension: %s' % graph.name)
if not self.config.translation.verbose and not mute_dot:
log.dot()
log.info('buildflowgraph, graph name after log.dot: %s' % graph.name)
self.graphs.append(graph) # store the graph in our list
return graph
......