1 /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
2 ** All rights reserved.
4 ** Authors: Christian Schaefer, Goetz Lindenmaier
15 * a dead block / unreachable code.
19 *** This file constructs a control flow of following shape:
26 *** Block1 Block2 deadBlock
33 *** This is a program as, e.g.,
36 *** { Jmp label1; } // happens anyways
38 *** { Jmp label1; } // happens anyways
45 int main(int argc, char **argv)
47 ir_graph *irg; /* this variable contains the irgraph */
48 type_class *owner; /* the class in which this method is defined */
49 type_method *proc_main; /* type information for the method main */
50 entity *ent; /* represents this method as entity of owner */
51 ir_node *c1, *c2, *cond, *f, *t, *endBlock, *Block1, *jmp, *Block2,
57 set_opt_cse(0); /* there is a bug: first and start block are cse!! @@@ */
59 /* FIRM was designed for oo languages where all methods belong to a class.
60 * For imperative languages like C we view a file as a large class containing
61 * all functions as methods in this file.
62 * Therefore we define a class "empty" according to the file name
63 * with a method main as an entity.
65 #define CLASSNAME "DEAD_BLOCK"
66 #define METHODNAME "main"
69 printf("\nCreating an IR graph: %s...\n", CLASSNAME);
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 1
80 irg = new_ir_graph (ent, NUM_OF_LOCAL_VARS);
82 /* to make a condition */
83 c1 = new_Const (mode_i, tarval_from_long (mode_i, 1));
84 c2 = new_Const (mode_i, tarval_from_long (mode_i, 2));
87 cond = new_Cond(new_Proj(new_Cmp(c1, c2), mode_b, Eq));
88 f = new_Proj(cond, mode_X, 0);
89 t = new_Proj(cond, mode_X, 1);
90 mature_block(get_irg_current_block(irg));
92 /* end block to add jmps */
93 endBlock = new_immBlock();
96 Block1 = new_immBlock();
97 add_in_edge(Block1, t);
100 add_in_edge(endBlock, jmp);
103 Block2 = new_immBlock();
104 add_in_edge(Block2, f);
105 mature_block(Block2);
107 add_in_edge(endBlock, jmp);
110 deadBlock = new_immBlock();
111 mature_block(deadBlock);
113 add_in_edge(endBlock, jmp);
115 /* finish end block */
116 switch_block(endBlock);
119 in[0] = get_value(0, mode_i);
121 x = new_Return (get_store(), 1, in);
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));
128 printf("Optimizing ...\n");
129 local_optimize_graph (irg);
130 dead_node_elimination (irg);
132 /* verify the graph */
135 printf("Dumping the graph and a control flow graph.\n");
136 dump_ir_block_graph (irg);
138 printf("Use xvcg to view these graphs:\n");
139 printf("/ben/goetz/bin/xvcg GRAPHNAME\n\n");