1 /* (C) 2002 by Universitaet Karlsruhe
2 ** All rights reserved.
4 ** Authors: Goetz Lindenmaier
19 *** This file constructs the ir for the following pseudo-program:
21 *** VAR_A is some extern variable.
23 *** main(int a) { // pos 0
24 *** int b = 1; // pos 1
27 *** while (0 == 0) loop {
46 ir_node *b, *x, *r, *t, *f;
48 printf("\nCreating an IR graph: ENDLESS_LOOP_EXAMPLE...\n");
53 set_opt_constant_folding(1);
55 set_opt_global_cse(0);
56 set_opt_dead_node_elimination (1);
58 prim_t_int = new_type_primitive(id_from_str ("int", 3), mode_Is);
60 #define METHODNAME "main_tp"
64 proc_main = new_type_method(id_from_str(METHODNAME, strlen(METHODNAME)),
66 set_method_param_type(proc_main, 0, prim_t_int);
67 set_method_res_type(proc_main, 0, prim_t_int);
70 owner = new_type_class (id_from_str ("ENDLESS_LOOP_EXAMPLE", 20));
71 ent = new_entity (owner, id_from_str ("main", strlen("main")), proc_main);
73 /* Generates start and end blocks and nodes and a first, initial block */
74 irg = new_ir_graph (ent, 4);
76 /* Generate two values */
77 set_value (0, new_Proj(get_irg_args(irg), mode_Is, 0));
78 set_value (1, new_Const (mode_Is, tarval_from_long (mode_Is, 1)));
81 mature_block (get_irg_current_block(irg));
83 /* generate a block for the loop header and the conditional branch */
86 x = new_Cond (new_Proj(new_Cmp(new_Const (mode_Is, tarval_from_long (mode_Is, 0)),
87 new_Const (mode_Is, tarval_from_long (mode_Is, 0))),
89 f = new_Proj (x, mode_X, 0);
90 t = new_Proj (x, mode_X, 1);
92 /* generate the block for the loop body */
98 /* The code in the loop body,
99 as we are dealing with local variables only the dataflow edges
101 set_value (2, get_value (0, mode_Is));
102 set_value (0, get_value (1, mode_Is));
103 set_value (1, get_value (2, mode_Is));
105 /* set VAR_A to constant value */
106 set_store (new_Proj (new_Store (get_store (),
107 new_Const (mode_P, tarval_P_from_str ("VAR_A")),
108 get_value(1, mode_Is)),
114 /* generate the return block */
121 in[0] = new_Sub (get_value (0, mode_Is), get_value (1, mode_Is), mode_Is);
123 x = new_Return (get_store (), 1, in);
126 /* finalize the end block generated in new_ir_graph() */
127 add_in_edge (get_irg_end_block(irg), x);
128 mature_block (get_irg_end_block(irg));
132 printf("Optimizing ...\n");
134 dead_node_elimination(irg);
135 local_optimize_graph(irg);
137 /* verify the graph */
140 /* output the vcg file */
141 printf("Done building the graph. Dumping it.\n");
142 //turn_of_edge_labels();
143 dump_keepalive_edges();
145 dump_ir_block_graph (irg);
146 printf("Use xvcg to view this graph:\n");
147 printf("/ben/goetz/bin/xvcg GRAPHNAME\n\n");