X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=testprograms%2Fglobal_cse.c;h=63273ad511caea2fe12be071881d67c22bd3298c;hb=a13bc569589cb903ac5ac102b9b875d0bb3d6fbd;hp=1d15440665ba0b2467bbc9b04dfc5d230e613f62;hpb=13588bfa29b57530c70851264dd5ea05184b9486;p=libfirm diff --git a/testprograms/global_cse.c b/testprograms/global_cse.c index 1d1544066..63273ad51 100644 --- a/testprograms/global_cse.c +++ b/testprograms/global_cse.c @@ -1,19 +1,19 @@ -/* Copyright (C) 2002 by Universitaet Karlsruhe -* All rights reserved. -* -* Authors: Christian Schaefer, Goetz Lindenmaier -* -* testprogram. -*/ - -/* $Id$ */ - -# include -# include - -# include "irvrfy.h" -# include "irdump.h" -# include "firm.h" +/* + * Project: libFIRM + * File name: testprograms/global_cse.c + * Purpose: Test global cse. + * Author: Christian Schaefer, Goetz Lindenmaier + * Modified by: + * Created: + * CVS-ID: $Id$ + * Copyright: (c) 1999-2003 Universität Karlsruhe + * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE. + */ + +#include +#include + +#include /** * This file constructs the ir for the following pseudo-program: @@ -34,22 +34,21 @@ int main(void) { ir_graph *irg; - type *owner; - entity *ent; - type *proc_main; /* type information for the method main */ - type *typ; + ir_type *owner; + ir_entity *ent; + ir_type *proc_main; /* ir_type information for the method main */ + ir_type *typ; ir_node *x, *r, *t, *f, *a, *cmp; int a_pos, b_pos; printf("\nCreating an IR graph: GLOBAL_CSE_EXAMPLE...\n"); - init_firm (NULL); + init_firm(NULL); set_optimize(1); set_opt_constant_folding(1); set_opt_cse(1); set_opt_global_cse(1); - set_opt_dead_node_elimination (1); #define CLASSNAME "GLOBAL_CSE_EXAMPLE" #define METHODNAME "GLOBAL_CSE_EXAMPLE_main" @@ -60,16 +59,16 @@ main(void) owner = get_glob_type(); /* Type information for the procedure */ - proc_main = new_type_method(id_from_str(METHODNAME, strlen(METHODNAME)), + proc_main = new_type_method(new_id_from_chars(METHODNAME, strlen(METHODNAME)), NRARGS, NRES); - /* The entity for the procedure */ - ent = new_entity (owner, - id_from_str (METHODNAME, strlen(METHODNAME)), - proc_main); - /* The type int. This type is necessary to model the result and parameters + /* The ir_entity for the procedure */ + ent = new_entity(owner, + new_id_from_chars(METHODNAME, strlen(METHODNAME)), + proc_main); + /* The ir_type int. This ir_type is necessary to model the result and parameters the procedure. */ #define PRIM_NAME "int" - typ = new_type_primitive(id_from_str(PRIM_NAME, strlen(PRIM_NAME)), mode_Is); + typ = new_type_primitive(new_id_from_chars(PRIM_NAME, strlen(PRIM_NAME)), mode_Is); /* The parameter and result types of the procedure. */ set_method_param_type(proc_main, 0, typ); set_method_res_type(proc_main, 0, typ); @@ -78,7 +77,7 @@ main(void) /* Generates start and end blocks and nodes, and a first, initial block */ #define NRLOCS 2 - irg = new_ir_graph (ent, NRLOCS); + irg = new_ir_graph(ent, NRLOCS); /* The value position used for: */ a_pos = 0; @@ -86,76 +85,76 @@ main(void) /* Get the procedure parameter and assign it to the parameter variable a. */ - set_value (a_pos, new_Proj (get_irg_args(irg), mode_Is, 0)); + set_value(a_pos, new_Proj(get_irg_args(irg), mode_Is, 0)); /* Generate the constant and assign it to b. The assignment is resovled to a dataflow edge. */ - set_value (b_pos, new_Const (mode_Is, new_tarval_from_long (2, mode_Is))); + set_value(b_pos, new_Const(mode_Is, new_tarval_from_long(2, mode_Is))); /* We know all predecessors of the block and all set_values and set_stores are preformed. We can mature the block. */ - mature_block (get_irg_current_block(irg)); + mature_immBlock(get_irg_current_block(irg)); /* Generate a conditional branch */ cmp = new_Cmp(get_value(a_pos, mode_Is), get_value(b_pos, mode_Is)); /* - cmp = new_Cmp(new_Const (mode_Is, new_tarval_from_long (2, mode_Is)), - new_Const (mode_Is, new_tarval_from_long (2, mode_Is)));*/ - x = new_Cond (new_Proj(cmp, mode_b, Eq)); - f = new_Proj (x, mode_X, 0); - t = new_Proj (x, mode_X, 1); + cmp = new_Cmp(new_Const(mode_Is, new_tarval_from_long(2, mode_Is)), + new_Const(mode_Is, new_tarval_from_long(2, mode_Is)));*/ + x = new_Cond(new_Proj(cmp, mode_b, pn_Cmp_Eq)); + f = new_Proj(x, mode_X, pn_Cond_false); + t = new_Proj(x, mode_X, pn_Cond_true); /* generate and fill the then block */ - r = new_immBlock (); - add_in_edge (r, t); + r = new_immBlock(); + add_immBlock_pred(r, t); a = new_Sub(get_value(a_pos, mode_Is), - new_Const (mode_Is, new_tarval_from_long (3, mode_Is)), + new_Const(mode_Is, new_tarval_from_long(3, mode_Is)), mode_Is); - set_value (a_pos, a); + set_value(a_pos, a); - mature_block (r); - t = new_Jmp (); + mature_immBlock(r); + t = new_Jmp(); /* generate the else block */ - r = new_immBlock (); - add_in_edge (r, f); + r = new_immBlock(); + add_immBlock_pred(r, f); a = new_Sub(get_value(a_pos, mode_Is), - new_Const (mode_Is, new_tarval_from_long (3, mode_Is)), + new_Const(mode_Is, new_tarval_from_long(3, mode_Is)), mode_Is); - a = new_Add(a, new_Const (mode_Is, new_tarval_from_long (5, mode_Is)), mode_Is); - set_value (a_pos, a); + a = new_Add(a, new_Const(mode_Is, new_tarval_from_long(5, mode_Is)), mode_Is); + set_value(a_pos, a); - mature_block (r); - f = new_Jmp (); + mature_immBlock(r); + f = new_Jmp(); /* generate the fall through block and add all cfg edges */ - r = new_immBlock (); - add_in_edge (r, f); - add_in_edge (r, t); - mature_block (r); + r = new_immBlock(); + add_immBlock_pred(r, f); + add_immBlock_pred(r, t); + mature_immBlock(r); /* The Return statement */ { ir_node *in[1], *store ; - in[0] = get_value (a_pos, mode_Is); + in[0] = get_value(a_pos, mode_Is); store = get_store(); - x = new_Return (store, 1, in); + x = new_Return(store, 1, in); } /* finalize the end block generated in new_ir_graph() */ - add_in_edge (get_irg_end_block(irg), x); - mature_block (get_irg_end_block(irg)); + add_immBlock_pred(get_irg_end_block(irg), x); + mature_immBlock(get_irg_end_block(irg)); /* verify the graph */ irg_vrfy(irg); - finalize_cons (irg); + irg_finalize_cons(irg); printf("Optimizing ...\n"); local_optimize_graph(irg); - dead_node_elimination(irg); + /* output the vcg file */ printf("Done building the graph. Dumping it.\n"); - dump_ir_block_graph (irg); - printf("use xvcg to view this graph:\n"); - printf("/ben/goetz/bin/xvcg GRAPHNAME\n\n"); + dump_ir_block_graph(irg, 0); + printf("Use ycomp to view this graph:\n"); + printf("ycomp GRAPHNAME\n\n"); - return (0); + return 0; }