X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=scripts%2Fir_spec.py;h=7e8b2c1506e53b675914e815f41e2985da231190;hb=296dfbcbe4da36ca193f81c60443dda80890fab4;hp=8a64808ed710acff0e99d735ee011f97f20a9cea;hpb=ce3205fbd27a87a89eeaf9980b364cc1f92226fc;p=libfirm diff --git a/scripts/ir_spec.py b/scripts/ir_spec.py index 8a64808ed..7e8b2c150 100755 --- a/scripts/ir_spec.py +++ b/scripts/ir_spec.py @@ -1,59 +1,120 @@ nodes = dict( -Start = dict( - mode = "mode_T", - op_flags = "cfopcode", - state = "pinned", - noconstr = True, - optimize = False -), -End = dict( - mode = "mode_X", - op_flags = "cfopcode", - state = "pinned", - arity = "dynamic", - noconstr = True, - optimize = False +# +# Abstract node types +# +unop = dict( + abstract = True, + ins = [ "op" ], + op_index = 0, ), -Phi = dict( - noconstr = True, - state = "pinned", - arity = "variable", +binop = dict( + abstract = True, + ins = [ "left", "right" ], + op_index = 0, ), -Jmp = dict( - mode = "mode_X", - op_flags = "cfopcode", - state = "pinned", - ins = [], +# +# Real node types +# +Abs = dict( + is_a = "unop", + flags = "none", ), -IJmp = dict( - mode = "mode_X", - op_flags = "cfopcode", - state = "pinned", - ins = [ "target" ], +Add = dict( + is_a = "binop", + flags = "commutative", ), -Const = dict( - mode = "", - knownBlock = True, - attrs_name = "con", - attrs = [ +Alloc = dict( + ins = [ "mem", "size" ], + outs = [ "M", "X_regular", "X_except", "res" ], + flags = "fragile, uses_memory", + attrs = [ dict( - type = "tarval*", - name = "tarval", + name = "type", + type = "ir_type*" + ), + dict( + name = "where", + type = "ir_where_alloc" ) ], + pinned = "yes", + d_post = ''' + #if PRECISE_EXC_CONTEXT + firm_alloc_frag_arr(res, op_Alloc, &res->attr.alloc.exc.frag_arr); + #endif + ''' ), -Block = dict( - mode = "mode_BB", +Anchor = dict( + mode = "mode_ANY", + arity = "variable", + flags = "dump_noblock", + knownBlock = True, + singleton = True, +), + +And = dict( + is_a = "binop", + flags = "commutative", +), + +ASM = dict( + mode = "mode_T", + arity = "variable", + flags = "keep, uses_memory", + attr_struct = "asm_attr", + pinned = "memory", + pinned_init = "pinned", + attrs = [ + dict( + name = "input_constraints", + type = "ir_asm_constraint*", + ), + dict( + name = "n_output_constraints", + type = "int", + ), + dict( + name = "output_constraints", + type = "ir_asm_constraint*", + ), + dict( + name = "n_clobbers", + type = "int", + ), + dict( + name = "clobbers", + type = "ident**", + ), + dict( + name = "text", + type = "ident*", + ), + ], + java_noconstr = True, +), + +Bad = dict( + mode = "mode_Bad", + flags = "cfopcode, fragile, start_block, dump_noblock", knownBlock = True, - noconstr = True, - optimize = False, - arity = "variable", + singleton = True, +), + +Block = dict( + mode = "mode_BB", + knownBlock = True, + block = "NULL", + optimize = False, + arity = "variable", + flags = "labeled", + attr_struct = "block_attr", + java_noconstr = True, init = ''' /* macroblock header */ @@ -74,6 +135,32 @@ Block = dict( 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); @@ -94,39 +181,43 @@ Block = dict( public void markBlockVisited() { binding.mark_Block_block_visited(ptr); - }''', + } + + public boolean isBad() { + return binding.is_Bad(ptr) != 0; + } + ''', ), -SymConst = dict( - mode = "mode_P", - knownBlock = True, - noconstr = True, - attrs = [ - dict( - type = "ir_entity*", - name = "entity" - ) - ], +Borrow = dict( + is_a = "binop", + flags = "none", ), -# SymConst +Bound = dict( + ins = [ "mem", "index", "lower", "upper" ], + outs = [ "M", "X_regular", "X_except", "res" ], + flags = "fragile, highlevel", + pinned = "exception", + pinned_init = "pinned", + attr_struct = "bound_attr", + 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", + flags = "cfopcode", ), Builtin = dict( ins = [ "mem" ], arity = "variable", outs = [ "M_regular", "X_regular", "X_except", "T_result", "M_except", "P_value_res_base" ], + flags = "uses_memory", attrs = [ dict( type = "ir_builtin_kind", @@ -136,101 +227,175 @@ 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" ], + flags = "fragile, uses_memory", + attrs = [ + dict( + type = "ir_type*", + name = "type" + ) + ], + attr_struct = "call_attr", + 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 + ''' +), + +CallBegin = dict( + ins = [ "ptr" ], + outs = [ "" ], # TODO + flags = "cfopcode, ip_cfopcode", + # TODO: attribute with call... + attr_struct = "callbegin_attr", + java_noconstr = True, + init = ''' + res->attr.callbegin.call = call; + ''', ), 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" + is_a = "binop", + flags = "commutative", ), -Eor = dict( - is_a = "binop" +Cast = dict( + ins = [ "op" ], + mode = "get_irn_mode(irn_op)", + flags = "highlevel", + attrs = [ + dict( + type = "ir_type*", + name = "type" + ) + ], + attr_struct = "cast_attr", + 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" ], + flags = "none", ), -Shl = dict( - is_a = "binop" +Cond = dict( + ins = [ "selector" ], + outs = [ "false", "true" ], + flags = "cfopcode, forking", + 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" + ) + ], + attr_struct = "cond_attr" ), -Shr = dict( - is_a = "binop" +Confirm = dict( + ins = [ "value", "bound" ], + mode = "get_irn_mode(irn_value)", + flags = "highlevel", + attrs = [ + dict( + name = "cmp", + type = "pn_Cmp" + ), + ], + attr_struct = "confirm_attr", ), -Shrs = dict( - is_a = "binop" +Const = dict( + mode = "", + flags = "constlike, start_block", + knownBlock = True, + attrs_name = "con", + attrs = [ + dict( + type = "tarval*", + name = "tarval", + ) + ], + attr_struct = "const_attr", ), -Rotl = dict( - is_a = "binop" +Conv = dict( + is_a = "unop", + flags = "none", + attrs = [ + dict( + name = "strict", + type = "int", + init = "0", + special = dict( + prefix = "strict", + init = "1" + ) + ) + ], + attr_struct = "conv_attr", ), -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" ], + flags = "fragile, highlevel, uses_memory", attrs = [ dict( - type = "ir_mode*", - name = "resmode" - ), - dict( - name = "state", - type = "op_pin_state" + name = "type", + type = "ir_type*" ) - ] + ], + attr_struct = "copyb_attr", + 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" ], + ins = [ "mem", "left", "right" ], outs = [ "M", "X_regular", "X_except", "res" ], + flags = "fragile, uses_memory", + attrs_name = "divmod", attrs = [ dict( type = "ir_mode*", name = "resmode" ), - dict( - name = "state", - type = "op_pin_state" - ), dict( name = "no_remainder", type = "int", @@ -240,42 +405,146 @@ Div = dict( init = "1" ) ) - ] + ], + attr_struct = "divmod_attr", + pinned = "exception", + op_index = 1, + 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" ], + ins = [ "mem", "left", "right" ], outs = [ "M", "X_regular", "X_except", "res_div", "res_mod" ], + flags = "fragile, uses_memory", + attrs_name = "divmod", attrs = [ dict( type = "ir_mode*", name = "resmode" ), + ], + attr_struct = "divmod_attr", + pinned = "exception", + op_index = 1, + d_post = ''' + #if PRECISE_EXC_CONTEXT + firm_alloc_frag_arr(res, op_DivMod, &res->attr.except.frag_arr); + #endif + ''' +), + +Dummy = dict( + ins = [], + flags = "cfopcode, fragile, start_block, constlike, dump_noblock", + knownBlock = True, + block = "get_irg_start_block(irg)", +), + +End = dict( + mode = "mode_X", + pinned = "yes", + arity = "dynamic", + flags = "cfopcode", + singleton = True, +), + +EndExcept = dict( + mode = "mode_X", + pinned = "yes", + arity = "dynamic", + flags = "cfopcode, ip_cfopcode", + singleton = True +), + +EndReg = dict( + mode = "mode_X", + pinned = "yes", + arity = "dynamic", + flags = "cfopcode, ip_cfopcode", + singleton = True +), + +Eor = dict( + is_a = "binop", + flags = "commutative", +), + +Filter = dict( + ins = [ "pred" ], + flags = "none", + attrs = [ dict( - name = "state", - type = "op_pin_state" + name = "proj", + type = "long" ) - ] + ], + attr_struct = "filter_attr", + java_noconstr = True + + # 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", + flags = "uses_memory", 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" + ) + ], + attr_struct = "free_attr", +), + +Id = dict( + ins = [ "pred" ], + flags = "none", +), + +IJmp = dict( + mode = "mode_X", + pinned = "yes", + ins = [ "target" ], + flags = "cfopcode, forking, keep", +), + +InstOf = dict( + ins = [ "store", "obj" ], + outs = [ "M", "X_regular", "X_except", "res", "M_except" ], + flags = "highlevel", + attrs = [ + dict( + name = "type", + type = "ir_type*" ) - ] + ], + attr_struct = "io_attr", + pinned = "memory", + pinned_init = "floats", +), + +Jmp = dict( + mode = "mode_X", + pinned = "yes", + ins = [], + flags = "cfopcode", ), Load = dict( ins = [ "mem", "ptr" ], outs = [ "M", "X_regular", "X_except", "res" ], + flags = "fragile, uses_memory", attrs = [ dict( type = "ir_mode*", @@ -283,197 +552,236 @@ Load = dict( java_name = "load_mode" ), ], + attr_struct = "load_attr", constructor_args = [ dict( 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", + flags = "none", +), + +Mod = dict( + ins = [ "mem", "left", "right" ], + outs = [ "M", "X_regular", "X_except", "res" ], + flags = "fragile, uses_memory", + attrs_name = "divmod", + attrs = [ dict( - type = "ir_cons_flags", - name = "flags", + type = "ir_mode*", + name = "resmode" ), ], + attr_struct = "divmod_attr", + pinned = "exception", + op_index = 1, + 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", + flags = "commutative", +), + +Mulh = dict( + is_a = "binop", + flags = "commutative", +), + +Mux = dict( + ins = [ "sel", "false", "true" ], + flags = "none", ), NoMem = dict( mode = "mode_M", + flags = "dump_noblock, dump_noinput", knownBlock = True, + singleton = True, ), -Bad = dict( - mode = "mode_Bad", - knownBlock = True, +Not = dict( + is_a = "unop", + flags = "none", +), + +Or = dict( + is_a = "binop", + flags = "commutative", +), + +Phi = dict( + pinned = "yes", + arity = "variable", + flags = "none", + attr_struct = "phi_attr", + custom_is = True, + java_noconstr = True, ), Pin = dict( ins = [ "op" ], - mode = "get_irn_mode(op);" + mode = "get_irn_mode(irn_op)", + flags = "highlevel", ), Proj = dict( ins = [ "pred" ], + flags = "none", attrs = [ dict( type = "long", - name = "proj" + name = "proj", + initname = "" ) - ] + ], + attr_struct = "long", + custom_is = True, ), -Sel = dict( - ins = [ "mem", "ptr" ], - arity = "variable", - mode = "mode_P", - attrs = [ +Quot = dict( + ins = [ "mem", "left", "right" ], + outs = [ "M", "X_regular", "X_except", "res" ], + flags = "fragile, uses_memory", + attrs_name = "divmod", + attrs = [ dict( - type = "ir_entity*", - name = "entity" - ) - ] + type = "ir_mode*", + name = "resmode" + ), + ], + attr_struct = "divmod_attr", + pinned = "exception", + op_index = 1, + d_post = ''' + #if PRECISE_EXC_CONTEXT + firm_alloc_frag_arr(res, op_Quot, &res->attr.except.frag_arr); + #endif + ''' ), -Sync = dict( - mode = "mode_M", - optimize = False, - arity = "dynamic" +Raise = dict( + ins = [ "mem", "exo_ptr" ], + outs = [ "M", "X" ], + flags = "highlevel, cfopcode", ), -Tuple = dict( +Return = dict( + ins = [ "mem" ], arity = "variable", - mode = "mode_T", + mode = "mode_X", + flags = "cfopcode", ), -Unknown = dict( - knownBlock = True +Rotl = dict( + is_a = "binop", + flags = "none", ), -Confirm = dict( - ins = [ "value", "bound" ], - mode = "get_irn_mode(value)", +Sel = dict( + ins = [ "mem", "ptr" ], + arity = "variable", + flags = "none", + 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" + ) ], + attr_struct = "sel_attr", ), -Return = dict( - ins = [ "mem" ], - arity = "variable", - mode = "mode_X" +Shl = dict( + is_a = "binop", + flags = "none", ), -unop = dict( - abstract = True, - ins = [ "op" ] +Shr = dict( + is_a = "binop", + flags = "none", ), -Minus = dict( - is_a = "unop" +Shrs = dict( + is_a = "binop", + flags = "none", ), -Mux = dict( - ins = [ "sel", "false", "true" ] +Start = dict( + mode = "mode_T", + pinned = "yes", + flags = "cfopcode", + singleton = True, ), -Cond = dict( - ins = [ "selector" ], - outs = [ "false", "true" ], - attrs = [ - dict( - name = "kind", - type = "cond_kind", - init = "dense" - ), +Store = dict( + ins = [ "mem", "ptr", "value" ], + outs = [ "M", "X_regular", "X_except" ], + flags = "fragile, uses_memory", + attr_struct = "store_attr", + constructor_args = [ dict( - name = "default_proj", - type = "long", - init = "0" + type = "ir_cons_flags", + name = "flags", ), - dict( - name = "jmp_pred", - type = "cond_jmp_predicate", - init = "COND_JMP_PRED_NONE" - ) - ] + ], + d_post = ''' +#if PRECISE_EXC_CONTEXT + firm_alloc_frag_arr(res, op_Store, &res->attr.store.exc.frag_arr); +#endif + ''' ), -Cmp = dict( +Sub = dict( is_a = "binop", - outs = [ "False", "Eq", "Lt", "Le", "Gt", "Ge", "Lg", "Leg", "Uo", "Ue", "Ul", "Ule", "Ug", "Uge", "Ne", "True" ], + flags = "none", ), -Conv = dict( - is_a = "unop", - attrs = [ +SymConst = dict( + mode = "mode_P", + flags = "constlike, start_block", + knownBlock = True, + attrs = [ dict( - name = "strict", - type = "int", - init = "0", - special = dict( - prefix = "strict", - init = "1" - ) + type = "ir_entity*", + name = "entity" ) - ] + ], + attr_struct = "symconst_attr", + java_noconstr = True, ), -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", + flags = "none", + 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", + flags = "labeled", + java_noconstr = True ), -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)", + flags = "cfopcode, fragile, start_block, constlike, dump_noblock", ), )