From 53145c4020d237d2572b4109e0d425863dc34f9b Mon Sep 17 00:00:00 2001 From: Richard-Qin-X Date: Mon, 17 Aug 2026 02:56:45 +0800 Subject: [RISCV][GlobalISel] Generate implicit-def selection --- .../lib/Target/RISCV/GISel/RISCVInstructionSelector.cpp | 3 --- backend/lib/Target/RISCV/RISCVGISelInteger.rccdesc | 10 ++++++++++ backend/utils/TableGen/Common/CodeGenSelection.cpp | 15 ++++++++++----- 3 files changed, 20 insertions(+), 8 deletions(-) (limited to 'backend') diff --git a/backend/lib/Target/RISCV/GISel/RISCVInstructionSelector.cpp b/backend/lib/Target/RISCV/GISel/RISCVInstructionSelector.cpp index bd46144..cde2c8d 100644 --- a/backend/lib/Target/RISCV/GISel/RISCVInstructionSelector.cpp +++ b/backend/lib/Target/RISCV/GISel/RISCVInstructionSelector.cpp @@ -405,7 +405,6 @@ public: case GenericOpcode::G_DEBUGTRAP: case GenericOpcode::G_UBSANTRAP: case GenericOpcode::G_PHI: - case GenericOpcode::G_IMPLICIT_DEF: return {}; default: return makeUnexpected(ErrorCode::Unsupported, @@ -493,8 +492,6 @@ public: return selectTrap(Instruction); case GenericOpcode::G_PHI: return Instruction.setOpcode(opcode(GenericOpcode::PHI)); - case GenericOpcode::G_IMPLICIT_DEF: - return Instruction.setOpcode(opcode(GenericOpcode::IMPLICIT_DEF)); case GenericOpcode::COPY: case GenericOpcode::IMPLICIT_DEF: case GenericOpcode::PHI: diff --git a/backend/lib/Target/RISCV/RISCVGISelInteger.rccdesc b/backend/lib/Target/RISCV/RISCVGISelInteger.rccdesc index 1667f66..f40e5d4 100644 --- a/backend/lib/Target/RISCV/RISCVGISelInteger.rccdesc +++ b/backend/lib/Target/RISCV/RISCVGISelInteger.rccdesc @@ -1,4 +1,14 @@ selection_rules: + - + id: select_g_implicit_def + priority: 100 + match: + opcode: G_IMPLICIT_DEF + apply: + instructions: + - opcode: IMPLICIT_DEF + root: true + operands: [{ operand: 0 }] - id: select_g_sext_s64_s32 priority: 500 diff --git a/backend/utils/TableGen/Common/CodeGenSelection.cpp b/backend/utils/TableGen/Common/CodeGenSelection.cpp index d3bc299..95a924f 100644 --- a/backend/utils/TableGen/Common/CodeGenSelection.cpp +++ b/backend/utils/TableGen/Common/CodeGenSelection.cpp @@ -416,10 +416,14 @@ bool CodeGenTarget::normalizeSelectionRules(NormalizedTargetModel &Result) { const auto ResultOpcode = resolveOpcode(Result, Action.ResultOpcodeSymbol); const NormalizedInstruction *ResultInstruction = findInstructionBySymbol(Result, Action.ResultOpcodeSymbol); - if (!ResultOpcode || ResultInstruction == nullptr || - isGenericOpcode(Opcode::fromValue(*ResultOpcode)) || - std::ranges::contains(ResultInstruction->Flags, "Generic")) { - fail(Action.Range, "selection instruction opcode must name a declared target instruction"); + const bool IsCorePseudo = + ResultOpcode && isCorePseudoOpcode(Opcode::fromValue(*ResultOpcode)); + if (!ResultOpcode || (ResultInstruction == nullptr && !IsCorePseudo) || + (ResultInstruction != nullptr && + (isGenericOpcode(Opcode::fromValue(*ResultOpcode)) || + std::ranges::contains(ResultInstruction->Flags, "Generic")))) { + fail(Action.Range, + "selection instruction opcode must name a declared target instruction or core pseudo"); return false; } if (Action.ReplacesRoot == HasRootAction || (Action.ReplacesRoot && ActionIndex != 0)) { @@ -428,7 +432,8 @@ bool CodeGenTarget::normalizeSelectionRules(NormalizedTargetModel &Result) { return false; } HasRootAction |= Action.ReplacesRoot; - if (ResultInstruction->Operands.size() != Action.OperandRenderers.size()) { + if (ResultInstruction != nullptr && + ResultInstruction->Operands.size() != Action.OperandRenderers.size()) { fail(Action.Range, "selection instruction has an incompatible operand count"); return false; } -- cgit v1.2.3