[llvm] [NFC][DecoderEmitter] Predicate generation code cleanup (PR #158140)
Rahul Joshi via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 11 12:38:47 PDT 2025
https://github.com/jurahul created https://github.com/llvm/llvm-project/pull/158140
Use `ListSeparator` to join individual predicated with `&&`. Eliminate `doesOpcodeNeedPredicate` and instead have `emitPredicateMatch` return true if any predicates were generated.
>From a6e90329a83e4495b35ece4cfbb31ff07179309e Mon Sep 17 00:00:00 2001
From: Rahul Joshi <rjoshi at nvidia.com>
Date: Thu, 11 Sep 2025 12:33:42 -0700
Subject: [PATCH] [NFC][DecoderEmitter] Predicate generation code cleanup
Use `ListSeparator` to join individual predicated with `&&`.
Eliminate `doesOpcodeNeedPredicate` and instead have
`emitPredicateMatch` return true if any predicates were generated.
---
llvm/utils/TableGen/DecoderEmitter.cpp | 32 ++++++--------------------
1 file changed, 7 insertions(+), 25 deletions(-)
diff --git a/llvm/utils/TableGen/DecoderEmitter.cpp b/llvm/utils/TableGen/DecoderEmitter.cpp
index 8747d02ac892b..96957aed60df3 100644
--- a/llvm/utils/TableGen/DecoderEmitter.cpp
+++ b/llvm/utils/TableGen/DecoderEmitter.cpp
@@ -635,8 +635,6 @@ class DecoderTableBuilder {
bool emitPredicateMatch(raw_ostream &OS, unsigned EncodingID) const;
- bool doesOpcodeNeedPredicate(unsigned EncodingID) const;
-
void emitPredicateTableEntry(unsigned EncodingID) const;
void emitSoftFailTableEntry(unsigned EncodingID) const;
@@ -1221,7 +1219,8 @@ bool DecoderTableBuilder::emitPredicateMatch(raw_ostream &OS,
unsigned EncodingID) const {
const ListInit *Predicates =
Encodings[EncodingID].getRecord()->getValueAsListInit("Predicates");
- bool IsFirstEmission = true;
+ ListSeparator LS(" && ");
+ bool AnyPredicate = false;
for (unsigned i = 0; i < Predicates->size(); ++i) {
const Record *Pred = Predicates->getElementAsRecord(i);
if (!Pred->getValue("AssemblerMatcherPredicate"))
@@ -1230,28 +1229,13 @@ bool DecoderTableBuilder::emitPredicateMatch(raw_ostream &OS,
if (!isa<DagInit>(Pred->getValue("AssemblerCondDag")->getValue()))
continue;
- if (!IsFirstEmission)
- OS << " && ";
+ AnyPredicate = true;
+ OS << LS;
if (emitPredicateMatchAux(*Pred->getValueAsDag("AssemblerCondDag"),
Predicates->size() > 1, OS))
PrintFatalError(Pred->getLoc(), "Invalid AssemblerCondDag!");
- IsFirstEmission = false;
- }
- return !Predicates->empty();
-}
-
-bool DecoderTableBuilder::doesOpcodeNeedPredicate(unsigned EncodingID) const {
- const ListInit *Predicates =
- Encodings[EncodingID].getRecord()->getValueAsListInit("Predicates");
- for (unsigned i = 0; i < Predicates->size(); ++i) {
- const Record *Pred = Predicates->getElementAsRecord(i);
- if (!Pred->getValue("AssemblerMatcherPredicate"))
- continue;
-
- if (isa<DagInit>(Pred->getValue("AssemblerCondDag")->getValue()))
- return true;
}
- return false;
+ return AnyPredicate;
}
unsigned DecoderTableBuilder::getPredicateIndex(StringRef Predicate) const {
@@ -1269,15 +1253,13 @@ unsigned DecoderTableBuilder::getPredicateIndex(StringRef Predicate) const {
}
void DecoderTableBuilder::emitPredicateTableEntry(unsigned EncodingID) const {
- if (!doesOpcodeNeedPredicate(EncodingID))
- return;
-
// Build up the predicate string.
SmallString<256> Predicate;
// FIXME: emitPredicateMatch() functions can take a buffer directly rather
// than a stream.
raw_svector_ostream PS(Predicate);
- emitPredicateMatch(PS, EncodingID);
+ if (!emitPredicateMatch(PS, EncodingID))
+ return;
// Figure out the index into the predicate table for the predicate just
// computed.
More information about the llvm-commits
mailing list