|
@@ -326,6 +326,17 @@ def simplify_values(entry_point):
|
|
|
cfg_ir.Literal(
|
|
|
eval('%r %s %r' % (lhs.literal, def_val.operator, rhs.literal))))
|
|
|
|
|
|
+def inline_constants(entry_point):
|
|
|
+ """Replaces reads of constant nodes by the literals they contain."""
|
|
|
+ for block in get_all_blocks(entry_point):
|
|
|
+ for definition in block.definitions:
|
|
|
+ def_val = cfg_ir.get_def_value(definition)
|
|
|
+ if isinstance(def_val, cfg_ir.Read):
|
|
|
+ read_node = cfg_ir.get_def_value(def_val.node)
|
|
|
+ if isinstance(read_node, cfg_ir.Literal):
|
|
|
+ val, = yield [("RV", [read_node.literal])]
|
|
|
+ definition.redefine(cfg_ir.Literal(val))
|
|
|
+
|
|
|
def optimize(entry_point, jit):
|
|
|
"""Optimizes the control-flow graph defined by the given entry point."""
|
|
|
optimize_graph_flow(entry_point)
|
|
@@ -333,6 +344,7 @@ def optimize(entry_point, jit):
|
|
|
optimize_graph_flow(entry_point)
|
|
|
eliminate_trivial_phis(entry_point)
|
|
|
optimize_calls(entry_point, jit)
|
|
|
+ yield [("CALL_ARGS", [inline_constants, (entry_point,)])]
|
|
|
simplify_values(entry_point)
|
|
|
eliminate_unused_definitions(entry_point)
|
|
|
optimize_graph_flow(entry_point)
|