1 /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
2 ** All rights reserved.
4 ** Authors: Christian Schaefer, Goetz Lindenmaier
17 * an irreducible loop.
21 *** This file constructs a control flow of following shape:
29 *** LoopBlock1 LoopBlock2
39 int main(int argc, char **argv)
41 ir_graph *irg; /* this variable contains the irgraph */
42 type *owner; /* the class in which this method is defined */
43 type *proc_main; /* typeinformation for the method main */
44 entity *ent; /* represents this method as entity of owner */
45 ir_node *expr, *c1, *c2, *c3, *cond, *f, *t, *loopBlock1, *f_l1, *t_l1,
46 *loopBlock2, *f_l2, *t_l2, *x;
51 set_opt_constant_folding (0); /* so that the stupid tests are not optimized. */
53 set_opt_dead_node_elimination(1);
55 /* FIRM was designed for oo languages where all methods belong to a class.
56 * For imperative languages like C we view a file as a large class containing
57 * all functions as methods in this file.
58 * Therefore we define a class "empty" according to the file name
59 * with a method main as an entity.
61 #define CLASSNAME "IRR_LOOP"
62 #define METHODNAME "main"
65 printf("\nCreating an IR graph: %s...\n", CLASSNAME);
67 owner = new_type_class (id_from_str (CLASSNAME, strlen(CLASSNAME)));
68 proc_main = new_type_method(id_from_str(METHODNAME, strlen(METHODNAME)),
70 ent = new_entity (owner,
71 id_from_str (METHODNAME, strlen(METHODNAME)),
74 #define NUM_OF_LOCAL_VARS 0
76 irg = new_ir_graph (ent, NUM_OF_LOCAL_VARS);
78 /* to make three conditionals */
79 expr = new_Const (mode_i, tarval_from_long (mode_i, 0));
80 c1 = new_Const (mode_i, tarval_from_long (mode_i, 1));
81 c2 = new_Const (mode_i, tarval_from_long (mode_i, 2));
82 c3 = new_Const (mode_i, tarval_from_long (mode_i, 2));
84 cond = new_Cond(new_Proj(new_Cmp(expr, c1), mode_b, Eq));
85 f = new_Proj(cond, mode_X, 0);
86 t = new_Proj(cond, mode_X, 1);
87 mature_block(get_irg_current_block(irg));
89 loopBlock1 = new_immBlock();
90 add_in_edge(loopBlock1, t);
91 cond = new_Cond(new_Proj(new_Cmp(expr, c2), mode_b, Eq));
92 f_l1 = new_Proj(cond, mode_X, 0);
93 t_l1 = new_Proj(cond, mode_X, 1);
95 loopBlock2 = new_immBlock();
96 add_in_edge(loopBlock2, f);
97 cond = new_Cond(new_Proj(new_Cmp(expr, c3), mode_b, Eq));
98 f_l2 = new_Proj(cond, mode_X, 0);
99 t_l2 = new_Proj(cond, mode_X, 1);
101 add_in_edge(loopBlock1, t_l2);
102 add_in_edge(loopBlock2, t_l1);
103 mature_block(loopBlock1);
104 mature_block(loopBlock2);
107 add_in_edge(get_irg_current_block(irg), f_l2);
108 add_in_edge(get_irg_current_block(irg), f_l1);
111 x = new_Return (get_store(), 0, in);
113 mature_block (get_irg_current_block(irg));
115 add_in_edge (get_irg_end_block(irg), x);
116 mature_block (get_irg_end_block(irg));
120 printf("Optimizing ...\n");
121 dead_node_elimination(irg);
123 /* verify the graph */
126 printf("Dumping the graph and a control flow graph.\n");
127 dump_ir_block_graph (irg);
129 printf("Use xvcg to view these graphs:\n");
130 printf("/ben/goetz/bin/xvcg GRAPHNAME\n\n");