]> granicus.if.org Git - clang/commitdiff
[mips] Reland r310704
authorStefan Maksimovic <stefan.maksimovic@mips.com>
Fri, 23 Feb 2018 08:37:48 +0000 (08:37 +0000)
committerStefan Maksimovic <stefan.maksimovic@mips.com>
Fri, 23 Feb 2018 08:37:48 +0000 (08:37 +0000)
Recommit this change which was previously reverted
for the 5.0.0 release since the failures identified
were dealt with in r325782.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@325872 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/TargetInfo.cpp
test/CodeGen/mips-aggregate-arg.c [new file with mode: 0644]

index 4ca421bb863fe294354dd9371927b916f2b35780..7d597437683c09a5fe2727f724e4e2c75b36a8a6 100644 (file)
@@ -6870,6 +6870,14 @@ MipsABIInfo::classifyArgumentType(QualType Ty, uint64_t &Offset) const {
       return getNaturalAlignIndirect(Ty, RAA == CGCXXABI::RAA_DirectInMemory);
     }
 
+    // Use indirect if the aggregate cannot fit into registers for
+    // passing arguments according to the ABI
+    unsigned Threshold = IsO32 ? 16 : 64;
+
+    if(getContext().getTypeSizeInChars(Ty) > CharUnits::fromQuantity(Threshold))
+      return ABIArgInfo::getIndirect(CharUnits::fromQuantity(Align), true,
+                                     getContext().getTypeAlign(Ty) / 8 > Align);
+
     // If we have reached here, aggregates are passed directly by coercing to
     // another structure type. Padding is inserted if the offset of the
     // aggregate is unaligned.
diff --git a/test/CodeGen/mips-aggregate-arg.c b/test/CodeGen/mips-aggregate-arg.c
new file mode 100644 (file)
index 0000000..ccf30df
--- /dev/null
@@ -0,0 +1,38 @@
+// RUN: %clang_cc1 -triple mipsel-unknown-linux-gnu -S -emit-llvm -o - %s | FileCheck -check-prefix=O32 %s
+// RUN: %clang_cc1 -triple mips64el-unknown-linux-gnu -S -emit-llvm -o - %s  -target-abi n32 | FileCheck -check-prefix=N32-N64 %s
+// RUN: %clang_cc1 -triple mips64el-unknown-linux-gnu -S -emit-llvm -o - %s  -target-abi n64 | FileCheck -check-prefix=N32-N64 %s
+
+struct t1 {
+  char t1[10];
+};
+
+struct t2 {
+  char t2[20];
+};
+
+struct t3 {
+  char t3[65];
+};
+
+extern struct t1 g1;
+extern struct t2 g2;
+extern struct t3 g3;
+extern void f1(struct t1);
+extern void f2(struct t2);
+extern void f3(struct t3);
+
+void f() {
+
+// O32:  call void @f1(i32 inreg %{{[0-9]+}}, i32 inreg %{{[0-9]+}}, i16 inreg %{{[0-9]+}})
+// O32:  call void @f2(%struct.t2* byval align 4 %{{.*}})
+// O32:  call void @f3(%struct.t3* byval align 4 %{{.*}})
+
+// N32-N64:  call void @f1(i64 inreg %{{[0-9]+}}, i16 inreg %{{[0-9]+}})
+// N32-N64:  call void @f2(i64 inreg %{{[0-9]+}}, i64 inreg %{{[0-9]+}}, i32 inreg %{{[0-9]+}})
+// N32-N64:  call void @f3(%struct.t3* byval align 8 %{{.*}})
+
+  f1(g1);
+  f2(g2);
+  f3(g3);
+}
+