Hi all,
I've been trying to add a pass in GCC 4.0.2 which is targeted for a
MIPS-like architecture (with small changes). The purpose of the pass is
to add prefetch instructions for some array references.
After I identify a MODIFY_EXPR which is a read from an array location,
I'm having trouble getting gcc to insert a prefetch instruction for it.
I've been trying to follow the same pattern as in
tree-ssa-loop-prefetch.c, which I got from the gcc-svn version. However,
it doesn't work, and Im not sure if it's because of the differences in
versions, or because I'm doing something wrong.
The output I get when I compile a program is:
===
In force_gimple_operand_bsi, inserting statements: D.1109_4 = &B[i_8];
The prefetch instr generated is: __builtin_prefetch (D.1109_4, 0);
done inserting
XMTS.simple32.c:6: internal compiler error: tree check: expected
ssa_name, have var_decl in verify_ssa, at tree-ssa.c:679
===
Here is the code from my pass. It's ran right before pass_loop, while in
SSA.
===
case MODIFY_EXPR:
lhs = TREE_OPERAND (stmt, 0);
rhs = TREE_OPERAND (stmt, 1);
if (TREE_CODE (rhs) == ARRAY_REF) {
/* Determine the address to prefetch. */
addr_base = build_fold_addr_expr_with_type (rhs, ptr_type_node);
addr_base = force_gimple_operand_bsi (&si, unshare_expr
(addr_base), true, NULL);
delta = 0;
addr = fold( build2 (PLUS_EXPR, ptr_type_node,
addr_base, build_int_cst (ptr_type_node, delta)));
addr = force_gimple_operand_bsi (&si, unshare_expr (addr), true,
NULL);
/* Create the prefetch instruction. */
write_p = integer_zero_node;
params = tree_cons (NULL_TREE, addr,
tree_cons (NULL_TREE, write_p, NULL_TREE));
prefetch = build_function_call_expr
(built_in_decls[BUILT_IN_PREFETCH],
params);
fprintf(stderr,"\nThe prefetch instr generated is: ");
print_generic_stmt(stderr,prefetch,0);
/* Insert the prefetch instruction. */
bsi_insert_before (&si, prefetch, BSI_SAME_STMT);
fprintf(stderr,"done inserting\n");
}
====
and I added the function:
===
tree
force_gimple_operand_bsi (block_stmt_iterator *bsi, tree expr,
bool simple_p, tree var)
{
tree stmts;
expr = force_gimple_operand (expr, &stmts, simple_p, var);
if (stmts) {
fprintf(stderr,"In force_gimple_operand_bsi, inserting statements: ");
print_generic_stmt(stderr,stmts,0);
fprintf(stderr,"\n");
bsi_insert_before (bsi, stmts, BSI_SAME_STMT);
}
return expr;
}
===
Any help would be greatly appreciated.
Thanks,
George Caragea