瀏覽代碼

Evaluate constant unaries in the CFG optimizer

jonathanvdc 8 年之前
父節點
當前提交
175d8ab3b8
共有 1 個文件被更改,包括 6 次插入0 次删除
  1. 6 0
      kernel/modelverse_jit/cfg_optimization.py

+ 6 - 0
kernel/modelverse_jit/cfg_optimization.py

@@ -316,6 +316,12 @@ def simplify_values(entry_point):
                     definition.redefine(
                         cfg_ir.Literal(
                             eval('%r %s %r' % (lhs.literal, def_val.operator, rhs.literal))))
+            elif isinstance(def_val, cfg_ir.Unary):
+                operand = cfg_ir.get_def_value(def_val.operand)
+                if isinstance(operand, cfg_ir.Literal):
+                    definition.redefine(
+                        cfg_ir.Literal(
+                            eval('%s %r' % (def_val.operator, operand.literal))))
 
 def inline_constants(entry_point):
     """Replaces reads of constant nodes by the literals they contain."""