diff -Naur gcc-4.5.0/gcc/common.opt gcc-4.5.0/gcc/common.opt --- gcc-4.5.0/gcc/common.opt 2010-03-18 08:31:09.000000000 +0530 +++ gcc-4.5.0/gcc/common.opt 2010-07-02 17:43:50.451668665 +0530 @@ -697,6 +697,10 @@ Common Report Var(flag_ipa_pta) Init(0) Optimization Perform interprocedural points-to analysis +fipa-gm +Common Report Var(flag_ipa_gimple_manipulation) Init(0) Optimization +Enable pass named pass_gimple_manipulation + fipa-reference Common Report Var(flag_ipa_reference) Init(0) Optimization Discover readonly and non addressable static variables diff -Naur gcc-4.5.0/gcc/gimple-manipulation.c gcc-4.5.0/gcc/gimple-manipulation.c --- gcc-4.5.0/gcc/gimple-manipulation.c 1970-01-01 05:30:00.000000000 +0530 +++ gcc-4.5.0/gcc/gimple-manipulation.c 2010-07-02 19:53:53.451681154 +0530 @@ -0,0 +1,186 @@ +/*--------------------------------------------------------------------- + A pass for gimple manipulation for GCC Workshop 2010. + - Calculate the number of Local Variables + - Calculate the number of Global Variables + - Calculate the number of Pointer Variables +-----------------------------------------------------------------------*/ +#include "config.h" +#include "system.h" +#include "coretypes.h" +#include "tm.h" +#include "tm_p.h" +#include "diagnostic.h" +#include "tree-flow.h" +#include "tree-pass.h" +#include "toplev.h" + +/* global declarations */ +int num_ptr_vars, num_global_vars, num_local_vars; +static void initialize_var_count (void); +static void print_var_count (void); +static unsigned int execute_gimple_manipulation (void); +static bool gate_gimple_manipulation (void); +static void gather_global_var_information (void); +static void gather_local_var_information (void); +static void analyze_parm_decl_arguments (struct function*); +extern const char * get_name (tree); + +/* ----------------------------------------------------------------------- + Function to initialize the variables used for collecting the information. + -------------------------------------------------------------------------*/ +static void +initialize_var_count (void) +{ + num_ptr_vars = 0; + num_global_vars = 0; + num_local_vars = 0; + if (dump_file) + fprintf (dump_file, "DUMPING THE GIMPLE STATEMENT ANALYSIS\n\n"); +} + +/* -------------------------------------------- + Function to print the collected statistics. + --------------------------------------------*/ +static void +print_var_count (void) +{ + if(dump_file) + { + fprintf (dump_file,"\n\nDUMPING THE COUNT STATISTICS\n\n"); + fprintf (dump_file, "Number of Local Variables : %d\n", num_local_vars); + fprintf (dump_file, "Number of Global Variables : %d\n", num_global_vars); + fprintf (dump_file, "Number of Pointer Variables: %d\n", num_ptr_vars); + } +} + +/* --------------------------------------------- + The main driver function to perform analysis. + ---------------------------------------------*/ +static unsigned int +execute_gimple_manipulation (void) +{ + struct cgraph_node *node; + + initialize_var_count (); + gather_global_var_information (); + for (node = cgraph_nodes; node; node=node->next) + { + /* Nodes without a body, and clone nodes are not interesting. */ + if (!gimple_has_body_p (node->decl) || node->clone_of) + continue; + + push_cfun (DECL_STRUCT_FUNCTION (node->decl)); + /* find out the local variables in formal parameters. */ + analyze_parm_decl_arguments (cfun); + gather_local_var_information (); + /* restoring the context by popping cfun. */ + pop_cfun (); + } + print_var_count (); + return 0; +} + +/*------------------------------------------------------------ + Analyze the function parameter declarations to identify the + formal parameter. + ------------------------------------------------------------*/ +static void +analyze_parm_decl_arguments (struct function* func) +{ + tree args = DECL_ARGUMENTS (func->decl); + while (args) + { + if (TREE_CODE(args) == PARM_DECL && !is_global_var (args)) + { + fprintf (dump_file, "Local Variable (parameter): %s\n", get_name (args)); + num_local_vars++; + } + args = TREE_CHAIN(args); + } +} + +/* ----------------------------------------------------------------------------------- + Iterate over the varpool_node data structure to compute the total number of global + variables, and identify the pointer variables amongst them. + ----------------------------------------------------------------------------------*/ +static void +gather_global_var_information (void) +{ + struct varpool_node *node; + for (node = varpool_nodes; node; node = node->next) + { + /* It should not be an artificial variable. */ + if (!DECL_ARTIFICIAL (node->decl)) + { + if (dump_file) + fprintf (dump_file, "Global Variable : %s\n", get_name (node->decl)); + num_global_vars++; + /* Check if the variable is a pointer */ + if (POINTER_TYPE_P (TREE_TYPE (node->decl))) + { + if (dump_file) + fprintf (dump_file, "Global Pointer Variable : %s\n", get_name (node->decl)); + num_ptr_vars++; + } + } + } +} + +/* ------------------------------------------------------------------------------------ + Iterate over the local_decls list of current function to compute the total number of + local variables, and identify the pointer variables amongst them. + -----------------------------------------------------------------------------------*/ +static void +gather_local_var_information (void) +{ + tree list = cfun->local_decls; + while (list) + { + tree vars = TREE_VALUE (list); + /* It should not be an artificial variable. */ + if (!DECL_ARTIFICIAL (vars)) + { + if (dump_file) + fprintf (dump_file, "Local Variable : %s\n", get_name (vars)); + num_local_vars++; + /* Check if the variable is a pointer */ + if (POINTER_TYPE_P (TREE_TYPE (vars))) + { + if (dump_file) + fprintf (dump_file, "Local Pointer Variable : %s\n", get_name (vars)); + num_ptr_vars++; + } + } + list = TREE_CHAIN (list); + } +} + +/* ------------------------------------------ + Return true if we should execute our pass. + ------------------------------------------*/ +static bool +gate_gimple_manipulation (void) +{ + return (flag_unit_at_a_time != 0 && flag_ipa_gimple_manipulation + /* Don't bother doing anything if the program has errors. */ + && !(errorcount || sorrycount)); +} + +struct simple_ipa_opt_pass pass_gimple_manipulation = +{ + { + SIMPLE_IPA_PASS, + "gm", /* name */ + gate_gimple_manipulation, /* gate */ + execute_gimple_manipulation, /* execute */ + NULL, /* sub */ + NULL, /* next */ + 0, /* static pass number */ + 0, /* tv_id */ + 0, /* properties required */ + 0, /* properties provided */ + 0, /* properties destroyed */ + 0, /* todo_flags start */ + 0 /* todo_flags end */ + } +}; diff -Naur gcc-4.5.0/gcc/Makefile.in gcc-4.5.0/gcc/Makefile.in --- gcc-4.5.0/gcc/Makefile.in 2010-04-02 13:19:06.000000000 +0530 +++ gcc-4.5.0/gcc/Makefile.in 2010-07-02 17:43:50.455657720 +0530 @@ -1206,6 +1206,7 @@ gimple.o \ gimple-iterator.o \ gimple-low.o \ + gimple-manipulation.o \ gimple-pretty-print.o \ gimplify.o \ graph.o \ @@ -2285,6 +2286,8 @@ $(GIMPLE_H) $(HASHTAB_H) $(FUNCTION_H) $(CGRAPH_H) \ $(TREE_PASS_H) $(TIMEVAR_H) alloc-pool.h $(SPLAY_TREE_H) $(PARAMS_H) \ gt-tree-ssa-structalias.h $(CGRAPH_H) $(ALIAS_H) pointer-set.h +gimple-manipulation.o : gimple-manipulation.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(RTL_H) \ + $(FLAGS_H) $(BASIC_BLOCK_H) $(DF_H) $(OBSTACK_H) $(TIMEVAR_H) tree-pass.h tree-ssa.o : tree-ssa.c $(TREE_FLOW_H) $(CONFIG_H) $(SYSTEM_H) \ $(RTL_H) $(TREE_H) $(TM_P_H) $(EXPR_H) output.h $(DIAGNOSTIC_H) \ $(TOPLEV_H) $(FUNCTION_H) $(TIMEVAR_H) $(TM_H) coretypes.h \ diff -Naur gcc-4.5.0/gcc/passes.c gcc-4.5.0/gcc/passes.c --- gcc-4.5.0/gcc/passes.c 2010-04-03 01:24:46.000000000 +0530 +++ gcc-4.5.0/gcc/passes.c 2010-07-02 17:43:50.507681021 +0530 @@ -803,6 +803,8 @@ p = &all_regular_ipa_passes; NEXT_PASS (pass_ipa_whole_program_visibility); + /* Invoke Gimple Analysis Pass */ + NEXT_PASS (pass_gimple_manipulation); NEXT_PASS (pass_ipa_cp); NEXT_PASS (pass_ipa_inline); NEXT_PASS (pass_ipa_reference); diff -Naur gcc-4.5.0/gcc/tree-pass.h gcc-4.5.0/gcc/tree-pass.h --- gcc-4.5.0/gcc/tree-pass.h 2010-04-03 01:24:46.000000000 +0530 +++ gcc-4.5.0/gcc/tree-pass.h 2010-07-02 17:43:50.524594064 +0530 @@ -454,6 +454,9 @@ extern struct simple_ipa_opt_pass pass_ipa_struct_reorg; extern struct ipa_opt_pass_d pass_ipa_lto_wpa_fixup; extern struct ipa_opt_pass_d pass_ipa_lto_finish_out; +/* Register the gimple analysis pass */ +extern struct simple_ipa_opt_pass pass_gimple_manipulation; + extern struct gimple_opt_pass pass_all_optimizations; extern struct gimple_opt_pass pass_cleanup_cfg_post_optimizing; diff -Naur gcc-4.5.0/Makefile.in gcc-4.5.0/Makefile.in --- gcc-4.5.0/Makefile.in 2010-02-17 16:31:44.000000000 +0530 +++ gcc-4.5.0/Makefile.in 2010-07-02 17:43:50.608650479 +0530 @@ -942,6 +942,11 @@ maybe-configure-target-libada \ maybe-configure-target-libgomp +# The target build for cc1 +.PHONY: cc1 +cc1: + make all-gcc TARGET-gcc=cc1$(exeext) + # The target built for a native non-bootstrap build. .PHONY: all all: