install new passes into gcc

This commit is contained in:
fanfuqiang 2018-10-28 21:26:26 +08:00
parent 7ebee58eca
commit fe6685225b
7 changed files with 72 additions and 9 deletions

@ -3,7 +3,7 @@ SRCS = $(wildcard *.c)
OBJS = $(SRCS:.c=.o) OBJS = $(SRCS:.c=.o)
LDFLAGS = -shared LDFLAGS = -shared
CFLAGS = -g3 -O0 -std=gnu++98 -ggdb -fvisibility=hidden -fno-rtti -fno-exceptions -fPIC -c CFLAGS = -g3 -O0 -std=gnu++98 -ggdb -fvisibility=hidden -fno-rtti -fno-exceptions -fPIC -shared -c
#CFLAGS = -O2 -std=gnu++98 -ggdb -fvisibility=hidden -fno-rtti -fno-exceptions -fPIC -c #CFLAGS = -O2 -std=gnu++98 -ggdb -fvisibility=hidden -fno-rtti -fno-exceptions -fPIC -c
HEADER = -I`$(CC) -print-file-name=plugin`/include -I`$(CC) -print-file-name=plugin`/include/c-family -I.. HEADER = -I`$(CC) -print-file-name=plugin`/include -I`$(CC) -print-file-name=plugin`/include/c-family -I..
#HEADER = -I/usr/lib/gcc/x86_64-linux-gnu/4.8/plugin/include -I../../gcc-plugins #HEADER = -I/usr/lib/gcc/x86_64-linux-gnu/4.8/plugin/include -I../../gcc-plugins

@ -59,6 +59,7 @@ void
rap_check_will_call_passes (void* gcc_data, void* user_data) rap_check_will_call_passes (void* gcc_data, void* user_data)
{ {
//gcc_assert (current_pass); //gcc_assert (current_pass);
#if 0
if (current_pass if (current_pass
&& &&
(! strcmp ((/*(struct opt_pass *)*/current_pass)->name, "inline"))) (! strcmp ((/*(struct opt_pass *)*/current_pass)->name, "inline")))
@ -66,7 +67,7 @@ rap_check_will_call_passes (void* gcc_data, void* user_data)
if (*(bool*)gcc_data) if (*(bool*)gcc_data)
fprintf(dump_rap_opt_statistics_fd, "[+] NOT call pass 'inline'\n"); fprintf(dump_rap_opt_statistics_fd, "[+] NOT call pass 'inline'\n");
} }
#endif
return; return;
} }
@ -76,7 +77,7 @@ rap_try_call_ipa_pta (void* gcc_data, void* user_data)
{ {
/* Make sure we have reach */ /* Make sure we have reach */
bool will_call_ipa_pta = false; bool will_call_ipa_pta = false;
#if 0
//gcc_assert (current_pass); //gcc_assert (current_pass);
if (current_pass if (current_pass
&& &&
@ -87,7 +88,7 @@ rap_try_call_ipa_pta (void* gcc_data, void* user_data)
*(int*)user_data = optimize; *(int*)user_data = optimize;
} }
//gcc_assert (init); //gcc_assert (init);
#endif
return; return;
} }
@ -224,6 +225,34 @@ rap_gather_function_targets ()
return; return;
} // end of rap_gather_function_targets } // end of rap_gather_function_targets
/* The wraper of hl_gather pass. */
static unsigned int
hl_gather_execute ()
{
rap_gather_function_targets ();
return 0;
}
/* Will we need the gather? */
static bool
hl_gather_gate ()
{
if (require_call_hl_gather)
return true;
return false;
}
/* Genetate the pass structure */
#define PASS_NAME hl_gather
#define NO_GATE
//#define PROPERTIES_REQUIRED PROP_gimple_any
//#define PROPERTIES_PROVIDED PROP_gimple_lcf
#define TODO_FLAGS_FINISH TODO_update_ssa_any | TODO_verify_all | TODO_dump_func | \
TODO_remove_unused_locals | TODO_cleanup_cfg | TODO_rebuild_cgraph_edges
#include "gcc-generate-simple_ipa-pass.h"
#undef PASS_NAME
/* Basic test of function nature */ /* Basic test of function nature */
static inline bool static inline bool
@ -626,7 +655,7 @@ build_cfi (gimple_stmt_iterator *gp)
/// cgraph_local_node_p /// cgraph_local_node_p
/* This new pass will be added after the GCC pass ipa "pta". */ /* This new pass will be added after the GCC pass ipa "pta". */
static unsigned int static unsigned int
rap_hl_cfi_execute () hl_cfi_execute ()
{ {
struct cgraph_node *node; struct cgraph_node *node;
@ -683,12 +712,22 @@ rap_hl_cfi_execute ()
return 0; return 0;
} }
/* Will need replace the forward cfi? */
static bool
hl_cfi_gate ()
{
if (require_call_hl_cfi)
return true;
return false;
}
/* Genetate the pass structure */ /* Genetate the pass structure */
#define PASS_NAME rap_hl_cfi #define PASS_NAME hl_cfi
#define NO_GATE
//#define PROPERTIES_REQUIRED PROP_gimple_any //#define PROPERTIES_REQUIRED PROP_gimple_any
//#define PROPERTIES_PROVIDED PROP_gimple_lcf //#define PROPERTIES_PROVIDED PROP_gimple_lcf
#define TODO_FLAGS_FINISH TODO_update_ssa_any | TODO_verify_all | TODO_dump_func | \ #define TODO_FLAGS_FINISH TODO_update_ssa_any | TODO_verify_all | TODO_dump_func | \
TODO_remove_unused_locals | TODO_cleanup_cfg | TODO_rebuild_cgraph_edges TODO_remove_unused_locals | TODO_cleanup_cfg | TODO_rebuild_cgraph_edges
#include "gcc-generate-simple_ipa-pass.h" #include "gcc-generate-simple_ipa-pass.h"
#undef PASS_NAME

@ -20,7 +20,7 @@ extern int rap_opt_statistics_data;
/* Try make GCC call ipa-pta pass if optimization level is NOT 0 */ /* 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_try_call_ipa_pta (void* gcc_data, void* user_data);
void rap_gather_function_targets (); //void rap_gather_function_targets ();
int is_rap_function_maybe_roped (tree f); int is_rap_function_maybe_roped (tree f);
void rap_optimization_clean (); void rap_optimization_clean ();

@ -14,6 +14,10 @@ typedef struct {
} rap_hash_flags_t; } rap_hash_flags_t;
extern rap_hash_flags_t imprecise_rap_hash_flags; extern rap_hash_flags_t imprecise_rap_hash_flags;
//
bool require_call_hl_cfi;
bool require_call_hl_gather;
extern bool report_fptr_hash; extern bool report_fptr_hash;
extern bool report_runtime; extern bool report_runtime;

@ -12,7 +12,10 @@ bool report_fptr_hash;
static bool rap_fptr_gate(void) static bool rap_fptr_gate(void)
{ {
return rap_cmodel_check(); if (require_call_hl_cfi)
return false;
else
return rap_cmodel_check();
} }
static tree build_rap_hash(gimple call_stmt, tree fntype) static tree build_rap_hash(gimple call_stmt, tree fntype)

@ -40,6 +40,11 @@ const char *rap_abort_call;
bool enable_type_ret = false; bool enable_type_ret = false;
bool enable_type_call = false; bool enable_type_call = false;
/* If this falg set we will replace original rap forward cfi with hl_cfi. */
bool require_call_hl_cfi = false;
/* Flag to indicate need the rap optimizations. */
bool require_call_hl_gather = false;
// create the equivalent of // create the equivalent of
// asm volatile("" : : : "memory"); // asm volatile("" : : : "memory");
// or // or
@ -622,6 +627,10 @@ __visible int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gc
bool enable_abs_ops = false; bool enable_abs_ops = false;
bool enable_abs_attr = false; bool enable_abs_attr = false;
// hl-cfi & pointer set build pass insert.
PASS_INFO(hl_gather, "pta", 1, PASS_POS_INSERT_AFTER);
PASS_INFO(hl_cfi, "hl_gather", 1, PASS_POS_INSERT_AFTER);
PASS_INFO(rap_ret, "optimized", 1, PASS_POS_INSERT_AFTER);
PASS_INFO(rap_ret, "optimized", 1, PASS_POS_INSERT_AFTER); PASS_INFO(rap_ret, "optimized", 1, PASS_POS_INSERT_AFTER);
PASS_INFO(rap_fptr, "rap_ret", 1, PASS_POS_INSERT_AFTER); PASS_INFO(rap_fptr, "rap_ret", 1, PASS_POS_INSERT_AFTER);
PASS_INFO(rap_mark_retloc, "mach", 1, PASS_POS_INSERT_AFTER); PASS_INFO(rap_mark_retloc, "mach", 1, PASS_POS_INSERT_AFTER);
@ -643,6 +652,12 @@ __visible int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gc
for (i = 0; i < argc; ++i) { for (i = 0; i < argc; ++i) {
if (!strcmp(argv[i].key, "disable")) if (!strcmp(argv[i].key, "disable"))
continue; continue;
/* Request rap optimizations. */
if (! strcmp(argv[i].key, "opt"))
require_call_hl_gather = true;
/* Request cfi replace. */
if (! strcmp(argv[i].key, "hl_cfi"))
require_call_hl_cfi = true;
if (!strcmp(argv[i].key, "typecheck")) { if (!strcmp(argv[i].key, "typecheck")) {
char *values, *value, *saveptr; char *values, *value, *saveptr;
@ -785,6 +800,8 @@ __visible int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gc
if (!enable_type_ret) if (!enable_type_ret)
rap_fptr_pass_info.reference_pass_name = "optimized"; rap_fptr_pass_info.reference_pass_name = "optimized";
register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &hl_gather_pass_info);
register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &hl_cfi_pass_info);
register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &rap_fptr_pass_info); register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &rap_fptr_pass_info);
} }

Binary file not shown.