From f5c592905e6e1ef4b78337d76c8215e543607b8d Mon Sep 17 00:00:00 2001 From: Richard-Qin-X Date: Mon, 17 Aug 2026 03:16:26 +0800 Subject: [RISCV][GlobalISel] Generate conditional branch selection --- .../CodeGen/GlobalISel/GIMatchTableExecutor.cpp | 32 ++++++++++++++++++---- 1 file changed, 27 insertions(+), 5 deletions(-) (limited to 'backend/lib/CodeGen/GlobalISel') diff --git a/backend/lib/CodeGen/GlobalISel/GIMatchTableExecutor.cpp b/backend/lib/CodeGen/GlobalISel/GIMatchTableExecutor.cpp index 739f12b..d4f73f6 100644 --- a/backend/lib/CodeGen/GlobalISel/GIMatchTableExecutor.cpp +++ b/backend/lib/CodeGen/GlobalISel/GIMatchTableExecutor.cpp @@ -94,15 +94,16 @@ namespace { } [[nodiscard]] Expected matchesIntegerPredicate(const MachineInstr &Instruction, - const GIMatchTableInstruction &Step) { - if (Step.Value >= static_cast(IntegerPredicate::Count)) { + std::size_t OperandIndex, + std::uint32_t PredicateValue) { + if (PredicateValue >= static_cast(IntegerPredicate::Count)) { return makeUnexpected(ErrorCode::VerificationError, "generated match table has an invalid integer predicate"); } - const MachineOperand *Operand = Instruction.operandAt(Step.OperandIndex); + const MachineOperand *Operand = Instruction.operandAt(OperandIndex); const auto *Predicate = Operand == nullptr ? nullptr : Operand->getIf(); const IntegerPredicate *Integer = Predicate == nullptr ? nullptr : Predicate->integerPredicate(); - return Integer != nullptr && static_cast(*Integer) == Step.Value; + return Integer != nullptr && static_cast(*Integer) == PredicateValue; } [[nodiscard]] std::optional immediateValue(const MachineOperand &Operand) { @@ -205,6 +206,15 @@ operandOrDefConstantValue(const MachineInstr &Instruction, const MachineFunction return Definition != nullptr && Definition->opcode().value() == Step.Value; } +[[nodiscard]] Expected +matchesOperandDefIntegerPredicate(const MachineInstr &Instruction, const MachineFunction &Function, + const GIMatchTableInstruction &Step) { + const MachineInstr *Definition = operandDefinition(Instruction, Function, Step.OperandIndex); + if (Definition == nullptr) + return false; + return matchesIntegerPredicate(*Definition, Step.Auxiliary, Step.Value); +} + [[nodiscard]] Expected matchesOperandDefOperandConstantRanges(const GIMatchTable &Table, const MachineInstr &Instruction, const MachineFunction &Function, @@ -367,7 +377,7 @@ matchRule(const GIMatchTable &Table, const GIMatchTableRule &Rule, const Machine return makeUnexpected(ErrorCode::VerificationError, "generated match table performs a predicate after an action"); } - auto Matched = matchesIntegerPredicate(Instruction, Step); + auto Matched = matchesIntegerPredicate(Instruction, Step.OperandIndex, Step.Value); if (!Matched) return std::unexpected(Matched.error()); if (!*Matched) @@ -422,6 +432,18 @@ matchRule(const GIMatchTable &Table, const GIMatchTableRule &Rule, const Machine return std::optional{}; break; } + case GIMatchTableOpcode::CheckOperandDefIntegerPredicate: { + if (Applying) { + return makeUnexpected(ErrorCode::VerificationError, + "generated match table performs a predicate after an action"); + } + auto Matched = matchesOperandDefIntegerPredicate(Instruction, Function, Step); + if (!Matched) + return std::unexpected(Matched.error()); + if (!*Matched) + return std::optional{}; + break; + } case GIMatchTableOpcode::CheckOperandDefOperandConstantRanges: { if (Applying) { return makeUnexpected(ErrorCode::VerificationError, -- cgit v1.2.3