带有方法的 GCC 插件在类中声明

发布于 2024-12-13 10:58:11 字数 1182 浏览 0 评论 0原文

我正在开发一个 GCC 插件来处理 SSA 形式的 AST。 每次编译 SSA 形式的函数后,我都会创建一个回调运行。

这是我的代码

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;   
}

,但上面的代码未针对在类声明内声明的类的方法运行 例如,使用此代码

class A {
    void method1();
    void method2() {
         // run some code here
    }
};

void A::method1() {
    // run some code here
}

我的插件仅运行method1,但不运行method2

首先,我认为这个问题是因为method2()将被视为内联函数,所以我在运行插件时添加选项-fno-inline。但这不起作用

有人能帮助我吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

闻呓 2024-12-20 10:58:11

问题可能在于将您的通行证插入到已执行的通行证中的何处。请记住,执行的 GCC 传递的集合和顺序随优化而变化(因此与 -O0-O1-O2、. ..)。我不明白你把它插入哪里。

有时我也会遇到同样的问题,即选择将通票插入何处。我经常采用反复试验的方法。查看 GCC 源代码树的文件 gcc/passes.c

如果您需要 Gimple 的 SSA 形式,请考虑在 "ssa" 传递之后或在 "phiopt" 之后插入。

如果您不需要 SSA,请考虑在 "cfg" 之后插入。

出于好奇,您能解释一下您的 GCC 插件是做什么的吗?

您是否考虑过在您的工作中使用 GCC MELT(MELT 是一种高级领域特定语言,用于编码 GCC 扩展)?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文