1 /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
2 ** All rights reserved.
4 ** Authors: Christian Schaefer, Goetz Lindenmaier
15 * irregular control flow
19 *** This file constructs a control flow of following shape:
35 *** This is a program as, e.g.,
46 int main(int argc, char **argv)
48 ir_graph *irg; /* this variable contains the irgraph */
49 type_class *owner; /* the class in which this method is defined */
50 type_method *proc_main; /* typeinformation for the method main */
51 entity *ent; /* represents this method as entity of owner */
52 ir_node *expr, *c1, *c2, *cond, *f, *t, *jmp, *x;
54 printf("\nCreating an IR graph: IRR_CF...\n");
58 set_opt_constant_folding(0); /* so that stupid test are not evaluated. */
60 /* FIRM was designed for oo languages where all methods belong to a class.
61 * For imperative languages like C we view a file as a large class containing
62 * all functions as methods in this file.
63 * Therefore we define a class "empty" according to the file name
64 * with a method main as an entity.
66 #define CLASSNAME "IRREGULAR_CF"
67 #define METHODNAME "main"
71 owner = new_type_class (id_from_str (CLASSNAME, strlen(CLASSNAME)));
72 proc_main = new_type_method(id_from_str(METHODNAME, strlen(METHODNAME)),
74 ent = new_entity ((type *)owner,
75 id_from_str (METHODNAME, strlen(METHODNAME)),
78 #define NUM_OF_LOCAL_VARS 0
80 irg = new_ir_graph (ent, NUM_OF_LOCAL_VARS);
82 /* two make two conditionals that represent a switch */
83 expr = new_Const (mode_i, tarval_from_long (mode_i, 0));
84 c1 = new_Const (mode_i, tarval_from_long (mode_i, 1));
85 c2 = new_Const (mode_i, tarval_from_long (mode_i, 2));
87 cond = new_Cond(new_Proj(new_Cmp(expr, c1), mode_b, Eq));
88 f = new_Proj(cond, mode_X, 0);
89 t = new_Proj(cond, mode_X, 1);
90 mature_block(irg->current_block);
93 add_in_edge(irg->current_block, t);
95 mature_block(irg->current_block);
98 add_in_edge(irg->current_block, f);
99 cond = new_Cond(new_Proj(new_Cmp(expr, c2), mode_b, Eq));
100 f = new_Proj(cond, mode_X, 0);
101 t = new_Proj(cond, mode_X, 1);
102 mature_block(irg->current_block);
105 add_in_edge(irg->current_block, t);
106 add_in_edge(irg->current_block, jmp);
108 mature_block(irg->current_block);
111 add_in_edge(irg->current_block, f);
113 mature_block(irg->current_block);
116 add_in_edge(irg->current_block, t);
117 add_in_edge(irg->current_block, jmp);
119 ir_node *in[0]; /* this is the array containing the return parameters */
120 x = new_Return (get_store(), 0, in);
122 mature_block (irg->current_block);
124 add_in_edge (irg->end_block, x);
125 mature_block (irg->end_block);
127 printf("Optimizing ...\n");
128 dead_node_elimination(irg);
130 /* verify the graph */
133 printf("Dumping the graph and a control flow graph.\n");
134 dump_ir_block_graph (irg);
136 printf("Use xvcg to view these graphs:\n");
137 printf("/ben/goetz/bin/xvcg GRAPHNAME\n\n");