irgmod: Pass the new inputs to turn_into_tuple() instead of initialising them with...
[libfirm] / scripts / ir_spec.py
index 5ee504c..7399034 100755 (executable)
@@ -122,6 +122,7 @@ class ASM:
        """
        mode             = "mode_T"
        arity            = "variable"
        """
        mode             = "mode_T"
        arity            = "variable"
+       input_name       = "input"
        flags            = [ "keep", "uses_memory" ]
        pinned           = "memory"
        pinned_init      = "op_pin_state_pinned"
        flags            = [ "keep", "uses_memory" ]
        pinned           = "memory"
        pinned_init      = "op_pin_state_pinned"
@@ -181,7 +182,7 @@ class Bad:
        that a control flow edge can never be executed.
 
        The gigo optimisations ensures that nodes with Bad as their block, get
        that a control flow edge can never be executed.
 
        The gigo optimisations ensures that nodes with Bad as their block, get
-       replaced by Bad themselfes. Nodes with at least 1 Bad input get exchanged
+       replaced by Bad themselves. Nodes with at least 1 Bad input get exchanged
        with Bad too. Exception to this rule are Block, Phi, Tuple and End node;
        This is because removing inputs from a Block is hairy operation (requiring,
        Phis to be shortened too for example). So instead of removing block inputs
        with Bad too. Exception to this rule are Block, Phi, Tuple and End node;
        This is because removing inputs from a Block is hairy operation (requiring,
        Phis to be shortened too for example). So instead of removing block inputs
@@ -215,6 +216,7 @@ class Block:
        block            = "NULL"
        pinned           = "yes"
        arity            = "variable"
        block            = "NULL"
        pinned           = "yes"
        arity            = "variable"
+       input_name       = "cfgpred"
        flags            = []
        attr_struct      = "block_attr"
        attrs            = [
        flags            = []
        attr_struct      = "block_attr"
        attrs            = [
@@ -229,56 +231,29 @@ class Block:
 
        init = '''
        res->attr.block.irg.irg     = irg;
 
        init = '''
        res->attr.block.irg.irg     = irg;
-       res->attr.block.backedge    = new_backedge_arr(irg->obst, arity);
+       res->attr.block.backedge    = new_backedge_arr(get_irg_obstack(irg), arity);
        set_Block_matured(res, 1);
 
        /* Create and initialize array for Phi-node construction. */
        set_Block_matured(res, 1);
 
        /* Create and initialize array for Phi-node construction. */
-       if (get_irg_phase_state(irg) == phase_building) {
-               res->attr.block.graph_arr = NEW_ARR_D(ir_node *, irg->obst, irg->n_loc);
-               memset(res->attr.block.graph_arr, 0, irg->n_loc * sizeof(ir_node*));
+       if (irg_is_constrained(irg, IR_GRAPH_CONSTRAINT_CONSTRUCTION)) {
+               res->attr.block.graph_arr = NEW_ARR_DZ(ir_node*, get_irg_obstack(irg), irg->n_loc);
        }
        '''
 
        }
        '''
 
-@op
-class Borrow(Binop):
-       """Returns the borrow bit from and implied subtractions of its 2 operands"""
-       flags = []
-
-@op
-class Bound:
-       """Performs a bounds-check: if lower <= index < upper then return index,
-       otherwise throw an exception."""
-       ins    = [
-               ("mem",    "memory dependency"),
-               ("index",  "value to test"),
-               ("lower",  "lower bound (inclusive)"),
-               ("upper",  "upper bound (exclusive)"),
-       ]
-       outs  = [
-               ("M",         "memory result"),
-               ("res",       "the checked index"),
-               ("X_regular", "control flow when no exception occurs"),
-               ("X_except",  "control flow when exception occured"),
-       ]
-       flags  = [ "fragile", "highlevel" ]
-       pinned = "exception"
-       pinned_init = "op_pin_state_pinned"
-       throws_init = "false"
-       attr_struct = "bound_attr"
-
 @op
 class Builtin:
        """performs a backend-specific builtin."""
 @op
 class Builtin:
        """performs a backend-specific builtin."""
-       ins      = [
+       ins         = [
                ("mem", "memory dependency"),
        ]
                ("mem", "memory dependency"),
        ]
-       arity    = "variable"
-       outs     = [
+       arity       = "variable"
+       input_name  = "param"
+       outs        = [
                ("M", "memory result"),
                # results follow here
        ]
                ("M", "memory result"),
                # results follow here
        ]
-       flags    = [ "uses_memory" ]
-       attrs    = [
+       flags       = [ "uses_memory" ]
+       attrs       = [
                dict(
                        type    = "ir_builtin_kind",
                        name    = "kind",
                dict(
                        type    = "ir_builtin_kind",
                        name    = "kind",
@@ -293,7 +268,7 @@ class Builtin:
        pinned      = "memory"
        pinned_init = "op_pin_state_pinned"
        attr_struct = "builtin_attr"
        pinned      = "memory"
        pinned_init = "op_pin_state_pinned"
        attr_struct = "builtin_attr"
-       init   = '''
+       init        = '''
        assert((get_unknown_type() == type) || is_Method_type(type));
        '''
 
        assert((get_unknown_type() == type) || is_Method_type(type));
        '''
 
@@ -303,19 +278,20 @@ class Call:
        operands are passed to the called code. Called code usually performs a
        return operation. The operands of this return operation are the result
        of the Call node."""
        operands are passed to the called code. Called code usually performs a
        return operation. The operands of this return operation are the result
        of the Call node."""
-       ins      = [
+       ins         = [
                ("mem",   "memory dependency"),
                ("ptr",   "pointer to called code"),
        ]
                ("mem",   "memory dependency"),
                ("ptr",   "pointer to called code"),
        ]
-       arity    = "variable"
-       outs     = [
+       arity       = "variable"
+       input_name  = "param"
+       outs        = [
                ("M",                "memory result"),
                ("T_result",         "tuple containing all results"),
                ("X_regular",        "control flow when no exception occurs"),
                ("X_except",         "control flow when exception occured"),
        ]
                ("M",                "memory result"),
                ("T_result",         "tuple containing all results"),
                ("X_regular",        "control flow when no exception occurs"),
                ("X_except",         "control flow when exception occured"),
        ]
-       flags    = [ "fragile", "uses_memory" ]
-       attrs    = [
+       flags       = [ "fragile", "uses_memory" ]
+       attrs       = [
                dict(
                        type    = "ir_type*",
                        name    = "type",
                dict(
                        type    = "ir_type*",
                        name    = "type",
@@ -330,27 +306,6 @@ class Call:
        assert((get_unknown_type() == type) || is_Method_type(type));
        '''
 
        assert((get_unknown_type() == type) || is_Method_type(type));
        '''
 
-@op
-class Carry(Binop):
-       """Computes the value of the carry-bit that would result when adding the 2
-       operands"""
-       flags = [ "commutative" ]
-
-@op
-class Cast(Unop):
-       """perform a high-level type cast"""
-       mode     = "get_irn_mode(irn_op)"
-       flags    = [ "highlevel" ]
-       attrs    = [
-               dict(
-                       type    = "ir_type*",
-                       name    = "type",
-                       comment = "target type of the case",
-               )
-       ]
-       attr_struct = "cast_attr"
-       init     = "assert(is_atomic_type(type));"
-
 @op
 class Cmp(Binop):
        """Compares its two operands and checks whether a specified
 @op
 class Cmp(Binop):
        """Compares its two operands and checks whether a specified
@@ -543,6 +498,7 @@ class End:
        mode             = "mode_X"
        pinned           = "yes"
        arity            = "dynamic"
        mode             = "mode_X"
        pinned           = "yes"
        arity            = "dynamic"
+       input_name       = "keepalive"
        flags            = [ "cfopcode" ]
        knownBlock       = True
        block            = "get_irg_end_block(irg)"
        flags            = [ "cfopcode" ]
        knownBlock       = True
        block            = "get_irg_end_block(irg)"
@@ -773,15 +729,11 @@ class Phi:
        all phi nodes produce their nth input as result."""
        pinned        = "yes"
        arity         = "variable"
        all phi nodes produce their nth input as result."""
        pinned        = "yes"
        arity         = "variable"
+       input_name    = "pred"
        flags         = []
        attr_struct   = "phi_attr"
        init          = '''
        flags         = []
        attr_struct   = "phi_attr"
        init          = '''
-       res->attr.phi.u.backedge = new_backedge_arr(irg->obst, arity);'''
-       init_after_opt = '''
-       /* Memory Phis in endless loops must be kept alive.
-          As we can't distinguish these easily we keep all of them alive. */
-       if (is_Phi(res) && mode == mode_M)
-               add_End_keepalive(get_irg_end(irg), res);'''
+       res->attr.phi.u.backedge = new_backedge_arr(get_irg_obstack(irg), arity);'''
        customSerializer = True
 
 @op
        customSerializer = True
 
 @op
@@ -837,13 +789,14 @@ class Raise:
 class Return:
        """Returns from the current function. Takes memory and return values as
        operands."""
 class Return:
        """Returns from the current function. Takes memory and return values as
        operands."""
-       ins      = [
+       ins        = [
                ("mem", "memory dependency"),
        ]
                ("mem", "memory dependency"),
        ]
-       arity    = "variable"
-       mode     = "mode_X"
-       flags    = [ "cfopcode" ]
-       pinned   = "yes"
+       arity      = "variable"
+       input_name = "res"
+       mode       = "mode_X"
+       flags      = [ "cfopcode" ]
+       pinned     = "yes"
 
 class Rotl(Binop):
        """Returns its first operand bits rotated left by the amount in the 2nd
 
 class Rotl(Binop):
        """Returns its first operand bits rotated left by the amount in the 2nd
@@ -857,15 +810,16 @@ class Sel:
 
        Optimisations assume that a Sel node can only produce a NULL pointer if the
        ptr input was NULL."""
 
        Optimisations assume that a Sel node can only produce a NULL pointer if the
        ptr input was NULL."""
-       ins    = [
+       ins         = [
                ("mem", "memory dependency"),
                ("ptr", "pointer to object to select from"),
        ]
                ("mem", "memory dependency"),
                ("ptr", "pointer to object to select from"),
        ]
-       arity  = "variable"
-       flags  = []
-       mode   = "is_Method_type(get_entity_type(entity)) ? mode_P_code : mode_P_data"
-       pinned = "no"
-       attrs  = [
+       arity       = "variable"
+       input_name  = "index"
+       flags       = []
+       mode        = "is_Method_type(get_entity_type(entity)) ? mode_P_code : mode_P_data"
+       pinned      = "no"
+       attrs       = [
                dict(
                        type    = "ir_entity*",
                        name    = "entity",
                dict(
                        type    = "ir_entity*",
                        name    = "entity",
@@ -1007,10 +961,11 @@ class Sync:
        be identical.  This operation allows to specify all operations that
        eventually need several partial memory blocks as input with a single
        entrance by unifying the memories with a preceding Sync operation."""
        be identical.  This operation allows to specify all operations that
        eventually need several partial memory blocks as input with a single
        entrance by unifying the memories with a preceding Sync operation."""
-       mode     = "mode_M"
-       flags    = []
-       pinned   = "no"
-       arity    = "dynamic"
+       mode       = "mode_M"
+       flags      = []
+       pinned     = "no"
+       arity      = "dynamic"
+       input_name = "pred"
 
 @op
 class Tuple:
 
 @op
 class Tuple:
@@ -1022,10 +977,11 @@ class Tuple:
        the implementation with pointers in only one direction.) The Tuple node is
        smaller than any other node, so that a node can be changed into a Tuple by
        just changing its opcode and giving it a new in array."""
        the implementation with pointers in only one direction.) The Tuple node is
        smaller than any other node, so that a node can be changed into a Tuple by
        just changing its opcode and giving it a new in array."""
-       arity  = "variable"
-       mode   = "mode_T"
-       pinned = "no"
-       flags  = []
+       arity      = "variable"
+       input_name = "pred"
+       mode       = "mode_T"
+       pinned     = "no"
+       flags      = []
 
 @op
 class Unknown:
 
 @op
 class Unknown: