public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* gimple va_arg for arc
@ 2004-07-08 21:57 Richard Henderson
  0 siblings, 0 replies; only message in thread
From: Richard Henderson @ 2004-07-08 21:57 UTC (permalink / raw)
  To: gcc-patches

Tested as with c4x.


r~


        * config/arc/arc-protos.h (arc_va_arg): Remove.
        * config/arc/arc.c (TARGET_GIMPLIFY_VA_ARG_EXPR): New.
        (arc_gimplify_va_arg_expr): Rewrite from arc_va_arg.
        * config/arc/arc.h (EXPAND_BUILTIN_VA_ARG): Remove.

Index: arc-protos.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/arc/arc-protos.h,v
retrieving revision 1.11
diff -c -p -d -r1.11 arc-protos.h
*** arc-protos.h	16 Mar 2004 18:14:31 -0000	1.11
--- arc-protos.h	8 Jul 2004 21:07:46 -0000
*************** along with GCC; see the file COPYING.  I
*** 18,28 ****
  the Free Software Foundation, 59 Temple Place - Suite 330,
  Boston, MA 02111-1307, USA.  */
  
- #ifdef RTX_CODE
- #ifdef TREE_CODE
  extern void arc_va_start (tree, rtx);
- extern rtx arc_va_arg (tree, tree);
- #endif /* TREE_CODE */
  
  extern enum machine_mode arc_select_cc_mode (enum rtx_code, rtx, rtx);
  
--- 18,24 ----
*************** extern int const_sint32_operand (rtx, en
*** 55,65 ****
  extern int const_uint32_operand (rtx, enum machine_mode);
  extern int proper_comparison_operator (rtx, enum machine_mode);
  extern int shift_operator (rtx, enum machine_mode);
- #endif /* RTX_CODE */
  
- #ifdef TREE_CODE
  extern enum arc_function_type arc_compute_function_type (tree);
- #endif /* TREE_CODE */
  
  
  extern void arc_init (void);
--- 51,58 ----
*************** extern void arc_finalize_pic (void);
*** 71,74 ****
  extern void arc_ccfsm_at_label (const char *, int);
  extern int arc_ccfsm_branch_deleted_p (void);
  extern void arc_ccfsm_record_branch_deleted (void);
- 
--- 64,66 ----
Index: arc.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/arc/arc.c,v
retrieving revision 1.54
diff -c -p -d -r1.54 arc.c
*** arc.c	3 Mar 2004 08:34:42 -0000	1.54
--- arc.c	8 Jul 2004 21:07:46 -0000
*************** static bool arc_rtx_costs (rtx, int, int
*** 102,107 ****
--- 102,108 ----
  static int arc_address_cost (rtx);
  static void arc_external_libcall (rtx);
  static bool arc_return_in_memory (tree, tree);
+ static tree arc_gimplify_va_arg_expr (tree, tree, tree *, tree *);
  \f
  /* Initialize the GCC target structure.  */
  #undef TARGET_ASM_ALIGNED_HI_OP
*************** static bool arc_return_in_memory (tree, 
*** 141,146 ****
--- 142,149 ----
  
  #undef TARGET_SETUP_INCOMING_VARARGS
  #define TARGET_SETUP_INCOMING_VARARGS arc_setup_incoming_varargs
+ #undef TARGET_GIMPLIFY_VA_ARG_EXPR
+ #define TARGET_GIMPLIFY_VA_ARG_EXPR arc_gimplify_va_arg_expr
  
  struct gcc_target targetm = TARGET_INITIALIZER;
  \f
*************** arc_va_start (tree valist, rtx nextarg)
*** 2289,2364 ****
    std_expand_builtin_va_start (valist, nextarg);
  }
  
! rtx
! arc_va_arg (tree valist, tree type)
  {
-   rtx addr_rtx;
-   tree addr, incr;
-   tree type_ptr = build_pointer_type (type);
- 
    /* All aggregates are passed by reference.  All scalar types larger
       than 8 bytes are passed by reference.  */
  
    if (AGGREGATE_TYPE_P (type) || int_size_in_bytes (type) > 8)
      {
!       tree type_ptr_ptr = build_pointer_type (type_ptr);
! 
!       addr = build (INDIRECT_REF, type_ptr,
! 		    build (NOP_EXPR, type_ptr_ptr, valist));
! 
!       incr = build (PLUS_EXPR, TREE_TYPE (valist),
! 		    valist, build_int_2 (UNITS_PER_WORD, 0));
!     }
!   else
!     {
!       HOST_WIDE_INT align, rounded_size;
! 
!       /* Compute the rounded size of the type.  */
!       align = PARM_BOUNDARY / BITS_PER_UNIT;
!       rounded_size = (((TREE_INT_CST_LOW (TYPE_SIZE (type)) / BITS_PER_UNIT
! 			+ align - 1) / align) * align);
! 
!       /* Align 8 byte operands.  */
!       addr = valist;
!       if (TYPE_ALIGN (type) > BITS_PER_WORD)
! 	{
! 	  /* AP = (TYPE *)(((int)AP + 7) & -8)  */
! 
! 	  addr = build (NOP_EXPR, integer_type_node, valist);
! 	  addr = fold (build (PLUS_EXPR, integer_type_node, addr,
! 			      build_int_2 (7, 0)));
! 	  addr = fold (build (BIT_AND_EXPR, integer_type_node, addr,
! 			      build_int_2 (-8, 0)));
! 	  addr = fold (build (NOP_EXPR, TREE_TYPE (valist), addr));
! 	}
! 
!       /* The increment is always rounded_size past the aligned pointer.  */
!       incr = fold (build (PLUS_EXPR, TREE_TYPE (addr), addr,
! 			  build_int_2 (rounded_size, 0)));
! 
!       /* Adjust the pointer in big-endian mode.  */
!       if (BYTES_BIG_ENDIAN)
! 	{
! 	  HOST_WIDE_INT adj;
! 	  adj = TREE_INT_CST_LOW (TYPE_SIZE (type)) / BITS_PER_UNIT;
! 	  if (rounded_size > align)
! 	    adj = rounded_size;
! 
! 	  addr = fold (build (PLUS_EXPR, TREE_TYPE (addr), addr,
! 			      build_int_2 (rounded_size - adj, 0)));
! 	}
      }
  
!   /* Evaluate the data address.  */
!   addr_rtx = expand_expr (addr, NULL_RTX, Pmode, EXPAND_NORMAL);
!   addr_rtx = copy_to_reg (addr_rtx);
!   
!   /* Compute new value for AP.  */
!   incr = build (MODIFY_EXPR, TREE_TYPE (valist), valist, incr);
!   TREE_SIDE_EFFECTS (incr) = 1;
!   expand_expr (incr, const0_rtx, VOIDmode, EXPAND_NORMAL);
! 
!   return addr_rtx;
  }
  
  /* This is how to output a definition of an internal numbered label where
--- 2292,2311 ----
    std_expand_builtin_va_start (valist, nextarg);
  }
  
! static tree
! arc_gimplify_va_arg_expr (tree valist, tree type, tree *pre_p, tree *post_p)
  {
    /* All aggregates are passed by reference.  All scalar types larger
       than 8 bytes are passed by reference.  */
  
    if (AGGREGATE_TYPE_P (type) || int_size_in_bytes (type) > 8)
      {
!       tree type_ptr = build_pointer_type (type);
!       tree addr = std_gimplify_va_arg_expr (valist, type_ptr, pre_p, post_p);
!       return build_fold_indirect_ref (addr);
      }
  
!   return std_gimplify_va_arg_expr (valist, type, pre_p, post_p);
  }
  
  /* This is how to output a definition of an internal numbered label where
Index: arc.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/arc/arc.h,v
retrieving revision 1.76
diff -c -p -d -r1.76 arc.h
*** arc.h	5 Jul 2004 19:49:12 -0000	1.76
--- arc.h	8 Jul 2004 21:07:46 -0000
*************** enum arc_function_type {
*** 1217,1223 ****
  /* Implement `va_start' for varargs and stdarg.  */
  #define EXPAND_BUILTIN_VA_START(valist, nextarg) \
    arc_va_start (valist, nextarg)
- 
- /* Implement `va_arg'.  */
- #define EXPAND_BUILTIN_VA_ARG(valist, type) \
-   arc_va_arg (valist, type)
--- 1217,1219 ----

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2004-07-08 21:11 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-07-08 21:57 gimple va_arg for arc Richard Henderson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).