X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;ds=sidebyside;f=testprograms%2Fnested_phi.c;h=78b298c4b279e02e042b9807cd137feabf7b991c;hb=9cd7c3c377e52cc5164e138cac2d50e3ee4b0ff5;hp=73ef569705e1bc2b8523e9111572dfaded6d32c1;hpb=2cd57a8b25d2cf8c34a1ee05bc2198a57ffdc0fc;p=libfirm diff --git a/testprograms/nested_phi.c b/testprograms/nested_phi.c index 73ef56970..78b298c4b 100644 --- a/testprograms/nested_phi.c +++ b/testprograms/nested_phi.c @@ -10,13 +10,10 @@ * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE. */ +#include +#include -# include -# include - -# include "irvrfy.h" -# include "irdump.h" -# include "firm.h" +#include /** * This file constructs the ir for the following pseudo-program: @@ -42,95 +39,94 @@ int main(void) { - type *prim_t_int; + ir_type *prim_t_int; ir_graph *irg; - type *owner; - type *proc_main; - entity *ent; + ir_type *owner; + ir_type *proc_main; + ir_entity *ent; ir_node *h1, *b1, *h2, *b2, *x, *r, *t1, *f1, *t2, *f2; printf("\nCreating an IR graph: NESTED_PHI...\n"); - init_firm (NULL); - // set_opt_normalize (0); + init_firm(NULL); set_optimize(1); set_opt_constant_folding(1); set_opt_cse(1); - set_opt_dead_node_elimination (1); - prim_t_int = new_type_primitive(id_from_str ("int", 3), mode_Is); + prim_t_int = new_type_primitive(new_id_from_str("int"), mode_Is); #define METHODNAME "main_tp" #define NRARGS 1 #define NRES 1 - proc_main = new_type_method(id_from_str(METHODNAME, strlen(METHODNAME)), - NRARGS, NRES); + proc_main = new_type_method(new_id_from_str(METHODNAME), NRARGS, NRES); set_method_param_type(proc_main, 0, prim_t_int); set_method_res_type(proc_main, 0, prim_t_int); - owner = new_type_class (new_id_from_str ("NESTED_PHI")); - ent = new_entity (owner, new_id_from_str ("main"), proc_main); + owner = new_type_class(new_id_from_str("NESTED_PHI")); + ent = new_entity(owner, new_id_from_str("main"), proc_main); /* Generates start and end blocks and nodes and a first, initial block */ - irg = new_ir_graph (ent, 4); + irg = new_ir_graph(ent, 4); /* Generate two values */ - set_value (a_pos, new_Proj(get_irg_args(irg), mode_Is, 0)); - set_value (b_pos, new_Proj(get_irg_args(irg), mode_Is, 0)); - set_value (c_pos, new_Const (mode_Is, new_tarval_from_long (1, mode_Is))); - set_value (d_pos, new_Const (mode_Is, new_tarval_from_long (2, mode_Is))); + set_value(a_pos, new_Proj(get_irg_args(irg), mode_Is, 0)); + set_value(b_pos, new_Proj(get_irg_args(irg), mode_Is, 0)); + set_value(c_pos, new_Const(mode_Is, new_tarval_from_long(1, mode_Is))); + set_value(d_pos, new_Const(mode_Is, new_tarval_from_long(2, mode_Is))); /* a block for the outer loop header and the conditional branch */ h1 = get_irg_current_block(irg); - x = new_Cond (new_Proj(new_Cmp(get_value(a_pos, mode_Is), get_value(c_pos, mode_Is)), - mode_b, Le)); - f1 = new_Proj (x, mode_X, 0); - t1 = new_Proj (x, mode_X, 1); + x = new_Cond(new_Proj(new_Cmp(get_value(a_pos, mode_Is), get_value(c_pos, mode_Is)), + mode_b, pn_Cmp_Le)); + f1 = new_Proj(x, mode_X, pn_Cond_false); + t1 = new_Proj(x, mode_X, pn_Cond_true); /* generate the block for the loop body */ - b1 = new_immBlock (); - add_in_edge (b1, t1); + b1 = new_immBlock(); + add_immBlock_pred(b1, t1); /* The loop body is the head of the inner loop */ h2 = b1; - x = new_Cond (new_Proj(new_Cmp(get_value(a_pos, mode_Is), get_value(d_pos, mode_Is)), - mode_b, Le)); - f2 = new_Proj (x, mode_X, 0); - t2 = new_Proj (x, mode_X, 1); - add_in_edge(h1, f2); - mature_block(h1); + x = new_Cond(new_Proj(new_Cmp(get_value(a_pos, mode_Is), get_value(d_pos, mode_Is)), + mode_b, pn_Cmp_Le)); + f2 = new_Proj(x, mode_X, pn_Cond_false); + t2 = new_Proj(x, mode_X, pn_Cond_true); + add_immBlock_pred(h1, f2); + mature_immBlock(h1); /* The inner loop body */ - b2 = new_immBlock (); - add_in_edge (b2, t2); - mature_block(b2); + b2 = new_immBlock(); + add_immBlock_pred(b2, t2); + mature_immBlock(b2); x = new_Jmp(); - add_in_edge (h2, x); - mature_block(h2); + add_immBlock_pred(h2, x); + mature_immBlock(h2); /* generate the return block */ - r = new_immBlock (); - add_in_edge (r, f1); - mature_block (r); + r = new_immBlock(); + add_immBlock_pred(r, f1); + mature_immBlock(r); { ir_node *in[1]; - in[0] = new_Sub (get_value (a_pos, mode_Is), get_value (b_pos, mode_Is), mode_Is); + in[0] = new_Sub(get_value(a_pos, mode_Is), get_value(b_pos, mode_Is), mode_Is); - x = new_Return (get_store (), 1, in); + x = new_Return(get_store(), 1, in); } /* finalize the end block generated in new_ir_graph() */ - add_in_edge (get_irg_end_block(irg), x); - mature_block (get_irg_end_block(irg)); + add_immBlock_pred(get_irg_end_block(irg), x); + mature_immBlock(get_irg_end_block(irg)); - irg_finalize_cons (irg); + irg_finalize_cons(irg); printf("Optimizing ...\n"); - //local_optimize_graph(irg), - //dead_node_elimination(irg); +#if 0 + local_optimize_graph(irg), + dead_node_elimination(irg); +#endif /* verify the graph */ irg_vrfy(irg); @@ -138,10 +134,11 @@ main(void) /* output the vcg file */ printf("Done building the graph. Dumping it.\n"); turn_off_edge_labels(); - dump_all_types(); - dump_ir_block_graph (irg); - printf("Use xvcg to view this graph:\n"); - printf("/ben/goetz/bin/xvcg GRAPHNAME\n\n"); + dump_all_types(""); + dump_ir_block_graph(irg, ""); + printf("Use ycomp to view this graphs:\n"); + printf("ycomp main.vcg\n\n"); + printf("ycomp All_types.vcg\n\n"); - return (0); + return 0; }