[PATCH] D20955: [Sparc] Complex return value ABI compliance.

Chris Dewhurst via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 3 04:06:29 PDT 2016


lero_chris created this revision.
lero_chris added reviewers: jacob_hansen, jyknight.
lero_chris added a subscriber: llvm-commits.
lero_chris set the repository for this revision to rL LLVM.
Herald added a subscriber: jyknight.

According to the Sparc V8 ABI, complex numbers should be passed and returned as pairs of registers:

https://docs.oracle.com/cd/E26502_01/html/E28387/gentextid-2734.html

This fix ensures this is the case. Without this, complex numbers are returned as a struct of two floats, which breaks the ABI rules.

Repository:
  rL LLVM

http://reviews.llvm.org/D20955

Files:
  tools/clang/lib/CodeGen/TargetInfo.cpp
  tools/clang/test/CodeGen/sparcv8-abi.c

Index: tools/clang/test/CodeGen/sparcv8-abi.c
===================================================================
--- tools/clang/test/CodeGen/sparcv8-abi.c
+++ tools/clang/test/CodeGen/sparcv8-abi.c
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -triple sparc-unknown-unknown -emit-llvm %s -o - | FileCheck %s
+
+// CHECK-LABEL: define { float, float } @p({ float, float }* byval align 4 %a, { float, float }* byval align 4 %b) #0 {
+float __complex__
+p (float __complex__  a, float __complex__  b)
+{
+}
Index: tools/clang/lib/CodeGen/TargetInfo.cpp
===================================================================
--- tools/clang/lib/CodeGen/TargetInfo.cpp
+++ tools/clang/lib/CodeGen/TargetInfo.cpp
@@ -6843,6 +6843,39 @@
 
 
 //===----------------------------------------------------------------------===//
+// SPARC v8 ABI Implementation.
+// Based on the SPARC Compliance Definition version 2.4.1.
+//
+// Ensures that complex values are passed in registers.
+//
+namespace {
+class SparcV8ABIInfo : public DefaultABIInfo {
+public:
+  SparcV8ABIInfo(CodeGenTypes &CGT) : DefaultABIInfo(CGT) {}
+
+private:
+  void computeInfo(CGFunctionInfo &FI) const override;
+};
+} // end anonymous namespace
+
+
+void SparcV8ABIInfo::computeInfo(CGFunctionInfo &FI) const {
+  DefaultABIInfo::computeInfo(FI);
+
+  if (FI.getReturnType()->isAnyComplexType()) {
+    FI.getReturnInfo() = ABIArgInfo::getDirect();
+  }
+}
+
+namespace {
+class SparcV8TargetCodeGenInfo : public TargetCodeGenInfo {
+public:
+  SparcV8TargetCodeGenInfo(CodeGenTypes &CGT)
+    : TargetCodeGenInfo(new SparcV8ABIInfo(CGT)) {}
+};
+} // end anonymous namespace
+
+//===----------------------------------------------------------------------===//
 // SPARC v9 ABI Implementation.
 // Based on the SPARC Compliance Definition version 2.4.1.
 //
@@ -7965,6 +7998,8 @@
     return SetCGInfo(new AMDGPUTargetCodeGenInfo(Types));
   case llvm::Triple::amdgcn:
     return SetCGInfo(new AMDGPUTargetCodeGenInfo(Types));
+  case llvm::Triple::sparc:
+    return SetCGInfo(new SparcV8TargetCodeGenInfo(Types));
   case llvm::Triple::sparcv9:
     return SetCGInfo(new SparcV9TargetCodeGenInfo(Types));
   case llvm::Triple::xcore:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D20955.59527.patch
Type: text/x-patch
Size: 2188 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160603/3746d004/attachment.bin>


More information about the llvm-commits mailing list