From 558485504773804d56f0552517dbe42722742741 Mon Sep 17 00:00:00 2001 From: Richard-Qin-X Date: Fri, 14 Aug 2026 22:07:42 +0800 Subject: [RISCV] Legalize va_copy intrinsics --- .../include/rcc/CodeGen/GlobalISel/LegalizerInfo.h | 79 ++++++++++------------ 1 file changed, 36 insertions(+), 43 deletions(-) (limited to 'backend/include') diff --git a/backend/include/rcc/CodeGen/GlobalISel/LegalizerInfo.h b/backend/include/rcc/CodeGen/GlobalISel/LegalizerInfo.h index d3515f3..9162526 100644 --- a/backend/include/rcc/CodeGen/GlobalISel/LegalizerInfo.h +++ b/backend/include/rcc/CodeGen/GlobalISel/LegalizerInfo.h @@ -4,8 +4,8 @@ #define RCC_CODEGEN_GLOBALISEL_LEGALIZERINFO_H #include "rcc/CodeGen/LowLevelType.h" -#include "rcc/CodeGen/MachineMemOperand.h" #include "rcc/CodeGen/MachineIRTypes.h" +#include "rcc/CodeGen/MachineMemOperand.h" #include "rcc/Support/Error.h" #include @@ -98,14 +98,12 @@ class LegalizeRuleSet final { public: LegalizeRuleSet &actionIf(LegalizationAction Action, LegalityPredicate Predicate, LegalizeMutation Mutation = {}); + LegalizeRuleSet &actionFor(LegalizationAction Action, std::initializer_list Types); LegalizeRuleSet &actionFor(LegalizationAction Action, - std::initializer_list Types); - LegalizeRuleSet &actionFor( - LegalizationAction Action, - std::initializer_list> Types); - LegalizeRuleSet &actionFor( - LegalizationAction Action, - std::initializer_list> Types); + std::initializer_list> Types); + LegalizeRuleSet & + actionFor(LegalizationAction Action, + std::initializer_list> Types); LegalizeRuleSet &legalIf(LegalityPredicate Predicate); LegalizeRuleSet &customIf(LegalityPredicate Predicate); LegalizeRuleSet &lowerIf(LegalityPredicate Predicate); @@ -119,38 +117,30 @@ public: LegalizeRuleSet &legalFor(std::initializer_list Types); LegalizeRuleSet &legalFor(bool Enabled, std::initializer_list Types); - LegalizeRuleSet &legalFor( - std::initializer_list> Types); - LegalizeRuleSet &legalFor( - bool Enabled, std::initializer_list> Types); - LegalizeRuleSet &legalFor( - std::initializer_list> Types); + LegalizeRuleSet &legalFor(std::initializer_list> Types); + LegalizeRuleSet &legalFor(bool Enabled, + std::initializer_list> Types); + LegalizeRuleSet & + legalFor(std::initializer_list> Types); LegalizeRuleSet &customFor(std::initializer_list Types); LegalizeRuleSet &customFor(bool Enabled, std::initializer_list Types); - LegalizeRuleSet &customFor( - std::initializer_list> Types); - LegalizeRuleSet &customFor( - bool Enabled, std::initializer_list> Types); + LegalizeRuleSet &customFor(std::initializer_list> Types); + LegalizeRuleSet &customFor(bool Enabled, + std::initializer_list> Types); LegalizeRuleSet &lowerFor(std::initializer_list Types); - LegalizeRuleSet &lowerFor( - std::initializer_list> Types); + LegalizeRuleSet &lowerFor(std::initializer_list> Types); LegalizeRuleSet &libcallFor(std::initializer_list Types); LegalizeRuleSet &libcallFor(bool Enabled, std::initializer_list Types); - LegalizeRuleSet &libcallFor( - std::initializer_list> Types); - LegalizeRuleSet &libcallFor( - bool Enabled, std::initializer_list> Types); - LegalizeRuleSet &legalForTypesWithMemDesc( - std::initializer_list Rules); - - LegalizeRuleSet &widenScalarToNextPow2(std::size_t TypeIndex, - std::uint32_t MinimumBitWidth = 0); + LegalizeRuleSet &libcallFor(std::initializer_list> Types); + LegalizeRuleSet &libcallFor(bool Enabled, + std::initializer_list> Types); + LegalizeRuleSet &legalForTypesWithMemDesc(std::initializer_list Rules); + + LegalizeRuleSet &widenScalarToNextPow2(std::size_t TypeIndex, std::uint32_t MinimumBitWidth = 0); LegalizeRuleSet &minScalar(std::size_t TypeIndex, LowLevelType MinimumType); - LegalizeRuleSet &minScalar(bool Enabled, std::size_t TypeIndex, - LowLevelType MinimumType); + LegalizeRuleSet &minScalar(bool Enabled, std::size_t TypeIndex, LowLevelType MinimumType); LegalizeRuleSet &maxScalar(std::size_t TypeIndex, LowLevelType MaximumType); - LegalizeRuleSet &maxScalar(bool Enabled, std::size_t TypeIndex, - LowLevelType MaximumType); + LegalizeRuleSet &maxScalar(bool Enabled, std::size_t TypeIndex, LowLevelType MaximumType); LegalizeRuleSet &clampScalar(std::size_t TypeIndex, LowLevelType MinimumType, LowLevelType MaximumType); LegalizeRuleSet &scalarSameSizeAs(std::size_t TypeIndex, std::size_t ReferenceTypeIndex); @@ -159,8 +149,7 @@ public: LegalizeRuleSet &lower(); LegalizeRuleSet &libcall(); - [[nodiscard]] std::optional - apply(const LegalizationQuery &Query) const; + [[nodiscard]] std::optional apply(const LegalizationQuery &Query) const; private: std::vector Rules; @@ -170,16 +159,15 @@ class LegalizerInfo { public: virtual ~LegalizerInfo() = default; - [[nodiscard]] static Expected - buildQuery(const MachineInstr &Instruction, const MachineFunction &Function, - const TargetDescription &Target); + [[nodiscard]] static Expected buildQuery(const MachineInstr &Instruction, + const MachineFunction &Function, + const TargetDescription &Target); - [[nodiscard]] Expected - getDecision(const MachineInstr &Instruction, const MachineFunction &Function, - const TargetDescription &Target) const; + [[nodiscard]] Expected getDecision(const MachineInstr &Instruction, + const MachineFunction &Function, + const TargetDescription &Target) const; - [[nodiscard]] Expected - getDecision(const LegalizationQuery &Query) const; + [[nodiscard]] Expected getDecision(const LegalizationQuery &Query) const; [[nodiscard]] Expected isLegal(const LegalizationQuery &Query) const; [[nodiscard]] Expected isUnsupported(const LegalizationQuery &Query) const; @@ -188,6 +176,11 @@ public: legalizeCustom(LegalizerHelper &Helper, MachineInstr &Instruction, const LegalizationDecision &Decision) const = 0; + // Target intrinsic lowering runs before the ordinary legality action. + [[nodiscard]] virtual Expected legalizeIntrinsic(LegalizerHelper &, MachineInstr &) const { + return true; + } + // This hook performs read-only target checks before a lowering mutation is committed. [[nodiscard]] virtual Expected validateLowering(const MachineInstr &, const MachineFunction &, -- cgit v1.2.3