[cfe-commits] r147791 - in /cfe/trunk: lib/CodeGen/TargetInfo.cpp test/CodeGen/mips64-padding-arg.c

Akira Hatanaka ahatanaka at mips.com
Mon Jan 9 11:31:25 PST 2012


Author: ahatanak
Date: Mon Jan  9 13:31:25 2012
New Revision: 147791

URL: http://llvm.org/viewvc/llvm-project?rev=147791&view=rev
Log:
Insert padding before unaligned long double arguments.


Modified:
    cfe/trunk/lib/CodeGen/TargetInfo.cpp
    cfe/trunk/test/CodeGen/mips64-padding-arg.c

Modified: cfe/trunk/lib/CodeGen/TargetInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetInfo.cpp?rev=147791&r1=147790&r2=147791&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/TargetInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/TargetInfo.cpp Mon Jan  9 13:31:25 2012
@@ -3042,6 +3042,7 @@
   unsigned MinABIStackAlignInBytes;
   llvm::Type* HandleStructTy(QualType Ty) const;
   llvm::Type* returnAggregateInRegs(QualType RetTy, uint64_t Size) const;
+  llvm::Type* getPaddingType(uint64_t Align, uint64_t Offset) const;
 public:
   MipsABIInfo(CodeGenTypes &CGT, bool _IsO32) :
     ABIInfo(CGT), IsO32(_IsO32), MinABIStackAlignInBytes(IsO32 ? 4 : 8) {}
@@ -3132,18 +3133,34 @@
   return llvm::StructType::get(getVMContext(), ArgList);
 }
 
+llvm::Type *MipsABIInfo::getPaddingType(uint64_t Align, uint64_t Offset) const {
+  // Padding is inserted only for N32/64.
+  if (IsO32)
+    return 0;
+
+  assert(Align <= 16 && "Alignment larger than 16 not handled.");
+  return (Align == 16 && Offset & 0xf) ?
+    llvm::IntegerType::get(getVMContext(), 64) : 0;
+}
+ 
 ABIArgInfo
 MipsABIInfo::classifyArgumentType(QualType Ty, uint64_t &Offset) const {
+  uint64_t OrigOffset = Offset;
+  uint64_t TySize =
+    llvm::RoundUpToAlignment(getContext().getTypeSize(Ty), 64) / 8;
+  uint64_t Align = getContext().getTypeAlign(Ty) / 8;
+  Offset = llvm::RoundUpToAlignment(Offset, std::max(Align, (uint64_t)8));
+  Offset += TySize;
+
   if (isAggregateTypeForABI(Ty)) {
     // Ignore empty aggregates.
-    uint64_t TySize = getContext().getTypeSize(Ty);
     if (TySize == 0)
       return ABIArgInfo::getIgnore();
 
     // Records with non trivial destructors/constructors should not be passed
     // by value.
     if (isRecordWithNonTrivialDestructorOrCopyConstructor(Ty)) {
-      Offset += 8;
+      Offset = OrigOffset + 8;
       return ABIArgInfo::getIndirect(0, /*ByVal=*/false);
     }
 
@@ -3152,23 +3169,21 @@
     // latter case, padding is inserted if the offset of the aggregate is
     // unaligned.
     llvm::Type *ResType = HandleStructTy(Ty);
-    uint64_t Align = getContext().getTypeAlign(Ty) / 8;
-    assert(Align <= 16 && "Alignment larger than 16 not handled.");
-    llvm::Type *PaddingTy = (ResType && Align == 16 && Offset & 0xf) ?
-      llvm::IntegerType::get(getVMContext(), 64) : 0;
-    Offset = llvm::RoundUpToAlignment(Offset, std::max(Align, (uint64_t)8));
-    Offset += llvm::RoundUpToAlignment(TySize, 8);
-    return ResType ? ABIArgInfo::getDirect(ResType, 0, PaddingTy) :
-                     ABIArgInfo::getIndirect(0);
+    
+    if (!ResType)
+      return ABIArgInfo::getIndirect(0);
+
+    return ABIArgInfo::getDirect(ResType, 0, getPaddingType(Align, OrigOffset));
   }
 
   // Treat an enum type as its underlying type.
   if (const EnumType *EnumTy = Ty->getAs<EnumType>())
     Ty = EnumTy->getDecl()->getIntegerType();
 
-  Offset += 8;
-  return (Ty->isPromotableIntegerType() ?
-          ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
+  if (Ty->isPromotableIntegerType())
+    return ABIArgInfo::getExtend();
+
+  return ABIArgInfo::getDirect(0, 0, getPaddingType(Align, OrigOffset));
 }
 
 llvm::Type*

Modified: cfe/trunk/test/CodeGen/mips64-padding-arg.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/mips64-padding-arg.c?rev=147791&r1=147790&r2=147791&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/mips64-padding-arg.c (original)
+++ cfe/trunk/test/CodeGen/mips64-padding-arg.c Mon Jan  9 13:31:25 2012
@@ -5,7 +5,7 @@
   long double ld;
 } S0;
 
-// Insert padding to ensure arugments of type S0 are aligned to 16-byte boundaries.
+// Insert padding to ensure arguments of type S0 are aligned to 16-byte boundaries.
 
 // CHECK: define void @foo1(i32 %a0, i64, double %a1.coerce0, i64 %a1.coerce1, i64 %a1.coerce2, i64 %a1.coerce3, double %a2.coerce0, i64 %a2.coerce1, i64 %a2.coerce2, i64 %a2.coerce3, i32 %b, i64, double %a3.coerce0, i64 %a3.coerce1, i64 %a3.coerce2, i64 %a3.coerce3)
 // CHECK: tail call void @foo2(i32 1, i32 2, i32 %a0, i64 undef, double %a1.coerce0, i64 %a1.coerce1, i64 %a1.coerce2, i64 %a1.coerce3, double %a2.coerce0, i64 %a2.coerce1, i64 %a2.coerce2, i64 %a2.coerce3, i32 3, i64 undef, double %a3.coerce0, i64 %a3.coerce1, i64 %a3.coerce2, i64 %a3.coerce3)
@@ -17,3 +17,15 @@
   foo2(1, 2, a0, a1, a2, 3, a3);
 }
 
+// Insert padding before long double argument.
+//
+// CHECK: define void @foo3(i32 %a0, i64, fp128 %a1)
+// CHECK: tail call void @foo4(i32 1, i32 2, i32 %a0, i64 undef, fp128 %a1)
+// CHECK: declare void @foo4(i32, i32, i32, i64, fp128)
+
+extern void foo4(int, int, int, long double);
+
+void foo3(int a0, long double a1) {
+  foo4(1, 2, a0, a1);
+}
+





More information about the cfe-commits mailing list