[PATCH] D137510: [clang] Add SwiftABIInfo support for PPC32

Alsey Coleman Miller via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Nov 6 15:53:12 PST 2022


colemancda created this revision.
Herald added subscribers: shchenz, kbarton, nemanjai.
Herald added a project: All.
colemancda requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

[clang] Add Swift CC support to PPC


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137510

Files:
  clang/lib/Basic/Targets/PPC.h
  clang/lib/CodeGen/TargetInfo.cpp


Index: clang/lib/CodeGen/TargetInfo.cpp
===================================================================
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -4700,19 +4700,23 @@
 // PowerPC-32
 namespace {
 /// PPC32_SVR4_ABIInfo - The 32-bit PowerPC ELF (SVR4) ABI information.
-class PPC32_SVR4_ABIInfo : public DefaultABIInfo {
+class PPC32_SVR4_ABIInfo final : public SwiftABIInfo {
   bool IsSoftFloatABI;
   bool IsRetSmallStructInRegABI;
 
   CharUnits getParamTypeAlignment(QualType Ty) const;
 
+private:
+  DefaultABIInfo defaultInfo;
+
 public:
   PPC32_SVR4_ABIInfo(CodeGen::CodeGenTypes &CGT, bool SoftFloatABI,
                      bool RetSmallStructInRegABI)
-      : DefaultABIInfo(CGT), IsSoftFloatABI(SoftFloatABI),
-        IsRetSmallStructInRegABI(RetSmallStructInRegABI) {}
+      : SwiftABIInfo(CGT), IsSoftFloatABI(SoftFloatABI),
+        IsRetSmallStructInRegABI(RetSmallStructInRegABI), defaultInfo(CGT) {}
 
   ABIArgInfo classifyReturnType(QualType RetTy) const;
+  ABIArgInfo classifyArgumentType(QualType Ty) const;
 
   void computeInfo(CGFunctionInfo &FI) const override {
     if (!getCXXABI().classifyReturnType(FI))
@@ -4723,6 +4727,15 @@
 
   Address EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
                     QualType Ty) const override;
+
+private:
+  bool shouldPassIndirectlyForSwift(ArrayRef<llvm::Type *> scalars,
+                                    bool asReturnValue) const override {
+    return occupiesMoreThan(CGT, scalars, /*total*/ 4);
+  }
+  bool isSwiftErrorInRegister() const override { return false; }
+  bool isLegalVectorTypeForSwift(CharUnits totalSize, llvm::Type *eltTy,
+                                 unsigned elts) const override;
 };
 
 class PPC32TargetCodeGenInfo : public TargetCodeGenInfo {
@@ -4794,7 +4807,25 @@
     }
   }
 
-  return DefaultABIInfo::classifyReturnType(RetTy);
+  return defaultInfo.classifyArgumentType(RetTy);
+}
+
+ABIArgInfo PPC32_SVR4_ABIInfo::classifyArgumentType(QualType Ty) const {
+  return defaultInfo.classifyArgumentType(Ty);
+}
+
+bool PPC32_SVR4_ABIInfo::isLegalVectorTypeForSwift(CharUnits vectorSize,
+                                                   llvm::Type *eltTy,
+                                                   unsigned numElts) const {
+  if (!llvm::isPowerOf2_32(numElts))
+    return false;
+  unsigned size = getDataLayout().getTypeStoreSizeInBits(eltTy);
+  if (size > 64)
+    return false;
+  if (vectorSize.getQuantity() != 8 &&
+      (vectorSize.getQuantity() != 16 || numElts == 1))
+    return false;
+  return true;
 }
 
 // TODO: this implementation is now likely redundant with
Index: clang/lib/Basic/Targets/PPC.h
===================================================================
--- clang/lib/Basic/Targets/PPC.h
+++ clang/lib/Basic/Targets/PPC.h
@@ -405,6 +405,17 @@
     // This is the ELF definition, and is overridden by the Darwin sub-target
     return TargetInfo::PowerABIBuiltinVaList;
   }
+
+  CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
+    switch (CC) {
+    case CC_Swift:
+      return CCCR_OK;
+    case CC_SwiftAsync:
+      return CCCR_Error;
+    default:
+      return CCCR_Warning;
+    }
+  }
 };
 
 // Note: ABI differences may eventually require us to have a separate


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137510.473516.patch
Type: text/x-patch
Size: 3310 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221106/09c02f86/attachment.bin>


More information about the cfe-commits mailing list