diff --git a/clang/lib/Basic/Targets/RISCV.h b/clang/lib/Basic/Targets/RISCV.h --- a/clang/lib/Basic/Targets/RISCV.h +++ b/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) diff --git a/clang/lib/CodeGen/TargetInfo.cpp b/clang/lib/CodeGen/TargetInfo.cpp --- a/clang/lib/CodeGen/TargetInfo.cpp +++ b/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 diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp --- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp +++ b/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: