aboutsummaryrefslogtreecommitdiff
path: root/backend/utils
diff options
context:
space:
mode:
authorRichard-Qin-X <richard.qin.001@gmail.com>2026-08-17 03:16:26 +0800
committerRichard-Qin-X <richard.qin.001@gmail.com>2026-08-17 03:16:26 +0800
commitf5c592905e6e1ef4b78337d76c8215e543607b8d (patch)
tree193400315338b57af33699ad7f952fb3731b3a65 /backend/utils
parent9720e989ccdce77a2c45a8379d36ff4428e6c2bf (diff)
downloadrcc-project-f5c592905e6e1ef4b78337d76c8215e543607b8d.tar.gz
rcc-project-f5c592905e6e1ef4b78337d76c8215e543607b8d.tar.xz
[RISCV][GlobalISel] Generate conditional branch selection
Diffstat (limited to 'backend/utils')
-rw-r--r--backend/utils/TableGen/Common/CodeGenSelection.cpp17
-rw-r--r--backend/utils/TableGen/Common/CodeGenTarget.h1
-rw-r--r--backend/utils/TableGen/GlobalISelEmitter.cpp8
3 files changed, 24 insertions, 2 deletions
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<std::uint32_t> 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<std::uint32_t>(Predicate.Captures.size()) +
+ Normalized.Specificity += 1U +
+ static_cast<std::uint32_t>(Predicate.IntegerPredicate.has_value()) +
+ static_cast<std::uint32_t>(Predicate.Captures.size()) +
static_cast<std::uint32_t>(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<NormalizedSelectionIntegerPredicate> IntegerPredicate;
std::vector<NormalizedSelectionDefUseCapture> Captures;
std::vector<NormalizedSelectionOperandDefConstantPredicate> OperandDefConstants;
};
diff --git a/backend/utils/TableGen/GlobalISelEmitter.cpp b/backend/utils/TableGen/GlobalISelEmitter.cpp
index 98568b1..d73d691 100644
--- a/backend/utils/TableGen/GlobalISelEmitter.cpp
+++ b/backend/utils/TableGen/GlobalISelEmitter.cpp
@@ -47,7 +47,8 @@ void emitTypePredicate(std::ostream &Output, std::uint32_t OperandIndex,
Rule.OperandImmediates.size() + Rule.OperandDefConstants.size() +
Rule.Temporaries.size() + Rule.EraseOperandDefinitions.size();
for (const NormalizedSelectionDefUsePredicate &Predicate : Rule.DefUsePredicates)
- Count += 1U + Predicate.Captures.size() + Predicate.OperandDefConstants.size();
+ Count += 1U + static_cast<std::size_t>(Predicate.IntegerPredicate.has_value()) +
+ Predicate.Captures.size() + Predicate.OperandDefConstants.size();
for (const NormalizedSelectionAction &Action : Rule.Actions)
Count += 1U + Action.OperandRenderers.size();
return Count;
@@ -137,6 +138,11 @@ std::string emitGlobalISel(const NormalizedTargetModel &Model, std::string_view
}
for (const NormalizedSelectionDefUsePredicate &DefUse : Rule.DefUsePredicates) {
emitInstruction(Output, "CheckOperandDefOpcode", DefUse.RootOperandIndex, DefUse.Opcode);
+ if (DefUse.IntegerPredicate) {
+ emitInstruction(Output, "CheckOperandDefIntegerPredicate", DefUse.RootOperandIndex,
+ DefUse.IntegerPredicate->Predicate,
+ std::to_string(DefUse.IntegerPredicate->OperandIndex));
+ }
for (const NormalizedSelectionOperandDefConstantPredicate &Predicate :
DefUse.OperandDefConstants) {
emitInstruction(Output, "CheckOperandDefOperandConstantRanges", DefUse.RootOperandIndex,