diff options
Diffstat (limited to 'backend/lib/CodeGen/GlobalISel/GIMatchTableExecutor.cpp')
| -rw-r--r-- | backend/lib/CodeGen/GlobalISel/GIMatchTableExecutor.cpp | 32 |
1 files changed, 27 insertions, 5 deletions
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<bool> matchesIntegerPredicate(const MachineInstr &Instruction, - const GIMatchTableInstruction &Step) { - if (Step.Value >= static_cast<std::uint32_t>(IntegerPredicate::Count)) { + std::size_t OperandIndex, + std::uint32_t PredicateValue) { + if (PredicateValue >= static_cast<std::uint32_t>(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<PredicateOperand>(); const IntegerPredicate *Integer = Predicate == nullptr ? nullptr : Predicate->integerPredicate(); - return Integer != nullptr && static_cast<std::uint32_t>(*Integer) == Step.Value; + return Integer != nullptr && static_cast<std::uint32_t>(*Integer) == PredicateValue; } [[nodiscard]] std::optional<std::int64_t> immediateValue(const MachineOperand &Operand) { @@ -206,6 +207,15 @@ operandOrDefConstantValue(const MachineInstr &Instruction, const MachineFunction } [[nodiscard]] Expected<bool> +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<bool> matchesOperandDefOperandConstantRanges(const GIMatchTable &Table, const MachineInstr &Instruction, const MachineFunction &Function, const GIMatchTableInstruction &Step) { @@ -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<MatchedRule>{}; 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<MatchedRule>{}; + break; + } case GIMatchTableOpcode::CheckOperandDefOperandConstantRanges: { if (Applying) { return makeUnexpected(ErrorCode::VerificationError, |
