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

C 给定一个有两个参数的GIMPLE调用语句,我想添加第三个参数,如何添加?,c,gcc,gimple,C,Gcc,Gimple,我必须做一些GIMPLE_CALL语句操作。这个GIMPLE_调用将有两个参数,例如:foo(a,b)。我的目标是将此方法更改为具有三个参数的不同方法,例如zoo(a、b、c) 在我当前的方法中,GCC在编译示例源程序时崩溃 当我所做的只是替换方法名(即不更改参数编号)时,我的代码就会工作 此外,我无法找到任何专门用于添加/删除GIMPLE_调用参数号的方法。这让我相信这可能不是正确的方法 代码: 看起来,使用这种方法只能将num_ops调整为较小的值 gimple\u set\u num\u

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

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

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

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

代码:


看起来,使用这种方法只能将
num_ops
调整为较小的值

gimple\u set\u num\u ops
是一个简单的设置程序,它不分配存储:

static inline void
gimple_set_num_ops (gimple *gs, unsigned num_ops)
{
  gs->num_ops = num_ops;
}
您必须创建另一个GIMPLE语句

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

/*将GSI指向的赋值语句的RHS设置为代码为
操作数OP1、OP2和OP3。
注:GSI指出的声明可能会重新分配,如果
没有足够的操作数插槽*/
无效的
gimple_assign_set_rhs_与_ops(gimple_stmt_迭代器*gsi,枚举树代码,
树op1、树op2、树op3)
{
未签名的新操作=获取操作(代码);
gimple*stmt=gsi\U stmt(*gsi);
gimple*old_stmt=stmt;
/*如果新代码需要更多操作数,请分配新语句*/
如果(gimple_num_ops(stmt)1)
gimple\U assign\U set\U rhs2(stmt,op2);
如果(新的轨道交通运行>2)
gimple\U assign\U set\U rhs3(stmt,op3);
如果(stmt!=旧的stmt)
gsi_替换(gsi、stmt、false);
}
static inline void
gimple_set_num_ops (gimple *gs, unsigned num_ops)
{
  gs->num_ops = num_ops;
}
/* 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);
}