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]

gimple va_arg for stormy16


Tested as for c4x.


r~


        * config/stormy16/stormy16-protos.h (xstormy16_expand_builtin_va_arg):
        Remove.
        * config/stormy16/stormy16.c (TARGET_GIMPLIFY_VA_ARG_EXPR): New.
        (xstormy16_gimplify_va_arg_expr): Rewrite from
        xstormy16_expand_builtin_va_arg.
        * config/stormy16/stormy16.h (EXPAND_BUILTIN_VA_ARG): Remove.

Index: config/stormy16/stormy16-protos.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/stormy16/stormy16-protos.h,v
retrieving revision 1.16
diff -u -p -c -r1.16 stormy16-protos.h
*** config/stormy16/stormy16-protos.h	25 Jan 2004 22:20:15 -0000	1.16
--- config/stormy16/stormy16-protos.h	9 Jul 2004 09:54:23 -0000
*************** extern rtx xstormy16_function_arg
*** 39,45 ****
  
  #if defined (TREE_CODE) && defined (RTX_CODE)
  extern void xstormy16_expand_builtin_va_start (tree, rtx);
- extern rtx xstormy16_expand_builtin_va_arg (tree, tree);
  extern void xstormy16_initialize_trampoline (rtx, rtx, rtx);
  extern rtx xstormy16_function_value (tree, tree);
  #endif
--- 39,44 ----
Index: config/stormy16/stormy16.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/stormy16/stormy16.c,v
retrieving revision 1.61
diff -u -p -c -r1.61 stormy16.c
*** config/stormy16/stormy16.c	22 Jun 2004 03:06:55 -0000	1.61
--- config/stormy16/stormy16.c	9 Jul 2004 09:54:23 -0000
*************** Boston, MA 02111-1307, USA.  */
*** 46,51 ****
--- 46,52 ----
  #include "target-def.h"
  #include "tm_p.h"
  #include "langhooks.h"
+ #include "tree-gimple.h"
  
  static rtx emit_addhi3_postreload (rtx, rtx, rtx);
  static void xstormy16_asm_out_constructor (rtx, int);
*************** xstormy16_expand_builtin_va_start (tree 
*** 1306,1323 ****
     of type va_list as a tree, TYPE is the type passed to va_arg.
     Note:  This algorithm is documented in stormy-abi.  */
     
! rtx
! xstormy16_expand_builtin_va_arg (tree valist, tree type)
  {
    tree f_base, f_count;
    tree base, count;
!   rtx count_rtx, addr_rtx, r;
!   rtx lab_gotaddr, lab_fromstack;
!   tree t;
    int size, size_of_reg_args, must_stack;
!   tree size_tree, count_plus_size;
!   rtx count_plus_size_rtx;
!   
    f_base = TYPE_FIELDS (va_list_type_node);
    f_count = TREE_CHAIN (f_base);
    
--- 1307,1323 ----
     of type va_list as a tree, TYPE is the type passed to va_arg.
     Note:  This algorithm is documented in stormy-abi.  */
     
! static tree
! xstormy16_expand_builtin_va_arg (tree valist, tree type, tree *pre_p,
! 				 tree *post_p ATTRIBUTE_UNUSED)
  {
    tree f_base, f_count;
    tree base, count;
!   tree count_tmp, addr, t;
!   tree lab_gotaddr, lab_fromstack;
    int size, size_of_reg_args, must_stack;
!   tree size_tree;
! 
    f_base = TYPE_FIELDS (va_list_type_node);
    f_count = TREE_CHAIN (f_base);
    
*************** xstormy16_expand_builtin_va_arg (tree va
*** 1327,1355 ****
  
    must_stack = MUST_PASS_IN_STACK (TYPE_MODE (type), type);
    size_tree = round_up (size_in_bytes (type), UNITS_PER_WORD);
    
    size_of_reg_args = NUM_ARGUMENT_REGISTERS * UNITS_PER_WORD;
  
!   count_rtx = expand_expr (count, NULL_RTX, HImode, EXPAND_NORMAL);
!   lab_gotaddr = gen_label_rtx ();
!   lab_fromstack = gen_label_rtx ();
!   addr_rtx = gen_reg_rtx (Pmode);
  
    if (!must_stack)
      {
!       count_plus_size = build (PLUS_EXPR, TREE_TYPE (count), count, size_tree);
!       count_plus_size_rtx = expand_expr (count_plus_size, NULL_RTX, HImode, EXPAND_NORMAL);
!       emit_cmp_and_jump_insns (count_plus_size_rtx, GEN_INT (size_of_reg_args),
! 			       GTU, const1_rtx, HImode, 1, lab_fromstack);
!   
!       t = build (PLUS_EXPR, ptr_type_node, base, count);
!       r = expand_expr (t, addr_rtx, Pmode, EXPAND_NORMAL);
!       if (r != addr_rtx)
! 	emit_move_insn (addr_rtx, r);
! 
!       emit_jump_insn (gen_jump (lab_gotaddr));
!       emit_barrier ();
!       emit_label (lab_fromstack);
      }
    
    /* Arguments larger than a word might need to skip over some
--- 1327,1364 ----
  
    must_stack = MUST_PASS_IN_STACK (TYPE_MODE (type), type);
    size_tree = round_up (size_in_bytes (type), UNITS_PER_WORD);
+   gimplify_expr (&size_tree, pre_p, NULL, is_gimple_val, fb_rvalue);
    
    size_of_reg_args = NUM_ARGUMENT_REGISTERS * UNITS_PER_WORD;
  
!   count_tmp = get_initialized_tmp_var (count, pre_p, NULL);
!   lab_gotaddr = create_artificial_label ();
!   lab_fromstack = create_artificial_label ();
!   addr = create_tmp_var (ptr_type_node, NULL);
  
    if (!must_stack)
      {
!       tree r;
! 
!       t = fold_convert (TREE_TYPE (count), size_tree);
!       t = build (PLUS_EXPR, TREE_TYPE (count), count_tmp, t);
!       r = fold_convert (TREE_TYPE (count), size_int (size_of_reg_args));
!       t = build (GT_EXPR, boolean_type_node, t, r);
!       t = build (COND_EXPR, void_type_node, t,
! 		 build (GOTO_EXPR, void_type_node, lab_fromstack),
! 		 NULL);
!       gimplify_and_add (t, pre_p);
!   
!       t = fold_convert (ptr_type_node, count_tmp);
!       t = build (PLUS_EXPR, ptr_type_node, base, t);
!       t = build (MODIFY_EXPR, void_type_node, addr, t);
!       gimplify_and_add (t, pre_p);
! 
!       t = build (GOTO_EXPR, void_type_node, lab_gotaddr);
!       gimplify_and_add (t, pre_p);
! 
!       t = build (LABEL_EXPR, void_type_node, lab_fromstack);
!       gimplify_and_add (t, pre_p);
      }
    
    /* Arguments larger than a word might need to skip over some
*************** xstormy16_expand_builtin_va_arg (tree va
*** 1358,1394 ****
    size = PUSH_ROUNDING (int_size_in_bytes (type));
    if (size > 2 || size < 0 || must_stack)
      {
!       rtx lab_notransition = gen_label_rtx ();
!       emit_cmp_and_jump_insns (count_rtx, GEN_INT (NUM_ARGUMENT_REGISTERS 
! 						   * UNITS_PER_WORD),
! 			       GEU, const1_rtx, HImode, 1, lab_notransition);
!       
!       t = build (MODIFY_EXPR, TREE_TYPE (count), count, 
! 		 build_int_2 (NUM_ARGUMENT_REGISTERS * UNITS_PER_WORD, 0));
!       TREE_SIDE_EFFECTS (t) = 1;
!       expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
!       
!       emit_label (lab_notransition);
!     }
  
!   t = build (PLUS_EXPR, sizetype, size_tree,
! 	     build_int_2 ((- NUM_ARGUMENT_REGISTERS * UNITS_PER_WORD
! 			   + INCOMING_FRAME_SP_OFFSET),
! 			  -1));
!   t = build (PLUS_EXPR, TREE_TYPE (count), count, fold (t));
    t = build (MINUS_EXPR, TREE_TYPE (base), base, t);
!   r = expand_expr (t, addr_rtx, Pmode, EXPAND_NORMAL);
!   if (r != addr_rtx)
!     emit_move_insn (addr_rtx, r);
! 	     
!   emit_label (lab_gotaddr);
  
!   count_plus_size = build (PLUS_EXPR, TREE_TYPE (count), count, size_tree);
!   t = build (MODIFY_EXPR, TREE_TYPE (count), count, count_plus_size);
!   TREE_SIDE_EFFECTS (t) = 1;
!   expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
  
!   return addr_rtx;
  }
  
  /* Initialize the variable parts of a trampoline.  ADDR is an RTX for
--- 1367,1404 ----
    size = PUSH_ROUNDING (int_size_in_bytes (type));
    if (size > 2 || size < 0 || must_stack)
      {
!       tree r, u;
! 
!       r = size_int (NUM_ARGUMENT_REGISTERS * UNITS_PER_WORD);
!       u = build (MODIFY_EXPR, void_type_node, count_tmp, r);
  
!       t = fold_convert (TREE_TYPE (count), r);
!       t = build (GE_EXPR, boolean_type_node, count_tmp, t);
!       t = build (COND_EXPR, void_type_node, t, NULL, u);
!       gimplify_and_add (t, pre_p);
!     }
! 
!   t = size_int (NUM_ARGUMENT_REGISTERS * UNITS_PER_WORD
! 		- INCOMING_FRAME_SP_OFFSET);
!   t = fold_convert (TREE_TYPE (count), t);
!   t = build (MINUS_EXPR, TREE_TYPE (count), count_tmp, t);
!   t = build (PLUS_EXPR, TREE_TYPE (count), t,
! 	     fold_convert (TREE_TYPE (count), size_tree));
!   t = fold_convert (TREE_TYPE (base), fold (t));
    t = build (MINUS_EXPR, TREE_TYPE (base), base, t);
!   t = build (MODIFY_EXPR, void_type_node, addr, t);
!   gimplify_and_add (t, pre_p);
  
!   t = build (LABEL_EXPR, void_type_node, lab_gotaddr);
!   gimplify_and_add (t, pre_p);
  
!   t = fold_convert (TREE_TYPE (count), size_tree);
!   t = build (PLUS_EXPR, TREE_TYPE (count), count_tmp, t);
!   t = build (MODIFY_EXPR, TREE_TYPE (count), count, t);
!   gimplify_and_add (t, pre_p);
!   
!   addr = fold_convert (build_pointer_type (type), addr);
!   return build_fold_indirect_ref (addr);
  }
  
  /* Initialize the variable parts of a trampoline.  ADDR is an RTX for
*************** xstormy16_return_in_memory (tree type, t
*** 2198,2203 ****
--- 2208,2215 ----
  
  #undef TARGET_BUILD_BUILTIN_VA_LIST
  #define TARGET_BUILD_BUILTIN_VA_LIST xstormy16_build_builtin_va_list
+ #undef TARGET_GIMPLIFY_VA_ARG_EXPR
+ #define TARGET_GIMPLIFY_VA_ARG_EXPR xstormy16_expand_builtin_va_arg
  
  #undef TARGET_PROMOTE_FUNCTION_ARGS
  #define TARGET_PROMOTE_FUNCTION_ARGS hook_bool_tree_true
Index: config/stormy16/stormy16.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/stormy16/stormy16.h,v
retrieving revision 1.89
diff -u -p -c -r1.89 stormy16.h
*** config/stormy16/stormy16.h	5 Jul 2004 19:49:19 -0000	1.89
--- config/stormy16/stormy16.h	9 Jul 2004 09:54:23 -0000
*************** enum reg_class
*** 481,491 ****
     implementation will be defined that works for arguments passed on the stack.  */
  #define EXPAND_BUILTIN_VA_START(VALIST, NEXTARG) \
    xstormy16_expand_builtin_va_start (VALIST, NEXTARG)
- 
- /* Implement the stdarg/varargs va_arg macro.  VALIST is the variable of type
-    va_list as a tree, TYPE is the type passed to va_arg.  */
- #define EXPAND_BUILTIN_VA_ARG(VALIST, TYPE) \
-   xstormy16_expand_builtin_va_arg (VALIST, TYPE)
  
  /* Trampolines for Nested Functions.  */
  
--- 481,486 ----


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]