GCC plugin with method was declared inside class
-
19-02-2021 - |
문제
I am developing an GCC plugin to process AST in SSA form. I create a callback run everytime after SSA form of function was compiled.
Here is my code
char* get_name_node(tree node) {
// return string represent node name
}
void execute_plugin_pass() {
printf("%s\n", get_name_node(cfun->decl));
}
struct opt_pass plugin_pass =
{
GIMPLE_PASS,
"plugin_pass",
0,
execute_plugin_pass,
NULL,
NULL,
0,
TV_PLUGIN_RUN,
PROP_gimple_any,
0,
0,
0,
0
};
extern "C" int
plugin_init(plugin_name_args* info, plugin_gcc_version* ver)
{
struct register_pass_info pass_info;
pass_info.reference_pass_name = where;
pass_info.pass = pass;
pass_info.ref_pass_instance_number = 0;
pass_info.pos_op = PASS_POS_INSERT_AFTER;
register_callback("plugin", PLUGIN_PASS_MANAGER_SETUP, NULL, &pass_info);
return 0;
}
But above code not run for method of class which was declare inside class declaration For example, with this code
class A {
void method1();
void method2() {
// run some code here
}
};
void A::method1() {
// run some code here
}
My plugin only run for method1, but dont run for method2
At begining, i think this problems is because method2() will be considered as inline function, so i add option -fno-inline when run plugin. But it doesn't work
Can anyone help me?
올바른 솔루션이 없습니다
다른 팁
Probably, the issue is where to insert your pass in the executed passes. Remember that the set and order of executed GCC passes vary with the optimization (so is different with -O0
, -O1
, -O2
, ...). I don't understand where you are inserting it.
I also sometimes have the same issue of choosing where should I insert my pass. I often have a trial and error approach. Look into file gcc/passes.c
of the GCC source tree.
If you need the SSA form of Gimple, consider inserting after the "ssa"
pass or maybe after "phiopt"
.
If you don't need SSA, consider inserting after "cfg"
.
Out of curiosity, could you explain what your GCC plugin is doing?
Did you consider using GCC MELT (MELT is a high level domain specific language to code GCC extensions) for your work?