forked from M-Labs/artiq
1
0
Fork 0

transforms/inline: implement 'portable' decorator

This commit is contained in:
Sebastien Bourdeauducq 2014-10-13 17:04:55 +08:00
parent 482f4651ff
commit 5b05a3f75b
1 changed files with 14 additions and 7 deletions

View File

@ -122,7 +122,7 @@ class _ReferenceManager:
raise NotImplementedError raise NotImplementedError
_embeddable_calls = ( _embeddable_funcs = (
core_language.delay, core_language.at, core_language.now, core_language.delay, core_language.at, core_language.now,
core_language.time_to_cycles, core_language.cycles_to_time, core_language.time_to_cycles, core_language.cycles_to_time,
core_language.syscall, core_language.syscall,
@ -131,13 +131,22 @@ _embeddable_calls = (
Fraction, units.Quantity, core_language.EncodedException Fraction, units.Quantity, core_language.EncodedException
) )
def _is_embeddable(call): def _is_embeddable(func):
for ec in _embeddable_calls: for ef in _embeddable_funcs:
if call is ec: if func is ef:
return True return True
return False return False
def _is_inlinable(core, func):
if hasattr(func, "k_function_info"):
if func.k_function_info.core_name == "":
return True # portable function
if getattr(func.__self__, func.k_function_info.core_name) is core:
return True # kernel function for the same core device
return False
class _ReferenceReplacer(ast.NodeVisitor): class _ReferenceReplacer(ast.NodeVisitor):
def __init__(self, core, rm, obj, func_name, retval_name): def __init__(self, core, rm, obj, func_name, retval_name):
self.core = core self.core = core
@ -231,9 +240,7 @@ class _ReferenceReplacer(ast.NodeVisitor):
ast.Call(func=new_func, args=new_args, ast.Call(func=new_func, args=new_args,
keywords=[], starargs=None, kwargs=None), keywords=[], starargs=None, kwargs=None),
node) node)
elif (hasattr(func, "k_function_info") elif _is_inlinable(self.core, func):
and getattr(func.__self__, func.k_function_info.core_name)
is self.core):
retval_name = self.rm.new_name( retval_name = self.rm.new_name(
func.k_function_info.k_function.__name__ + "_return") func.k_function_info.k_function.__name__ + "_return")
args = [func.__self__] + new_args args = [func.__self__] + new_args