1 /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
2 ** All rights reserved.
4 ** Authors: Christian Schaefer, Goetz Lindenmaier
17 * a dead block / unreachable code.
21 *** This file constructs a control flow of following shape:
28 *** Block1 Block2 deadBlock
35 *** This is a program as, e.g.,
38 *** { Jmp label1; } // happens anyways
40 *** { Jmp label1; } // happens anyways
47 int main(int argc, char **argv)
49 ir_graph *irg; /* this variable contains the irgraph */
50 type *owner; /* the class in which this method is defined */
51 type *proc_main; /* type information for the method main */
53 entity *ent; /* represents this method as entity of owner */
54 ir_node *c1, *c2, *cond, *f, *t, *endBlock, *Block1, *jmp, *Block2,
60 set_opt_cse(0); /* there is a bug: first and start block are cse!! @@@ */
62 /*** Make basic type information for primitive type int. ***/
63 prim_t_int = new_type_primitive(id_from_str ("int", 3), mode_i);
65 /* FIRM was designed for oo languages where all methods belong to a class.
66 * For imperative languages like C we view a file as a large class containing
67 * all functions as methods in this file.
68 * Therefore we define a class "empty" according to the file name
69 * with a method main as an entity.
71 #define CLASSNAME "DEAD_BLOCK"
72 #define METHODNAME "main"
75 printf("\nCreating an IR graph: %s...\n", CLASSNAME);
77 owner = new_type_class (id_from_str (CLASSNAME, strlen(CLASSNAME)));
78 proc_main = new_type_method(id_from_str(METHODNAME, strlen(METHODNAME)),
80 set_method_res_type(proc_main, 0, prim_t_int);
81 ent = new_entity (owner,
82 id_from_str (METHODNAME, strlen(METHODNAME)),
85 #define NUM_OF_LOCAL_VARS 1
87 irg = new_ir_graph (ent, NUM_OF_LOCAL_VARS);
89 /* to make a condition */
90 c1 = new_Const (mode_i, tarval_from_long (mode_i, 1));
91 c2 = new_Const (mode_i, tarval_from_long (mode_i, 2));
94 cond = new_Cond(new_Proj(new_Cmp(c1, c2), mode_b, Eq));
95 f = new_Proj(cond, mode_X, 0);
96 t = new_Proj(cond, mode_X, 1);
97 mature_block(get_irg_current_block(irg));
99 /* end block to add jmps */
100 endBlock = new_immBlock();
103 Block1 = new_immBlock();
104 add_in_edge(Block1, t);
105 mature_block(Block1);
107 add_in_edge(endBlock, jmp);
110 Block2 = new_immBlock();
111 add_in_edge(Block2, f);
112 mature_block(Block2);
114 add_in_edge(endBlock, jmp);
117 deadBlock = new_immBlock();
118 mature_block(deadBlock);
120 add_in_edge(endBlock, jmp);
122 /* finish end block */
123 switch_block(endBlock);
126 in[0] = get_value(0, mode_i);
128 x = new_Return (get_store(), 1, in);
130 mature_block (get_irg_current_block(irg));
132 add_in_edge (get_irg_end_block(irg), x);
133 mature_block (get_irg_end_block(irg));
137 printf("Optimizing ...\n");
138 local_optimize_graph (irg);
139 dead_node_elimination (irg);
141 /* verify the graph */
144 printf("Dumping the graph and a control flow graph.\n");
145 dump_ir_block_graph (irg);
147 printf("Use xvcg to view these graphs:\n");
148 printf("/ben/goetz/bin/xvcg GRAPHNAME\n\n");