From f99ef4322a7a2c09380fff61f88ab9440f05a92c Mon Sep 17 00:00:00 2001 From: Richard-Qin-X Date: Fri, 7 Aug 2026 22:06:28 +0800 Subject: [CodeGen] Complete machine pass and ABI lowering infrastructure --- backend/include/rcc/CodeGen/GenericOpcodes.h | 68 ++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 backend/include/rcc/CodeGen/GenericOpcodes.h (limited to 'backend/include/rcc/CodeGen/GenericOpcodes.h') diff --git a/backend/include/rcc/CodeGen/GenericOpcodes.h b/backend/include/rcc/CodeGen/GenericOpcodes.h new file mode 100644 index 0000000..5a46e21 --- /dev/null +++ b/backend/include/rcc/CodeGen/GenericOpcodes.h @@ -0,0 +1,68 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +#ifndef RCC_CODEGEN_GENERICOPCODES_H +#define RCC_CODEGEN_GENERICOPCODES_H + +#include "rcc/CodeGen/InstructionDescriptor.h" + +#include +#include +#include +#include + +namespace rcc { + +// Target-independent values are build-local. Target tables start at 1024 and +// are appended to this set when a target description is constructed. +enum class GenericOpcode : std::uint32_t { + Invalid, +#define RCC_CORE_OPCODE(Name) Name, +#define RCC_GENERIC_OPCODE(Name) +#include "rcc/CodeGen/GenericOpcode.def" +#undef RCC_GENERIC_OPCODE +#undef RCC_CORE_OPCODE + CORE_PSEUDO_END, + +#define RCC_CORE_OPCODE(Name) +#define RCC_GENERIC_OPCODE(Name) Name, +#include "rcc/CodeGen/GenericOpcode.def" +#undef RCC_GENERIC_OPCODE +#undef RCC_CORE_OPCODE + G_GENERIC_END, +}; + +[[nodiscard]] constexpr Opcode opcode(GenericOpcode Generic) noexcept { + return Opcode::fromValue(static_cast(Generic)); +} + +[[nodiscard]] constexpr bool isGenericOpcode(Opcode Value) noexcept { + return Value.value() >= static_cast(GenericOpcode::G_ASSERT_SEXT) && + Value.value() < static_cast(GenericOpcode::G_GENERIC_END); +} + +[[nodiscard]] constexpr bool isCorePseudoOpcode(Opcode Value) noexcept { + return Value.value() >= static_cast(GenericOpcode::PHI) && + Value.value() < static_cast(GenericOpcode::CORE_PSEUDO_END); +} + +inline constexpr std::size_t CorePseudoOpcodeCount = + static_cast(GenericOpcode::CORE_PSEUDO_END) - + static_cast(GenericOpcode::PHI); + +inline constexpr std::size_t GenericOpcodeCount = + static_cast(GenericOpcode::G_GENERIC_END) - + static_cast(GenericOpcode::G_ASSERT_SEXT); + +[[nodiscard]] std::string_view getGenericOpcodeName(GenericOpcode OpcodeValue) noexcept; + +[[nodiscard]] std::span genericInstructionDescriptors() noexcept; + +[[nodiscard]] std::span genericImmediatePredicates() noexcept; + +[[nodiscard]] Expected +appendGenericInstructionInfo(std::vector &Descriptors, + std::vector &Predicates); + +} // namespace rcc + +#endif // RCC_CODEGEN_GENERICOPCODES_H -- cgit v1.2.3