-
Notifications
You must be signed in to change notification settings - Fork 14.8k
[NFC][DecoderEmitter] Predicate generation code cleanup #158140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-tablegen Author: Rahul Joshi (jurahul) ChangesUse Full diff: https://github.com/llvm/llvm-project/pull/158140.diff 1 Files Affected:
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.
|
a6e9032
to
c1f1dec
Compare
✅ With the latest revision this PR passed the C/C++ code formatter. |
Use `ListSeparator` to join individual predicated with `&&`. Eliminate `doesOpcodeNeedPredicate` and instead have `emitPredicateMatch` return true if any predicates were generated.
c1f1dec
to
328f1f3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
(The description needs an update.) |
Updated, thanks |
} | ||
} | ||
return true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, missed it. emitPredicateMatchAux is now unused.
Thanks, will fix
…On Mon, Sep 15, 2025 at 8:13 PM Sergei Barannikov ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In llvm/utils/TableGen/DecoderEmitter.cpp
<#158140 (comment)>:
> @@ -1134,41 +1133,19 @@ bool DecoderTableBuilder::emitPredicateMatchAux(const Init &Val,
return true;
}
Sorry, missed it. emitPredicateMatchAux is now unused.
—
Reply to this email directly, view it on GitHub
<#158140 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/APRMUB4ESQQ7J67UA5P27QL3S554LAVCNFSM6AAAAACGIYVINGVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZTEMRWHEYTOMZYGY>
.
You are receiving this because you modified the open/close state.Message
ID: ***@***.***>
|
Eliminate
doesOpcodeNeedPredicate
and instead haveemitPredicateMatch
return true if any predicates were generated. Delegate actual predicate generation inemitPredicateMatch
toSubtargetFeatureInfo::emitMCPredicateCheck
. Additionally, remove the redundant parenthesis around the predicate conditions in the generatedcheckDecoderPredicate
function.Note that for ARM/AMDGPU this reduces the total # of predicates generated by a few. It seems the old code would sometimes generate duplicate predicates which were identical in semantics but one had an extra pair of parentheses (i..e,
X
and(X)
).emitMCPredicateCheck
does not seems to have that issue.