1 /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
2 ** All rights reserved.
4 ** Authors: Christian Schaefer, Goetz Lindenmaier
15 * an irreducible loop.
19 *** This file constructs a control flow of following shape:
27 *** LoopBlock1 LoopBlock2
37 int main(int argc, char **argv)
39 ir_graph *irg; /* this variable contains the irgraph */
40 type *owner; /* the class in which this method is defined */
41 type *proc_main; /* typeinformation for the method main */
42 entity *ent; /* represents this method as entity of owner */
43 ir_node *expr, *c1, *c2, *c3, *cond, *f, *t, *loopBlock1, *f_l1, *t_l1,
44 *loopBlock2, *f_l2, *t_l2, *x;
49 set_opt_constant_folding (0); /* so that the stupid tests are not optimized. */
51 set_opt_dead_node_elimination(1);
53 /* FIRM was designed for oo languages where all methods belong to a class.
54 * For imperative languages like C we view a file as a large class containing
55 * all functions as methods in this file.
56 * Therefore we define a class "empty" according to the file name
57 * with a method main as an entity.
59 #define CLASSNAME "IRR_LOOP"
60 #define METHODNAME "main"
63 printf("\nCreating an IR graph: %s...\n", CLASSNAME);
65 owner = new_type_class (id_from_str (CLASSNAME, strlen(CLASSNAME)));
66 proc_main = new_type_method(id_from_str(METHODNAME, strlen(METHODNAME)),
68 ent = new_entity (owner,
69 id_from_str (METHODNAME, strlen(METHODNAME)),
72 #define NUM_OF_LOCAL_VARS 0
74 irg = new_ir_graph (ent, NUM_OF_LOCAL_VARS);
76 /* to make three conditionals */
77 expr = new_Const (mode_i, tarval_from_long (mode_i, 0));
78 c1 = new_Const (mode_i, tarval_from_long (mode_i, 1));
79 c2 = new_Const (mode_i, tarval_from_long (mode_i, 2));
80 c3 = new_Const (mode_i, tarval_from_long (mode_i, 2));
82 cond = new_Cond(new_Proj(new_Cmp(expr, c1), mode_b, Eq));
83 f = new_Proj(cond, mode_X, 0);
84 t = new_Proj(cond, mode_X, 1);
85 mature_block(get_irg_current_block(irg));
87 loopBlock1 = new_immBlock();
88 add_in_edge(loopBlock1, t);
89 cond = new_Cond(new_Proj(new_Cmp(expr, c2), mode_b, Eq));
90 f_l1 = new_Proj(cond, mode_X, 0);
91 t_l1 = new_Proj(cond, mode_X, 1);
93 loopBlock2 = new_immBlock();
94 add_in_edge(loopBlock2, f);
95 cond = new_Cond(new_Proj(new_Cmp(expr, c3), mode_b, Eq));
96 f_l2 = new_Proj(cond, mode_X, 0);
97 t_l2 = new_Proj(cond, mode_X, 1);
99 add_in_edge(loopBlock1, t_l2);
100 add_in_edge(loopBlock2, t_l1);
101 mature_block(loopBlock1);
102 mature_block(loopBlock2);
105 add_in_edge(get_irg_current_block(irg), f_l2);
106 add_in_edge(get_irg_current_block(irg), f_l1);
109 x = new_Return (get_store(), 0, in);
111 mature_block (get_irg_current_block(irg));
113 add_in_edge (get_irg_end_block(irg), x);
114 mature_block (get_irg_end_block(irg));
118 printf("Optimizing ...\n");
119 dead_node_elimination(irg);
121 /* verify the graph */
124 printf("Dumping the graph and a control flow graph.\n");
125 dump_ir_block_graph (irg);
127 printf("Use xvcg to view these graphs:\n");
128 printf("/ben/goetz/bin/xvcg GRAPHNAME\n\n");