aboutsummaryrefslogtreecommitdiff
path: root/backend/lib/CodeGen/GlobalISel/GIMatchTableExecutor.cpp
diff options
context:
space:
mode:
authorRichard-Qin-X <richard.qin.001@gmail.com>2026-08-19 03:19:40 +0800
committerRichard-Qin-X <richard.qin.001@gmail.com>2026-08-19 03:19:40 +0800
commit69e1baa931dfa63838683378fa20ed9c46c68a70 (patch)
treed8ae9222ed52c3036b30371241bd593e0324ce6c /backend/lib/CodeGen/GlobalISel/GIMatchTableExecutor.cpp
parentc0f2700e0c7effc5da267bf501232ff4bfea63bc (diff)
downloadrcc-project-69e1baa931dfa63838683378fa20ed9c46c68a70.tar.gz
rcc-project-69e1baa931dfa63838683378fa20ed9c46c68a70.tar.xz
[RISCV][GlobalISel] Match floating comparisons
Diffstat (limited to 'backend/lib/CodeGen/GlobalISel/GIMatchTableExecutor.cpp')
-rw-r--r--backend/lib/CodeGen/GlobalISel/GIMatchTableExecutor.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/backend/lib/CodeGen/GlobalISel/GIMatchTableExecutor.cpp b/backend/lib/CodeGen/GlobalISel/GIMatchTableExecutor.cpp
index d4f73f6..3597509 100644
--- a/backend/lib/CodeGen/GlobalISel/GIMatchTableExecutor.cpp
+++ b/backend/lib/CodeGen/GlobalISel/GIMatchTableExecutor.cpp
@@ -106,6 +106,20 @@ namespace {
return Integer != nullptr && static_cast<std::uint32_t>(*Integer) == PredicateValue;
}
+[[nodiscard]] Expected<bool> matchesFloatingPredicate(const MachineInstr &Instruction,
+ std::size_t OperandIndex,
+ std::uint32_t PredicateValue) {
+ if (PredicateValue >= static_cast<std::uint32_t>(FloatingPredicate::Count)) {
+ return makeUnexpected(ErrorCode::VerificationError,
+ "generated match table has an invalid floating predicate");
+ }
+ const MachineOperand *Operand = Instruction.operandAt(OperandIndex);
+ const auto *Predicate = Operand == nullptr ? nullptr : Operand->getIf<PredicateOperand>();
+ const FloatingPredicate *Floating =
+ Predicate == nullptr ? nullptr : Predicate->floatingPredicate();
+ return Floating != nullptr && static_cast<std::uint32_t>(*Floating) == PredicateValue;
+}
+
[[nodiscard]] std::optional<std::int64_t> immediateValue(const MachineOperand &Operand) {
if (const std::int64_t *Immediate = Operand.getIf<std::int64_t>())
return *Immediate;
@@ -384,6 +398,18 @@ matchRule(const GIMatchTable &Table, const GIMatchTableRule &Rule, const Machine
return std::optional<MatchedRule>{};
break;
}
+ case GIMatchTableOpcode::CheckFloatingPredicate: {
+ if (Applying) {
+ return makeUnexpected(ErrorCode::VerificationError,
+ "generated match table performs a predicate after an action");
+ }
+ auto Matched = matchesFloatingPredicate(Instruction, Step.OperandIndex, Step.Value);
+ if (!Matched)
+ return std::unexpected(Matched.error());
+ if (!*Matched)
+ return std::optional<MatchedRule>{};
+ break;
+ }
case GIMatchTableOpcode::CheckTargetPredicate: {
if (Applying || Step.Symbol.empty()) {
return makeUnexpected(ErrorCode::VerificationError,