From 20ca6997bf08d796a3c17a6ce149b9d58b6c5754 Mon Sep 17 00:00:00 2001 From: =?utf8?q?G=C3=B6tz=20Lindenmaier?= Date: Fri, 5 Mar 2004 16:38:36 +0000 Subject: [PATCH] statistics about data sizes [r2500] --- ir/common/Makefile.in | 4 +- ir/common/firm.h | 2 - ir/common/statistics.c | 96 ++++++++++++++++++++++++++++++++++++++++++ ir/common/statistics.h | 56 ++++++++++++++++++++++++ 4 files changed, 154 insertions(+), 4 deletions(-) create mode 100644 ir/common/statistics.c create mode 100644 ir/common/statistics.h diff --git a/ir/common/Makefile.in b/ir/common/Makefile.in index bdb6699eb..7509e84a2 100644 --- a/ir/common/Makefile.in +++ b/ir/common/Makefile.in @@ -15,13 +15,13 @@ srcdir = @srcdir@ topdir = ../.. subdir := ir/common -INSTALL_HEADERS := firm_common.h firm.h firmwalk.h +INSTALL_HEADERS := firm_common.h firm.h firmwalk.h statistics.h SOURCES = $(INSTALL_HEADERS) SOURCES += Makefile.in \ panic.c firm_common.c firm.c firmwalk.c \ - panic.h firm_common_t.h + panic.h firm_common_t.h statistics.c include $(topdir)/MakeRules diff --git a/ir/common/firm.h b/ir/common/firm.h index eec1a4dda..608a0a134 100644 --- a/ir/common/firm.h +++ b/ir/common/firm.h @@ -62,8 +62,6 @@ * */ -/* $Id$ */ - # ifndef _FIRM_H_ # define _FIRM_H_ diff --git a/ir/common/statistics.c b/ir/common/statistics.c new file mode 100644 index 000000000..1af3281dc --- /dev/null +++ b/ir/common/statistics.c @@ -0,0 +1,96 @@ +/* + * Project: libFIRM + * File name: ir/common/statistics.c + * Purpose: Compute statistics about firm library. + * Author: Goetz Lindenmaier + * Modified by: + * Created: + * CVS-ID: $Id$ + * Copyright: (c) 2004 Universität Karlsruhe + * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE. + */ + +#include "statistics.h" +#include "irgraph.h" +#include "irnode.h" +#include "irprog.h" +#include "irgwalk.h" + +/***********************************************************************/ +/* Statistics about allocated datastructures: counts. */ + +static void count_nodes(ir_node *n, void *env) { + int * counter_ptr = (int *)env; + (*counter_ptr)++; +} + + +/** Prints number of irgraphs, number of nodes in them and + * totals. */ +void print_graph_counts(int verbosity) { + int i, counter, total = 0; + int view = interprocedural_view; + interprocedural_view = 0; + ir_graph *old = current_ir_graph; + + for (i = 0; i < get_irp_n_irgs(); i++) { + counter = 0; + irg_walk_graph(get_irp_irg(i), count_nodes, NULL, &counter); + if (verbosity == 1) + printf(" +%4d nodes in graph %s.\n", counter, get_entity_name(get_irg_entity(get_irp_irg(i)))); + total += counter; + } + printf(" +++ There are %d graphs with total %d nodes.\n", get_irp_n_irgs(), total); + + current_ir_graph = old; + interprocedural_view = view; +} + +/** Prints number of types, number of entities and totals. + * */ +void print_type_counts(int verbosity) { + int i, counter, total = 0; + for (i = 0; i < get_irp_n_types(); i++) { + type *tp = get_irp_type(i); + counter = -1; + if (is_class_type(tp)) counter = get_class_n_members(tp); + if (is_struct_type(tp)) counter = get_struct_n_members(tp); + if (is_union_type(tp)) counter = get_union_n_members(tp); + if (counter > -1) { + if (verbosity == 1) + printf(" +%3d entities in %s type %s.\n", counter, get_type_tpop_name(tp), get_type_name(tp)); + total += counter; + } + } + printf(" +++ There are %d types with total %d entities.\n", get_irp_n_types(), total); + printf(" +++ Global type has %d entities\n", + get_class_n_members(get_glob_type())); + +} + +/** Prints number of tarvals. + * */ +void print_tarval_counts(int verbosity) { + printf("tarval count not implemented.\n\n"); +} + +/** Prints number of idents. + * */ +void print_ident_counts(int verbosity) { + printf("ident count not implemented.\n\n"); +} + + +void print_all_counts(int verbosity) { + printf(" +++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"); + print_graph_counts(verbosity); + printf(" +++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"); + print_type_counts(verbosity); + printf(" +++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"); + /* + print_tarval_counts(verbosity); + printf(" +++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"); + print_ident_counts(verbosity); + printf(" +++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"); + */ +} diff --git a/ir/common/statistics.h b/ir/common/statistics.h new file mode 100644 index 000000000..2ddd97bd2 --- /dev/null +++ b/ir/common/statistics.h @@ -0,0 +1,56 @@ +/* + * Project: libFIRM + * File name: ir/common/statistics.h + * Purpose: Compute statistics about firm library. + * Author: Goetz Lindenmaier + * Modified by: + * Created: + * CVS-ID: $Id$ + * Copyright: (c) 2004 Universität Karlsruhe + * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE. + */ + +/** + * @file statistics.h + * + * This file defines a set ouf routines to output statistics + * about the firm library. These statistics include + * - number of datastructures allocated, as entities, types, nodes... + * - memory consumption of data structures + * - effectiveness of optimizations + * - ... more to come. + * + * This file is thought for compiler optimization, not to run it in a + * production compiler. I.e., the routines may be inefficient. + */ + +# ifndef _STATISTICS_H_ +# define _STATISTICS_H_ + +/* Statistics about allocated datastructures: counts. */ +/** verbosity: + * 0: information about the whole program + * 1: information per type/procedure + */ + +void print_all_counts(int verbosity); + +/** Prints number of irgraphs, number of nodes in them and + * totals in intRAprocedural view. */ +void print_graph_counts(int verbosity); + +/** Prints number of types, number of entities and totals. + * Does not consider frame types or types to representent call by + * value arguments/results. */ +void print_type_counts(int verbosity); + +/** Prints number of tarvals. + * */ +void print_tarval_counts(int verbosity); + +/** Prints number of idents. + * */ +void print_ident_counts(int verbosity); + + +# endif /* _STATISTICS_H_ */ -- 2.20.1