首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >给定一个有两个参数的GIMPLE Call语句,我想添加第三个参数,如何添加?

给定一个有两个参数的GIMPLE Call语句,我想添加第三个参数,如何添加?
EN

Stack Overflow用户
提问于 2019-05-06 21:53:58
回答 1查看 97关注 0票数 4

我必须做一些GIMPLE_CALL语句操作。此GIMPLE_CALL将有两个参数,例如: foo(a,b)。我的目标是将此方法更改为具有三个参数的不同方法,例如zoo(a,b,c)

在我目前的方法中,GCC在编译示例源程序时崩溃。

当我所做的只是替换方法名(即不改变参数编号)时,我的代码就可以工作了。

此外,我也找不到任何专门用于为GIMPLE_CALL添加/删除参数编号的方法。这让我相信这可能不是正确的方法。

代码:

代码语言:javascript
复制
   //Getting the current number of  Call Arguments from target GIMPLE               
   //statememt
   unsigned num_of_ops = gimple_call_num_args(stmt);

   //Replace the method name to a new Method   
   gimple_call_set_fndecl(stmt, new_method);


   //We need to increment total number of call arguments by 1
   //Total numer of arguments are, Number of CALL Arguments + 3
   //You can confirm this in definitions of gimple_call_num_args() and 
   //gimple_call_set_arg()
   gimple_set_num_ops(stmt,num_of_ops+3+1);


   //Add the new argument
   gimple_call_set_arg(stmt, num_of_ops, third_argument);
   update_stmt (stmt);
EN

回答 1

Stack Overflow用户

发布于 2019-05-07 00:50:36

似乎,您只能使用此方法将num_ops调整为较小的值。

gimple_set_num_ops是一个简单的设置器,它不分配存储:

代码语言:javascript
复制
static inline void
gimple_set_num_ops (gimple *gs, unsigned num_ops)
{
  gs->num_ops = num_ops;
}

您必须创建另一个GIMPLE语句。

我认为,在GCC代码库中的这种用法解决了与您(来自gcc/gimple.c)完全相同的问题:

代码语言:javascript
复制
/* Set the RHS of assignment statement pointed-to by GSI to CODE with
   operands OP1, OP2 and OP3.

   NOTE: The statement pointed-to by GSI may be reallocated if it
   did not have enough operand slots.  */

void
gimple_assign_set_rhs_with_ops (gimple_stmt_iterator *gsi, enum tree_code code,
                tree op1, tree op2, tree op3)
{
  unsigned new_rhs_ops = get_gimple_rhs_num_ops (code);
  gimple *stmt = gsi_stmt (*gsi);
  gimple *old_stmt = stmt;

  /* If the new CODE needs more operands, allocate a new statement.  */
  if (gimple_num_ops (stmt) < new_rhs_ops + 1)
    {
      tree lhs = gimple_assign_lhs (old_stmt);
      stmt = gimple_alloc (gimple_code (old_stmt), new_rhs_ops + 1);
      memcpy (stmt, old_stmt, gimple_size (gimple_code (old_stmt)));
      gimple_init_singleton (stmt);

      /* The LHS needs to be reset as this also changes the SSA name
     on the LHS.  */
      gimple_assign_set_lhs (stmt, lhs);
    }

  gimple_set_num_ops (stmt, new_rhs_ops + 1);
  gimple_set_subcode (stmt, code);
  gimple_assign_set_rhs1 (stmt, op1);
  if (new_rhs_ops > 1)
    gimple_assign_set_rhs2 (stmt, op2);
  if (new_rhs_ops > 2)
    gimple_assign_set_rhs3 (stmt, op3);
  if (stmt != old_stmt)
    gsi_replace (gsi, stmt, false);
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56006656

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档