redo pinned mode handling in spec generator
[libfirm] / scripts / ir_spec.py
index 46d2b1c..ce4c0a5 100755 (executable)
 nodes = dict(
-Start = dict(
-       mode       = "mode_T",
-       op_flags   = "cfopcode",
-       state      = "pinned",
-       knownBlock = True,
-       noconstr   = True,
-),
 
-End = dict(
-       mode       = "mode_X",
-       op_flags   = "cfopcode",
-       state      = "pinned",
-       arity      = "dynamic",
-       knownBlock = True,
-       noconstr   = True,
+#
+# Abstract node types
+#
+unop = dict(
+       abstract = True,
+       ins      = [ "op" ]
 ),
 
-Phi = dict(
-       noconstr = True,
-       state    = "pinned",
-       arity    = "variable",
+binop = dict(
+       abstract = True,
+       ins      = [ "left", "right" ]
 ),
 
-Jmp = dict(
-       mode     = "mode_X",
-       op_flags = "cfopcode",
-       state    = "pinned",
-       ins      = [],
+#
+# Real node types
+#
+Abs = dict(
+       is_a     = "unop"
 ),
 
-IJmp = dict(
-       mode     = "mode_X",
-       op_flags = "cfopcode",
-       state    = "pinned",
-       ins      = [ "target" ],
+Add = dict(
+       is_a     = "binop"
 ),
 
-Const = dict(
-       mode       = "",
-       knownBlock = True,
-       attrs      = [
+Alloc = dict(
+       ins   = [ "mem", "size" ],
+       outs  = [ "M", "X_regular", "X_except", "res" ],
+       attrs = [
                dict(
-                       type = "tarval*",
-                       name = "tarval",
+                       name = "type",
+                       type = "ir_type*"
+               ),
+               dict(
+                       name = "where",
+                       type = "ir_where_alloc"
                )
        ],
+       pinned      = "exception",
+       pinned_init = "pinned",
+       d_post = '''
+       #if PRECISE_EXC_CONTEXT
+       firm_alloc_frag_arr(res, op_Alloc, &res->attr.alloc.exc.frag_arr);
+       #endif
+       '''
+),
+
+Anchor = dict(
+       mode       = "mode_ANY",
+       arity      = "variable",
+       knownBlock = True,
+       noconstr   = True
+),
+
+And = dict(
+       is_a     = "binop"
+),
+
+Bad = dict(
+       mode       = "mode_Bad",
+       knownBlock = True,
 ),
 
 Block = dict(
-       mode   = "mode_BB",
+       mode       = "mode_BB",
        knownBlock = True,
+       block      = "NULL",
        noconstr   = True,
+       optimize   = False,
        arity      = "variable",
+
+       init = '''
+       /* macroblock header */
+       res->in[0] = res;
+
+       res->attr.block.is_dead     = 0;
+       res->attr.block.is_mb_head  = 1;
+       res->attr.block.has_label   = 0;
+       res->attr.block.irg         = irg;
+       res->attr.block.backedge    = new_backedge_arr(irg->obst, arity);
+       res->attr.block.in_cg       = NULL;
+       res->attr.block.cg_backedge = NULL;
+       res->attr.block.extblk      = NULL;
+       res->attr.block.mb_depth    = 0;
+       res->attr.block.label       = 0;
+
+       set_Block_matured(res, 1);
+       set_Block_block_visited(res, 0);
+       ''',
+
+       d_pre = '''
+       int i;
+       int has_unknown = 0;
+       ''',
+
+       d_post = '''
+       /* Create and initialize array for Phi-node construction. */
+       if (get_irg_phase_state(current_ir_graph) == phase_building) {
+               res->attr.block.graph_arr = NEW_ARR_D(ir_node *, current_ir_graph->obst,
+                                                     current_ir_graph->n_loc);
+               memset(res->attr.block.graph_arr, 0, sizeof(ir_node *)*current_ir_graph->n_loc);
+       }
+
+       for (i = arity - 1; i >= 0; i--)
+               if (is_Unknown(in[i])) {
+                       has_unknown = 1;
+                       break;
+               }
+
+       if (!has_unknown) res = optimize_node(res);
+
+       current_ir_graph->current_block = res;
+
+       IRN_VRFY_IRG(res, current_ir_graph);
+       ''',
+
        java_add   = '''
        public void addPred(Node node) {
                binding_cons.add_immBlock_pred(ptr, node.ptr);
@@ -75,30 +138,25 @@ Block = dict(
        }''',
 ),
 
-SymConst = dict(
-       mode       = "mode_P",
-       knownBlock = True,
-       noconstr   = True,
-       attrs      = [
-               dict(
-                       type = "ir_entity*",
-                       name = "entity"
-               )
-       ],
+Borrow = dict(
+       is_a     = "binop"
 ),
 
-# SymConst
+Bound = dict(
+       ins    = [ "mem", "index", "lower", "upper" ],
+       outs   = [ "M", "X_regular", "X_except", "res" ],
+       pinned = "exception",
+       pinned_init = "pinned",
+       d_post = '''
+       #if PRECISE_EXC_CONTEXT
+       firm_alloc_frag_arr(res, op_Bound, &res->attr.bound.exc.frag_arr);
+       #endif
+       '''
+),
 
-Call = dict(
-       ins      = [ "mem", "ptr" ],
-       arity    = "variable",
-       outs     = [ "M_regular", "X_regular", "X_except", "T_result", "M_except", "P_value_res_base" ],
-       attrs    = [
-               dict(
-                       type = "ir_type*",
-                       name = "type"
-               )
-       ]
+
+Break = dict(
+       mode = "mode_X"
 ),
 
 Builtin = dict(
@@ -114,134 +172,255 @@ Builtin = dict(
                        type = "ir_type*",
                        name = "type"
                )
-       ]
-),
+       ],
+       pinned      = "memory",
+       pinned_init = "pinned",
+       init   = '''
+       assert((get_unknown_type() == type) || is_Method_type(type));
+       '''
 
-binop = dict(
-       abstract = True,
-       ins      = [ "left", "right" ]
+       # TODO: No firm_alloc_frag_arr??
 ),
 
-Add = dict(
-       is_a     = "binop"
+Call = dict(
+       ins      = [ "mem", "ptr" ],
+       arity    = "variable",
+       outs     = [ "M_regular", "X_regular", "X_except", "T_result", "M_except", "P_value_res_base" ],
+       attrs    = [
+               dict(
+                       type = "ir_type*",
+                       name = "type"
+               )
+       ],
+       pinned      = "memory",
+       pinned_init = "pinned",
+       init = '''
+       assert((get_unknown_type() == type) || is_Method_type(type));
+       ''',
+       d_post = '''
+       #if PRECISE_EXC_CONTEXT
+       firm_alloc_frag_arr(res, op_Call, &res->attr.call.exc.frag_arr);
+       #endif
+       '''
 ),
 
 Carry = dict(
        is_a     = "binop"
 ),
 
-Sub = dict(
-       is_a     = "binop"
-),
-
-Borrow = dict(
-       is_a     = "binop"
-),
-
-Mul = dict(
-       is_a     = "binop"
-),
-
-Mulh = dict(
-       is_a     = "binop"
-),
-
-Abs = dict(
-       is_a     = "unop"
-),
-
-And = dict(
-       is_a     = "binop"
-),
-
-Or = dict(
-       is_a     = "binop"
-),
-
-Eor = dict(
-       is_a     = "binop"
+Cast = dict(
+       ins      = [ "op" ],
+       mode     = "get_irn_mode(irn_op)",
+       attrs    = [
+               dict(
+                       type = "ir_type*",
+                       name = "type"
+               )
+       ],
+       init     = "assert(is_atomic_type(type));"
 ),
 
-Not = dict(
-       is_a     = "unop"
+Cmp = dict(
+       is_a     = "binop",
+       outs     = [ "False", "Eq", "Lt", "Le", "Gt", "Ge", "Lg", "Leg", "Uo", "Ue", "Ul", "Ule", "Ug", "Uge", "Ne", "True" ],
 ),
 
-Shl = dict(
-       is_a     = "binop"
+Cond = dict(
+       ins      = [ "selector" ],
+       outs     = [ "false", "true" ],
+       attrs    = [
+               dict(
+                       name = "kind",
+                       type = "cond_kind",
+                       init = "dense"
+               ),
+               dict(
+                       name = "default_proj",
+                       type = "long",
+                       init = "0"
+               ),
+               dict(
+                       name = "jmp_pred",
+                       type = "cond_jmp_predicate",
+                       init = "COND_JMP_PRED_NONE"
+               )
+       ]
 ),
 
-Shr = dict(
-       is_a     = "binop"
+Confirm = dict(
+       ins      = [ "value", "bound" ],
+       mode     = "get_irn_mode(irn_value)",
+       attrs    = [
+               dict(
+                       name = "cmp",
+                       type = "pn_Cmp"
+               ),
+       ],
 ),
 
-Shrs = dict(
-       is_a     = "binop"
+Const = dict(
+       mode       = "",
+       knownBlock = True,
+       attrs_name = "con",
+       attrs      = [
+               dict(
+                       type = "tarval*",
+                       name = "tarval",
+               )
+       ],
 ),
 
-Rotl = dict(
-       is_a     = "binop"
+Conv = dict(
+       is_a     = "unop",
+       attrs = [
+               dict(
+                       name = "strict",
+                       type = "int",
+                       init = "0",
+                       special = dict(
+                               prefix = "strict",
+                               init = "1"
+                       )
+               )
+       ]
 ),
 
-Quot = dict(
-       ins   = [ "mem", "dividend", "divisor" ],
-       outs  = [ "M", "X_regular", "X_except", "res" ],
+CopyB = dict(
+       ins   = [ "mem", "dst", "src" ],
+       outs  = [ "M", "X_regular", "X_except" ],
        attrs = [
                dict(
-                       type = "ir_mode*",
-                       name = "resmode"
-               ),
-               dict(
-                       name = "state",
-                       type = "op_pin_state"
+                       name = "type",
+                       type = "ir_type*"
                )
-       ]
+       ],
+       pinned      = "memory",
+       pinned_init = "pinned",
+       d_post = '''
+       #if PRECISE_EXC_CONTEXT
+       firm_alloc_frag_arr(res, op_CopyB, &res->attr.copyb.exc.frag_arr);
+       #endif
+       '''
 ),
 
 Div = dict(
        ins   = [ "mem", "dividend", "divisor" ],
        outs  = [ "M", "X_regular", "X_except", "res" ],
+       attrs_name = "divmod",
        attrs = [
                dict(
                        type = "ir_mode*",
                        name = "resmode"
                ),
                dict(
-                       name = "state",
-                       type = "op_pin_state"
+                       name = "no_remainder",
+                       type = "int",
+                       init = "0",
+                       special = dict(
+                               suffix = "RL",
+                               init = "1"
+                       )
                )
-       ]
+       ],
+       pinned = "exception",
+       d_post = '''
+       #if PRECISE_EXC_CONTEXT
+       firm_alloc_frag_arr(res, op_Div, &res->attr.except.frag_arr);
+       #endif
+       '''
 ),
 
 DivMod = dict(
        ins   = [ "mem", "dividend", "divisor" ],
        outs  = [ "M", "X_regular", "X_except", "res_div", "res_mod" ],
+       attrs_name = "divmod",
        attrs = [
                dict(
                        type = "ir_mode*",
                        name = "resmode"
                ),
+       ],
+       pinned = "exception",
+       d_post = '''
+       #if PRECISE_EXC_CONTEXT
+       firm_alloc_frag_arr(res, op_DivMod, &res->attr.except.frag_arr);
+       #endif
+       '''
+),
+
+End = dict(
+       mode       = "mode_X",
+       op_flags   = "cfopcode",
+       pinned     = "yes",
+       arity      = "dynamic",
+       noconstr   = True,
+       optimize   = False
+),
+
+Eor = dict(
+       is_a     = "binop"
+),
+
+Filter = dict(
+       ins   = [ "pred" ],
+       attrs = [
                dict(
-                       name = "state",
-                       type = "op_pin_state"
+                       name = "proj",
+                       type = "long"
                )
        ]
+
+       # TODO: Broken asserts in original:
+       # assert(get_Proj_pred(res));
+       # assert(get_nodes_block(get_Proj_pred(res)));
 ),
 
-Mod = dict(
-       ins   = [ "mem", "dividend", "divisor" ],
-       outs  = [ "M", "X_regular", "X_except", "res" ],
+Free = dict(
+       ins   = [ "mem", "ptr", "size" ],
+       mode  = "mode_M",
        attrs = [
                dict(
-                       type = "ir_mode*",
-                       name = "resmode"
+                       name = "type",
+                       type = "ir_type*"
                ),
                dict(
-                       name = "state",
-                       type = "op_pin_state"
+                       name = "where",
+                       type = "ir_where_alloc"
                )
        ]
 ),
 
+Id = dict(
+       ins = [ "pred" ]
+),
+
+IJmp = dict(
+       mode     = "mode_X",
+       op_flags = "cfopcode",
+       pinned   = "yes",
+       ins      = [ "target" ],
+),
+
+InstOf = dict(
+       ins   = [ "store", "objptr" ],
+       outs  = [ "M", "X_regular", "X_except", "res", "M_except" ],
+       attrs = [
+               dict(
+                       name = "type",
+                       type = "ir_type*"
+               )
+       ],
+       pinned      = "memory",
+       pinned_init = "floats",
+),
+
+Jmp = dict(
+       mode     = "mode_X",
+       op_flags = "cfopcode",
+       pinned   = "yes",
+       ins      = [],
+),
+
 Load = dict(
        ins      = [ "mem", "ptr" ],
        outs     = [ "M", "X_regular", "X_except", "res" ],
@@ -254,31 +433,49 @@ Load = dict(
        ],
        constructor_args = [
                dict(
-                       type = "cons_flags",
+                       type = "ir_cons_flags",
                        name = "flags",
                ),
        ],
+       d_post = '''
+#if PRECISE_EXC_CONTEXT
+       firm_alloc_frag_arr(res, op_Load, &res->attr.load.exc.frag_arr);
+#endif
+       '''
 ),
 
-Store = dict(
-       ins      = [ "mem", "ptr", "value" ],
-       outs     = [ "M", "X_regular", "X_except" ],
-       constructor_args = [
+Minus = dict(
+       is_a     = "unop"
+),
+
+Mod = dict(
+       ins   = [ "mem", "dividend", "divisor" ],
+       outs  = [ "M", "X_regular", "X_except", "res" ],
+       attrs_name = "divmod",
+       attrs = [
                dict(
-                       type = "cons_flags",
-                       name = "flags",
+                       type = "ir_mode*",
+                       name = "resmode"
                ),
        ],
+       pinned = "exception",
+       d_post = '''
+       #if PRECISE_EXC_CONTEXT
+       firm_alloc_frag_arr(res, op_Mod, &res->attr.except.frag_arr);
+       #endif
+       '''
 ),
 
-Anchor = dict(
-       mode       = "mode_ANY",
-       ins        = [ "end_block", "start_block", "end", "start",
-                      "end_reg", "end_except", "initial_exec",
-                                  "frame", "tls", "initial_mem", "args",
-                                  "bad", "no_mem" ],
-       knownBlock = True,
-       noconstr   = True
+Mul = dict(
+       is_a     = "binop"
+),
+
+Mulh = dict(
+       is_a     = "binop"
+),
+
+Mux = dict(
+       ins      = [ "sel", "false", "true" ]
 ),
 
 NoMem = dict(
@@ -286,14 +483,23 @@ NoMem = dict(
        knownBlock = True,
 ),
 
-Bad = dict(
-       mode       = "mode_Bad",
-       knownBlock = True,
+Not = dict(
+       is_a     = "unop"
+),
+
+Or = dict(
+       is_a     = "binop"
+),
+
+Phi = dict(
+       noconstr = True,
+       pinned   = "yes",
+       arity    = "variable",
 ),
 
 Pin = dict(
        ins      = [ "op" ],
-       mode     = "get_irn_mode(op);"
+       mode     = "get_irn_mode(irn_op)"
 ),
 
 Proj = dict(
@@ -301,126 +507,123 @@ Proj = dict(
        attrs    = [
                dict(
                        type = "long",
-                       name = "proj"
+                       name = "proj",
+                       initname = ""
                )
        ]
 ),
 
-Sel = dict(
-       ins    = [ "mem", "ptr" ],
-       arity  = "variable",
-       mode   = "mode_P",
-       attrs    = [
+Quot = dict(
+       ins   = [ "mem", "dividend", "divisor" ],
+       outs  = [ "M", "X_regular", "X_except", "res" ],
+       attrs_name = "divmod",
+       attrs = [
                dict(
-                       type = "ir_entity*",
-                       name = "entity"
-               )
-       ]
+                       type = "ir_mode*",
+                       name = "resmode"
+               ),
+       ],
+       pinned = "exception",
+       d_post = '''
+       #if PRECISE_EXC_CONTEXT
+       firm_alloc_frag_arr(res, op_Quot, &res->attr.except.frag_arr);
+       #endif
+       '''
 ),
 
-Sync = dict(
-       mode     = "mode_M",
-       arity    = "dynamic"
+Raise = dict(
+       ins   = [ "mem", "exo_ptr" ],
+       outs  = [ "M", "X" ]
 ),
 
-Tuple = dict(
+Return = dict(
+       ins      = [ "mem" ],
        arity    = "variable",
-       mode     = "mode_T",
+       mode     = "mode_X"
 ),
 
-Unknown = dict(
-       knownBlock = True
+Rotl = dict(
+       is_a     = "binop"
 ),
 
-Confirm = dict(
-       ins      = [ "value", "bound" ],
-       block    = "get_nodes_block(value)",
-       mode     = "get_irn_mode(value)",
+Sel = dict(
+       ins    = [ "mem", "ptr" ],
+       arity  = "variable",
+       mode   = "is_Method_type(get_entity_type(entity)) ? mode_P_code : mode_P_data",
        attrs    = [
                dict(
-                       name = "cmp",
-                       type = "pn_Cmp"
-               ),
-       ],
+                       type = "ir_entity*",
+                       name = "entity"
+               )
+       ]
 ),
 
-Return = dict(
-       ins      = [ "mem" ],
-       arity    = "variable",
-       mode     = "mode_X"
+Shl = dict(
+       is_a     = "binop"
 ),
 
-unop = dict(
-       abstract = True,
-       ins      = [ "op" ]
+Shr = dict(
+       is_a     = "binop"
 ),
 
-Minus = dict(
-       is_a     = "unop"
+Shrs = dict(
+       is_a     = "binop"
 ),
 
-Mux = dict(
-       ins      = [ "sel", "false", "true" ]
+Start = dict(
+       mode       = "mode_T",
+       op_flags   = "cfopcode",
+       pinned     = "yes",
+       noconstr   = True,
+       optimize   = False
 ),
 
-Cond = dict(
-       ins      = [ "selector" ],
-       outs     = [ "false", "true" ],
+Store = dict(
+       ins      = [ "mem", "ptr", "value" ],
+       outs     = [ "M", "X_regular", "X_except" ],
+       constructor_args = [
+               dict(
+                       type = "ir_cons_flags",
+                       name = "flags",
+               ),
+       ],
+       d_post = '''
+#if PRECISE_EXC_CONTEXT
+       firm_alloc_frag_arr(res, op_Store, &res->attr.store.exc.frag_arr);
+#endif
+       '''
 ),
 
-Cmp = dict(
-       is_a     = "binop",
-       outs     = [ "False", "Eq", "Lt", "Le", "Gt", "Ge", "Lg", "Leg", "Uo", "Ue", "Ul", "Ule", "Ug", "Uge", "Ne", "True" ],
+Sub = dict(
+       is_a     = "binop"
 ),
 
-Conv = dict(
-       is_a     = "unop",
-       attrs = [
+SymConst = dict(
+       mode       = "mode_P",
+       knownBlock = True,
+       noconstr   = True,
+       attrs      = [
                dict(
-                       name = "strict",
-                       type = "int"
+                       type = "ir_entity*",
+                       name = "entity"
                )
-       ]
+       ],
 ),
 
-Alloc = dict(
-       ins   = [ "mem", "size" ],
-       outs  = [ "M", "X_regular", "X_except", "res" ],
-       attrs = [
-               dict(
-                       name = "type",
-                       type = "ir_type*"
-               ),
-               dict(
-                       name = "where",
-                       type = "ir_where_alloc"
-               )
-       ]
+Sync = dict(
+       mode     = "mode_M",
+       optimize = False,
+       arity    = "dynamic"
 ),
 
-Free = dict(
-       ins   = [ "mem", "ptr", "size" ],
-       mode  = "mode_M",
-       attrs = [
-               dict(
-                       name = "type",
-                       type = "ir_type*"
-               ),
-               dict(
-                       name = "where",
-                       type = "ir_where_alloc"
-               )
-       ]
+Tuple = dict(
+       arity    = "variable",
+       mode     = "mode_T",
 ),
 
-CopyB = dict(
-       ins   = [ "mem", "dst", "src" ],
-       outs  = [ "M", "X_regular", "X_except" ],
-       attrs = [
-               dict(
-                       name = "type",
-                       type = "ir_type*"
-               )
-       ]
+Unknown = dict(
+       knownBlock = True,
+       block      = "get_irg_start_block(irg)",
+       nodbginfo  = True
 ),
 )