This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [tree-ssa] Lowering of VLA's, part 2
Hello,
> > * gimplify.c (struct tree_p_list): New type.
> > (join_tree_p_list, add_tree_p_list, free_tree_p_list,
> > build_stack_save_restore, prepend_to_exit_gotos): New functions.
>
> Use a TRY_FINALLY_EXPR instead.
here it is.
Zdenek
Index: builtins.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/builtins.c,v
retrieving revision 1.152.2.31
diff -c -3 -p -r1.152.2.31 builtins.c
*** builtins.c 26 Aug 2003 22:29:33 -0000 1.152.2.31
--- builtins.c 27 Aug 2003 17:31:55 -0000
*************** expand_builtin (tree exp, rtx target, rt
*** 5026,5032 ****
case BUILT_IN_STACK_ALLOC:
expand_stack_alloc (TREE_VALUE (arglist),
TREE_VALUE (TREE_CHAIN (arglist)));
! return NULL_RTX;
case BUILT_IN_FFS:
case BUILT_IN_FFSL:
--- 5026,5039 ----
case BUILT_IN_STACK_ALLOC:
expand_stack_alloc (TREE_VALUE (arglist),
TREE_VALUE (TREE_CHAIN (arglist)));
! return const0_rtx;
!
! case BUILT_IN_STACK_SAVE:
! return expand_stack_save ();
!
! case BUILT_IN_STACK_RESTORE:
! expand_stack_restore (TREE_VALUE (arglist));
! return const0_rtx;
case BUILT_IN_FFS:
case BUILT_IN_FFSL:
Index: builtins.def
===================================================================
RCS file: /cvs/gcc/gcc/gcc/builtins.def,v
retrieving revision 1.29.2.21
diff -c -3 -p -r1.29.2.21 builtins.def
*** builtins.def 26 Aug 2003 22:29:33 -0000 1.29.2.21
--- builtins.def 27 Aug 2003 17:31:55 -0000
*************** DEF_GCC_BUILTIN (BUILT_IN_RETURN_
*** 318,323 ****
--- 318,325 ----
DEF_GCC_BUILTIN (BUILT_IN_SAVEREGS, "saveregs", BT_FN_PTR_VAR, ATTR_NULL)
DEF_GCC_BUILTIN (BUILT_IN_SETJMP, "setjmp", BT_FN_INT_PTR, ATTR_NULL)
DEF_GCC_BUILTIN (BUILT_IN_STACK_ALLOC, "stack_alloc", BT_FN_VOID_PTR_SIZE, ATTR_NULL)
+ DEF_GCC_BUILTIN (BUILT_IN_STACK_SAVE, "stack_save", BT_FN_PTR, ATTR_NULL)
+ DEF_GCC_BUILTIN (BUILT_IN_STACK_RESTORE, "stack_restore", BT_FN_VOID_PTR, ATTR_NULL)
DEF_GCC_BUILTIN (BUILT_IN_STDARG_START, "stdarg_start", BT_FN_VOID_VALIST_REF_VAR, ATTR_NULL)
DEF_EXT_LIB_BUILTIN (BUILT_IN_STRFMON, "strfmon", BT_FN_SSIZE_STRING_SIZE_CONST_STRING_VAR, ATTR_FORMAT_STRFMON_3_4)
DEF_LIB_BUILTIN (BUILT_IN_STRFTIME, "strftime", BT_FN_SIZE_STRING_SIZE_CONST_STRING_CONST_PTR, ATTR_FORMAT_STRFTIME_3_0)
Index: stmt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/stmt.c,v
retrieving revision 1.267.2.28
diff -c -3 -p -r1.267.2.28 stmt.c
*** stmt.c 26 Aug 2003 22:29:34 -0000 1.267.2.28
--- stmt.c 27 Aug 2003 17:33:35 -0000
*************** expand_stack_alloc (tree alloc, tree t_s
*** 4059,4069 ****
type = TREE_TYPE (var);
- /* Record the stack pointer on entry to block, if have
- not already done so. */
- do_pending_stack_adjust ();
- save_stack_pointer ();
-
/* In function-at-a-time mode, variable_size doesn't expand this,
so do it now. */
if (TREE_CODE (type) == ARRAY_TYPE && TYPE_DOMAIN (type))
--- 4025,4030 ----
*************** expand_stack_alloc (tree alloc, tree t_s
*** 4087,4092 ****
--- 4048,4073 ----
DECL_ALIGN (var) = BIGGEST_ALIGNMENT;
#endif
DECL_USER_ALIGN (var) = 0;
+ }
+
+ /* Emit code to save the current value of stack. */
+ rtx
+ expand_stack_save ()
+ {
+ rtx ret = NULL_RTX;
+
+ do_pending_stack_adjust ();
+ emit_stack_save (SAVE_BLOCK, &ret, NULL_RTX);
+ return ret;
+ }
+
+ /* Emit code to restore the current value of stack. */
+ void
+ expand_stack_restore (tree var)
+ {
+ rtx sa = DECL_RTL (var);
+
+ emit_stack_restore (SAVE_BLOCK, sa, NULL_RTX);
}
/* Emit code to perform the initialization of a declaration DECL. */
Index: tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.h,v
retrieving revision 1.342.2.91
diff -c -3 -p -r1.342.2.91 tree.h
*** tree.h 27 Aug 2003 04:31:36 -0000 1.342.2.91
--- tree.h 27 Aug 2003 17:42:05 -0000
*************** extern int expand_exit_loop_top_cond (st
*** 3093,3098 ****
--- 3093,3100 ----
extern int expand_exit_something (void);
extern void expand_stack_alloc (tree, tree);
+ extern rtx expand_stack_save (void);
+ extern void expand_stack_restore (tree);
extern void expand_return (tree);
extern int optimize_tail_recursion (tree, rtx);
extern void expand_start_bindings_and_block (int, tree);
Index: gimplify.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/gimplify.c,v
retrieving revision 1.1.2.74
diff -c -3 -p -r1.1.2.74 gimplify.c
*** gimplify.c 26 Aug 2003 22:21:16 -0000 1.1.2.74
--- gimplify.c 27 Aug 2003 21:27:08 -0000
*************** static tree gimple_boolify (tree);
*** 89,98 ****
--- 89,100 ----
static void gimplify_conversion (tree *);
static int gimplify_init_constructor (tree *, tree *, int);
static void gimplify_minimax_expr (tree *, tree *, tree *);
+ static void build_stack_save_restore (tree *, tree *);
static struct gimplify_ctx
{
tree current_bind_expr;
+ bool save_stack;
tree temps;
tree conditional_cleanups;
int conditions;
*************** gimplify_bind_expr (tree *expr_p, tree *
*** 879,887 ****
--- 881,906 ----
{
tree bind_expr = *expr_p;
tree temp = voidify_wrapper_expr (bind_expr);
+ bool old_save_stack = gimplify_ctxp->save_stack;
gimple_push_bind_expr (bind_expr);
+ gimplify_ctxp->save_stack = false;
+
gimplify_stmt (&BIND_EXPR_BODY (bind_expr));
+ if (gimplify_ctxp->save_stack)
+ {
+ tree stack_save, stack_restore;
+
+ /* Save stack on entry and restore it on exit. Add a try_finally
+ block to achieve this. */
+ build_stack_save_restore (&stack_save, &stack_restore);
+ add_tree (stack_save, pre_p);
+ BIND_EXPR_BODY (bind_expr) = build (TRY_FINALLY_EXPR, void_type_node,
+ BIND_EXPR_BODY (bind_expr),
+ stack_restore);
+ }
+
+ gimplify_ctxp->save_stack = old_save_stack;
gimple_pop_bind_expr ();
if (temp)
*************** gimplify_call_expr (tree *expr_p, tree *
*** 1584,1589 ****
--- 1603,1613 ----
return;
}
+ /* If it is allocation of stack, record the need to restore the memory
+ when the enclosing bind_expr is exited. */
+ if (DECL_FUNCTION_CODE (decl) == BUILT_IN_STACK_ALLOC)
+ gimplify_ctxp->save_stack = true;
+
new = simplify_builtin (*expr_p, gimple_test_f == is_gimple_stmt);
if (new && new != *expr_p)
*************** gimplify_target_expr (tree *expr_p, tree
*** 2930,2933 ****
--- 2954,2975 ----
}
*expr_p = temp;
+ }
+
+ /* Prepare calls to builtins to SAVE and RESTORE the stack as well as temporary
+ through that they comunicate. */
+ static void
+ build_stack_save_restore (tree *save, tree *restore)
+ {
+ tree save_call, tmp_var;
+
+ save_call = build_function_call_expr (
+ implicit_built_in_decls[BUILT_IN_STACK_SAVE],
+ NULL_TREE);
+ tmp_var = create_tmp_var (ptr_type_node, "saved_stack");
+
+ *save = build (MODIFY_EXPR, ptr_type_node, tmp_var, save_call);
+ *restore = build_function_call_expr (
+ implicit_built_in_decls[BUILT_IN_STACK_RESTORE],
+ tree_cons (NULL_TREE, tmp_var, NULL_TREE));
}