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<llvm::Type *> 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 @@ CharUnits Field1Off, llvm::Type *Field2Ty, CharUnits Field2Off) const; + +private: + bool shouldPassIndirectlyForSwift(ArrayRef<llvm::Type *> 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)
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits