From c9bea48f570667bbc5d50504a8e6372260d73145 Mon Sep 17 00:00:00 2001 From: =?utf8?q?G=C3=B6tz=20Lindenmaier?= Date: Thu, 8 Jul 2004 15:51:24 +0000 Subject: [PATCH] various changes to get firm faster [r3377] --- ir/ir/ircgopt.c | 2 +- ir/ir/irgopt.c | 46 ++++++++++--------- ir/ir/irgwalk.c | 72 +++++++++++++++++++++++++++++- ir/ir/irnode.c | 12 +++-- ir/ir/irnode.h | 12 ++--- ir/ir/iropt.c | 2 +- ir/ir/irprog.c | 36 ++++++--------- ir/ir/irprog_t.h | 51 +++++++++++++++++++++ ir/stat/firmstat.h | 5 +-- ir/tr/type.c | 13 +++--- ir/tr/type_identify.c | 21 ++++----- ir/tv/tv.c | 1 - testprograms/Makefile.in | 2 +- testprograms/array-stack_example.c | 3 +- testprograms/call_str_example.c | 5 ++- testprograms/endless_loop.c | 1 + testprograms/oo_inline_example.c | 3 +- testprograms/oo_program_example.c | 3 +- testprograms/while_example.c | 1 + 19 files changed, 209 insertions(+), 82 deletions(-) diff --git a/ir/ir/ircgopt.c b/ir/ir/ircgopt.c index 06cef8351..0771b278d 100644 --- a/ir/ir/ircgopt.c +++ b/ir/ir/ircgopt.c @@ -24,7 +24,7 @@ #include "array.h" #include "irprog.h" #include "irgwalk.h" -#include "irloop.h" +#include "irloop_t.h" #include "irflag_t.h" static void clear_link(ir_node * node, void * env) { diff --git a/ir/ir/irgopt.c b/ir/ir/irgopt.c index 7798f0f73..733fe7dc7 100644 --- a/ir/ir/irgopt.c +++ b/ir/ir/irgopt.c @@ -15,27 +15,31 @@ # include #endif -# include -# include - -# include "irprog.h" -# include "irgopt.h" -# include "irnode_t.h" -# include "irgraph_t.h" -# include "iropt_t.h" -# include "irgwalk.h" -# include "ircons_t.h" -# include "irgmod.h" -# include "array.h" -# include "pset.h" -# include "eset.h" -# include "pdeq.h" /* Fuer code placement */ -# include "irouts.h" -# include "irloop.h" -# include "irbackedge_t.h" -# include "irflag_t.h" -# include "firmstat.h" -# include "cgana.h" +#include +#include + +#include "irnode_t.h" +#include "irgraph_t.h" +#include "irprog_t.h" + +#include "ircons.h" +#include "iropt_t.h" +#include "irgopt.h" +#include "irgmod.h" +#include "irgwalk.h" + +#include "array.h" +#include "pset.h" +#include "eset.h" +#include "pdeq.h" /* Fuer code placement */ + +#include "irouts.h" +#include "irloop_t.h" +#include "irbackedge_t.h" +#include "cgana.h" + +#include "irflag_t.h" +#include "firmstat.h" /* Defined in iropt.c */ pset *new_identities (void); diff --git a/ir/ir/irgwalk.c b/ir/ir/irgwalk.c index 79c334cad..efcfefa13 100644 --- a/ir/ir/irgwalk.c +++ b/ir/ir/irgwalk.c @@ -120,12 +120,71 @@ static void collect_irgs(ir_node * node, eset * irg_set) { } } +static void +irg_walk_2_pre(ir_node *node, irg_walk_func *pre, void * env) { + int i; + set_irn_visited(node, current_ir_graph->visited); + + pre(node, env); + + if (node->op != op_Block) { + ir_node *pred = get_irn_n(node, -1); + if (pred->visited < current_ir_graph->visited) + irg_walk_2_pre(pred, pre, env); + } + for (i = get_irn_arity(node) - 1; i >= 0; --i) { + ir_node *pred = get_irn_n(node, i); + if (pred->visited < current_ir_graph->visited) + irg_walk_2_pre(pred, pre, env); + } +} + +static void +irg_walk_2_post(ir_node *node, irg_walk_func *post, void * env) { + int i; + set_irn_visited(node, current_ir_graph->visited); + + if (node->op != op_Block) { + ir_node *pred = get_irn_n(node, -1); + if (pred->visited < current_ir_graph->visited) + irg_walk_2_post(pred, post, env); + } + for (i = get_irn_arity(node) - 1; i >= 0; --i) { + ir_node *pred = get_irn_n(node, i); + if (pred->visited < current_ir_graph->visited) + irg_walk_2_post(pred, post, env); + } + + post(node, env); +} + +static void +irg_walk_2_both(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void * env) { + int i; + set_irn_visited(node, current_ir_graph->visited); + + pre(node, env); + + if (node->op != op_Block) { + ir_node *pred = get_irn_n(node, -1); + if (pred->visited < current_ir_graph->visited) + irg_walk_2_both(pred, pre, post, env); + } + for (i = get_irn_arity(node) - 1; i >= 0; --i) { + ir_node *pred = get_irn_n(node, i); + if (pred->visited < current_ir_graph->visited) + irg_walk_2_both(pred, pre, post, env); + } + + post(node, env); +} + + static void irg_walk_2(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void * env) { +#if 0 /* safe, old */ int i; - assert(node && node->kind==k_ir_node); -#if 0 /* safe */ if (get_irn_visited(node) < get_irg_visited(current_ir_graph)) { set_irn_visited(node, get_irg_visited(current_ir_graph)); @@ -139,7 +198,9 @@ irg_walk_2(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void * env) if (post) post(node, env); } #else /* faster */ +#if 0 if (node->visited < current_ir_graph->visited) { + int i; set_irn_visited(node, current_ir_graph->visited); if (pre) pre(node, env); @@ -151,6 +212,13 @@ irg_walk_2(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void * env) if (post) post(node, env); } +#else /* even faster */ + if (node->visited < current_ir_graph->visited) { + if (!post) irg_walk_2_pre (node, pre, env); + else if (!pre) irg_walk_2_post(node, post, env); + else irg_walk_2_both(node, pre, post, env); + } +#endif #endif } diff --git a/ir/ir/irnode.c b/ir/ir/irnode.c index 603bb9035..5fe1675e6 100644 --- a/ir/ir/irnode.c +++ b/ir/ir/irnode.c @@ -1921,11 +1921,17 @@ skip_nop (ir_node *node) { ir_node *pred; /* don't assert node !!! */ + if (!node || (node->op != op_Id)) return node; + if (!get_opt_normalize()) return node; /* Don't use get_Id_pred: We get into an endless loop for self-referencing Ids. */ - if (node && (node->op == op_Id) && (node != (pred = node->in[0+1]))) { + pred = node->in[0+1]; + + if (pred->op != op_Id) return pred; + + if (node != pred) { /* not a self referencing Id. Resolve Id chain. */ ir_node *rem_pred, *res; if (pred->op != op_Id) return pred; /* shortcut */ @@ -1933,11 +1939,11 @@ skip_nop (ir_node *node) { assert (get_irn_arity (node) > 0); - node->in[0+1] = node; + node->in[0+1] = node; /* turn us into a self referencing Id: shorten Id cycles. */ res = skip_nop(rem_pred); if (res->op == op_Id) /* self-loop */ return node; - node->in[0+1] = res; + node->in[0+1] = res; /* Turn Id chain into Ids all referencing the chain end. */ return res; } else { return node; diff --git a/ir/ir/irnode.h b/ir/ir/irnode.h index e17a8deae..0f4d84a37 100644 --- a/ir/ir/irnode.h +++ b/ir/ir/irnode.h @@ -392,9 +392,6 @@ void set_Const_type (ir_node *node, type *tp); depends on this tag. Use the proper access routine after testing this flag. */ -#define type_tag symconst_type_tag -//#define size symconst_size geht nicht, benennt auf size in type.c um! -#define linkage_ptr_info symconst_addr_name typedef enum { symconst_type_tag, /**< The SymConst is a type tag for the given type. Type_or_id_p is type *. */ @@ -411,12 +408,15 @@ typedef enum { /** SymConst attributes This union contains the symbolic information represented by the node */ union symconst_symbol { - type *type_p; //old typ - ident *ident_p; // old ptrinfo - entity *entity_p; // entity_p + type *type_p; + ident *ident_p; + entity *entity_p; }; + + typedef union symconst_symbol symconst_symbol; + /** Access the kind of the SymConst. */ symconst_kind get_SymConst_kind (const ir_node *node); void set_SymConst_kind (ir_node *node, symconst_kind num); diff --git a/ir/ir/iropt.c b/ir/ir/iropt.c index ba6894c0c..561e0509c 100644 --- a/ir/ir/iropt.c +++ b/ir/ir/iropt.c @@ -21,7 +21,7 @@ # include "ircons_t.h" # include "irgmod.h" # include "irvrfy.h" -# include "tv.h" +# include "tv_t.h" # include "dbginfo_t.h" # include "iropt_dbg.h" # include "irflag_t.h" diff --git a/ir/ir/irprog.c b/ir/ir/irprog.c index 372e45633..0c702fb31 100644 --- a/ir/ir/irprog.c +++ b/ir/ir/irprog.c @@ -108,9 +108,8 @@ void set_irp_main_irg(ir_graph *main_irg) { irp->main_irg = main_irg; } -type *get_glob_type(void) { - assert(irp); - return irp->glob_type = skip_tid(irp->glob_type); +type *(get_glob_type)(void) { + return __get_glob_type(); } /* Adds irg to the list of ir graphs in irp. */ @@ -136,16 +135,12 @@ void remove_irp_irg(ir_graph *irg){ } } -int get_irp_n_irgs() { - assert (irp && irp->graphs); - /* Strangely the first element of the array is NULL. Why?? */ - return (ARR_LEN((irp)->graphs) - 1); +int (get_irp_n_irgs)(void) { + return __get_irp_n_irgs(); } -ir_graph *get_irp_irg(int pos){ - assert (irp && irp->graphs); - /* Strangely the first element of the array is NULL. Why?? */ - return irp->graphs[pos+1]; +ir_graph *(get_irp_irg)(int pos){ + return __get_irp_irg(pos); } void set_irp_irg(int pos, ir_graph *irg) { @@ -166,17 +161,12 @@ void remove_irp_type(type *typ) { remove_irp_type_from_list (typ); } -int get_irp_n_types (void) { - assert (irp && irp->types); - /* Strangely the first element of the array is NULL. Why?? */ - return (ARR_LEN((irp)->types) - 1); +int (get_irp_n_types) (void) { + return __get_irp_n_types(); } -type *get_irp_type(int pos) { - assert (irp && irp->types); - /* Strangely the first element of the array is NULL. Why?? */ - /* Don't set the skip_tid result so that no double entries are generated. */ - return skip_tid(irp->types[pos+1]); +type *(get_irp_type) (int pos) { + return __get_irp_type(pos); } void set_irp_type(int pos, type *typ) { @@ -206,17 +196,19 @@ const char *get_irp_prog_name(void) { } -ir_graph *get_const_code_irg(void) +ir_graph *(get_const_code_irg)(void) { - return irp->const_code_irg; + return __get_const_code_irg(); } irg_outs_state get_irp_ip_outs_state() { return irp->outs_state; } + void set_irp_ip_outs_inconsistent() { irp->outs_state = outs_inconsistent; } + void set_irp_ip_outedges(ir_node ** ip_outedges) { irp -> ip_outedges = ip_outedges; diff --git a/ir/ir/irprog_t.h b/ir/ir/irprog_t.h index 40a12b6bf..ddaae7628 100644 --- a/ir/ir/irprog_t.h +++ b/ir/ir/irprog_t.h @@ -25,7 +25,9 @@ #include "irgraph.h" #include "ircgcons.h" #include "firm_common_t.h" +#include "typegmod.h" +#include "array.h" /** ir_prog */ struct ir_prog { @@ -56,9 +58,58 @@ struct ir_prog { INLINE void remove_irp_type_from_list (type *typ); +static INLINE type * +__get_glob_type(void) { + assert(irp); + return irp->glob_type = skip_tid(irp->glob_type); +} + +static INLINE int +__get_irp_n_irgs(void) { + assert (irp && irp->graphs); + /* Strangely the first element of the array is NULL. Why?? */ + return (ARR_LEN((irp)->graphs) - 1); +} + +static INLINE ir_graph * +__get_irp_irg(int pos){ + assert (irp && irp->graphs); + /* Strangely the first element of the array is NULL. Why?? */ + return irp->graphs[pos+1]; +} + + +static INLINE int +__get_irp_n_types (void) { + assert (irp && irp->types); + /* Strangely the first element of the array is NULL. Why?? */ + return (ARR_LEN((irp)->types) - 1); +} + +static INLINE type * +__get_irp_type(int pos) { + assert (irp && irp->types); + /* Strangely the first element of the array is NULL. Why?? */ + /* Don't set the skip_tid result so that no double entries are generated. */ + return skip_tid(irp->types[pos+1]); +} + #ifdef DEBUG_libfirm /** Returns a new, unique number to number nodes or the like. */ int get_irp_new_node_nr(void); #endif +static INLINE ir_graph * +__get_const_code_irg(void) +{ + return irp->const_code_irg; +} + +#define get_irp_n_irgs() __get_irp_n_irgs() +#define get_irp_irg(pos) __get_irp_irg(pos) +#define get_irp_n_types() __get_irp_n_types() +#define get_irp_type(pos) __get_irp_type(pos) +#define get_const_code_irg() __get_const_code_irg() +#define get_glob_type() __get_glob_type() + #endif /* ifndef _IRPROG_T_H_ */ diff --git a/ir/stat/firmstat.h b/ir/stat/firmstat.h index 581d0cfce..752819b27 100644 --- a/ir/stat/firmstat.h +++ b/ir/stat/firmstat.h @@ -33,9 +33,8 @@ typedef enum { STAT_OPT_CONST_EVAL, /**< constant evaluation */ STAT_LOWERED, /**< lowered */ - STAT_OPT_MAX -} -stat_opt_kind; + STAT_OPT_MAX = 10 +} stat_opt_kind; /** * initialize the statistics module. diff --git a/ir/tr/type.c b/ir/tr/type.c index eb0574070..962d7a324 100644 --- a/ir/tr/type.c +++ b/ir/tr/type.c @@ -39,19 +39,20 @@ # include #endif - # include # include # include + # include "type_t.h" -# include "tpop_t.h" + # include "irprog_t.h" +# include "ircons.h" +# include "tpop_t.h" # include "typegmod.h" -# include "array.h" -# include "irprog.h" # include "mangle.h" -# include "tv.h" -# include "ircons.h" +# include "tv_t.h" + +# include "array.h" /*******************************************************************/ /** TYPE **/ diff --git a/ir/tr/type_identify.c b/ir/tr/type_identify.c index 1780362d9..684af480c 100644 --- a/ir/tr/type_identify.c +++ b/ir/tr/type_identify.c @@ -25,16 +25,17 @@ #include "type_identify.h" -# include -# include -# include -# include "type_t.h" -# include "tpop_t.h" -# include "irprog_t.h" -# include "typegmod.h" -# include "array.h" -# include "irprog.h" -# include "mangle.h" +#include +#include +#include + +#include "type_t.h" +#include "tpop_t.h" +#include "irprog_t.h" +#include "typegmod.h" +#include "array.h" +#include "irprog_t.h" +#include "mangle.h" #include "pset.h" /* The hash set for types. */ diff --git a/ir/tv/tv.c b/ir/tv/tv.c index 330b941d4..92a2aec36 100644 --- a/ir/tv/tv.c +++ b/ir/tv/tv.c @@ -44,7 +44,6 @@ #include "set.h" /* to store tarvals in */ /* #include "tune.h" */ /* some constants */ #include "entity_t.h" /* needed to store pointers to entities */ -#include "irmode.h" /* defines modes etc */ #include "irmode_t.h" #include "irnode.h" /* defines boolean return values (pnc_number)*/ #include "host.h" diff --git a/testprograms/Makefile.in b/testprograms/Makefile.in index dd47599ea..dda661f09 100644 --- a/testprograms/Makefile.in +++ b/testprograms/Makefile.in @@ -55,7 +55,7 @@ include $(topdir)/MakeRules CPPFLAGS += -I$(top_srcdir)/ir/adt -I$(top_srcdir)/ir/common -I$(top_srcdir)/ir/debug \ -I$(top_srcdir)/ir/ident -I$(top_srcdir)/ir/ir -I$(top_srcdir)/ir/tr \ -I$(top_srcdir)/ir/tv -I$(top_srcdir)/ir/st -I$(top_srcdir)/ir/ana \ - -I$(top_srcdir)/ir/opt + -I$(top_srcdir)/ir/opt -I$(top_srcdir)/ir/stat LDFLAGS = -L$(topdir) LDFLAGS+= @LDFLAGS@ diff --git a/testprograms/array-stack_example.c b/testprograms/array-stack_example.c index 890d59937..9c57e917a 100644 --- a/testprograms/array-stack_example.c +++ b/testprograms/array-stack_example.c @@ -77,9 +77,10 @@ main(void) /* build typeinformation of procedure main */ owner = new_type_class (id_from_str ("ARRAY-STACK_EXAMPLE", 19)); - proc_main = new_type_method(id_from_str("main_tp", 4), 0, 1); + proc_main = new_type_method(id_from_str("main_tp", 7), 0, 1); set_method_res_type(proc_main, 0, prim_t_int); proc_main_e = new_entity (owner, id_from_str ("main", 4), proc_main); + get_entity_ld_name(proc_main_e); /* force name mangling */ /* make type information for the array and set the bounds */ # define N_DIMS 1 diff --git a/testprograms/call_str_example.c b/testprograms/call_str_example.c index 604a1d7e6..f72c96b5b 100644 --- a/testprograms/call_str_example.c +++ b/testprograms/call_str_example.c @@ -103,8 +103,9 @@ int main(int argc, char **argv) /* get the pointer to the procedure from the class type */ /* this is how a pointer to be fixed by the linker is represented. */ - proc_ptr = new_SymConst ((type_or_id_p)id_from_str (F_METHODNAME, strlen(F_METHODNAME)), - linkage_ptr_info); + symconst_symbol sym; + sym.ident_p = new_id_from_str (F_METHODNAME); + proc_ptr = new_SymConst (sym, symconst_addr_name); /* call procedure set_a, first built array with parameters */ { diff --git a/testprograms/endless_loop.c b/testprograms/endless_loop.c index 48b7db3bd..765c2d362 100644 --- a/testprograms/endless_loop.c +++ b/testprograms/endless_loop.c @@ -73,6 +73,7 @@ main(void) owner = new_type_class (id_from_str ("ENDLESS_LOOP_EXAMPLE", 20)); ent = new_entity (owner, id_from_str ("main", strlen("main")), proc_main); + get_entity_ld_name(ent); /* force name mangling */ /* Generates start and end blocks and nodes and a first, initial block */ irg = new_ir_graph (ent, 4); diff --git a/testprograms/oo_inline_example.c b/testprograms/oo_inline_example.c index d88c8c217..d8ba70c31 100644 --- a/testprograms/oo_inline_example.c +++ b/testprograms/oo_inline_example.c @@ -121,7 +121,8 @@ main(void) /* There is only one block in main, it contains the allocation and the calls. */ /* Allocate the defined object and generate the type information. */ - obj_size = new_SymConst((type_or_id_p)class_prima, size); + symconst_symbol sym = { class_prima }; + obj_size = new_SymConst(sym, symconst_size); obj_o = new_Alloc(get_store(), obj_size, class_prima, heap_alloc); set_store(new_Proj(obj_o, mode_M, 0)); /* make the changed memory visible */ obj_o = new_Proj(obj_o, mode_P, 2); /* remember the pointer to the object */ diff --git a/testprograms/oo_program_example.c b/testprograms/oo_program_example.c index 0c2de25ac..a0d31c5c3 100644 --- a/testprograms/oo_program_example.c +++ b/testprograms/oo_program_example.c @@ -119,7 +119,8 @@ main(void) /* There is only one block in main, it contains the allocation and the calls. */ /* Allocate the defined object and generate the type information. */ - obj_size = new_SymConst((type_or_id_p)class_prima, size); + symconst_symbol sym = {class_prima}; + obj_size = new_SymConst(sym, symconst_size); obj_o = new_Alloc(get_store(), obj_size, class_prima, heap_alloc); set_store(new_Proj(obj_o, mode_M, 0)); /* make the changed memory visible */ obj_o = new_Proj(obj_o, mode_P, 2); /* remember the pointer to the object */ diff --git a/testprograms/while_example.c b/testprograms/while_example.c index 7f6215593..302214c54 100644 --- a/testprograms/while_example.c +++ b/testprograms/while_example.c @@ -68,6 +68,7 @@ main(void) owner = new_type_class (id_from_str ("WHILE_EXAMPLE", 13)); ent = new_entity (owner, id_from_str ("main", strlen("main")), proc_main); + get_entity_ld_name(ent); /* force name mangling */ /* Generates start and end blocks and nodes and a first, initial block */ irg = new_ir_graph (ent, 4); -- 2.20.1