From 6cacf3bfddd7b786cd8e48dba30f996db933e733 Mon Sep 17 00:00:00 2001 From: =?utf8?q?G=C3=B6tz=20Lindenmaier?= Date: Fri, 29 Oct 2004 07:58:04 +0000 Subject: [PATCH] adapted to new function name in irtypeinfo, output of ana data as csv [r4244] --- ir/ir/irdump.c | 8 +- ir/ir/irdump.h | 7 +- ir/ir/irdumptxt.c | 327 +++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 304 insertions(+), 38 deletions(-) diff --git a/ir/ir/irdump.c b/ir/ir/irdump.c index 9393af1d0..8d5227b02 100644 --- a/ir/ir/irdump.c +++ b/ir/ir/irdump.c @@ -564,7 +564,7 @@ static int dump_node_typeinfo(FILE *F, ir_node *n) { if (opt_dump_analysed_type_info) { if (get_irg_typeinfo_state(current_ir_graph) == irg_typeinfo_consistent || get_irg_typeinfo_state(current_ir_graph) == irg_typeinfo_inconsistent) { - type *tp = get_irn_type(n); + type *tp = get_irn_typeinfo_type(n); if (tp != none_type) fprintf(F, " [%s]", get_type_name_ex(tp, &bad)); else @@ -801,6 +801,7 @@ static INLINE int dump_node_info(FILE *F, ir_node *n) fprintf(F, "kind size\n"); break; } + fprintf(F, "SymConst of type %s \n", get_type_name_ex(get_SymConst_value_type(n), &bad)); } break; case iro_Filter: { int i; @@ -831,8 +832,8 @@ static INLINE int dump_node_info(FILE *F, ir_node *n) if (get_irg_typeinfo_state(get_irn_irg(n)) == irg_typeinfo_consistent || get_irg_typeinfo_state(get_irn_irg(n)) == irg_typeinfo_inconsistent ) - if (get_irn_type(n) != none_type) - fprintf (F, "\nAnalysed type: %s", get_type_name_ex(get_irn_type(n), &bad)); + if (get_irn_typeinfo_type(n) != none_type) + fprintf (F, "\nAnalysed type: %s", get_type_name_ex(get_irn_typeinfo_type(n), &bad)); fprintf (F, "\""); @@ -2348,6 +2349,7 @@ void dump_loops_standalone(FILE *F, ir_loop *loop) { bad |= dump_node_nodeattr(F, n); fprintf (F, " %ld", get_irn_node_nr(n)); if (is_Block(n)) fprintf (F, "\t ->%d", (int)get_irn_link(n)); + if (has_backedges(n)) fprintf(F, "\t loop head!"); } else { /* for callgraph loop tree */ assert(get_kind(son) == k_ir_graph); /* We are a loop node -> Collect firm graphs */ diff --git a/ir/ir/irdump.h b/ir/ir/irdump.h index 2532f5668..c9a7d6054 100644 --- a/ir/ir/irdump.h +++ b/ir/ir/irdump.h @@ -272,6 +272,7 @@ typedef enum { dump_verbosity_entconsts = 0x00000020, /**< dump entity constants */ dump_verbosity_accessStats = 0x00000100, /**< dump entity access statistics */ + dump_verbosity_csv = 0x00000200, /**< dump access statistics as comma separated list */ dump_verbosity_noClassTypes = 0x00001000, /**< dump no class types */ dump_verbosity_noStructTypes = 0x00002000, /**< dump no struct types */ @@ -291,7 +292,8 @@ typedef enum { dump_verbosity_onlyPrimitiveTypes = 0x000BF000, /**< dump only primitive types */ dump_verbosity_onlyEnumerationTypes=0x0007F000, /**< dump only enumeration types */ - dump_verbosity_max = 0x48888887 /**< turn on all verbosity. */ + dump_verbosity_max = 0x4FF00FFE /**< turn on all verbosity. + @@@ Because of a bug in gcc 3.2 we can not set the first two bits. */ } dump_verbosity; @@ -322,7 +324,8 @@ void dump_type (type *tp); * the global type nor frame types or the like. * * The file name is the program name (get_irp_name()), or 'TextTypes' - * if the program name is not set appended by -types.txt. + * if the program name is not set, appended by -types.txt. + * For verbosity see the documentation of the verbosity flags above. */ void dump_types_as_text(unsigned verbosity, const char *suffix); diff --git a/ir/ir/irdumptxt.c b/ir/ir/irdumptxt.c index b66d51ff8..172d960cb 100644 --- a/ir/ir/irdumptxt.c +++ b/ir/ir/irdumptxt.c @@ -24,17 +24,65 @@ #include "field_temperature.h" +#define MY_SIZE 32 /* Size of an array that actually should be computed. */ + int dump_node_opcode(FILE *F, ir_node *n); /* from irdump.c */ +int addr_is_alloc(ir_node *acc) { + ir_node *addr = NULL; + opcode addr_op; + if (is_memop(acc)) { + addr = get_memop_ptr(acc); + } else { + assert(get_irn_op(acc) == op_Call); + addr = get_Call_ptr(acc); + } + + addr_op = get_irn_opcode(addr); + + while (addr_op != iro_Alloc) { + + switch (addr_op) { + case iro_Sel: + addr = get_Sel_ptr(addr); + break; + case iro_Cast: + addr = get_Cast_op(addr); + break; + case iro_Proj: + addr = get_Proj_pred(addr); + break; + case iro_SymConst: + case iro_Const: + return 0; + break; + case iro_Phi: + case iro_Load: + case iro_Call: + case iro_Start: + return 0; + break; + + default: + DDMN(addr); + assert(0 && "unexpected address node"); + } + addr_op = get_irn_opcode(addr); + } + + /* In addition, the alloc must be in the same loop. */ + + return 1; +} + #define X(a) case a: fprintf(F, #a); break void dump_entity_to_file_prefix (FILE *F, entity *ent, char *prefix, unsigned verbosity) { int i, j; assert(ent && ent->kind == k_entity); type *owner = get_entity_owner(ent); type *type = get_entity_type(ent); - if (verbosity & dump_verbosity_onlynames) { fprintf(F, "%sentity %s.%s (%ld)\n", prefix, get_type_name(get_entity_owner(ent)), get_entity_name(ent), get_entity_nr(ent)); @@ -65,7 +113,7 @@ void dump_entity_to_file_prefix (FILE *F, entity *ent, char *prefix, unsigned get_type_name(get_entity_owner(ov))); } } else { - fprintf(F, "%s Is not overwriten by other entities. \n", prefix); + fprintf(F, "%s Is not overwritten by other entities. \n", prefix); } } @@ -98,12 +146,9 @@ void dump_entity_to_file_prefix (FILE *F, entity *ent, char *prefix, unsigned if (is_method_type(get_entity_type(ent))) fprintf(F, "(...)"); if (verbosity & dump_verbosity_accessStats) { - if (get_entity_allocation(ent) == allocation_static) { - fprintf(F, " (stat)"); - } else { - if (get_entity_peculiarity(ent) == peculiarity_description) fprintf(F, " (desc)"); - if (get_entity_peculiarity(ent) == peculiarity_inherited) fprintf(F, " (inh)"); - } + if (get_entity_allocation(ent) == allocation_static) fprintf(F, " (stat)"); + if (get_entity_peculiarity(ent) == peculiarity_description) fprintf(F, " (desc)"); + if (get_entity_peculiarity(ent) == peculiarity_inherited) fprintf(F, " (inh)"); } fprintf(F, "\n"); } @@ -136,7 +181,6 @@ void dump_entity_to_file_prefix (FILE *F, entity *ent, char *prefix, unsigned } } - if (verbosity & dump_verbosity_entattrs) { fprintf(F, "%s volatility: ", prefix); switch (get_entity_volatility(ent)) { @@ -163,23 +207,93 @@ void dump_entity_to_file_prefix (FILE *F, entity *ent, char *prefix, unsigned if (verbosity & dump_verbosity_accessStats) { int n_acc = get_entity_n_accesses(ent); - fprintf(F, "%s Access Stats", prefix); - char comma = ':'; + int L_freq[MY_SIZE]; + int max_L_freq = -1; + int S_freq[MY_SIZE]; + int max_S_freq = -1; + int LA_freq[MY_SIZE]; + int max_LA_freq = -1; + int SA_freq[MY_SIZE]; + int max_SA_freq = -1; + for (i = 0; i < MY_SIZE; ++i) { + L_freq[i] = 0; + LA_freq[i] = 0; + S_freq[i] = 0; + SA_freq[i] = 0; + } + for (i = 0; i < n_acc; ++i) { ir_node *acc = get_entity_access(ent, i); - if (get_irn_op(acc) == op_Load) { - fprintf(F, "%c L", comma); + int depth = get_weighted_loop_depth(acc); + assert(depth < MY_SIZE); + if ((get_irn_op(acc) == op_Load) || (get_irn_op(acc) == op_Call)) { + L_freq[depth]++; + max_L_freq = (depth > max_L_freq) ? depth : max_L_freq; + if (addr_is_alloc(acc)) { + LA_freq[depth]++; + max_LA_freq = (depth > max_LA_freq) ? depth : max_LA_freq; + } } else if (get_irn_op(acc) == op_Store) { - fprintf(F, "%c S", comma); + S_freq[depth]++; + max_S_freq = (depth > max_S_freq) ? depth : max_S_freq; + if (addr_is_alloc(acc)) { + SA_freq[depth]++; + max_SA_freq = (depth > max_SA_freq) ? depth : max_SA_freq; + } } else { assert(0); } - fprintf(F, " %d", get_weighted_loop_depth(acc)); - comma = ','; } - fprintf(F, "\n"); - } + if (max_L_freq >= 0) { + fprintf(F, "%s Load Stats", prefix); + char comma = ':'; + for (i = 0; i <= max_L_freq; ++i) { + if (L_freq[i]) + fprintf(F, "%c %d x L%d", comma, L_freq[i], i); + else + fprintf(F, " "); + comma = ','; + } + fprintf(F, "\n"); + } + if (max_LA_freq >= 0) { + //fprintf(F, "%s LoadA Stats", prefix); + char comma = ':'; + for (i = 0; i <= max_LA_freq; ++i) { + //if (LA_freq[i]) + //fprintf(F, "%c %d x LA%d", comma, LA_freq[i], i); + //else + //fprintf(F, " "); + comma = ','; + } + fprintf(F, "\n"); + } + if (max_S_freq >= 0) { + fprintf(F, "%s Store Stats", prefix); + char comma = ':'; + for (i = 0; i <= max_S_freq; ++i) { + if (S_freq[i]) + fprintf(F, "%c %d x S%d", comma, S_freq[i], i); + else + fprintf(F, " "); + comma = ','; + } + fprintf(F, "\n"); + } + if (max_SA_freq >= 0) { + //fprintf(F, "%s StoreAStats", prefix); + char comma = ':'; + for (i = 0; i <= max_SA_freq; ++i) { + //if (SA_freq[i]) + //fprintf(F, "%c %d x SA%d", comma, SA_freq[i], i); + //else + //fprintf(F, " "); + comma = ','; + } + fprintf(F, "\n"); + } + } } #undef X @@ -193,6 +307,127 @@ void dump_entity (entity *ent) { dump_entity_to_file(stdout, ent, dump_verbosity_max); } +void dump_entitycsv_to_file_prefix (FILE *F, entity *ent, char *prefix, unsigned verbosity, + int *max_disp, int disp[], const char *comma) { + int i; + int n_acc = get_entity_n_accesses(ent); + int L_freq[MY_SIZE]; + int max_L_freq = -1; + int S_freq[MY_SIZE]; + int max_S_freq = -1; + int LA_freq[MY_SIZE]; + int max_LA_freq = -1; + int SA_freq[MY_SIZE]; + int max_SA_freq = -1; + for (i = 0; i < MY_SIZE; ++i) { + L_freq[i] = 0; + LA_freq[i] = 0; + S_freq[i] = 0; + SA_freq[i] = 0; + } + + for (i = 0; i < n_acc; ++i) { + ir_node *acc = get_entity_access(ent, i); + int depth = get_weighted_loop_depth(acc); + assert(depth < MY_SIZE); + if ((get_irn_op(acc) == op_Load) || (get_irn_op(acc) == op_Call)) { + L_freq[depth]++; + max_L_freq = (depth > max_L_freq) ? depth : max_L_freq; + if (addr_is_alloc(acc)) { + LA_freq[depth]++; + max_LA_freq = (depth > max_LA_freq) ? depth : max_LA_freq; + } + if (get_entity_allocation(ent) == allocation_static) { + disp[depth]++; + *max_disp = (depth > *max_disp) ? depth : *max_disp; + } + } else if (get_irn_op(acc) == op_Store) { + S_freq[depth]++; + max_S_freq = (depth > max_S_freq) ? depth : max_S_freq; + if (addr_is_alloc(acc)) { + SA_freq[depth]++; + max_SA_freq = (depth > max_SA_freq) ? depth : max_SA_freq; + } + if (get_entity_allocation(ent) == allocation_static) { + assert(0); + } + } else { + assert(0); + } + } + + if (get_entity_allocation(ent) == allocation_static) return; + + fprintf(F, "%s_%s", get_type_name(get_entity_owner(ent)), get_entity_name(ent)); + + if (max_L_freq >= 0) { + fprintf(F, "%s Load", comma); + for (i = 0; i <= max_L_freq; ++i) { + fprintf(F, "%s %d", comma, L_freq[i]); + } + } + if (max_S_freq >= 0) { + if (max_L_freq >= 0) fprintf(F, "\n%s_%s", get_type_name(get_entity_owner(ent)), get_entity_name(ent)); + fprintf(F, "%s Store", comma); + for (i = 0; i <= max_S_freq; ++i) { + fprintf(F, "%s %d", comma, S_freq[i]); + } + } + fprintf(F, "\n"); +} + +/* A fast hack to dump a csv. */ +void dump_typecsv_to_file(FILE *F, type *tp, dump_verbosity verbosity, const char *comma) { + if (!is_class_type(tp)) return; + + if (verbosity & dump_verbosity_accessStats) { + int i, n_all = get_type_n_allocations(tp); + int freq[MY_SIZE]; + int max_freq = -1; + int disp[MY_SIZE]; /* Accumulated accesses to static members: dispatch table. */ + int max_disp = -1; + for (i = 0; i < MY_SIZE; ++i) { + freq[i] = 0; + disp[i] = 0; + } + + for (i = 0; i < n_all; ++i) { + ir_node *all = get_type_allocation(tp, i); + int depth = get_weighted_loop_depth(all); + assert(depth < MY_SIZE); + freq[depth]++; + max_freq = (depth > max_freq) ? depth : max_freq; + assert(get_irn_op(all) == op_Alloc); + } + + fprintf(F, "%s ", get_type_name(tp)); + fprintf(F, "%s Alloc ", comma); + + if (max_freq >= 0) { + for (i = 0; i <= max_freq; ++i) { + fprintf(F, "%s %d", comma, freq[i]); + } + } + fprintf(F, "\n"); + + for (i = 0; i < get_class_n_members(tp); ++i) { + entity *mem = get_class_member(tp, i); + if (((verbosity & dump_verbosity_methods) && is_method_type(get_entity_type(mem))) || + ((verbosity & dump_verbosity_fields) && !is_method_type(get_entity_type(mem))) ) { + dump_entitycsv_to_file_prefix(F, mem, " ", verbosity, &max_disp, disp, comma); + } + } + + if (max_disp >= 0) { + fprintf(F, "%s__disp_tab%s Load", get_type_name(tp), comma); + for (i = 0; i <= max_disp; ++i) { + fprintf(F, "%s %d", comma, disp[i]); + } + fprintf(F, "\n"); + } + } +} + void dump_type_to_file (FILE *F, type *tp, dump_verbosity verbosity) { int i; @@ -264,15 +499,28 @@ void dump_type_to_file (FILE *F, type *tp, dump_verbosity verbosity) { if (verbosity & dump_verbosity_accessStats) { int n_all = get_type_n_allocations(tp); - fprintf(F, " Access Stats"); - char comma = ':'; + int freq[MY_SIZE]; + int max_freq = -1; + for (i = 0; i < MY_SIZE; ++i) freq[i] = 0; + for (i = 0; i < n_all; ++i) { ir_node *all = get_type_allocation(tp, i); - fprintf(F, "%c A", comma); - fprintf(F, " %d", get_weighted_loop_depth(all)); - comma = ','; + int depth = get_weighted_loop_depth(all); + assert(depth < MY_SIZE); + freq[depth]++; + max_freq = (depth > max_freq) ? depth : max_freq; + assert(get_irn_op(all) == op_Alloc); + } + + if (max_freq >= 0) { + fprintf(F, " Alloc Stats"); + char comma = ':'; + for (i = 0; i <= max_freq; ++i) { + fprintf(F, "%c %d x A%d", comma, freq[i], i); + comma = ','; + } + fprintf(F, "\n"); } - fprintf(F, "\n"); } fprintf(F, "\n\n"); @@ -282,9 +530,16 @@ void dump_type(type *tp) { dump_type_to_file (stdout, tp, dump_verbosity_max); } +/* Just opens a file, mangling a file name. + * + * The name consists of the following parts: + * + * @arg basename The basis of the name telling about the content. + * @arg + * + */ - -static FILE *text_open (const char *basename, const char * suffix1, const char *suffix2) { +static FILE *text_open (const char *basename, const char * suffix1, const char *suffix2, const char *suffix3) { FILE *F; int len = strlen(basename), i, j; char *fname; /* filename to put the vcg information in */ @@ -292,6 +547,7 @@ static FILE *text_open (const char *basename, const char * suffix1, const char * if (!basename) assert(basename); if (!suffix1) suffix1 = ""; if (!suffix2) suffix2 = ""; + if (!suffix3) suffix3 = ".txt"; /* open file for vcg graph */ fname = malloc (strlen(basename)*2 + strlen(suffix1) + strlen(suffix2) + 5); /* *2: space for excapes. */ @@ -309,7 +565,7 @@ static FILE *text_open (const char *basename, const char * suffix1, const char * fname[j] = '\0'; strcat (fname, suffix1); /* append file suffix */ strcat (fname, suffix2); /* append file suffix */ - strcat (fname, ".txt"); /* append the .txt suffix */ + strcat (fname, suffix3); /* append the .txt suffix */ F = fopen (fname, "w"); /* open file for writing */ if (!F) { @@ -322,15 +578,16 @@ static FILE *text_open (const char *basename, const char * suffix1, const char * void dump_types_as_text(unsigned verbosity, const char *suffix) { const char *basename; - FILE *F; + FILE *F, *CSV; int i, n_types = get_irp_n_types(); - if (get_irp_prog_ident() == new_id_from_str("no_name_set")) { - basename = "TextTypes"; - } else { - basename = get_irp_prog_name(); + basename = irp_prog_name_is_set() ? get_irp_prog_name() : "TextTypes"; + F = text_open (basename, suffix, "-types", ".txt"); + + if (verbosity & dump_verbosity_csv) { + CSV = text_open (basename, suffix, "-types", ".csv"); + //fprintf(CSV, "Class, Field, Operation, L0, L1, L2, L3\n"); } - F = text_open (basename, suffix, "-types"); for (i = 0; i < n_types; ++i) { type *t = get_irp_type(i); @@ -338,7 +595,11 @@ void dump_types_as_text(unsigned verbosity, const char *suffix) { if (is_jack_rts_class(t)) continue; dump_type_to_file(F, t, verbosity); + if (verbosity & dump_verbosity_csv) { + dump_typecsv_to_file(CSV, t, verbosity, ""); + } } fclose (F); + if (verbosity & dump_verbosity_csv) fclose (CSV); } -- 2.20.1