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_class *owner; /* the class in which this method is defined */
41 type_method *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 (1);
51 /* FIRM was designed for oo languages where all methods belong to a class.
52 * For imperative languages like C we view a file as a large class containing
53 * all functions as methods in this file.
54 * Therefore we define a class "empty" according to the file name
55 * with a method main as an entity.
57 #define CLASSNAME "IRR_LOOP"
58 #define METHODNAME "main"
61 printf("creating an IR graph: %s...\n", CLASSNAME);
63 owner = new_type_class (id_from_str (CLASSNAME, strlen(CLASSNAME)));
64 proc_main = new_type_method(id_from_str(METHODNAME, strlen(METHODNAME)),
66 ent = new_entity ((type *)owner,
67 id_from_str (METHODNAME, strlen(METHODNAME)),
70 #define NUM_OF_LOCAL_VARS 0
72 irg = new_ir_graph (ent, NUM_OF_LOCAL_VARS);
74 /* two make three conditionals */
75 expr = new_Const (mode_i, tarval_from_long (mode_i, 0));
76 c1 = new_Const (mode_i, tarval_from_long (mode_i, 1));
77 c2 = new_Const (mode_i, tarval_from_long (mode_i, 2));
78 c3 = new_Const (mode_i, tarval_from_long (mode_i, 2));
80 cond = new_Cond(new_Proj(new_Cmp(expr, c1), mode_b, Eq));
81 f = new_Proj(cond, mode_X, 0);
82 t = new_Proj(cond, mode_X, 1);
83 mature_block(irg->current_block);
85 loopBlock1 = new_Block();
86 add_in_edge(loopBlock1, t);
87 cond = new_Cond(new_Proj(new_Cmp(expr, c2), mode_b, Eq));
88 f_l1 = new_Proj(cond, mode_X, 0);
89 t_l1 = new_Proj(cond, mode_X, 1);
91 loopBlock2 = new_Block();
92 add_in_edge(loopBlock2, f);
93 cond = new_Cond(new_Proj(new_Cmp(expr, c3), mode_b, Eq));
94 f_l2 = new_Proj(cond, mode_X, 0);
95 t_l2 = new_Proj(cond, mode_X, 1);
97 add_in_edge(loopBlock1, t_l2);
98 add_in_edge(loopBlock2, t_l1);
99 mature_block(loopBlock1);
100 mature_block(loopBlock2);
103 add_in_edge(irg->current_block, f_l2);
104 add_in_edge(irg->current_block, f_l1);
107 x = new_Return (get_store(), 1, in);
109 mature_block (irg->current_block);
111 add_in_edge (irg->end_block, x);
112 mature_block (irg->end_block);
114 /* verify the graph */
117 printf("\nDone building the graph..\n");
118 printf("Dumping the graph and a control flow graph.\n");
119 dump_ir_block_graph (irg);
122 printf("use xvcg to view these graphs:\n");
123 printf("/ben/goetz/bin/xvcg GRAPHNAME\n");