You can assign the "a" TREE_NODE to a temporary variable and call make_ssa_name on the temp, allowing you to use it as an argument to a GIMPLE_CALL. Here is the function I use for that purpose:
/* Create a GIMPLE statement assigning a reference to a temporary variable, add that statement at the iterator gsi, then return the temporary variable. */ static tree assign_ref_to_tmp (gimple_stmt_iterator *gsi, tree ref, const char *tmp_prefix) { tree tmp = create_tmp_var (TREE_TYPE (ref), tmp_prefix); /* Construct an assign statement: tmp = ref; */ gimple assign_stmt = gimple_build_assign (tmp, ref); /* The left side of the assignment should be an SSA_NAME, but we can't create the SSA_NAME until after we build the assign statement. */ gimple_assign_set_lhs(assign_stmt, make_ssa_name (tmp, assign_stmt)); gsi_insert_before (gsi, assign_stmt, GSI_SAME_STMT); return gimple_assign_lhs (assign_stmt); } I can't verify that this will work in all cases (I'm far from an expert), but I've successfully compiled a lot of code with this transformation. --Justin On Wed, Dec 23, 2009 at 5:19 PM, Aravinda <aravindakida...@gmail.com> wrote: > Hi, > > After the tree-loop pass, I need to perform some analysis on the loop > and insert a "gimple function call statement" before the loop body. > The function call looks like, > > foo(a, 1, 1); for a loop that looks like, > > for (i = 0; i < 20; i ++) { > a[i]++; > } > > When compiled with -O2, after the tree loop init, the loops have SSA > names for variables. Based on the analysis I do on the loop, I get a > TREE_NODE for the variable 'a', and two integer_one_node s. > I have trouble constructing the gimple_call_statement and adding it > before the loop_body. I am running into 'expected ssa_name have > var_decl' error. I am not sure I can use make_ssa_name for the > TREE_NODE of variable 'a' since I am yet to build a gimple_stmt that > will contain this variable. > > How could I insert a call statement after a loop analysis ? > > Thanks, > Aravinda >