[llvm-commits] [PATCH] ARM ABI: handle varargs with vector types.

Eli Friedman eli.friedman at gmail.com
Mon Oct 15 17:11:30 PDT 2012


On Mon, Oct 15, 2012 at 4:46 PM, manman ren <mren at apple.com> wrote:
>
> The initial patch was updated and separated to two patches (attached).
>
> The first patch will fix passing legal vector types as varargs:
> We make sure the vector is correctly aligned before casting it to the vector type.

+  uint64_t Size = CGF.getContext().getTypeSize(Ty) / 8;
+  uint64_t TyAlign = CGF.getContext().getTypeAlign(Ty) / 8;
+
+  // The ABI alignment for vectors is 8 for AAPCS and 4 for APCS.
+  if (Ty->getAs<VectorType>() && Size >= 8) {
+    if (getABIKind() == ARMABIInfo::AAPCS_VFP ||
+        getABIKind() == ARMABIInfo::AAPCS)
+      TyAlign = 8;
+    else
+      TyAlign = 4;
+  }

We should be using the same rules here we do for argument passing.  In
particular, for APCS, the argument-passing type alignment is
unconditionally 4.  (This can have effects for structs marked with
"__attribute__((aligned(16)))", etc.)

+  if (Ty->getAs<VectorType>() && ((Size == 8 && TyAlign < 8) ||
+           (Size >= 16 && TyAlign < 16))) {
+    // We can't directly cast ap.cur to pointer to a vector type, since ap.cur
+    // may not be correctly aligned for the vector type. We create an aligned
+    // temporary space and copy the content over from ap.cur to the temporary
+    // space. This is necessary if TyAlign < 8 for Size == 8, or
+    // TyAlign < 16 for Size >= 16.

The general rule here is something like "TyAlign <
CGF.getContext().getTypeAlign(Ty) / 8" (i.e. the natural alignment of
the type is greater than the argument-passing alignment).

-Eli



More information about the llvm-commits mailing list