1 /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
2 ** All rights reserved.
4 ** Authors: Christian Schaefer, Goetz Lindenmaier
17 * irregular control flow
21 *** This file constructs a control flow of following shape:
37 *** This is a program as, e.g.,
48 int main(int argc, char **argv)
50 ir_graph *irg; /* this variable contains the irgraph */
51 type *owner; /* the class in which this method is defined */
52 type *proc_main; /* typeinformation for the method main */
53 entity *ent; /* represents this method as entity of owner */
54 ir_node *expr, *c1, *c2, *cond, *f, *t, *jmp, *x;
56 printf("\nCreating an IR graph: IRR_CF...\n");
60 set_opt_constant_folding(0); /* so that stupid test are not evaluated. */
62 /* FIRM was designed for oo languages where all methods belong to a class.
63 * For imperative languages like C we view a file as a large class containing
64 * all functions as methods in this file.
65 * Therefore we define a class "empty" according to the file name
66 * with a method main as an entity.
68 #define CLASSNAME "IRREGULAR_CF"
69 #define METHODNAME "main"
73 owner = new_type_class (id_from_str (CLASSNAME, strlen(CLASSNAME)));
74 proc_main = new_type_method(id_from_str(METHODNAME, strlen(METHODNAME)),
76 ent = new_entity ((type *)owner,
77 id_from_str (METHODNAME, strlen(METHODNAME)),
80 #define NUM_OF_LOCAL_VARS 0
82 irg = new_ir_graph (ent, NUM_OF_LOCAL_VARS);
84 /* two make two conditionals that represent a switch */
85 expr = new_Const (mode_Is, tarval_from_long (mode_Is, 0));
86 c1 = new_Const (mode_Is, tarval_from_long (mode_Is, 1));
87 c2 = new_Const (mode_Is, tarval_from_long (mode_Is, 2));
89 cond = new_Cond(new_Proj(new_Cmp(expr, c1), mode_b, Eq));
90 f = new_Proj(cond, mode_X, 0);
91 t = new_Proj(cond, mode_X, 1);
92 mature_block(get_irg_current_block(irg));
95 add_in_edge(get_irg_current_block(irg), t);
97 mature_block(get_irg_current_block(irg));
100 add_in_edge(get_irg_current_block(irg), f);
101 cond = new_Cond(new_Proj(new_Cmp(expr, c2), mode_b, Eq));
102 f = new_Proj(cond, mode_X, 0);
103 t = new_Proj(cond, mode_X, 1);
104 mature_block(get_irg_current_block(irg));
107 add_in_edge(get_irg_current_block(irg), t);
108 add_in_edge(get_irg_current_block(irg), jmp);
110 mature_block(get_irg_current_block(irg));
113 add_in_edge(get_irg_current_block(irg), f);
115 mature_block(get_irg_current_block(irg));
118 add_in_edge(get_irg_current_block(irg), t);
119 add_in_edge(get_irg_current_block(irg), jmp);
121 ir_node *in[0]; /* this is the array containing the return parameters */
122 x = new_Return (get_store(), 0, in);
124 mature_block (get_irg_current_block(irg));
126 add_in_edge (get_irg_end_block(irg), x);
127 mature_block (get_irg_end_block(irg));
131 printf("Optimizing ...\n");
132 dead_node_elimination(irg);
134 /* verify the graph */
137 printf("Dumping the graph and a control flow graph.\n");
138 dump_ir_block_graph (irg);
140 printf("Use xvcg to view these graphs:\n");
141 printf("/ben/goetz/bin/xvcg GRAPHNAME\n\n");