From f7916b3a4436b4b0629ee35e9e3ac3d5b883159e Mon Sep 17 00:00:00 2001 From: fanfuqiang Date: Mon, 3 Sep 2018 12:53:58 +0800 Subject: [PATCH] new dump function --- src/rap_plugin/rap_opt.h | 30 ++++++++++----------------- src/rap_plugin/rap_opt_pass0.c | 38 +++++++++++++++++++++++++++------- 2 files changed, 41 insertions(+), 27 deletions(-) diff --git a/src/rap_plugin/rap_opt.h b/src/rap_plugin/rap_opt.h index f01589a..9fcb8bd 100644 --- a/src/rap_plugin/rap_opt.h +++ b/src/rap_plugin/rap_opt.h @@ -1,27 +1,19 @@ /* The impelmentation code of optimization pass for RAP. - -We supply the API for RAP */ + Supply the API for RAP */ #ifndef RAP_OPT_H #define RAP_OPT_H +/* Contains the beed called optimization level of GCC */ +extern int gcc_optimize_level; +/* Count how many function we have optimized */ +extern int rap_opt_statistics; -//extern int rap_available_naive(tree p, tree func); - -/* This function is defined in gcc/c-decl.c */ -//extern tree lookup_name(tree); -/* */ -//#define I_SYMBOL_BINDING(node) \ -// (((struct lang_identifier *) IDENTIFIER_NODE_CHECK(node))->symbol_binding) - -//#define RAP_POINTER_TO_FUNCTION(P) - -/* This is defined in gcc/c-decl.c but as static linkage, so we reuse it here. - And the depth of external scope is 0. - If scope depth is more than 1 it's local scope */ -//#define FILE_SCOPE_DEPTH 1 - -/* File scope function*/ -extern bool is_rap_function_never_escape (tree t); +/* Try make GCC call ipa-pta pass if optimization level is NOT 0 */ +void rap_try_call_ipa_pta (void* gcc_data, void* user_data); +void rap_gather_function_targets (); +int is_rap_function_maybe_roped (tree f); +void rap_opt_statistics (); +void rap_optimization_clean (); #endif /* RAP_OPT_H */ diff --git a/src/rap_plugin/rap_opt_pass0.c b/src/rap_plugin/rap_opt_pass0.c index 46182d2..52255cd 100644 --- a/src/rap_plugin/rap_opt_pass0.c +++ b/src/rap_plugin/rap_opt_pass0.c @@ -1,8 +1,8 @@ /* The impelmentation code of optimization pass for RAP. - We supply the API for RAP */ + Supply the API for RAP */ #include "../gcc-common.h" -#include "bitmap.h" +#include /* There are many optimization methrod can do for RAP. From simple to complex and aside with the gcc internal work stage. @@ -20,16 +20,16 @@ 2, Global alias anylysis for the avail function set. */ -/* This variable defined in GCC source */ -struct opt_pass *current_pass; -struct simple_ipa_opt_pass pass_ipa_pta; -// Hold all the ROP target functions. -bitmap sensi_funcs = BITMAP_ALLOC (NULL); - /* Contains the beed called optimization level of GCC */ int gcc_optimize_level = 0; /* Count how many function we have optimized */ int rap_opt_statistics = 0; +/* Contain the statistics data, maybe gcc will called many times, we need output + data in the same file, for the conventices of scripts process. */ +char *dump_rap_opt_statistics_filename = "rap_opt_statistics"; +FILE *dump_rap_opt_statistics_fd; +// Hold all the ROP target functions. +static bitmap sensi_funcs = BITMAP_ALLOC (NULL); /* Contains the type database which are pointer analysis can not sloved */ static struct pointer_set_t *pointer_types; @@ -210,3 +210,25 @@ is_rap_function_maybe_roped (tree f) return ! bitmap_bit_p (DECL_UID (f)) } +/* Write some statistics for our algorithm */ +void +dump_rap_opt_statistics () +{ + dump_rap_opt_statistics_fd = fopen (dump_rap_opt_statistics_filename, "a"); + fprintf (dump_rap_opt_statistics_fd, "%d\n", rap_opt_statistics); + + return; +} + +/* Clean and cloese function for optimizations */ +void +rap_optimization_clean () +{ + /* Now we have finish our job, close file and destroy the GCC allocated data*/ + fclose (dump_rap_opt_statistics_fd); + bitmap_clear (sensi_funcs); + pointer_set_destroy (pointer_types); + + return; +} +