|
@@ -237,7 +237,10 @@ def try_redefine_as_direct_call(definition, jit, called_globals):
|
|
|
# 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)
|
|
|
+ definition.redefine(
|
|
|
+ cfg_ir.DirectFunctionCall(
|
|
|
+ resolved_var_name, call.argument_list,
|
|
|
+ cfg_ir.JIT_CFG_INTRINSIC_CALLING_CONVENTION))
|
|
|
else:
|
|
|
# Otherwise, build a thunk.
|
|
|
thunk_name = jit.jit_thunk_global(resolved_var_name)
|
|
@@ -287,8 +290,7 @@ def optimize_calls(entry_point, jit):
|
|
|
given entry point."""
|
|
|
called_globals = set()
|
|
|
global_exists_defs = defaultdict(list)
|
|
|
- all_blocks = list(cfg_ir.get_all_blocks(entry_point))
|
|
|
- for block in all_blocks:
|
|
|
+ for block in cfg_ir.get_all_blocks(entry_point):
|
|
|
for definition in block.definitions:
|
|
|
checked_global = get_checked_global(definition)
|
|
|
if checked_global is not None:
|
|
@@ -300,6 +302,17 @@ def optimize_calls(entry_point, jit):
|
|
|
for exists_def in global_exists_defs[resolve_global]:
|
|
|
exists_def.redefine(cfg_ir.Literal(False))
|
|
|
|
|
|
+def expand_cfg_intrinsics(entry_point, jit):
|
|
|
+ """Expands CFG JIT intrinsics in the control-flow graph defined by the given entry point."""
|
|
|
+ for block in cfg_ir.get_all_blocks(entry_point):
|
|
|
+ for definition in block.definitions:
|
|
|
+ def_value = definition.value
|
|
|
+ if (isinstance(def_value, cfg_ir.DirectFunctionCall)
|
|
|
+ and def_value.calling_convention ==
|
|
|
+ cfg_ir.JIT_CFG_INTRINSIC_CALLING_CONVENTION):
|
|
|
+ intrinsic = jit.get_cfg_intrinsic(def_value.target_name)
|
|
|
+ apply_cfg_intrinsic(intrinsic, definition, def_value.argument_list)
|
|
|
+
|
|
|
def simplify_values(entry_point):
|
|
|
"""Simplifies values in the control-flow graph defined by the given entry point."""
|
|
|
for block in cfg_ir.get_all_blocks(entry_point):
|
|
@@ -514,6 +527,7 @@ def optimize(entry_point, jit):
|
|
|
if jit.direct_calls_allowed:
|
|
|
optimize_calls(entry_point, jit)
|
|
|
cfg_data_structures.optimize_data_structures(entry_point)
|
|
|
+ expand_cfg_intrinsics(entry_point, jit)
|
|
|
yield [("CALL_ARGS", [inline_constants, (entry_point,)])]
|
|
|
optimize_reads(entry_point)
|
|
|
simplify_values(entry_point)
|