diff options
| author | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-08 02:58:50 +0800 |
|---|---|---|
| committer | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-08 02:58:50 +0800 |
| commit | 10b7e69448f866bcd6893b21d7f78d766252eb11 (patch) | |
| tree | fe937dbf2084a0c176a23ed8a08a47ea20a9c1a3 /backend/include/rcc/CodeGen/TargetCodeGen.h | |
| parent | f99ef4322a7a2c09380fff61f88ab9440f05a92c (diff) | |
| download | rcc-project-10b7e69448f866bcd6893b21d7f78d766252eb11.tar.gz rcc-project-10b7e69448f866bcd6893b21d7f78d766252eb11.tar.xz | |
[CodeGen] Implement RV64GC legalization and instruction selection
Diffstat (limited to 'backend/include/rcc/CodeGen/TargetCodeGen.h')
| -rw-r--r-- | backend/include/rcc/CodeGen/TargetCodeGen.h | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/backend/include/rcc/CodeGen/TargetCodeGen.h b/backend/include/rcc/CodeGen/TargetCodeGen.h new file mode 100644 index 0000000..b1be1f6 --- /dev/null +++ b/backend/include/rcc/CodeGen/TargetCodeGen.h @@ -0,0 +1,94 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +#ifndef RCC_CODEGEN_TARGETCODEGEN_H +#define RCC_CODEGEN_TARGETCODEGEN_H + +#include "rcc/CodeGen/MachineIRTypes.h" +#include "rcc/CodeGen/Register.h" +#include "rcc/Support/Error.h" + +#include <cstdint> +#include <optional> + +namespace rcc { + +class MachineFunction; +class MachineInstr; +class MachineRegisterInfo; +class TargetDescription; +struct VirtualRegisterInfo; + +enum class LegalizationAction : std::uint8_t { + Legal, + Unsupported, + Custom, + Lower, + Libcall, + WidenScalar, + NarrowScalar, + MoreElements, + FewerElements, + Bitcast, + ChangeElementType, + ChangeAddressSpace, +}; + +class TargetLegalizerInfo { +public: + virtual ~TargetLegalizerInfo() = default; + + [[nodiscard]] virtual Expected<LegalizationAction> + classify(const MachineInstr &Instruction, const MachineFunction &Function, + const TargetDescription &Target) const = 0; + + [[nodiscard]] virtual Expected<void> lower(MachineInstr &Instruction, MachineFunction &Function, + const TargetDescription &Target, + LegalizationAction Action) const = 0; + + // This hook performs read-only target checks before a lowering mutation is committed. + [[nodiscard]] virtual Expected<void> validateLowering(const MachineInstr &, + const MachineFunction &, + const TargetDescription &, + LegalizationAction) const { + return {}; + } +}; + +class TargetRegisterBankInfo { +public: + virtual ~TargetRegisterBankInfo() = default; + + [[nodiscard]] virtual Expected<RegisterBankID> + selectBank(const MachineFunction &Function, Register Reg, const VirtualRegisterInfo &Info, + const MachineInstr *Context, const TargetDescription &Target) const = 0; + + [[nodiscard]] virtual Expected<void> + constrainInstruction(MachineInstr &Instruction, MachineFunction &Function, + const TargetDescription &Target) const = 0; + + // This hook must not mutate MachineIR. It allows the pass to reject a bad mapping + // before publishing any bank or class assignment. + [[nodiscard]] virtual Expected<void> validateInstruction(const MachineInstr &, + const MachineFunction &, + const TargetDescription &) const { + return {}; + } +}; + +class TargetInstructionSelector { +public: + virtual ~TargetInstructionSelector() = default; + + [[nodiscard]] virtual Expected<void> select(MachineInstr &Instruction, MachineFunction &Function, + const TargetDescription &Target) const = 0; + + // Selection matching is read-only and must complete before select() mutates MachineIR. + [[nodiscard]] virtual Expected<void> canSelect(const MachineInstr &, const MachineFunction &, + const TargetDescription &) const { + return {}; + } +}; + +} // namespace rcc + +#endif // RCC_CODEGEN_TARGETCODEGEN_H |
