From 12dcc180caf1f1e416456277f2dcb92fbe260c3d Mon Sep 17 00:00:00 2001 From: Richard-Qin-X Date: Thu, 27 Aug 2026 16:09:44 +0800 Subject: [GlobalISel] Select each instruction once --- .../rcc/CodeGen/GlobalISel/InstructionSelector.h | 6 -- .../lib/CodeGen/GlobalISel/InstructionSelect.cpp | 3 - .../RISCV/GISel/RISCVInstructionSelector.cpp | 84 ---------------------- 3 files changed, 93 deletions(-) diff --git a/backend/include/rcc/CodeGen/GlobalISel/InstructionSelector.h b/backend/include/rcc/CodeGen/GlobalISel/InstructionSelector.h index f45b24d..70771bb 100644 --- a/backend/include/rcc/CodeGen/GlobalISel/InstructionSelector.h +++ b/backend/include/rcc/CodeGen/GlobalISel/InstructionSelector.h @@ -19,12 +19,6 @@ public: [[nodiscard]] virtual Expected select(MachineInstr &Instruction, MachineFunction &Function, const TargetDescription &Target) const = 0; - // Selection matching is read-only and completes before select() mutates MachineIR. - [[nodiscard]] virtual Expected canSelect(const MachineInstr &, const MachineFunction &, - const TargetDescription &) const { - return {}; - } - [[nodiscard]] virtual Expected constrainSelectedInstruction(MachineInstr &, MachineFunction &, const TargetDescription &) const { return {}; diff --git a/backend/lib/CodeGen/GlobalISel/InstructionSelect.cpp b/backend/lib/CodeGen/GlobalISel/InstructionSelect.cpp index 6aab43d..88bc78e 100644 --- a/backend/lib/CodeGen/GlobalISel/InstructionSelect.cpp +++ b/backend/lib/CodeGen/GlobalISel/InstructionSelect.cpp @@ -277,9 +277,6 @@ Expected InstructionSelect::runImplementation(MachineFunction CurrentDescriptor->Name + "'", ErrorCode::InternalError)); } - auto Match = Info->canSelect(*Instruction, Function, Target); - if (!Match) - return std::unexpected(Match.error()); std::string Rule = "select."; Rule.append(CurrentDescriptor->Name); auto Accepted = Analyses.requestAction(Rule, Function, Instruction->stableID()); diff --git a/backend/lib/Target/RISCV/GISel/RISCVInstructionSelector.cpp b/backend/lib/Target/RISCV/GISel/RISCVInstructionSelector.cpp index ca702ed..c8e9ab6 100644 --- a/backend/lib/Target/RISCV/GISel/RISCVInstructionSelector.cpp +++ b/backend/lib/Target/RISCV/GISel/RISCVInstructionSelector.cpp @@ -561,87 +561,6 @@ public: }; } - [[nodiscard]] Expected canSelect(const MachineInstr &Instruction, - const MachineFunction &Function, - const TargetDescription &Target) const override { - auto Generated = - GIMatchTableExecutor::match(generatedGlobalISelMatchTable(), Instruction, Function, Target); - if (!Generated) - return std::unexpected(Generated.error()); - if (*Generated) - return {}; - if (!isGenericOpcode(Instruction.opcode())) { - const InstructionDescriptor *Descriptor = Target.instructionDescriptor(Instruction.opcode()); - if (Descriptor != nullptr && !Descriptor->Flags.has(InstructionFlag::Generic)) - return {}; - return makeUnexpected(ErrorCode::Unsupported, - "RISC-V instruction selector has no generated rule for target pseudo"); - } - const GenericOpcode Generic = static_cast(Instruction.opcode().value()); - const std::optional Type = resultType(Function, Instruction); - const auto Integer = [Type] { return Type && isSupportedIntegerType(*Type); }; - const auto Float = [Type] { return Type && isSupportedFloatingScalar(*Type); }; - switch (Generic) { - case GenericOpcode::G_CONSTANT: - if (!Integer()) - return makeUnexpected(ErrorCode::Unsupported, - "RISC-V selector requires an i1-i64 integer or 64-bit pointer value"); - if (Generic == GenericOpcode::G_CONSTANT) { - const MachineOperand *Immediate = Instruction.operandAt(1); - if (Immediate == nullptr || (Immediate->kind() != MachineOperand::Kind::Immediate && - Immediate->kind() != MachineOperand::Kind::IntegerImmediate)) - return makeUnexpected(ErrorCode::VerificationError, - "RISC-V integer constant requires an immediate operand"); - } - return {}; - case GenericOpcode::G_FPEXTLOAD: - case GenericOpcode::G_FPTRUNCSTORE: - case GenericOpcode::G_GLOBAL_VALUE: - case GenericOpcode::G_JUMP_TABLE: - case GenericOpcode::G_CONSTANT_POOL: - return {}; - case GenericOpcode::G_FCONSTANT: { - const MachineOperand *Immediate = Instruction.operandAt(1); - const auto *Floating = - Immediate == nullptr ? nullptr : Immediate->getIf(); - if (!Float() || Floating == nullptr || Floating->Bits.bitWidth() != Type->scalarBitWidth()) - return makeUnexpected(ErrorCode::Unsupported, - "RISC-V selector requires a matching floating constant"); - return {}; - } - case GenericOpcode::G_ANYEXT: - case GenericOpcode::G_ASSERT_SEXT: - case GenericOpcode::G_ASSERT_ZEXT: - case GenericOpcode::G_ASSERT_ALIGN: - case GenericOpcode::G_FREEZE: - case GenericOpcode::G_CONSTANT_FOLD_BARRIER: - case GenericOpcode::G_PTRTOINT: - case GenericOpcode::G_INTTOPTR: - case GenericOpcode::G_TRUNC: - case GenericOpcode::G_FCMP: - case GenericOpcode::G_SMULH: - case GenericOpcode::G_UMULH: - case GenericOpcode::G_SELECT: - case GenericOpcode::G_ATOMICRMW_XCHG: - case GenericOpcode::G_ATOMICRMW_ADD: - case GenericOpcode::G_ATOMICRMW_SUB: - case GenericOpcode::G_ATOMICRMW_AND: - case GenericOpcode::G_ATOMICRMW_OR: - case GenericOpcode::G_ATOMICRMW_XOR: - case GenericOpcode::G_ATOMICRMW_MAX: - case GenericOpcode::G_ATOMICRMW_MIN: - case GenericOpcode::G_ATOMICRMW_UMAX: - case GenericOpcode::G_ATOMICRMW_UMIN: - case GenericOpcode::G_FENCE: - case GenericOpcode::G_BRINDIRECT: - case GenericOpcode::G_PHI: - return {}; - default: - return makeUnexpected(ErrorCode::Unsupported, - "RISC-V instruction selector has no rule for generic opcode"); - } - } - [[nodiscard]] Expected select(MachineInstr &Instruction, MachineFunction &Function, const TargetDescription &Target) const override { auto Generated = GIMatchTableExecutor::select(generatedGlobalISelMatchTable(), Instruction, @@ -652,9 +571,6 @@ public: return {}; if (Instruction.opcode() == opcode(GenericOpcode::COPY)) return selectCopy(Instruction, Function, Target); - auto Match = canSelect(Instruction, Function, Target); - if (!Match) - return std::unexpected(Match.error()); const GenericOpcode Generic = static_cast(Instruction.opcode().value()); const std::optional Type = resultType(Function, Instruction); -- cgit v1.2.3