From 9720a2dc65303f54ff5ee8c04248eab4617a0afd Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Mon, 18 May 2015 11:02:12 -0700 Subject: Align scalar types > 4 bytes to 4 bytes Intel MCU psABI specifies scalar types > 4 bytes should be aligned to 4 bytes. * config/i386/i386.c (iamcu_alignment): New function. (ix86_data_alignment): Call iamcu_alignment if TARGET_IAMCU is true. (x86_field_alignment): Return iamcu_alignment if TARGET_IAMCU is true. --- gcc/config/i386/i386.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index 394832966cd..9d712dd4b0a 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -26600,6 +26600,34 @@ ix86_constant_alignment (tree exp, int align) return align; } +/* Compute the alignment for a variable for Intel MCU psABI. TYPE is + the data type, and ALIGN is the alignment that the object would + ordinarily have. */ + +static int +iamcu_alignment (tree type, int align) +{ + enum machine_mode mode; + + if (align < 32 || TYPE_USER_ALIGN (type)) + return align; + + /* Intel MCU psABI specifies scalar types > 4 bytes aligned to 4 + bytes. */ + mode = TYPE_MODE (strip_array_types (type)); + switch (GET_MODE_CLASS (mode)) + { + case MODE_INT: + case MODE_COMPLEX_INT: + case MODE_COMPLEX_FLOAT: + case MODE_FLOAT: + case MODE_DECIMAL_FLOAT: + return 32; + default: + return align; + } +} + /* Compute the alignment for a static variable. TYPE is the data type, and ALIGN is the alignment that the object would ordinarily have. The value of this function is used @@ -26628,6 +26656,9 @@ ix86_data_alignment (tree type, int align, bool opt) if (max_align < BITS_PER_WORD) max_align = BITS_PER_WORD; + if (TARGET_IAMCU) + align = iamcu_alignment (type, align); + if (opt && AGGREGATE_TYPE_P (type) && TYPE_SIZE (type) @@ -38913,6 +38944,8 @@ x86_field_alignment (tree field, int computed) if (TARGET_64BIT || TARGET_ALIGN_DOUBLE) return computed; + if (TARGET_IAMCU) + return iamcu_alignment (type, computed); mode = TYPE_MODE (strip_array_types (type)); if (mode == DFmode || mode == DCmode || GET_MODE_CLASS (mode) == MODE_INT -- cgit v1.2.1