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 --- backend/utils/TableGen/Common/CodeGenSelection.cpp | 17 ++++++++++++++++- backend/utils/TableGen/Common/CodeGenTarget.h | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) (limited to 'backend/utils/TableGen/Common') diff --git a/backend/utils/TableGen/Common/CodeGenSelection.cpp b/backend/utils/TableGen/Common/CodeGenSelection.cpp index 95a924f..df9bf7b 100644 --- a/backend/utils/TableGen/Common/CodeGenSelection.cpp +++ b/backend/utils/TableGen/Common/CodeGenSelection.cpp @@ -355,9 +355,22 @@ bool CodeGenTarget::normalizeSelectionRules(NormalizedTargetModel &Result) { NormalizedSelectionDefUsePredicate NormalizedPredicate{ .RootOperandIndex = Predicate.RootOperandIndex, .Opcode = *DefOpcode, + .IntegerPredicate = std::nullopt, .Captures = {}, .OperandDefConstants = {}, }; + if (Predicate.IntegerPredicate) { + const auto Integer = integerPredicateValue(Predicate.IntegerPredicate->Predicate); + if (!Integer) { + fail(Predicate.IntegerPredicate->Range, + "selection def-use integer predicate is not a recognized integer predicate"); + return false; + } + NormalizedPredicate.IntegerPredicate = { + .OperandIndex = Predicate.IntegerPredicate->OperandIndex, + .Predicate = *Integer, + }; + } std::unordered_set CapturedOperands; for (const SourceSelectionDefUseCapture &Capture : Predicate.Captures) { if (!isIdentifier(Capture.Symbol) || @@ -390,7 +403,9 @@ bool CodeGenTarget::normalizeSelectionRules(NormalizedTargetModel &Result) { }); } Normalized.DefUsePredicates.push_back(std::move(NormalizedPredicate)); - Normalized.Specificity += 1U + static_cast(Predicate.Captures.size()) + + Normalized.Specificity += 1U + + static_cast(Predicate.IntegerPredicate.has_value()) + + static_cast(Predicate.Captures.size()) + static_cast(Predicate.OperandDefConstants.size()); } diff --git a/backend/utils/TableGen/Common/CodeGenTarget.h b/backend/utils/TableGen/Common/CodeGenTarget.h index d66cfee..97e1447 100644 --- a/backend/utils/TableGen/Common/CodeGenTarget.h +++ b/backend/utils/TableGen/Common/CodeGenTarget.h @@ -217,6 +217,7 @@ struct NormalizedSelectionDefUseCapture final { struct NormalizedSelectionDefUsePredicate final { std::uint32_t RootOperandIndex = 0; std::uint32_t Opcode = 0; + std::optional IntegerPredicate; std::vector Captures; std::vector OperandDefConstants; }; -- cgit v1.2.3