[cfe-commits] r114112 - in /cfe/trunk: lib/CodeGen/TargetInfo.cpp test/CodeGen/x86_32-arguments-linux.c

Daniel Dunbar daniel at zuster.org
Thu Sep 16 13:41:57 PDT 2010


Author: ddunbar
Date: Thu Sep 16 15:41:56 2010
New Revision: 114112

URL: http://llvm.org/viewvc/llvm-project?rev=114112&view=rev
Log:
IRgen/x86_32/Linux: Linux seems to align all stack objects to 4 bytes, unlike
Darwin. Checked vs the handiest Linux llvm-gcc I had around, someone on Linux is
welcome to investigate more.

Added:
    cfe/trunk/test/CodeGen/x86_32-arguments-linux.c
Modified:
    cfe/trunk/lib/CodeGen/TargetInfo.cpp

Modified: cfe/trunk/lib/CodeGen/TargetInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetInfo.cpp?rev=114112&r1=114111&r2=114112&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/TargetInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/TargetInfo.cpp Thu Sep 16 15:41:56 2010
@@ -336,6 +336,8 @@
 
 /// X86_32ABIInfo - The X86-32 ABI information.
 class X86_32ABIInfo : public ABIInfo {
+  static const unsigned MinABIStackAlignInBytes = 4;
+
   bool IsDarwinVectorABI;
   bool IsSmallStructInRegABI;
 
@@ -349,6 +351,9 @@
   /// such that the argument will be passed in memory.
   ABIArgInfo getIndirectResult(QualType Ty, bool ByVal = true) const;
 
+  /// \brief Return the alignment to use for the given type on the stack.
+  unsigned getTypeStackAlignInBytes(QualType Ty) const;
+
 public:
 
   ABIArgInfo classifyReturnType(QualType RetTy) const;
@@ -547,15 +552,30 @@
           ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
 }
 
+unsigned X86_32ABIInfo::getTypeStackAlignInBytes(QualType Ty) const {
+  // On non-Darwin, the stack type alignment is always 4.
+  if (!IsDarwinVectorABI)
+    return MinABIStackAlignInBytes;
+
+  // Otherwise, if the alignment is less than or equal to 4, use the minimum ABI
+  // alignment.
+  unsigned Align = getContext().getTypeAlign(Ty) / 8;
+  if (Align <= MinABIStackAlignInBytes)
+    return MinABIStackAlignInBytes;
+
+  // Otherwise, if the type contains SSE or MMX vector types, then the alignment
+  // matches that of the struct.
+  return Align;
+}
+
 ABIArgInfo X86_32ABIInfo::getIndirectResult(QualType Ty, bool ByVal) const {
   if (!ByVal)
     return ABIArgInfo::getIndirect(0, false);
 
   // Compute the byval alignment. We trust the back-end to honor the
   // minimum ABI alignment for byval, to make cleaner IR.
-  const unsigned MinABIAlign = 4;
-  unsigned Align = getContext().getTypeAlign(Ty) / 8;
-  if (Align > MinABIAlign)
+  unsigned Align = getTypeStackAlignInBytes(Ty);
+  if (Align > MinABIStackAlignInBytes)
     return ABIArgInfo::getIndirect(Align);
   return ABIArgInfo::getIndirect(0);
 }

Added: cfe/trunk/test/CodeGen/x86_32-arguments-linux.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/x86_32-arguments-linux.c?rev=114112&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/x86_32-arguments-linux.c (added)
+++ cfe/trunk/test/CodeGen/x86_32-arguments-linux.c Thu Sep 16 15:41:56 2010
@@ -0,0 +1,51 @@
+// RUN: %clang_cc1 -w -fblocks -triple i386-pc-linux-gnu -emit-llvm -o %t %s
+// RUN: FileCheck < %t %s
+
+// CHECK: define void @f56(
+// CHECK: i8 signext %a0, %struct.s56_0* byval %a1,
+// CHECK: <2 x i32> %a2, %struct.s56_1* byval %a3,
+// CHECK: <1 x double> %a4, %struct.s56_2* byval %a5,
+// CHECK: <4 x i32> %a6, %struct.s56_3* byval %a7,
+// CHECK: <2 x double> %a8, %struct.s56_4* byval %a9,
+// CHECK: <8 x i32> %a10, %struct.s56_5* byval %a11,
+// CHECK: <4 x double> %a12, %struct.s56_6* byval %a13)
+
+// CHECK: call void (i32, ...)* @f56_0(i32 1,
+// CHECK: i32 %{{.*}}, %struct.s56_0* byval %{{[^ ]*}},
+// CHECK: <2 x i32> %{{[^ ]*}}, %struct.s56_1* byval %{{[^ ]*}},
+// CHECK: <1 x double> %{{[^ ]*}}, %struct.s56_2* byval %{{[^ ]*}},
+// CHECK: <4 x i32> %{{[^ ]*}}, %struct.s56_3* byval %{{[^ ]*}},
+// CHECK: <2 x double> %{{[^ ]*}}, %struct.s56_4* byval %{{[^ ]*}},
+// CHECK: <8 x i32> %{{[^ ]*}}, %struct.s56_5* byval %{{[^ ]*}},
+// CHECK: <4 x double> %{{[^ ]*}}, %struct.s56_6* byval %{{[^ ]*}})
+// CHECK: }
+//
+// <rdar://problem/7964854> [i386] clang misaligns long double in structures
+// when passed byval
+// <rdar://problem/8431367> clang misaligns parameters on stack
+typedef int __attribute__((vector_size (8))) t56_v2i;
+typedef double __attribute__((vector_size (8))) t56_v1d;
+typedef int __attribute__((vector_size (16))) t56_v4i;
+typedef double __attribute__((vector_size (16))) t56_v2d;
+typedef int __attribute__((vector_size (32))) t56_v8i;
+typedef double __attribute__((vector_size (32))) t56_v4d;
+
+struct s56_0 { char a; };
+struct s56_1 { t56_v2i a; };
+struct s56_2 { t56_v1d a; };
+struct s56_3 { t56_v4i a; };
+struct s56_4 { t56_v2d a; };
+struct s56_5 { t56_v8i a; };
+struct s56_6 { t56_v4d a; };
+
+void f56(char a0, struct s56_0 a1, 
+         t56_v2i a2, struct s56_1 a3, 
+         t56_v1d a4, struct s56_2 a5, 
+         t56_v4i a6, struct s56_3 a7, 
+         t56_v2d a8, struct s56_4 a9, 
+         t56_v8i a10, struct s56_5 a11, 
+         t56_v4d a12, struct s56_6 a13) {
+  extern void f56_0(int x, ...);
+  f56_0(1, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9,
+        a10, a11, a12, a13);
+}





More information about the cfe-commits mailing list