aboutsummaryrefslogtreecommitdiff
path: root/backend/lib/Target/RISCV/RISCVCallingConv.h
blob: ba2dcf2ded87603aeffbd42592829746b1a1a628 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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 <cstddef>
#include <cstdint>
#include <span>
#include <string>
#include <vector>

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<std::uint32_t>(Convention));
}

struct ArgumentAssignmentResult final {
  std::vector<CCAssignment> Assignments;
  StackArgumentArea StackArea;
  std::size_t FirstUnallocatedGPR = 0;
};

[[nodiscard]] Expected<std::size_t> verifyValueSequence(std::span<const ABIValue> Values,
                                                        bool RequireRegisters);
[[nodiscard]] Expected<ArgumentAssignmentResult>
assignArguments(std::span<const ABIValue> Values, std::size_t FixedArgumentCount, bool IsVariadic,
                const CallingConventionInfo &Convention);
[[nodiscard]] Expected<std::vector<CCAssignment>>
assignReturns(std::span<const ABIValue> Values, bool RequireRegisters,
              const CallingConventionInfo &Convention);
[[nodiscard]] bool hasStructReturn(std::span<const ABIValue> Arguments) noexcept;
[[nodiscard]] Expected<std::string>
tailCallRejection(const CallLoweringRequest &Request, const ArgumentAssignmentResult &Arguments,
                  std::span<const CCAssignment> Results,
                  std::span<const ByValCopyAssignment> ByValCopies,
                  const CallingConventionInfo &Convention);
[[nodiscard]] Expected<const CallingConventionInfo *>
riscvConvention(CallingConventionID Convention);

} // namespace rcc::riscv

#endif // RCC_LIB_TARGET_RISCV_RISCVCALLINGCONV_H