From 6e8feb15a0d256ca19e88185f78c81f689ce7d34 Mon Sep 17 00:00:00 2001 From: Richard-Qin-X Date: Fri, 28 Aug 2026 14:07:11 +0800 Subject: [RISCV] Separate calling convention assignment --- backend/lib/Target/RISCV/RISCVCallingConv.h | 52 +++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 backend/lib/Target/RISCV/RISCVCallingConv.h (limited to 'backend/lib/Target/RISCV/RISCVCallingConv.h') diff --git a/backend/lib/Target/RISCV/RISCVCallingConv.h b/backend/lib/Target/RISCV/RISCVCallingConv.h new file mode 100644 index 0000000..ba2dcf2 --- /dev/null +++ b/backend/lib/Target/RISCV/RISCVCallingConv.h @@ -0,0 +1,52 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +#ifndef RCC_LIB_TARGET_RISCV_RISCVCALLINGCONV_H +#define RCC_LIB_TARGET_RISCV_RISCVCALLINGCONV_H + +#include "rcc/CodeGen/TargetCallLowering.h" +#include "rcc/Target/RISCV/RISCVInstructions.h" + +#include +#include +#include +#include +#include + +namespace rcc::riscv { + +struct CallingConventionInfo; + +inline constexpr std::uint64_t XLenBytes = 8; +inline constexpr std::uint64_t ABIStackAlignmentBytes = 16; + +[[nodiscard]] constexpr CallingConventionID +callingConventionID(CallingConvention Convention) noexcept { + return CallingConventionID::fromValue(static_cast(Convention)); +} + +struct ArgumentAssignmentResult final { + std::vector Assignments; + StackArgumentArea StackArea; + std::size_t FirstUnallocatedGPR = 0; +}; + +[[nodiscard]] Expected verifyValueSequence(std::span Values, + bool RequireRegisters); +[[nodiscard]] Expected +assignArguments(std::span Values, std::size_t FixedArgumentCount, bool IsVariadic, + const CallingConventionInfo &Convention); +[[nodiscard]] Expected> +assignReturns(std::span Values, bool RequireRegisters, + const CallingConventionInfo &Convention); +[[nodiscard]] bool hasStructReturn(std::span Arguments) noexcept; +[[nodiscard]] Expected +tailCallRejection(const CallLoweringRequest &Request, const ArgumentAssignmentResult &Arguments, + std::span Results, + std::span ByValCopies, + const CallingConventionInfo &Convention); +[[nodiscard]] Expected +riscvConvention(CallingConventionID Convention); + +} // namespace rcc::riscv + +#endif // RCC_LIB_TARGET_RISCV_RISCVCALLINGCONV_H -- cgit v1.2.3