1 /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
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)),
79 get_entity_ld_name(ent);
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, new_tarval_from_long (0, mode_Is));
86 c1 = new_Const (mode_Is, new_tarval_from_long (1, mode_Is));
87 c2 = new_Const (mode_Is, new_tarval_from_long (2, mode_Is));
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 x = new_Return (get_store(), 0, NULL);
123 mature_block (get_irg_current_block(irg));
125 add_in_edge (get_irg_end_block(irg), x);
126 mature_block (get_irg_end_block(irg));
130 printf("Optimizing ...\n");
131 dead_node_elimination(irg);
133 /* verify the graph */
136 printf("Dumping the graph and a control flow graph.\n");
137 dump_ir_block_graph (irg);
139 printf("Use xvcg to view these graphs:\n");
140 printf("/ben/goetz/bin/xvcg GRAPHNAME\n\n");