diff -Naur gcc-4.3.1/gcc/common.opt Workshops/GCCWorkshop09/GIMPLE/gcc-4.3.1/gcc/common.opt --- gcc-4.3.1/gcc/common.opt 2008-01-22 19:41:44.000000000 +0530 +++ Workshops/GCCWorkshop09/GIMPLE/gcc-4.3.1/gcc/common.opt 2009-07-09 00:06:33.000000000 +0530 @@ -600,6 +600,10 @@ Common Report Var(flag_ipa_pure_const) Init(0) Optimization Discover pure and const functions +fipa-gccwk09 +Common Report Var(flag_ipa_gccwk09) Init(1) Analysis +Enable pass named pass_gccwk09 + fipa-pta Common Report Var(flag_ipa_pta) Init(0) Optimization Perform interprocedural points-to analysis diff -Naur gcc-4.3.1/gcc/gccwk09.c Workshops/GCCWorkshop09/GIMPLE/gcc-4.3.1/gcc/gccwk09.c --- gcc-4.3.1/gcc/gccwk09.c 1970-01-01 05:30:00.000000000 +0530 +++ Workshops/GCCWorkshop09/GIMPLE/gcc-4.3.1/gcc/gccwk09.c 2009-07-09 01:33:49.000000000 +0530 @@ -0,0 +1,155 @@ +#include "config.h" +#include "system.h" +#include "coretypes.h" +#include "tm.h" +#include "tree.h" +#include "rtl.h" +#include "tm_p.h" +#include "hard-reg-set.h" +#include "basic-block.h" +#include "output.h" +#include "flags.h" +#include "function.h" +#include "expr.h" +#include "ggc.h" +#include "langhooks.h" +#include "diagnostic.h" +#include "tree-flow.h" +#include "timevar.h" +#include "tree-dump.h" +#include "tree-pass.h" +#include "toplev.h" +#include "except.h" +#include "cfgloop.h" +#include "cfglayout.h" +#include "tree-ssa-propagate.h" +#include "value-prof.h" +#include "pointer-set.h" +#include "tree-inline.h" + + +/* global declarations */ +int num_assignment, total_assignment; +void initialize_stats(void); +void process_statement(tree stmt); +void printstatistics(void); +static unsigned int gccwk09_main(void); +static bool gate_gccwk09 (void); + +/* ----------------------------------------------------------------------- + Function to initialize the variables used for collecting the information. + -------------------------------------------------------------------------*/ +void +initialize_stats(void) +{ + num_assignment = 0; + total_assignment = 0; +} + +/* -------------------------------------------- + Function to print the collected statistics. + --------------------------------------------*/ +void +printstatistics(void) +{ + if(dump_file) + { + fprintf(dump_file,"\nNumber of assignment statements:: %d\n",num_assignment); + fprintf(dump_file,"\nTotal Number of assignment statements (including temp vars): %d\n",total_assignment); + } +} + +/* ---------------------------------- + function to process each statement. + ----------------------------------*/ +void +process_statement(tree stmt) +{ + tree lval,rval; + switch (TREE_CODE (stmt)) + { + case GIMPLE_MODIFY_STMT: + /* extract the lval and rval trees from the given statement. + If the statement is of the form a = b + c, + lval = a, which is the tree indexed at 0 +` rval = b + c, which is the tree indexed at 1. */ + lval=GIMPLE_STMT_OPERAND(stmt,0); + rval=GIMPLE_STMT_OPERAND(stmt,1); + + /* For counting number of assignment statements, we have to check if lval is variable + declaration, and if it is, then ensure that its not an artificial variable. */ + if(TREE_CODE(lval) == VAR_DECL) + { + if(!DECL_ARTIFICIAL(lval)) + num_assignment++; + /* the total assignments including temporary variables */ + total_assignment++; + } + break; + default : + break; + } +} + +/* --------------------------------------------- + The main driver function to perform analysis. + ---------------------------------------------*/ +static unsigned int +gccwk09_main(void) +{ + struct cgraph_node *node; + basic_block bb; + block_stmt_iterator bsi; + + initialize_stats(); + for (node = cgraph_nodes; node; node=node->next) + { + if (node->analyzed && cgraph_is_master_clone (node)) + { + push_cfun (DECL_STRUCT_FUNCTION (node->decl)); + FOR_EACH_BB (bb) + { + for (bsi=bsi_start(bb); !bsi_end_p(bsi) ; bsi_next(&bsi) ) + { + tree stmt = bsi_stmt(bsi); + process_statement(stmt); + } + } + /* restoring the context by popping cfun. */ + pop_cfun (); + } + } + printstatistics(); + return 0; +} + +/* ------------------------------------------ + Return true if we should execute our pass. + ------------------------------------------*/ +static bool +gate_gccwk09 (void) +{ + return (flag_unit_at_a_time != 0 + && flag_ipa_gccwk09 + /* Don't bother doing anything if the program has errors. */ + && !(errorcount || sorrycount)); +} + + +struct tree_opt_pass pass_gccwk09 = +{ + "gccwk09", /* name */ + gate_gccwk09, /* gate */ + gccwk09_main, /* 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 */ + 0 /* rtl pass number */ +}; + diff -Naur gcc-4.3.1/gcc/Makefile.in Workshops/GCCWorkshop09/GIMPLE/gcc-4.3.1/gcc/Makefile.in --- gcc-4.3.1/gcc/Makefile.in 2008-05-12 00:24:15.000000000 +0530 +++ Workshops/GCCWorkshop09/GIMPLE/gcc-4.3.1/gcc/Makefile.in 2009-07-09 00:08:18.000000000 +0530 @@ -1224,7 +1224,8 @@ version.o \ vmsdbgout.o \ web.o \ - xcoffout.o + xcoffout.o \ + gccwk09.o # Target object files. OBJS-md = $(out_object_file) @@ -2326,6 +2327,10 @@ $(MACHMODE_H) $(TARGET_DEF_H) $(TARGET_H) $(GGC_H) gt-targhooks.h \ $(OPTABS_H) +# Added the NEW Rule for gccwk09.o +gccwk09.o : gccwk09.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 + toplev.o : toplev.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) \ version.h $(RTL_H) $(FUNCTION_H) $(FLAGS_H) xcoffout.h input.h \ $(INSN_ATTR_H) output.h $(DIAGNOSTIC_H) debug.h insn-config.h intl.h \ diff -Naur gcc-4.3.1/gcc/passes.c Workshops/GCCWorkshop09/GIMPLE/gcc-4.3.1/gcc/passes.c --- gcc-4.3.1/gcc/passes.c 2008-01-22 18:57:52.000000000 +0530 +++ Workshops/GCCWorkshop09/GIMPLE/gcc-4.3.1/gcc/passes.c 2009-07-09 00:09:41.000000000 +0530 @@ -502,6 +502,8 @@ NEXT_PASS (pass_inline_parameters); NEXT_PASS (pass_rebuild_cgraph_edges); } + /* Invoke the gimple analysis pass. */ + NEXT_PASS (pass_gccwk09); NEXT_PASS (pass_early_local_passes); { struct tree_opt_pass **p = &pass_early_local_passes.sub; diff -Naur gcc-4.3.1/gcc/tree-pass.h Workshops/GCCWorkshop09/GIMPLE/gcc-4.3.1/gcc/tree-pass.h --- gcc-4.3.1/gcc/tree-pass.h 2008-02-13 16:45:51.000000000 +0530 +++ Workshops/GCCWorkshop09/GIMPLE/gcc-4.3.1/gcc/tree-pass.h 2009-07-09 00:11:03.000000000 +0530 @@ -449,6 +449,8 @@ extern struct tree_opt_pass pass_apply_inline; extern struct tree_opt_pass pass_all_early_optimizations; extern struct tree_opt_pass pass_update_address_taken; +/* Register the gimple analysis pass */ +extern struct tree_opt_pass pass_gccwk09; /* The root of the compilation pass tree, once constructed. */ extern struct tree_opt_pass *all_passes, *all_ipa_passes, *all_lowering_passes; diff -Naur gcc-4.3.1/Makefile.in Workshops/GCCWorkshop09/GIMPLE/gcc-4.3.1/Makefile.in --- gcc-4.3.1/Makefile.in 2007-12-13 15:00:49.000000000 +0530 +++ Workshops/GCCWorkshop09/GIMPLE/gcc-4.3.1/Makefile.in 2009-07-09 00:13:48.000000000 +0530 @@ -725,6 +725,10 @@ maybe-configure-target-libgomp # The target built for a native non-bootstrap build. +.PHONY: cc1 +cc1: + make all-gcc TARGET-gcc=cc1$(exeext) + .PHONY: all all: @if gcc-bootstrap