gpt4 book ai didi

How do I locate the gimple I want and change it?(我如何找到我想要的Gimple并更改它?)

转载 作者:bug小助手 更新时间:2023-10-25 15:56:05 34 4
gpt4 key购买 nike



I'm trying to write a pass in gcc to implementing structure splitting. And I'm having a problem that I don't know how to locate the gimple that I want and I need to change it of course.

我正在尝试用gcc写一个通道来实现结构分割。我遇到了一个问题,我不知道如何找到我想要的万向节,当然我需要改变它。


This is the origin C code and the gimple:

这是原始的C代码和Gimple:


struct node {
float _Complex al;
unsigned long long state;
};

struct reg {
int size;
struct node *node;
};
// example function
void func(int c1, int c2, int target, struct reg* r) {
for (int i = 0; i < r->size; i++) {
if (c1) {
r->node[i].state += 3;
}
}
}

void func (int c1, int c2, int target, struct reg * r)
{
{
int i;

i = 0;
goto <D.2885>;
<D.2884>:
if (c1 != 0) goto <D.2895>; else goto <D.2896>;
<D.2895>:
_1 = r->node;
_2 = (long unsigned int) i;
_3 = _2 * 16;
_4 = _1 + _3;
_5 = _4->state;
_6 = r->node;
// ...
}
}

And Here's C code and gimple that I want to change to:

下面是我想要更改的C代码和Gimple:


struct node {
float _Complex *al; // changed
unsigned long long *state; // changed
};

struct reg {
int size;
struct node *node;
};

void func(int c1, int c2, int target, struct reg* r) {
for (int i = 0; i < r->size; i++) {
if (c1) {
r->node->state[i] += 3; // changed
}
}
}

void func (int c1, int c2, int target, struct reg * r)
{
{
int i;
i = 0;
goto <D.2884>;
<D.2883>:
if (c1 != 0) goto <D.2894>; else goto <D.2895>;
<D.2894>:
_1 = r->node;
_2 = _1->state;
_3 = (long unsigned int) i;
_4 = _3 * 8;
_5 = _2 + _4;
_6 = *_5;
_7 = r->node;
// ...
}
}

And I put my pass at ipa-late-pass and declared it as a SIMPLE_IPA_PASS. Here is my code in the pass:

我将我的PASS放在IPA-LATE-PASS,并将其声明为SIMPLE_IPA_PASS。以下是我在PASS中的代码:


unsigned int
pass_struct_split::execute (function *)
{
// 1. get desire struct type
tree desire_type = get_split_types(); // `struct node`
if (!desire_type) return 0;

// 2. find the struct type and split it
struct cgraph_node *node;
FOR_EACH_DEFINED_FUNCTION(node) {
printf("===start func===\n");
struct function *func = DECL_STRUCT_FUNCTION (node->decl);
basic_block bb;
FOR_EACH_BB_FN (bb, func) {
gimple_stmt_iterator start, end;
for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) {
gimple *stmt = gsi_stmt (gsi);
// find xx = r->node
if (gimple_code(stmt) == GIMPLE_ASSIGN) {
if (gimple_assign_rhs_code(stmt) == COMPONENT_REF) {
tree lhsop = gimple_assign_lhs (stmt);
tree rhsop = gimple_assign_rhs1 (stmt);
if (TREE_CODE(TREE_TYPE(rhsop)) == POINTER_TYPE && TREE_CODE(TREE_TYPE(TREE_TYPE(rhsop))) == RECORD_TYPE) {
tree pointee_type = TREE_TYPE(TREE_TYPE(rhsop));
if (pointee_type == desire_type) {
// record start
start = gsi;
}
}
}
}
// find the end place: find xx = xx->state

}
}


}


return 0;
}

I can't locate the r->node[i].state parts. I only get the start point which I don't know if it's the right way to record the start point. And I'm stucked with locating the end point. And this is just an ASSIGN statement. I'm not sure if I can handle other kind of statements like malloc and some tricky ones. So how can I locate it? Or is there a better way or some interfaces to make it work?

我找不到r->node[i].state parts。我只得到了起点,我不知道这是否是记录起点的正确方法。我被找到终点卡住了。这只是一个ASSIGN语句。我不确定我是否能处理其他类型的语句,如malloc和一些棘手的语句。我怎么才能找到它呢?或者有更好的方法或一些接口来使其工作?


Thanks for your help!

谢谢你的帮忙!


更多回答

You're far likely to get help by asking this on the gcc internals mailing list. This is above the head of, in my estimate, 99.5% of this audience, which mostly consists of coding puzzles afficionadoes and the feelings enforcement police.

你很有可能通过在GCC内部邮件列表上问这个问题来获得帮助。据我估计,这超过了99.5%的观众,他们主要由编码谜题、情侣和情感执法警察组成。

Yeah, I tried it this morning and yesterday. But no one has answered me yet.

是的,我今天早上和昨天都试过了。但还没有人回答我的问题。

I see that you sent it to gcc-help. Did you try gcc? Based on gcc.gnu.org/lists.html I would say that gcc, not gcc-help, would be more appropriate.

我看到你把它寄给GCC了--救命。你试过GCC吗?根据gcc.gnu.org/lists.html,我认为GCC,而不是GCC-帮助更合适。

优秀答案推荐
更多回答

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com