diff options
| author | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-27 16:09:44 +0800 |
|---|---|---|
| committer | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-27 16:09:44 +0800 |
| commit | 12dcc180caf1f1e416456277f2dcb92fbe260c3d (patch) | |
| tree | da8322bb19deb2f95ae95a6f2365f26c476f301a | |
| parent | 5fd19fbe147eaff6e65e7dc3b63b324d80f19a05 (diff) | |
| download | rcc-project-12dcc180caf1f1e416456277f2dcb92fbe260c3d.tar.gz rcc-project-12dcc180caf1f1e416456277f2dcb92fbe260c3d.tar.xz | |
[GlobalISel] Select each instruction once
3 files changed, 0 insertions, 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<void> select(MachineInstr &Instruction, MachineFunction &Function, const TargetDescription &Target) const = 0; - // Selection matching is read-only and completes before select() mutates MachineIR. - [[nodiscard]] virtual Expected<void> canSelect(const MachineInstr &, const MachineFunction &, - const TargetDescription &) const { - return {}; - } - [[nodiscard]] virtual Expected<void> 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<MachinePassResult> 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<void> 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<GenericOpcode>(Instruction.opcode().value()); - const std::optional<LowLevelType> 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<FloatingImmediateOperand>(); - 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<void> 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<GenericOpcode>(Instruction.opcode().value()); const std::optional<LowLevelType> Type = resultType(Function, Instruction); |
