1 /* (C) 2002 by Universitaet Karlsruhe
2 ** All rights reserved.
4 ** Authors: Goetz Lindenmaier
16 *** This file constructs the ir for the following pseudo-program:
18 *** VAR_A is some extern variable.
20 *** main(int a) { // pos 0
21 *** int b = 1; // pos 1
24 *** while (0 == 0) loop {
43 ir_node *b, *x, *r, *t, *f;
45 printf("\nCreating an IR graph: ENDLESS_LOOP_EXAMPLE...\n");
50 set_opt_constant_folding(1);
52 set_opt_global_cse(1);
53 set_opt_dead_node_elimination (1);
55 prim_t_int = new_type_primitive(id_from_str ("int", 3), mode_i);
57 #define METHODNAME "main_tp"
61 proc_main = new_type_method(id_from_str(METHODNAME, strlen(METHODNAME)),
63 set_method_param_type(proc_main, 0, prim_t_int);
64 set_method_res_type(proc_main, 0, prim_t_int);
67 owner = new_type_class (id_from_str ("ENDLESS_LOOP_EXAMPLE", 20));
68 ent = new_entity (owner, id_from_str ("main", strlen("main")), proc_main);
70 /* Generates start and end blocks and nodes and a first, initial block */
71 irg = new_ir_graph (ent, 4);
73 /* Generate two values */
74 set_value (0, new_Proj(get_irg_args(irg), mode_i, 0));
75 set_value (1, new_Const (mode_i, tarval_from_long (mode_i, 1)));
78 mature_block (get_irg_current_block(irg));
80 /* generate a block for the loop header and the conditional branch */
83 x = new_Cond (new_Proj(new_Cmp(new_Const (mode_i, tarval_from_long (mode_i, 0)),
84 new_Const (mode_i, tarval_from_long (mode_i, 0))),
86 f = new_Proj (x, mode_X, 0);
87 t = new_Proj (x, mode_X, 1);
89 /* generate the block for the loop body */
95 /* The code in the loop body,
96 as we are dealing with local variables only the dataflow edges
98 set_value (2, get_value (0, mode_i));
99 set_value (0, get_value (1, mode_i));
100 set_value (1, get_value (2, mode_i));
102 /* set VAR_A to constant value */
103 set_store (new_Proj (new_Store (get_store (),
104 new_Const (mode_p, tarval_p_from_str ("VAR_A")),
105 get_value(1, mode_i)),
111 /* generate the return block */
118 in[0] = new_Sub (get_value (0, mode_i), get_value (1, mode_i), mode_i);
120 x = new_Return (get_store (), 1, in);
123 /* finalize the end block generated in new_ir_graph() */
124 add_in_edge (get_irg_end_block(irg), x);
125 mature_block (get_irg_end_block(irg));
129 printf("Optimizing ...\n");
131 dead_node_elimination(irg);
132 local_optimize_graph(irg);
134 /* verify the graph */
137 /* output the vcg file */
138 printf("Done building the graph. Dumping it.\n");
139 //turn_of_edge_labels();
140 dump_keepalive_edges();
142 dump_ir_block_graph (irg);
143 printf("Use xvcg to view this graph:\n");
144 printf("/ben/goetz/bin/xvcg GRAPHNAME\n\n");