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 --- backend/lib/CodeGen/GlobalISel/Legalizer.cpp | 33 ++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'backend/lib/CodeGen/GlobalISel') diff --git a/backend/lib/CodeGen/GlobalISel/Legalizer.cpp b/backend/lib/CodeGen/GlobalISel/Legalizer.cpp index c749039..dfa4523 100644 --- a/backend/lib/CodeGen/GlobalISel/Legalizer.cpp +++ b/backend/lib/CodeGen/GlobalISel/Legalizer.cpp @@ -70,6 +70,18 @@ namespace { } } +[[nodiscard]] bool isIntrinsicOpcode(Opcode InstructionOpcode) noexcept { + switch (static_cast(InstructionOpcode.value())) { + default: + return false; + case GenericOpcode::G_INTRINSIC: + case GenericOpcode::G_INTRINSIC_W_SIDE_EFFECTS: + case GenericOpcode::G_INTRINSIC_CONVERGENT: + case GenericOpcode::G_INTRINSIC_CONVERGENT_W_SIDE_EFFECTS: + return true; + } +} + using InstList = GISelWorkList<256>; using ArtifactList = GISelWorkList<128>; @@ -329,6 +341,27 @@ Expected Legalizer::runImplementation(MachineFunction &Functi withErrorContext(Validation.error(), "legalizer input is invalid: ")); } + if (isIntrinsicOpcode(Instruction->opcode())) { + auto Accepted = Actions.request("legalize.intrinsic", Function, Instruction->stableID()); + if (!Accepted) + return std::unexpected(Accepted.error()); + if (!*Accepted) + return std::unexpected(passFailure("required intrinsic legalization action was rejected", + ErrorCode::VerificationError)); + auto IntrinsicResult = Info->legalizeIntrinsic(Helper, *Instruction); + if (!IntrinsicResult) + return std::unexpected(IntrinsicResult.error()); + if (!*IntrinsicResult) { + const std::string_view Name = Descriptor->Name; + return std::unexpected(passFailure("target legalizer rejected intrinsic instruction '" + + std::string(Name) + "'", + ErrorCode::Unsupported)); + } + Result.Changed = true; + Result.Changes.add(MachinePassChange::Instructions); + continue; + } + auto Decision = Info->getDecision(*Instruction, Function, Target); if (!Decision) return std::unexpected(Decision.error()); -- cgit v1.2.3