+/* Callback of walk_aliased_vdefs. Flags that it has been invoked to the
+ boolean variable pointed to by DATA. */
+
+static bool
+mark_modified (ao_ref *ao ATTRIBUTE_UNUSED, tree vdef ATTRIBUTE_UNUSED,
+ void *data)
+{
+ bool *b = (bool *) data;
+ *b = true;
+ return true;
+}
+
+/* If OP reffers to value of function parameter, return
+ the corresponding parameter. */
+
+static tree
+unmodified_parm (gimple stmt, tree op)
+{
+ /* SSA_NAME referring to parm default def? */
+ if (TREE_CODE (op) == SSA_NAME
+ && SSA_NAME_IS_DEFAULT_DEF (op)
+ && TREE_CODE (SSA_NAME_VAR (op)) == PARM_DECL)
+ return SSA_NAME_VAR (op);
+ /* Non-SSA parm reference? */
+ if (TREE_CODE (op) == PARM_DECL)
+ {
+ bool modified = false;
+
+ ao_ref refd;
+ ao_ref_init (&refd, op);
+ walk_aliased_vdefs (&refd, gimple_vuse (stmt), mark_modified, &modified,
+ NULL);
+ if (!modified)
+ return op;
+ }
+ /* Assignment from a parameter? */
+ if (TREE_CODE (op) == SSA_NAME
+ && !SSA_NAME_IS_DEFAULT_DEF (op)
+ && gimple_assign_single_p (SSA_NAME_DEF_STMT (op)))
+ return unmodified_parm (SSA_NAME_DEF_STMT (op),
+ gimple_assign_rhs1 (SSA_NAME_DEF_STMT (op)));
+ return NULL;
+}
+