From: Götz Lindenmaier Date: Thu, 20 Jul 2000 13:56:08 +0000 (+0000) Subject: *** empty log message *** X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=eed0e43a82a6da6d60cf9d2e67f2394ca9f34e8d;p=libfirm *** empty log message *** [r52] --- diff --git a/Changes b/Changes index 24bb7bb01..2eaa03663 100644 --- a/Changes +++ b/Changes @@ -1,7 +1,19 @@ + + 20.7.2000 Goetz + Fixed bug in optimize(). Returned Null instead n if + get_optimize() == false. + 19.7.2000 Christian Added some access routines in type.[hc]. Solved a recursive definition of type_class struct, entity struct and type union. + 18.7.2000 Goetz + Separated entity header into pure functional header and header + with data types. + + Goetz + ... a bunch small changes not documented + 12.7.2000 Goetz Changed output of oo_prog_example: now uses the internal list of all irgs. Had to implement some of the access routines for diff --git a/ir/ir/ircons.c b/ir/ir/ircons.c index 8707a2566..ea1573d85 100644 --- a/ir/ir/ircons.c +++ b/ir/ir/ircons.c @@ -198,8 +198,9 @@ new_r_Phi_in (ir_graph *irg, ir_node *block, ir_mode *mode, #else res = known = new_ir_node (irg, block, op_Phi, mode, ins, in); #endif - /* The in-array can contain NULLs. These were returned by get_r_value_internal - if it reached the same block/definition on a second path. + /* The in-array can contain NULLs. These were returned by + get_r_value_internal if it reached the same block/definition on a + second path. The NULLs are replaced by the node itself to simplify the test in the next loop. */ for (i=0; i < ins; ++i) @@ -743,6 +744,7 @@ new_End (void) res = optimize (res); irn_vrfy (res); + return res; } @@ -886,7 +888,7 @@ get_r_value_internal (ir_node *block, int pos, ir_mode *mode) if (block->attr.block.matured) { /* case 3 */ /* The Phi has the same amount of ins as the corresponding block. */ - int ins = get_irn_arity(block); // ARR_LEN (block->in)-1; + int ins = get_irn_arity(block); ir_node **nin; NEW_ARR_A (ir_node *, nin, ins); diff --git a/ir/ir/irgraph.h b/ir/ir/irgraph.h index b9a9bd30f..3eca20c04 100644 --- a/ir/ir/irgraph.h +++ b/ir/ir/irgraph.h @@ -13,9 +13,9 @@ # include "tv.h" # include "pset.h" +/* to resolve recursion between irnode.h and irgraph.h */ #ifndef _IR_NODE_TYPEDEF_ #define _IR_NODE_TYPEDEF_ -/* to resolve recursion between irnode.h and irgraph.h */ typedef struct ir_node ir_node; #endif @@ -30,24 +30,22 @@ struct ir_graph { struct ir_node *end; /* end node of this ir_graph */ struct ir_node *cstore; /* constant store */ struct ir_node *frame; /* method's frame */ - struct ir_node *globals; /* pointer to the data segment containing all globals as - well as global procedures. */ + struct ir_node *globals; /* pointer to the data segment containing all + globals as well as global procedures. */ struct ir_node *args; /* methods arguments */ struct ir_node *bad; /* bad node of this ir_graph, the one and only in this graph */ struct obstack *obst; /* obstack where all of the ir_nodes live */ #if USE_EXPICIT_PHI_IN_STACK - struct Phi_in_stack *Phi_in_stack; /* needed for automatic Phi - construction */ + struct Phi_in_stack *Phi_in_stack; /* needed for automatic Phi construction */ #endif struct ir_node *current_block; /* block for newly gen_*()-erated ir_nodes */ int params; /* number of local variable in this procedure; should be n_loc or so, params is ambiguous. */ - pset *value_table; /* value table for global value - numbering for optimizing use in - iropt.c */ + pset *value_table; /* value table for global value numbering + for optimizing use in iropt.c */ unsigned long visited; /* this flag is an identifier for ir walk. it will be incremented, every time, someone walk through @@ -56,14 +54,12 @@ struct ir_graph { complete block */ }; - +/* to resolve recursion between entity.h and irgraph.h */ #ifndef _IR_GRAPH_TYPEDEF_ #define _IR_GRAPH_TYPEDEF_ -/* to resolve recursion between entity.h and irgraph.h */ typedef struct ir_graph ir_graph; #endif - /* Global variable holding the current_ir_graph. This global variable is used by the ir construction interface in ircons and by the optimizations. */ @@ -76,35 +72,35 @@ ir_graph *new_ir_graph (entity *ent, int params); /* access routines for all ir_graph attributes */ ir_node *get_irg_start_block (ir_graph *irg); -void set_irg_start_block (ir_graph *irg, ir_node *node); +void set_irg_start_block (ir_graph *irg, ir_node *node); ir_node *get_irg_start (ir_graph *irg); -void set_irg_start (ir_graph *irg, ir_node *node); +void set_irg_start (ir_graph *irg, ir_node *node); ir_node *get_start_of_irgraph (ir_graph *irg); void set_start_of_irgraph(ir_graph *irg, ir_node *node); ir_node *get_irg_end_block (ir_graph *irg); -void set_irg_end_block (ir_graph *irg, ir_node *node); +void set_irg_end_block (ir_graph *irg, ir_node *node); ir_node *get_irg_end (ir_graph *irg); -void set_irg_end (ir_graph *irg, ir_node *node); +void set_irg_end (ir_graph *irg, ir_node *node); ir_node *get_irg_cstore (ir_graph *irg); -void set_irg_cstore (ir_graph *irg, ir_node *node); +void set_irg_cstore (ir_graph *irg, ir_node *node); ir_node *get_irg_frame (ir_graph *irg); -void set_irg_frame (ir_graph *irg, ir_node *node); +void set_irg_frame (ir_graph *irg, ir_node *node); ir_node *get_irg_globals (ir_graph *irg); void set_irg_globals (ir_graph *irg, ir_node *node); ir_node *get_irg_args (ir_graph *irg); -void set_irg_args (ir_graph *irg, ir_node *node); +void set_irg_args (ir_graph *irg, ir_node *node); /* Use new_Bad() instead!! */ ir_node *get_irg_bad (ir_graph *irg); -void set_irg_bad (ir_graph *irg, ir_node *node); +void set_irg_bad (ir_graph *irg, ir_node *node); /* not implemented yet struct obstack *get_obst_of_irgraph (ir_graph *irg); @@ -112,25 +108,23 @@ void set_obst_of_irgraph (ir_graph *irg, struct obstack *obst); */ ir_node *get_irg_current_block (ir_graph *irg); -void set_irg_current_block (ir_graph *irg, ir_node *node); +void set_irg_current_block (ir_graph *irg, ir_node *node); -entity *get_irg_ent (ir_graph *irg); -void set_irg_ent (ir_graph *irg, entity *ent); +entity *get_irg_ent (ir_graph *irg); +void set_irg_ent (ir_graph *irg, entity *ent); -int get_irg_params (ir_graph *irg); -void set_irg_params (ir_graph *irg, int params); - -unsigned long get_irg_visited (ir_graph *irg); -void set_irg_visited(ir_graph *irg, unsigned long i); +int get_irg_params (ir_graph *irg); +void set_irg_params (ir_graph *irg, int params); /* increments visited by one */ -void inc_irg_visited(ir_graph *irg); - -unsigned long get_irg_block_visited (ir_graph *irg); -void set_irg_block_visited(ir_graph *irg, unsigned long i); +void inc_irg_visited(ir_graph *irg); +unsigned long get_irg_visited (ir_graph *irg); +void set_irg_visited(ir_graph *irg, unsigned long i); /* increments block_visited by one */ -void inc_irg_block_visited(ir_graph *irg); +void inc_irg_block_visited(ir_graph *irg); +unsigned long get_irg_block_visited (ir_graph *irg); +void set_irg_block_visited(ir_graph *irg, unsigned long i); int get_params_of_irgraph (ir_graph *irg); void set_params_of_irgraph (ir_graph *irg, int params); diff --git a/ir/ir/iropt.c b/ir/ir/iropt.c index 2d4c1186c..ec56f83ac 100644 --- a/ir/ir/iropt.c +++ b/ir/ir/iropt.c @@ -891,7 +891,7 @@ optimize (ir_node *n) tarval *tv; ir_node *old_n = n; - if (!get_optimize()) return NULL; + if ((!get_optimize()) && (get_irn_op(n) != op_Phi)) return n; /* if not optimize return n */ if (n == NULL) { diff --git a/testprograms/Makefile b/testprograms/Makefile index a56ae0a12..ffb0889a5 100644 --- a/testprograms/Makefile +++ b/testprograms/Makefile @@ -12,7 +12,8 @@ all: empty const_eval_example \ if_example if_else_example if_while_example cond_example \ call_str_example memory_example array-stack_example \ array-heap_example oo_program_example irr_cf_example \ - irr_loop_example dead_block_example global_var_example + irr_loop_example dead_block_example global_var_example \ + three_cfpred_example clean: rm -f \ @@ -23,7 +24,7 @@ clean: array-stack_example array-heap_example \ oo_program_example irr_cf_example \ irr_loop_example dead_block_example \ - global_var_example \ + global_var_example three_cfpred_example \ *.o *.vcg core realclean: clean @@ -43,7 +44,8 @@ run: irr_cf_example; \ irr_loop_example; \ dead_block_example; \ - global_var_example; + global_var_example; \ + three_cfpred_example empty: empty.o gcc -o empty empty.o $(LIBDIRS) $(LIBS) @@ -89,3 +91,6 @@ dead_block_example: dead_block_example.o global_var_example: global_var_example.o gcc -o global_var_example global_var_example.o $(LIBDIRS) $(LIBS) + +three_cfpred_example: three_cfpred_example.o + gcc -o three_cfpred_example three_cfpred_example.o $(LIBDIRS) $(LIBS) diff --git a/testprograms/empty.c b/testprograms/empty.c index 75d130dbb..c34b656ed 100644 --- a/testprograms/empty.c +++ b/testprograms/empty.c @@ -36,13 +36,12 @@ int main(int argc, char **argv) /* init library */ init_firm (); - set_opt_dead_node_elimination (0); + /* Don't optimize anything */ + set_optimize(0); /* FIRM was designed for oo languages where all methods belong to a class. * For imperative languages like C we view a file as a large class containing * all functions as methods in this file. - * (Therefore we define a class "empty" according to the file name - * with a method main as an entity.) * This class now is automatically generated. */ #define METHODNAME "main" diff --git a/testprograms/three_cfpred_example.c b/testprograms/three_cfpred_example.c new file mode 100644 index 000000000..ea9aea4d7 --- /dev/null +++ b/testprograms/three_cfpred_example.c @@ -0,0 +1,156 @@ +/* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe +** All rights reserved. +** +** Authors: Christian Schaefer, Goetz Lindenmaier +** +** testprogram. +*/ + +# include + +# include "irdump.h" +# include "firm.h" + +/* + * a dead block / unreachable code. + */ + +/** +*** This file constructs a control flow of following shape: +*** +*** +*** firstCondBlock +*** / \ +*** / \ +*** |/_ _\| +*** Block1 scnCondBlock +*** | | | +*** | | | +*** | \ / \ / +*** | Block2 Block3 +*** \ | / +*** \ | / +*** _\| \ / |/_ +*** nextBlock +*** +*** +*** This is a program as, e.g., +*** +*** if () then +*** { Jmp label1; } // happens anyways +*** else +*** { Jmp label1; } // happens anyways +*** label1: +*** return(); +*** Jmp label1; +*** +**/ + +int main(int argc, char **argv) +{ + ir_graph *irg; /* this variable contains the irgraph */ + type_class *owner; /* the class in which this method is defined */ + type_method *proc_main; /* type information for the method main */ + entity *ent; /* represents this method as entity of owner */ + ir_node *c1, *c2, *cond, *f, *t, *endBlock, *Block1, *jmp, + *scndCondBlock, *Block2, *Block3, *x; + + /* init library */ + init_firm (); + + set_optimize(1); + + /* FIRM was designed for oo languages where all methods belong to a class. + * For imperative languages like C we view a file as a large class containing + * all functions as methods in this file. + * This class now is automatically generated. + */ +#define METHODNAME "main" +#define NRARGS 1 +#define NRES 1 + printf("creating an IR graph: ...\n"); + + owner = get_glob_type(); + proc_main = new_type_method(id_from_str(METHODNAME, strlen(METHODNAME)), + NRARGS, NRES); + /** @@@ setting of arg/res types misses **/ + ent = new_entity ((type *)owner, + id_from_str (METHODNAME, strlen(METHODNAME)), + (type *)proc_main); + +#define NUM_OF_LOCAL_VARS 2 + + irg = new_ir_graph (ent, NUM_OF_LOCAL_VARS); + + /* to make a condition */ + c1 = new_Const (mode_i, tarval_from_long (mode_i, 1)); + c2 = new_Proj (get_irg_args(irg), mode_i, 0); + set_value(1, c2); + + cond = new_Cond(new_Proj(new_Cmp(c1, c2), mode_b, Eq)); + set_value(0, new_Const (mode_i, tarval_from_long (mode_i, 6))); + f = new_Proj(cond, mode_X, 0); + t = new_Proj(cond, mode_X, 1); + mature_block(irg->current_block); + + /* end block to add jmps */ + endBlock = new_Block(); + + /* Block 1 */ + Block1 = new_Block(); + add_in_edge(Block1, t); + mature_block(Block1); + set_value(0, new_Const (mode_i, tarval_from_long (mode_i, 5))); + jmp = new_Jmp(); + add_in_edge(endBlock, jmp); + + /* scndCondBlock */ + scndCondBlock = new_Block(); + add_in_edge(scndCondBlock, f); + mature_block(scndCondBlock); + c1 = new_Const (mode_i, tarval_from_long (mode_i, 3)); + cond = new_Cond(new_Proj(new_Cmp(c1, get_value(1, mode_i)), mode_b, Eq)); + f = new_Proj(cond, mode_X, 0); + t = new_Proj(cond, mode_X, 1); + mature_block(irg->current_block); + + /* Block 2 */ + Block2 = new_Block(); + add_in_edge(Block2, f); + mature_block(Block2); + jmp = new_Jmp(); + add_in_edge(endBlock, jmp); + + /* Block 3 */ + Block3 = new_Block(); + add_in_edge(Block3, t); + mature_block(Block3); + jmp = new_Jmp(); + add_in_edge(endBlock, jmp); + + /* finish the end Block */ + switch_block(endBlock); + { + ir_node *in[1]; + in[0] = get_value(0, mode_i); + x = new_Return (get_store(), 1, in); + } + mature_block (irg->current_block); + + /* finish the Block with the end node */ + add_in_edge (irg->end_block, x); + mature_block (irg->end_block); + + printf("\nDone building the graph.\n"); + + /* verify the graph */ + irg_vrfy(irg); + + printf("Dumping the graph and a control flow graph.\n"); + dump_ir_block_graph (irg); + dump_cfg (irg); + printf("use xvcg to view these graphs:\n"); + printf("/ben/goetz/bin/xvcg GRAPHNAME\n"); + + return (0); +}