-
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ae4f936
[NFC][DecoderEmitter] Predicate generation code cleanup
jurahul 62a1ea2
Review feedback
jurahul 29a6875
Drop outer ()
jurahul 139f7f2
Clang-format fixes
jurahul 328f1f3
Review feedback
jurahul 2798560
One more missing ;
jurahul File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
#include "Common/CodeGenTarget.h" | ||
#include "Common/InfoByHwMode.h" | ||
#include "Common/InstructionEncoding.h" | ||
#include "Common/SubtargetFeatureInfo.h" | ||
#include "Common/VarLenCodeEmitterGen.h" | ||
#include "TableGenBackends.h" | ||
#include "llvm/ADT/APInt.h" | ||
|
@@ -519,8 +520,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; | ||
|
@@ -839,12 +838,12 @@ void DecoderEmitter::emitPredicateFunction(formatted_raw_ostream &OS, | |
// The predicate function is just a big switch statement based on the | ||
// input predicate index. | ||
OS << "static bool checkDecoderPredicate(unsigned Idx, const FeatureBitset " | ||
"&Bits) {\n"; | ||
"&FB) {\n"; | ||
OS << " switch (Idx) {\n"; | ||
OS << " default: llvm_unreachable(\"Invalid index!\");\n"; | ||
for (const auto &[Index, Predicate] : enumerate(Predicates)) { | ||
OS << " case " << Index << ":\n"; | ||
OS << " return (" << Predicate << ");\n"; | ||
OS << " return " << Predicate << ";\n"; | ||
} | ||
OS << " }\n"; | ||
OS << "}\n\n"; | ||
|
@@ -1134,41 +1133,19 @@ bool DecoderTableBuilder::emitPredicateMatchAux(const Init &Val, | |
return true; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, missed it. emitPredicateMatchAux is now unused. |
||
|
||
// Returns true if there was any predicate emitted. | ||
bool DecoderTableBuilder::emitPredicateMatch(raw_ostream &OS, | ||
unsigned EncodingID) const { | ||
const ListInit *Predicates = | ||
Encodings[EncodingID].getRecord()->getValueAsListInit("Predicates"); | ||
bool IsFirstEmission = true; | ||
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())) | ||
continue; | ||
|
||
if (!IsFirstEmission) | ||
OS << " && "; | ||
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; | ||
std::vector<const Record *> Predicates = | ||
Encodings[EncodingID].getRecord()->getValueAsListOfDefs("Predicates"); | ||
auto It = llvm::find_if(Predicates, [](const Record *R) { | ||
return R->getValueAsBit("AssemblerMatcherPredicate"); | ||
}); | ||
bool AnyAsmPredicate = It != Predicates.end(); | ||
if (!AnyAsmPredicate) | ||
return false; | ||
SubtargetFeatureInfo::emitMCPredicateCheck(OS, Target.getName(), Predicates); | ||
return true; | ||
} | ||
|
||
unsigned DecoderTableBuilder::getPredicateIndex(StringRef Predicate) const { | ||
|
@@ -1186,15 +1163,11 @@ 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; | ||
jurahul marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
// Figure out the index into the predicate table for the predicate just | ||
// computed. | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.