aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Macleod <amacleod@redhat.com>2008-05-28 15:55:27 +0000
committerAndrew Macleod <amacleod@redhat.com>2008-05-28 15:55:27 +0000
commit9de14e29b57a75b8ad4db5f717240347a92897f4 (patch)
tree9fed2ea32279d9e6e21109108954334947d7e369
parent1f195db6c8f5cca8e86cafeff8523c5ba81dcca4 (diff)
First rough cut on stage 1, nmo changelog or anything. just want to tag these changes so farpass-activity-log
git-svn-id: https://gcc.gnu.org/svn/gcc/branches/pass-activity-log@136109 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/Makefile.in2
-rw-r--r--gcc/logging.c222
-rw-r--r--gcc/logging.h87
-rw-r--r--gcc/passes.c6
-rw-r--r--gcc/tree-cfg.c8
-rw-r--r--gcc/tree-flow-inline.h9
-rw-r--r--gcc/tree-flow.h1
-rw-r--r--gcc/tree-optimize.c2
-rw-r--r--gcc/tree-ssanames.c5
9 files changed, 341 insertions, 1 deletions
diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 7553dcb554f..e15b84bccf4 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -1152,6 +1152,7 @@ OBJS-common = \
tree-if-conv.o \
tree-into-ssa.o \
tree-iterator.o \
+ logging.o \
tree-loop-linear.o \
tree-nested.o \
tree-nrv.o \
@@ -2305,6 +2306,7 @@ tree-pretty-print.o : tree-pretty-print.c $(CONFIG_H) $(SYSTEM_H) \
$(TREE_H) $(DIAGNOSTIC_H) $(REAL_H) $(HASHTAB_H) $(TREE_FLOW_H) \
$(TM_H) coretypes.h tree-iterator.h tree-chrec.h langhooks.h tree-pass.h \
value-prof.h fixed-value.h output.h
+logging.o : errors.h logging.c logging.h
fold-const.o : fold-const.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
$(TREE_H) $(FLAGS_H) $(REAL_H) toplev.h $(HASHTAB_H) $(EXPR_H) $(RTL_H) \
$(GGC_H) $(TM_P_H) langhooks.h $(MD5_H) intl.h fixed-value.h
diff --git a/gcc/logging.c b/gcc/logging.c
new file mode 100644
index 00000000000..ea1802b8134
--- /dev/null
+++ b/gcc/logging.c
@@ -0,0 +1,222 @@
+/* Definitions for various logging mechanisms in GCC.
+ Copyright (C) 2008 Free Software Foundation, Inc.
+ Contributed by Andrew MacLeod <amacleod@redhat.com>
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3. If not see
+<http://www.gnu.org/licenses/>. */
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "tm.h"
+#include "function.h"
+#include "langhooks.h"
+#include "logging.h"
+
+#ifdef ENABLE_LOGGING
+
+/* This will form a stack of Pass Activity Logs. */
+typedef struct pass_activity_log_stack {
+ struct pass_activity_log log;
+ struct pass_activity_log_stack *next;
+ int depth;
+} pal_stack;
+
+
+
+pal_stack root_log = { EMPTY_PASS_ACTIVITY_LOG, NULL, 0 };
+static pal_stack *current_pal_stack = &root_log;
+struct pass_activity_log *current_log = &(root_log.log);
+
+static void finalize_pal (FILE *, pal_stack *);
+static void push_pass_action (const char *);
+static pal_stack * pop_pass_action (void);
+static int stack_depth = 0;
+
+static FILE *logfile = NULL;
+
+
+
+#define print_field (f,name,value) if (value) \
+ fprintf (f, " %s:%ld", name, value)
+
+
+/* Add PTR's data to the permanent log. */
+static void
+finalize_pal (FILE *f, pal_stack *stack_ptr)
+{
+ pal *ptr = &(stack_ptr->log);
+
+ if (f == NULL)
+ return;
+
+ fprintf (f, "Pass '%s ' SA:%ld SC:%ld SD:%ld SM:%ld NC:%ld NR:%ld NL:%ld NDL:%ld\n",
+ ptr->name, ptr->stmts_added, ptr->stmts_changed,
+ ptr->stmts_deleted, ptr->stmts_moved, ptr->names_created,
+ ptr->names_removed, ptr->imm_links, ptr->imm_delinks);
+
+#if 0
+ fprintf (f, "Pass '%s'", ptr->name);
+ print_field (f, "Stmts-added", ptr->stmts_added);
+ print_field (f, "Stmts-changed", ptr->stmts_changed);
+ print_field (f, "Stmts-deleted", ptr->stmts_deleted);
+ print_field (f, "Stmts-moved", ptr->stmts_moved);
+ print_field (f, "SSA-names-created", ptr->names_created);
+ print_field (f, "SSA-names-removed", ptr->names_removed);
+ print_field (f, "Imm-links-added", ptr->imm_links);
+ print_field (f, "Imm-links-removed", ptr->imm_delinks);
+ fprintf (f, "\n");
+#endif
+}
+
+
+/* Create a new current pass action log called NAME on the stack. */
+
+void
+push_pass_action (const char *pass_name)
+{
+ pal_stack *tmp = xmalloc (sizeof (pal_stack));
+
+ memset (tmp, 0, sizeof (pal_stack));
+ if (pass_name != NULL)
+ {
+ strncpy (tmp->log.name, pass_name, PAL_NAME_SIZE - 1);
+ tmp->log.name[PAL_NAME_SIZE - 1] = '\0';
+ }
+
+ tmp->next = current_pal_stack;
+ tmp->depth = ++stack_depth;
+ current_pal_stack = tmp;
+ current_log = &(current_pal_stack->log);
+}
+
+
+/* Remove the current pass action log from the stack and return it.
+ Return root_log if the stack is emp. */
+
+pal_stack *
+pop_pass_action (void)
+{
+ pal_stack *ret = current_pal_stack;
+
+ if (ret != &root_log)
+ {
+ current_pal_stack = current_pal_stack->next;
+ current_log = &(current_pal_stack->log);
+ }
+ --stack_depth;
+ return ret;
+}
+
+
+static void
+clear_root_log (void)
+{
+ strcpy (root_log.log.name, "Root");
+ root_log.log.stmts_added = root_log.log.stmts_changed = 0;
+ root_log.log.stmts_deleted = 0;
+ root_log.log.stmts_moved = root_log.log.names_created = 0;
+ root_log.log.names_removed= 0;
+ root_log.log.imm_links = root_log.log.imm_delinks = 0;
+ root_log.depth = 0;
+ root_log.next = NULL;
+
+ stack_depth = 0;
+
+}
+/* Start all the logging routines. */
+
+void
+initialize_logging (tree fndecl)
+{
+ clear_root_log ();
+ current_pal_stack = &root_log;
+ current_log = &(current_pal_stack->log);
+
+ logfile = fopen ("/tmp/gcc-logging", "a");
+ fprintf (logfile, "### Start logging : ");
+
+ if (fndecl)
+ {
+ if (cfun)
+ switch (cfun->function_frequency)
+ {
+ case FUNCTION_FREQUENCY_HOT:
+ fprintf (logfile, "hot ");
+ break;
+
+ case FUNCTION_FREQUENCY_UNLIKELY_EXECUTED:
+ fprintf (logfile, "cold ");
+ break;
+
+ default:
+ fprintf (logfile, "normal ");
+ }
+
+ fprintf (logfile, "%s (%s)",
+ lang_hooks.decl_printable_name (fndecl, 2),
+ (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl))));
+ }
+ fprintf (logfile, "\n");
+}
+
+
+/* Terminate all the logging routines and fush any remaining logs. */
+
+void
+finalize_logging (void)
+{
+ pal_stack *tmp;
+
+ while ((tmp = pop_pass_action ()) != &root_log)
+ {
+ finalize_pal (logfile, tmp);
+ free (tmp);
+ }
+ finalize_pal (logfile, &root_log);
+
+ gcc_assert (stack_depth == -1);
+
+ fprintf (logfile, "### End logging\n");
+ /* Clear root log. */
+ clear_root_log ();
+ fclose (logfile);
+ logfile = NULL;
+}
+
+
+void start_pass_logging (const char *name)
+{
+ push_pass_action (name);
+}
+
+
+void finish_pass_logging (const char *name)
+{
+ pal_stack *tmp = pop_pass_action ();
+
+ /* Make sure its the right pass being removed. */
+ if (name != NULL)
+ gcc_assert (strncmp (tmp->log.name, name, PAL_NAME_SIZE - 1) == 0);
+ else
+ gcc_assert (tmp->log.name[0] == '\0');
+
+ finalize_pal (logfile, tmp);
+ free (tmp);
+
+}
+
+#endif
diff --git a/gcc/logging.h b/gcc/logging.h
new file mode 100644
index 00000000000..4825bfaecf6
--- /dev/null
+++ b/gcc/logging.h
@@ -0,0 +1,87 @@
+/* Definitions for various logging mechanisms in GCC.
+ Copyright (C) 2008 Free Software Foundation, Inc.
+ Contributed by Andrew MacLeod <amacleod@redhat.com>
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3. If not see
+<http://www.gnu.org/licenses/>. */
+
+
+#ifndef GCC_LOGGING_H
+#define GCC_LOGGING_H 1
+
+
+#define ENABLE_LOGGING
+
+/* Max size of a PAL name. */
+#define PAL_NAME_SIZE 200
+
+/* Define the Pass Activity Log structure. */
+typedef struct pass_activity_log
+{
+ char name[PAL_NAME_SIZE];
+ long stmts_added;
+ long stmts_changed;
+ long stmts_deleted;
+ long stmts_moved;
+ long names_created;
+ long names_removed;
+ long imm_links;
+ long imm_delinks;
+} pal;
+
+#define EMPTY_PASS_ACTIVITY_LOG { "root", 0, 0, 0, 0, 0, 0, 0, 0 }
+
+extern struct pass_activity_log *current_log;
+
+
+#ifdef ENABLE_LOGGING
+#define LOG_PASS_ACTION_ADD_STMT current_log->stmts_added++
+#define LOG_PASS_ACTION_CHANGE_STMT current_log->stmts_changed++
+#define LOG_PASS_ACTION_REMOVE_STMT current_log->stmts_deleted++
+#define LOG_PASS_ACTION_INSERT_STMT current_log->stmts_added++, \
+ current_log->stmts_changed--
+#define LOG_PASS_ACTION_MOVE_STMT current_log->stmts_moved++, \
+ current_log->stmts_changed--, \
+ current_log->stmts_deleted--, \
+ current_log->stmts_added--
+#define LOG_PASS_ACTION_CREATE_NAME current_log->names_created++
+#define LOG_PASS_ACTION_REMOVE_NAME current_log->names_removed++
+#define LOG_PASS_ACTION_IMM_DELINK current_log->imm_delinks++
+#define LOG_PASS_ACTION_IMM_LINK current_log->imm_links++
+#define LOG_PASS_ACTION_BB_TIME(BB,T) register_bb_time ((BB),(T))
+
+#else
+
+#define LOG_PASS_ACTION_ADD_STMT 0
+#define LOG_PASS_ACTION_INSERT_STMT 0
+#define LOG_PASS_ACTION_CHANGE_STMT 0
+#define LOG_PASS_ACTION_REMOVE_STMT 0
+#define LOG_PASS_ACTION_CREATE_NAME 0
+#define LOG_PASS_ACTION_REMOVE_NAME 0
+#define LOG_PASS_ACTION_IMM_DELINK 0
+#define LOG_PASS_ACTION_IMM_LINK 0
+#define LOG_PASS_ACTION_BB_TIME(BB,T) 0
+#endif
+
+
+void initialize_logging (tree);
+void finalize_logging (void);
+void start_pass_logging (const char *);
+void finish_pass_logging (const char *);
+
+
+
+#endif /* GCC_LOGGING_H */
diff --git a/gcc/passes.c b/gcc/passes.c
index 2614c90b3ca..d6b3e31235f 100644
--- a/gcc/passes.c
+++ b/gcc/passes.c
@@ -1081,6 +1081,9 @@ execute_one_pass (struct tree_opt_pass *pass)
This is a hack until the new folder is ready. */
in_gimple_form = (cfun && (cfun->curr_properties & PROP_trees)) != 0;
+ if (in_gimple_form)
+ start_pass_logging (pass->name);
+
/* Run pre-pass verification. */
execute_todo (pass->todo_flags_start);
@@ -1144,6 +1147,9 @@ execute_one_pass (struct tree_opt_pass *pass)
execute_todo (todo_after | pass->todo_flags_finish);
verify_interpass_invariants ();
+ if (in_gimple_form)
+ finish_pass_logging (pass->name);
+
if (!current_function_decl)
cgraph_process_new_functions ();
diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c
index ffb4983744e..b1d95b307cd 100644
--- a/gcc/tree-cfg.c
+++ b/gcc/tree-cfg.c
@@ -2768,6 +2768,7 @@ bsi_insert_before (block_stmt_iterator *i, tree t, enum bsi_iterator_update m)
set_bb_for_stmt (t, i->bb);
update_modified_stmts (t);
tsi_link_before (&i->tsi, t, m);
+ LOG_PASS_ACTION_INSERT_STMT;
}
@@ -2781,6 +2782,7 @@ bsi_insert_after (block_stmt_iterator *i, tree t, enum bsi_iterator_update m)
set_bb_for_stmt (t, i->bb);
update_modified_stmts (t);
tsi_link_after (&i->tsi, t, m);
+ LOG_PASS_ACTION_INSERT_STMT;
}
@@ -2807,6 +2809,7 @@ bsi_remove (block_stmt_iterator *i, bool remove_eh_info)
remove_stmt_from_eh_region (t);
gimple_remove_stmt_histograms (cfun, t);
}
+ LOG_PASS_ACTION_REMOVE_STMT;
}
@@ -2820,6 +2823,7 @@ bsi_move_after (block_stmt_iterator *from, block_stmt_iterator *to)
/* We must have BSI_NEW_STMT here, as bsi_move_after is sometimes used to
move statements to an empty block. */
bsi_insert_after (to, stmt, BSI_NEW_STMT);
+ LOG_PASS_ACTION_MOVE_STMT;
}
@@ -2834,6 +2838,7 @@ bsi_move_before (block_stmt_iterator *from, block_stmt_iterator *to)
BSI_NEW_STMT here; however, that breaks several places that expect
that TO does not change. */
bsi_insert_before (to, stmt, BSI_SAME_STMT);
+ LOG_PASS_ACTION_MOVE_STMT;
}
@@ -2849,6 +2854,7 @@ bsi_move_to_bb_end (block_stmt_iterator *from, basic_block bb)
bsi_move_before (from, &last);
else
bsi_move_after (from, &last);
+ LOG_PASS_ACTION_MOVE_STMT;
}
@@ -2885,6 +2891,8 @@ bsi_replace (const block_stmt_iterator *bsi, tree stmt, bool update_eh_info)
*bsi_stmt_ptr (*bsi) = stmt;
mark_stmt_modified (stmt);
update_modified_stmts (stmt);
+ LOG_PASS_ACTION_REMOVE_STMT;
+ LOG_PASS_ACTION_ADD_STMT;
}
diff --git a/gcc/tree-flow-inline.h b/gcc/tree-flow-inline.h
index 1afbd1a8fc7..44e6243dba7 100644
--- a/gcc/tree-flow-inline.h
+++ b/gcc/tree-flow-inline.h
@@ -355,13 +355,17 @@ update_stmt (tree t)
return;
mark_stmt_modified (t);
update_stmt_operands (t);
+ LOG_PASS_ACTION_CHANGE_STMT;
}
static inline void
update_stmt_if_modified (tree t)
{
if (stmt_modified_p (t))
- update_stmt_operands (t);
+ {
+ update_stmt_operands (t);
+ LOG_PASS_ACTION_CHANGE_STMT;
+ }
}
/* Return true if T is marked as modified, false otherwise. */
@@ -388,6 +392,7 @@ delink_imm_use (ssa_use_operand_t *linknode)
linknode->next->prev = linknode->prev;
linknode->prev = NULL;
linknode->next = NULL;
+ LOG_PASS_ACTION_IMM_DELINK;
}
/* Link ssa_imm_use node LINKNODE into the chain for LIST. */
@@ -400,6 +405,7 @@ link_imm_use_to_list (ssa_use_operand_t *linknode, ssa_use_operand_t *list)
linknode->next = list->next;
list->next->prev = linknode;
list->next = linknode;
+ LOG_PASS_ACTION_IMM_LINK;
}
/* Link ssa_imm_use node LINKNODE into the chain for DEF. */
@@ -428,6 +434,7 @@ set_ssa_use_from_ptr (use_operand_p use, tree val)
delink_imm_use (use);
*(use->use) = val;
link_imm_use (use, val);
+ LOG_PASS_ACTION_CHANGE_STMT;
}
/* Link ssa_imm_use node LINKNODE into the chain for DEF, with use occurring
diff --git a/gcc/tree-flow.h b/gcc/tree-flow.h
index adc2508b1c1..494e97e36e9 100644
--- a/gcc/tree-flow.h
+++ b/gcc/tree-flow.h
@@ -30,6 +30,7 @@ along with GCC; see the file COPYING3. If not see
#include "tree-ssa-operands.h"
#include "cgraph.h"
#include "ipa-reference.h"
+#include "logging.h"
/* Forward declare structures for the garbage collector GTY markers. */
#ifndef GCC_BASIC_BLOCK_H
diff --git a/gcc/tree-optimize.c b/gcc/tree-optimize.c
index cb30ba401cd..b1028c11a6b 100644
--- a/gcc/tree-optimize.c
+++ b/gcc/tree-optimize.c
@@ -380,6 +380,7 @@ tree_rest_of_compilation (tree fndecl)
gcc_assert (!flag_unit_at_a_time || cgraph_global_info_ready);
+ initialize_logging (fndecl);
node = cgraph_node (fndecl);
/* Initialize the default bitmap obstack. */
@@ -454,5 +455,6 @@ tree_rest_of_compilation (tree fndecl)
input_location = saved_loc;
ggc_collect ();
+ finalize_logging ();
timevar_pop (TV_EXPAND);
}
diff --git a/gcc/tree-ssanames.c b/gcc/tree-ssanames.c
index 956dd00206d..ea25bbb572a 100644
--- a/gcc/tree-ssanames.c
+++ b/gcc/tree-ssanames.c
@@ -159,6 +159,8 @@ make_ssa_name (tree var, tree stmt)
imm->next = imm;
imm->stmt = t;
+ LOG_PASS_ACTION_CREATE_NAME;
+
return t;
}
@@ -234,6 +236,9 @@ release_ssa_name (tree var)
TREE_CHAIN (var) = FREE_SSANAMES (cfun);
FREE_SSANAMES (cfun) = var;
}
+
+ LOG_PASS_ACTION_REMOVE_NAME;
+
}
/* Creates a duplicate of a ssa name NAME defined in statement STMT. */