Use DECL_ALIGN_UNIT and TYPE_ALIGN_UNIT

Richard Kenner kenner@vlsi1.ultra.nyu.edu
Tue Aug 31 23:16:00 GMT 2004


I checked in this obvious patch to use those macros in more places instead
of the equivalent of using {DECL,TYPE}ALIGN / BITS_PER_UNIT.  I also noticed
one place where an alignment was signed instead of unsigned.

Tested on x86-64 (like the previous patch, where I forgot to say that).

2004-08-31  Richard Kenner  <kenner@vlsi1.ultra.nyu.edu>

	* c-common.c (c_alignof_expr): Use DECL_ALIGN_UNIT and TYPE_ALIGN_UNIT.
	(c_sizeof_of_alignof_type): Likewise.
	* expr.c (array_ref_element_size): Likewise.
	(highest_pow2_factor_for_target): Likewise.
	* gimplify.c (canonicalize_addr_expr): Likewise.
	(gimplify_compound_lval): Likewise.
	* stor-layout.c (finalize_record_size, finalize_type_size): Likewise.
	* tree-ssa-ccp.c (maybe_fold_offset_to_array_ref): Likewise.
	* varasm.c (assemble_variable): Likewise.
	(output_constant_def_contents): Alignments are unsigned.

*** c-common.c	28 Aug 2004 02:33:45 -0000	1.562
--- c-common.c	29 Aug 2004 21:32:32 -0000
*************** c_sizeof_or_alignof_type (tree type, enu
*** 2775,2779 ****
  				      / BITS_PER_UNIT));
        else
! 	value = size_int (TYPE_ALIGN (type) / BITS_PER_UNIT);
      }
  
--- 2775,2779 ----
  				      / BITS_PER_UNIT));
        else
! 	value = size_int (TYPE_ALIGN_UNIT (type));
      }
  
*************** c_alignof_expr (tree expr)
*** 2799,2803 ****
  
    if (TREE_CODE (expr) == VAR_DECL)
!     t = size_int (DECL_ALIGN (expr) / BITS_PER_UNIT);
  
    else if (TREE_CODE (expr) == COMPONENT_REF
--- 2799,2803 ----
  
    if (TREE_CODE (expr) == VAR_DECL)
!     t = size_int (DECL_ALIGN_UNIT (expr));
  
    else if (TREE_CODE (expr) == COMPONENT_REF
*************** c_alignof_expr (tree expr)
*** 2809,2813 ****
    else if (TREE_CODE (expr) == COMPONENT_REF
  	   && TREE_CODE (TREE_OPERAND (expr, 1)) == FIELD_DECL)
!     t = size_int (DECL_ALIGN (TREE_OPERAND (expr, 1)) / BITS_PER_UNIT);
  
    else if (TREE_CODE (expr) == INDIRECT_REF)
--- 2809,2813 ----
    else if (TREE_CODE (expr) == COMPONENT_REF
  	   && TREE_CODE (TREE_OPERAND (expr, 1)) == FIELD_DECL)
!     t = size_int (DECL_ALIGN_UNIT (TREE_OPERAND (expr, 1)));
  
    else if (TREE_CODE (expr) == INDIRECT_REF)
*** expr.c	30 Aug 2004 21:39:38 -0000	1.713
--- expr.c	31 Aug 2004 12:04:09 -0000
*************** array_ref_element_size (tree exp)
*** 5488,5492 ****
  	aligned_size = fold_convert (sizetype, aligned_size);
        return size_binop (MULT_EXPR, aligned_size,
! 		         size_int (TYPE_ALIGN (elmt_type) / BITS_PER_UNIT));
      }
  
--- 5491,5495 ----
  	aligned_size = fold_convert (sizetype, aligned_size);
        return size_binop (MULT_EXPR, aligned_size,
! 		         size_int (TYPE_ALIGN_UNIT (elmt_type)));
      }
  
*************** highest_pow2_factor_for_target (tree tar
*** 6007,6013 ****
    factor = highest_pow2_factor (exp);
    if (TREE_CODE (target) == COMPONENT_REF)
!     target_align = DECL_ALIGN (TREE_OPERAND (target, 1)) / BITS_PER_UNIT;
    else
!     target_align = TYPE_ALIGN (TREE_TYPE (target)) / BITS_PER_UNIT;
    return MAX (factor, target_align);
  }
--- 6010,6016 ----
    factor = highest_pow2_factor (exp);
    if (TREE_CODE (target) == COMPONENT_REF)
!     target_align = DECL_ALIGN_UNIT (TREE_OPERAND (target, 1));
    else
!     target_align = TYPE_ALIGN_UNIT (TREE_TYPE (target));
    return MAX (factor, target_align);
  }
*** gimplify.c	28 Aug 2004 02:33:48 -0000	2.68
--- gimplify.c	29 Aug 2004 21:32:57 -0000
*************** canonicalize_addr_expr (tree *expr_p)
*** 1393,1398 ****
  		    TYPE_MIN_VALUE (TYPE_DOMAIN (datype)),
  		    size_binop (EXACT_DIV_EXPR, TYPE_SIZE_UNIT (dctype),
! 				size_int (TYPE_ALIGN (dctype)
! 					  / BITS_PER_UNIT)));
    *expr_p = build1 (ADDR_EXPR, ctype, *expr_p);
  }
--- 1396,1400 ----
  		    TYPE_MIN_VALUE (TYPE_DOMAIN (datype)),
  		    size_binop (EXACT_DIV_EXPR, TYPE_SIZE_UNIT (dctype),
! 				size_int (TYPE_ALIGN_UNIT (dctype))));
    *expr_p = build1 (ADDR_EXPR, ctype, *expr_p);
  }
*************** gimplify_compound_lval (tree *expr_p, tr
*** 1521,1525 ****
  	      tree elmt_type = TREE_TYPE (TREE_TYPE (TREE_OPERAND (t, 0)));
  	      tree elmt_size = unshare_expr (array_ref_element_size (t));
! 	      tree factor = size_int (TYPE_ALIGN (elmt_type) / BITS_PER_UNIT);
  
  	      /* Divide the element size by the alignment of the element
--- 1523,1527 ----
  	      tree elmt_type = TREE_TYPE (TREE_TYPE (TREE_OPERAND (t, 0)));
  	      tree elmt_size = unshare_expr (array_ref_element_size (t));
! 	      tree factor = size_int (TYPE_ALIGN_UNIT (elmt_type));
  
  	      /* Divide the element size by the alignment of the element
*** stor-layout.c	27 Aug 2004 16:48:31 -0000	1.208
--- stor-layout.c	29 Aug 2004 21:32:59 -0000
*************** finalize_record_size (record_layout_info
*** 1196,1201 ****
    /* Round the size up to be a multiple of the required alignment.  */
    TYPE_SIZE (rli->t) = round_up (unpadded_size, TYPE_ALIGN (rli->t));
!   TYPE_SIZE_UNIT (rli->t) = round_up (unpadded_size_unit,
! 				      TYPE_ALIGN (rli->t) / BITS_PER_UNIT);
  
    if (warn_padded && TREE_CONSTANT (unpadded_size)
--- 1196,1201 ----
    /* Round the size up to be a multiple of the required alignment.  */
    TYPE_SIZE (rli->t) = round_up (unpadded_size, TYPE_ALIGN (rli->t));
!   TYPE_SIZE_UNIT (rli->t)
!     = round_up (unpadded_size_unit, TYPE_ALIGN_UNIT (rli->t));
  
    if (warn_padded && TREE_CONSTANT (unpadded_size)
*************** finalize_type_size (tree type)
*** 1358,1363 ****
      {
        TYPE_SIZE (type) = round_up (TYPE_SIZE (type), TYPE_ALIGN (type));
!       TYPE_SIZE_UNIT (type)
! 	= round_up (TYPE_SIZE_UNIT (type), TYPE_ALIGN (type) / BITS_PER_UNIT);
      }
  
--- 1358,1363 ----
      {
        TYPE_SIZE (type) = round_up (TYPE_SIZE (type), TYPE_ALIGN (type));
!       TYPE_SIZE_UNIT (type) = round_up (TYPE_SIZE_UNIT (type),
! 					TYPE_ALIGN_UNIT (type));
      }
  
*** tree-ssa-ccp.c	29 Aug 2004 06:16:02 -0000	2.34
--- tree-ssa-ccp.c	29 Aug 2004 21:33:04 -0000
*************** maybe_fold_offset_to_array_ref (tree bas
*** 1381,1385 ****
    return build (ARRAY_REF, orig_type, base, idx, min_idx,
  		size_int (tree_low_cst (elt_size, 1)
! 			  / (TYPE_ALIGN (elt_type) / BITS_PER_UNIT)));
  }
  
--- 1386,1390 ----
    return build (ARRAY_REF, orig_type, base, idx, min_idx,
  		size_int (tree_low_cst (elt_size, 1)
! 			  / (TYPE_ALIGN_UNIT (elt_type))));
  }
  
*** varasm.c	19 Aug 2004 06:16:37 -0000	1.445
--- varasm.c	29 Aug 2004 21:33:16 -0000
*************** assemble_variable (tree decl, int top_le
*** 1644,1648 ****
  
  #if !defined(ASM_OUTPUT_ALIGNED_COMMON) && !defined(ASM_OUTPUT_ALIGNED_DECL_COMMON) && !defined(ASM_OUTPUT_ALIGNED_BSS)
!       if ((unsigned HOST_WIDE_INT) DECL_ALIGN (decl) / BITS_PER_UNIT > rounded)
  	warning ("%Jrequested alignment for '%D' is greater than "
                   "implemented alignment of %d", decl, decl, rounded);
--- 1644,1648 ----
  
  #if !defined(ASM_OUTPUT_ALIGNED_COMMON) && !defined(ASM_OUTPUT_ALIGNED_DECL_COMMON) && !defined(ASM_OUTPUT_ALIGNED_BSS)
!       if ((unsigned HOST_WIDE_INT) DECL_ALIGN_UNIT (decl) > rounded)
  	warning ("%Jrequested alignment for '%D' is greater than "
                   "implemented alignment of %d", decl, decl, rounded);
*************** assemble_variable (tree decl, int top_le
*** 1672,1679 ****
    /* Output the alignment of this data.  */
    if (align > BITS_PER_UNIT)
!     {
!       ASM_OUTPUT_ALIGN (asm_out_file,
! 			floor_log2 (DECL_ALIGN (decl) / BITS_PER_UNIT));
!     }
  
    /* Do any machine/system dependent processing of the object.  */
--- 1672,1676 ----
    /* Output the alignment of this data.  */
    if (align > BITS_PER_UNIT)
!     ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DECL_ALIGN_UNIT (decl)));
  
    /* Do any machine/system dependent processing of the object.  */
*************** output_constant_def_contents (rtx symbol
*** 2660,2664 ****
  
    /* Align the location counter as required by EXP's data type.  */
!   int align = TYPE_ALIGN (TREE_TYPE (exp));
  #ifdef CONSTANT_ALIGNMENT
    align = CONSTANT_ALIGNMENT (exp, align);
--- 2657,2661 ----
  
    /* Align the location counter as required by EXP's data type.  */
!   unsigned int align = TYPE_ALIGN (TREE_TYPE (exp));
  #ifdef CONSTANT_ALIGNMENT
    align = CONSTANT_ALIGNMENT (exp, align);



More information about the Gcc-patches mailing list