This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [tree-ssa] Lowering of VLA's, part 2


Hello,

> The stack save should also go inside the BIND_EXPR, but before the
> TRY_FINALLY_EXPR.
> 
> Also, you need to make sure that you don't add these again if the BIND_EXPR
> gets gimplified again.

done. Just retesting it, ok if it passes?

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	28 Aug 2003 17:50:49 -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	28 Aug 2003 17:50:49 -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: gimplify.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/gimplify.c,v
retrieving revision 1.1.2.75
diff -c -3 -p -r1.1.2.75 gimplify.c
*** gimplify.c	27 Aug 2003 21:30:21 -0000	1.1.2.75
--- gimplify.c	28 Aug 2003 17:50:49 -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,908 ----
  {
    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);
+       BIND_EXPR_BODY (bind_expr) =
+ 	  build (COMPOUND_EXPR, void_type_node,
+ 		 stack_save,
+ 		 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 ****
--- 1605,1621 ----
  	  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;
+ 
+       /* If it is restore of the stack, reset it, since it means we are
+ 	 regimplifying the bind_expr.  Note that we use the fact that
+ 	 for try_finally_expr, try part is processed first.  */
+       if (DECL_FUNCTION_CODE (decl) == BUILT_IN_STACK_RESTORE)
+ 	gimplify_ctxp->save_stack = false;
+ 
        new = simplify_builtin (*expr_p, gimple_test_f == is_gimple_stmt);
  
        if (new && new != *expr_p)
*************** gimplify_target_expr (tree *expr_p, tree
*** 2882,2885 ****
--- 2914,2936 ----
      }
  
    *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));
  }
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	28 Aug 2003 17:50:49 -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))
--- 4059,4064 ----
*************** expand_stack_alloc (tree alloc, tree t_s
*** 4087,4092 ****
--- 4082,4107 ----
    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	28 Aug 2003 17:50:49 -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 Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]