I noticed that if I try not to mark a variable as escaping, we don't
get the function
call to have V_MAY_DEF for that variable.
For an example in this Fortran code:
function i()
INTEGER :: i
INTEGER :: t
call f(t)
t = 2;
call g()
if (t .ne. 2) then
call abort ()
end if
i = t
end function
t cannot escape from the function as the variable is not marked as a
TARGET.
Is there a way to mark the function call for f as clobbering t but not
escaping?
Or do I have to modify tree-ssa-operands code to do it correctly?
PS I attached the patch which I am currently working on to make the
variable as not
being call clobbered. I use an attribute instead of a bit in the
decls' structure
since it seems only to happen for Fortran code.
Thanks,
Andrew Pinski
Index: fortran/trans-decl.c
===================================================================
--- fortran/trans-decl.c (revision 109033)
+++ fortran/trans-decl.c (working copy)
@@ -447,6 +447,7 @@ gfc_finish_decl (tree decl, tree init)
}
+static GTY(()) tree noescape_attribute = NULL_TREE;
/* Apply symbol attributes to a variable, and add it to the function scope. */
@@ -457,13 +458,26 @@ gfc_finish_var_decl (tree decl, gfc_symb
This is the equivalent of the TARGET variables.
We also need to set this if the variable is passed by reference in a
CALL statement. */
-
+
/* Set DECL_VALUE_EXPR for Cray Pointees. */
if (sym->attr.cray_pointee)
gfc_finish_cray_pointee (decl, sym);
if (sym->attr.target)
TREE_ADDRESSABLE (decl) = 1;
+
+ /* Add the attribute to tell the middle-end this variable can never
+ escape. */
+ if (!sym->attr.target && !sym->attr.cray_pointee)
+ {
+ if (noescape_attribute == NULL_TREE)
+ {
+ tree noescape = get_identifier ("no escape");
+ noescape_attribute = build_tree_list (noescape, NULL_TREE);
+ }
+ DECL_ATTRIBUTES (decl) = noescape_attribute;
+ }
+
/* If it wasn't used we wouldn't be getting it. */
TREE_USED (decl) = 1;
Index: tree-ssa-structalias.c
===================================================================
--- tree-ssa-structalias.c (revision 109033)
+++ tree-ssa-structalias.c (working copy)
@@ -2965,7 +2965,11 @@ update_alias_info (tree stmt, struct ali
unsigned i;
EXECUTE_IF_SET_IN_BITMAP (addr_taken, 0, i, bi)
- mark_call_clobbered (referenced_var (i));
+ {
+ tree decl = referenced_var (i);
+ if (!lookup_attribute ("no escape", DECL_ATTRIBUTES (decl)))
+ mark_call_clobbered (decl);
+ }
}
}