aboutsummaryrefslogtreecommitdiff
path: root/backend/utils/TableGen
diff options
context:
space:
mode:
authorRichard-Qin-X <richard.qin.001@gmail.com>2026-08-19 03:41:05 +0800
committerRichard-Qin-X <richard.qin.001@gmail.com>2026-08-19 03:41:05 +0800
commit219b315373ef34ca20cc78b89bf3c3d19442ffbd (patch)
treee65feacb93b93fee1d591486b97573ce7b78b85e /backend/utils/TableGen
parent3cc064e41f6913b176fbfb2d6e65d049f611b1d4 (diff)
downloadrcc-project-219b315373ef34ca20cc78b89bf3c3d19442ffbd.tar.gz
rcc-project-219b315373ef34ca20cc78b89bf3c3d19442ffbd.tar.xz
[RISCV][GlobalISel] Generate integer load selection
Diffstat (limited to 'backend/utils/TableGen')
-rw-r--r--backend/utils/TableGen/Common/CodeGenSelection.cpp14
-rw-r--r--backend/utils/TableGen/Common/CodeGenTarget.h6
-rw-r--r--backend/utils/TableGen/GlobalISelEmitter.cpp13
3 files changed, 28 insertions, 5 deletions
diff --git a/backend/utils/TableGen/Common/CodeGenSelection.cpp b/backend/utils/TableGen/Common/CodeGenSelection.cpp
index defe98b..0d59d6b 100644
--- a/backend/utils/TableGen/Common/CodeGenSelection.cpp
+++ b/backend/utils/TableGen/Common/CodeGenSelection.cpp
@@ -297,6 +297,20 @@ bool CodeGenTarget::normalizeSelectionRules(NormalizedTargetModel &Result) {
++Normalized.Specificity;
}
+ if (Rule.MemoryPredicate) {
+ if (Rule.MemoryPredicate->Bytes == 0 ||
+ (MatchInstruction != nullptr && !MatchInstruction->RequiresMemoryOperands)) {
+ fail(Rule.MemoryPredicate->Range,
+ "selection memory predicate requires a nonzero size and a memory opcode");
+ return false;
+ }
+ Normalized.MemoryPredicate = {
+ .MemoryOperandIndex = Rule.MemoryPredicate->MemoryOperandIndex,
+ .Bytes = Rule.MemoryPredicate->Bytes,
+ };
+ ++Normalized.Specificity;
+ }
+
std::unordered_set<std::string> TargetPredicateSymbols;
for (const SourceSelectionTargetPredicate &Predicate : Rule.TargetPredicates) {
if (!isIdentifier(Predicate.Symbol) ||
diff --git a/backend/utils/TableGen/Common/CodeGenTarget.h b/backend/utils/TableGen/Common/CodeGenTarget.h
index 020bb88..3a7d299 100644
--- a/backend/utils/TableGen/Common/CodeGenTarget.h
+++ b/backend/utils/TableGen/Common/CodeGenTarget.h
@@ -200,6 +200,11 @@ struct NormalizedSelectionFloatingPredicate final {
std::uint32_t Predicate = 0;
};
+struct NormalizedSelectionMemoryPredicate final {
+ std::uint32_t MemoryOperandIndex = 0;
+ std::uint32_t Bytes = 0;
+};
+
struct NormalizedSelectionConstantRange final {
std::int64_t Minimum = 0;
std::int64_t Maximum = 0;
@@ -272,6 +277,7 @@ struct NormalizedSelectionRule final {
std::optional<NormalizedSelectionTypePredicate> ResultType;
std::optional<NormalizedSelectionIntegerPredicate> IntegerPredicate;
std::optional<NormalizedSelectionFloatingPredicate> FloatingPredicate;
+ std::optional<NormalizedSelectionMemoryPredicate> MemoryPredicate;
std::vector<std::string> TargetPredicates;
std::vector<NormalizedSelectionOperandTypePredicate> OperandTypes;
std::vector<NormalizedSelectionOperandBankPredicate> OperandBanks;
diff --git a/backend/utils/TableGen/GlobalISelEmitter.cpp b/backend/utils/TableGen/GlobalISelEmitter.cpp
index 7390bdf..092969d 100644
--- a/backend/utils/TableGen/GlobalISelEmitter.cpp
+++ b/backend/utils/TableGen/GlobalISelEmitter.cpp
@@ -42,11 +42,11 @@ void emitTypePredicate(std::ostream &Output, std::uint32_t OperandIndex,
[[nodiscard]] std::size_t instructionCount(const NormalizedSelectionRule &Rule) noexcept {
std::size_t Count = 2U + (Rule.ResultType ? 1U : 0U) + (Rule.IntegerPredicate ? 1U : 0U) +
- (Rule.FloatingPredicate ? 1U : 0U) + Rule.TargetPredicates.size() +
- Rule.OperandTypes.size() + Rule.OperandBanks.size() +
- Rule.OperandClasses.size() + Rule.OperandImmediates.size() +
- Rule.OperandDefConstants.size() + Rule.Temporaries.size() +
- Rule.EraseOperandDefinitions.size();
+ (Rule.FloatingPredicate ? 1U : 0U) + (Rule.MemoryPredicate ? 1U : 0U) +
+ Rule.TargetPredicates.size() + Rule.OperandTypes.size() +
+ Rule.OperandBanks.size() + Rule.OperandClasses.size() +
+ Rule.OperandImmediates.size() + Rule.OperandDefConstants.size() +
+ Rule.Temporaries.size() + Rule.EraseOperandDefinitions.size();
for (const NormalizedSelectionDefUsePredicate &Predicate : Rule.DefUsePredicates)
Count += 1U + static_cast<std::size_t>(Predicate.IntegerPredicate.has_value()) +
Predicate.Captures.size() + Predicate.OperandDefConstants.size();
@@ -119,6 +119,9 @@ std::string emitGlobalISel(const NormalizedTargetModel &Model, std::string_view
if (Rule.FloatingPredicate)
emitInstruction(Output, "CheckFloatingPredicate", Rule.FloatingPredicate->OperandIndex,
Rule.FloatingPredicate->Predicate);
+ if (Rule.MemoryPredicate)
+ emitInstruction(Output, "CheckMemorySize", Rule.MemoryPredicate->MemoryOperandIndex,
+ Rule.MemoryPredicate->Bytes);
for (const std::string &Predicate : Rule.TargetPredicates)
emitInstruction(Output, "CheckTargetPredicate", 0, 0, "0", 0, Predicate);
for (const NormalizedSelectionOperandTypePredicate &Predicate : Rule.OperandTypes)