aboutsummaryrefslogtreecommitdiff
path: root/backend/lib/CodeGen/GlobalISel
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/lib/CodeGen/GlobalISel
parent9720e989ccdce77a2c45a8379d36ff4428e6c2bf (diff)
downloadrcc-project-f5c592905e6e1ef4b78337d76c8215e543607b8d.tar.gz
rcc-project-f5c592905e6e1ef4b78337d76c8215e543607b8d.tar.xz
[RISCV][GlobalISel] Generate conditional branch selection
Diffstat (limited to 'backend/lib/CodeGen/GlobalISel')
-rw-r--r--backend/lib/CodeGen/GlobalISel/GIMatchTableExecutor.cpp32
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,