[PATCH] D137309: [clang] Added Swift support for RISCV64

2022-11-02 Thread Alsey Coleman Miller via Phabricator via cfe-commits
colemancda created this revision.
Herald added subscribers: sunshaoce, VincentWu, vkmr, frasercrmck, evandro, 
luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, 
PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, 
shiva0217, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, asb, 
hiraditya, arichardson.
Herald added a project: All.
colemancda requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, pcwang-thead, eopXD, 
MaskRay.
Herald added projects: clang, LLVM.

Adds support for compiling Swift targeting the RISCV64 ABI


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137309

Files:
  clang/lib/Basic/Targets/RISCV.h
  clang/lib/CodeGen/TargetInfo.cpp
  llvm/lib/Target/RISCV/RISCVISelLowering.cpp


Index: llvm/lib/Target/RISCV/RISCVISelLowering.cpp
===
--- llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -8443,6 +8443,8 @@
   default:
 report_fatal_error("Unsupported calling convention");
   case CallingConv::C:
+  case CallingConv::Swift:
+  case CallingConv::SwiftTail:
   case CallingConv::Fast:
 break;
   case CallingConv::GHC:
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -10552,8 +10552,9 @@
 
//===--===//
 
 namespace {
-class RISCVABIInfo : public DefaultABIInfo {
+class RISCVABIInfo : public SwiftABIInfo {
 private:
+  DefaultABIInfo defaultInfo;
   // Size of the integer ('x') registers in bits.
   unsigned XLen;
   // Size of the floating point ('f') registers in bits. Note that the target
@@ -10570,7 +10571,7 @@
 
 public:
   RISCVABIInfo(CodeGen::CodeGenTypes &CGT, unsigned XLen, unsigned FLen)
-  : DefaultABIInfo(CGT), XLen(XLen), FLen(FLen) {}
+  : SwiftABIInfo(CGT), defaultInfo(CGT), XLen(XLen), FLen(FLen) {}
 
   // DefaultABIInfo's classifyReturnType and classifyArgumentType are
   // non-virtual, but computeInfo is virtual, so we overload it.
@@ -10593,6 +10594,14 @@
CharUnits Field1Off,
llvm::Type *Field2Ty,
CharUnits Field2Off) const;
+
+private:
+  bool shouldPassIndirectlyForSwift(ArrayRef scalars,
+bool asReturnValue) const override {
+return occupiesMoreThan(CGT, scalars, /*total*/ 4);
+  }
+
+  bool isSwiftErrorInRegister() const override { return false; }
 };
 } // end anonymous namespace
 
Index: clang/lib/Basic/Targets/RISCV.h
===
--- clang/lib/Basic/Targets/RISCV.h
+++ clang/lib/Basic/Targets/RISCV.h
@@ -96,7 +96,19 @@
 DiagnosticsEngine &Diags) override;
 
   bool hasExtIntType() const override { return true; }
+
+  CallingConvCheckResult checkCallingConvention(CallingConv CC) const override 
{
+switch (CC) {
+case CC_Swift:
+  return CCCR_OK;
+case CC_SwiftAsync:
+  return CCCR_Error;
+default:
+  return CCCR_Warning;
+}
+  }
 };
+
 class LLVM_LIBRARY_VISIBILITY RISCV32TargetInfo : public RISCVTargetInfo {
 public:
   RISCV32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)


Index: llvm/lib/Target/RISCV/RISCVISelLowering.cpp
===
--- llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -8443,6 +8443,8 @@
   default:
 report_fatal_error("Unsupported calling convention");
   case CallingConv::C:
+  case CallingConv::Swift:
+  case CallingConv::SwiftTail:
   case CallingConv::Fast:
 break;
   case CallingConv::GHC:
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -10552,8 +10552,9 @@
 //===--===//
 
 namespace {
-class RISCVABIInfo : public DefaultABIInfo {
+class RISCVABIInfo : public SwiftABIInfo {
 private:
+  DefaultABIInfo defaultInfo;
   // Size of the integer ('x') registers in bits.
   unsigned XLen;
   // Size of the floating point ('f') registers in bits. Note that the target
@@ -10570,7 +10571,7 @@
 
 public:
   RISCVABIInfo(CodeGen::CodeGenTypes &CGT, unsigned XLen, unsigned FLen)
-  : DefaultABIInfo(CGT), XLen(XLen), FLen(FLen) {}
+  : SwiftABIInfo(CGT), defaultInfo(CGT), XLen(XLen), FLen(FLen) {}
 
   // DefaultABIInfo's classifyReturnType and classifyArgumentType are
   // non-virtual, but computeInfo is virtual, so we overload it.
@@ -10593,6 +10594,14 @@
   

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

2022-11-06 Thread Alsey Coleman Miller via Phabricator via cfe-commits
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 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


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,
  

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

2022-11-06 Thread Alsey Coleman Miller via Phabricator via cfe-commits
colemancda updated this revision to Diff 473517.
colemancda added a comment.

Updated clang changes


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137510/new/

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 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


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 scalar

[PATCH] D137512: [clang] Add Swift support for MIPS

2022-11-06 Thread Alsey Coleman Miller via Phabricator via cfe-commits
colemancda created this revision.
Herald added subscribers: atanasyan, jrtc27, arichardson, sdardis.
Herald added a project: All.
colemancda requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Adds support for compiling Swift targeting the MIPS ABI


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137512

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


Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -7704,7 +7704,7 @@
 
//===--===//
 
 namespace {
-class MipsABIInfo : public ABIInfo {
+class MipsABIInfo : public SwiftABIInfo {
   bool IsO32;
   unsigned MinABIStackAlignInBytes, StackAlignInBytes;
   void CoerceToIntArgs(uint64_t TySize,
@@ -7713,9 +7713,10 @@
   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),
-StackAlignInBytes(IsO32 ? 8 : 16) {}
+  MipsABIInfo(CodeGenTypes &CGT, bool _IsO32)
+  : SwiftABIInfo(CGT), IsO32(_IsO32),
+MinABIStackAlignInBytes(IsO32 ? 4 : 8),
+StackAlignInBytes(IsO32 ? 8 : 16) {}
 
   ABIArgInfo classifyReturnType(QualType RetTy) const;
   ABIArgInfo classifyArgumentType(QualType RetTy, uint64_t &Offset) const;
@@ -7723,6 +7724,14 @@
   Address EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
 QualType Ty) const override;
   ABIArgInfo extendType(QualType Ty) const;
+
+private:
+  bool shouldPassIndirectlyForSwift(ArrayRef scalars,
+bool asReturnValue) const override {
+return occupiesMoreThan(CGT, scalars, /*total*/ 4);
+  }
+
+  bool isSwiftErrorInRegister() const override { return false; }
 };
 
 class MIPSTargetCodeGenInfo : public TargetCodeGenInfo {
Index: clang/lib/Basic/Targets/Mips.h
===
--- clang/lib/Basic/Targets/Mips.h
+++ clang/lib/Basic/Targets/Mips.h
@@ -407,6 +407,17 @@
 
   bool validateTarget(DiagnosticsEngine &Diags) const override;
   bool hasExtIntType() const override { return true; }
+
+  CallingConvCheckResult checkCallingConvention(CallingConv CC) const override 
{
+switch (CC) {
+case CC_Swift:
+  return CCCR_OK;
+case CC_SwiftAsync:
+  return CCCR_Error;
+default:
+  return CCCR_Warning;
+}
+  }
 };
 } // namespace targets
 } // namespace clang


Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -7704,7 +7704,7 @@
 //===--===//
 
 namespace {
-class MipsABIInfo : public ABIInfo {
+class MipsABIInfo : public SwiftABIInfo {
   bool IsO32;
   unsigned MinABIStackAlignInBytes, StackAlignInBytes;
   void CoerceToIntArgs(uint64_t TySize,
@@ -7713,9 +7713,10 @@
   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),
-StackAlignInBytes(IsO32 ? 8 : 16) {}
+  MipsABIInfo(CodeGenTypes &CGT, bool _IsO32)
+  : SwiftABIInfo(CGT), IsO32(_IsO32),
+MinABIStackAlignInBytes(IsO32 ? 4 : 8),
+StackAlignInBytes(IsO32 ? 8 : 16) {}
 
   ABIArgInfo classifyReturnType(QualType RetTy) const;
   ABIArgInfo classifyArgumentType(QualType RetTy, uint64_t &Offset) const;
@@ -7723,6 +7724,14 @@
   Address EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
 QualType Ty) const override;
   ABIArgInfo extendType(QualType Ty) const;
+
+private:
+  bool shouldPassIndirectlyForSwift(ArrayRef scalars,
+bool asReturnValue) const override {
+return occupiesMoreThan(CGT, scalars, /*total*/ 4);
+  }
+
+  bool isSwiftErrorInRegister() const override { return false; }
 };
 
 class MIPSTargetCodeGenInfo : public TargetCodeGenInfo {
Index: clang/lib/Basic/Targets/Mips.h
===
--- clang/lib/Basic/Targets/Mips.h
+++ clang/lib/Basic/Targets/Mips.h
@@ -407,6 +407,17 @@
 
   bool validateTarget(DiagnosticsEngine &Diags) const override;
   bool hasExtIntType() const override { return true; }
+
+  CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
+switch (CC) {
+case CC_Swift:
+  return CCCR_OK;
+case CC_SwiftAsync:
+  return CCCR_Error;
+default:
+  return CCCR_Warning;
+}
+  }
 };
 

[PATCH] D137309: [clang] Added Swift support for RISCV

2022-11-08 Thread Alsey Coleman Miller via Phabricator via cfe-commits
colemancda added a comment.

RV32 is enabled as well. I'll add unit tests.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137309/new/

https://reviews.llvm.org/D137309

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D137512: [clang] Add Swift support for MIPS

2022-11-14 Thread Alsey Coleman Miller via Phabricator via cfe-commits
colemancda updated this revision to Diff 475337.
colemancda added a comment.

Rebased


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137512/new/

https://reviews.llvm.org/D137512

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


Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -7864,7 +7864,7 @@
 
//===--===//
 
 namespace {
-class MipsABIInfo : public ABIInfo {
+class MipsABIInfo : public SwiftABIInfo {
   bool IsO32;
   const unsigned MinABIStackAlignInBytes, StackAlignInBytes;
   void CoerceToIntArgs(uint64_t TySize,
@@ -7873,9 +7873,10 @@
   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),
-StackAlignInBytes(IsO32 ? 8 : 16) {}
+  MipsABIInfo(CodeGenTypes &CGT, bool _IsO32)
+  : SwiftABIInfo(CGT), IsO32(_IsO32),
+MinABIStackAlignInBytes(IsO32 ? 4 : 8),
+StackAlignInBytes(IsO32 ? 8 : 16) {}
 
   ABIArgInfo classifyReturnType(QualType RetTy) const;
   ABIArgInfo classifyArgumentType(QualType RetTy, uint64_t &Offset) const;
@@ -7883,6 +7884,14 @@
   Address EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
 QualType Ty) const override;
   ABIArgInfo extendType(QualType Ty) const;
+
+private:
+  bool shouldPassIndirectlyForSwift(ArrayRef scalars,
+bool asReturnValue) const override {
+return occupiesMoreThan(CGT, scalars, /*total*/ 4);
+  }
+
+  bool isSwiftErrorInRegister() const override { return false; }
 };
 
 class MIPSTargetCodeGenInfo : public TargetCodeGenInfo {
Index: clang/lib/Basic/Targets/Mips.h
===
--- clang/lib/Basic/Targets/Mips.h
+++ clang/lib/Basic/Targets/Mips.h
@@ -407,6 +407,17 @@
 
   bool validateTarget(DiagnosticsEngine &Diags) const override;
   bool hasBitIntType() const override { return true; }
+
+  CallingConvCheckResult checkCallingConvention(CallingConv CC) const override 
{
+switch (CC) {
+case CC_Swift:
+  return CCCR_OK;
+case CC_SwiftAsync:
+  return CCCR_Error;
+default:
+  return CCCR_Warning;
+}
+  }
 };
 } // namespace targets
 } // namespace clang


Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -7864,7 +7864,7 @@
 //===--===//
 
 namespace {
-class MipsABIInfo : public ABIInfo {
+class MipsABIInfo : public SwiftABIInfo {
   bool IsO32;
   const unsigned MinABIStackAlignInBytes, StackAlignInBytes;
   void CoerceToIntArgs(uint64_t TySize,
@@ -7873,9 +7873,10 @@
   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),
-StackAlignInBytes(IsO32 ? 8 : 16) {}
+  MipsABIInfo(CodeGenTypes &CGT, bool _IsO32)
+  : SwiftABIInfo(CGT), IsO32(_IsO32),
+MinABIStackAlignInBytes(IsO32 ? 4 : 8),
+StackAlignInBytes(IsO32 ? 8 : 16) {}
 
   ABIArgInfo classifyReturnType(QualType RetTy) const;
   ABIArgInfo classifyArgumentType(QualType RetTy, uint64_t &Offset) const;
@@ -7883,6 +7884,14 @@
   Address EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
 QualType Ty) const override;
   ABIArgInfo extendType(QualType Ty) const;
+
+private:
+  bool shouldPassIndirectlyForSwift(ArrayRef scalars,
+bool asReturnValue) const override {
+return occupiesMoreThan(CGT, scalars, /*total*/ 4);
+  }
+
+  bool isSwiftErrorInRegister() const override { return false; }
 };
 
 class MIPSTargetCodeGenInfo : public TargetCodeGenInfo {
Index: clang/lib/Basic/Targets/Mips.h
===
--- clang/lib/Basic/Targets/Mips.h
+++ clang/lib/Basic/Targets/Mips.h
@@ -407,6 +407,17 @@
 
   bool validateTarget(DiagnosticsEngine &Diags) const override;
   bool hasBitIntType() const override { return true; }
+
+  CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
+switch (CC) {
+case CC_Swift:
+  return CCCR_OK;
+case CC_SwiftAsync:
+  return CCCR_Error;
+default:
+  return CCCR_Warning;
+}
+  }
 };
 } // namespace targets
 } // namespace clang
___
cfe-commits mailing list
cfe-commits@lists.llv

[PATCH] D137309: [clang] Added Swift support for RISCV

2022-11-14 Thread Alsey Coleman Miller via Phabricator via cfe-commits
colemancda added a comment.

In D137309#3914550 , @asb wrote:

> In D137309#3914494 , @colemancda 
> wrote:
>
>> RV32 is enabled as well. I'll add unit tests.
>
> Great, thanks. Is it really the case that shouldPassIndirectlyForSwift has 
> the same result regardless of native word size?

Yes, if you check other implementations like Arm and AArch64, the 
implementation is the same.
Where is a good place to start for the unit test development for this ABI?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137309/new/

https://reviews.llvm.org/D137309

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits