|
@@ -228,6 +228,12 @@ def erase_parameters(entry_point, parameters_to_erase):
|
|
|
for parameter_def in parameters_to_erase:
|
|
|
parameter_def.block.remove_parameter(parameter_def)
|
|
|
|
|
|
+def apply_cfg_intrinsic(intrinsic_function, original_definition, named_args):
|
|
|
+ """Applies the given intrinsic to the given sequence of named arguments."""
|
|
|
+ kwargs = dict(named_args)
|
|
|
+ kwargs['original_def'] = original_definition
|
|
|
+ return intrinsic_function(**kwargs)
|
|
|
+
|
|
|
def try_redefine_as_direct_call(definition, jit, called_globals):
|
|
|
"""Tries to redefine the given indirect call definition as a direct call."""
|
|
|
call = cfg_ir.get_def_value(definition)
|
|
@@ -239,18 +245,19 @@ def try_redefine_as_direct_call(definition, jit, called_globals):
|
|
|
loaded_ptr = cfg_ir.get_def_value(target.pointer)
|
|
|
if isinstance(loaded_ptr, cfg_ir.ResolveGlobal):
|
|
|
resolved_var_name = loaded_ptr.variable.name
|
|
|
-
|
|
|
- # # Try to resolve the callee as an intrinsic.
|
|
|
- # intrinsic = jit.get_intrinsic(resolved_var_name)
|
|
|
- # if intrinsic is not None:
|
|
|
- # return redefine_as_intrinsic(definition, intrinsic, call.argument_list)
|
|
|
-
|
|
|
- # Otherwise, build a thunk.
|
|
|
- thunk_name = jit.jit_thunk_global(resolved_var_name)
|
|
|
- definition.redefine(
|
|
|
- cfg_ir.DirectFunctionCall(
|
|
|
- thunk_name, call.argument_list, cfg_ir.JIT_CALLING_CONVENTION))
|
|
|
called_globals.add(loaded_ptr)
|
|
|
+
|
|
|
+ # Try to resolve the callee as an intrinsic.
|
|
|
+ intrinsic = jit.get_cfg_intrinsic(resolved_var_name)
|
|
|
+ if intrinsic is not None:
|
|
|
+ apply_cfg_intrinsic(intrinsic, definition, call.argument_list)
|
|
|
+ else:
|
|
|
+ # Otherwise, build a thunk.
|
|
|
+ thunk_name = jit.jit_thunk_global(resolved_var_name)
|
|
|
+ definition.redefine(
|
|
|
+ cfg_ir.DirectFunctionCall(
|
|
|
+ thunk_name, call.argument_list, cfg_ir.JIT_CALLING_CONVENTION))
|
|
|
+ called_globals.add(loaded_ptr)
|
|
|
elif isinstance(target, cfg_ir.Literal):
|
|
|
node_id = target.literal
|
|
|
thunk_name = jit.jit_thunk_constant(node_id)
|