-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[TableGen][DecoderEmitter] Inline a couple of trivial functions (NFC) #159099
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
s-barannikov
merged 1 commit into
llvm:main
from
s-barannikov:tablegen/decoder/inline-predicate-decoder-index
Sep 16, 2025
Merged
[TableGen][DecoderEmitter] Inline a couple of trivial functions (NFC) #159099
s-barannikov
merged 1 commit into
llvm:main
from
s-barannikov:tablegen/decoder/inline-predicate-decoder-index
Sep 16, 2025
Conversation
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
Member
|
@llvm/pr-subscribers-tablegen Author: Sergei Barannikov (s-barannikov) ChangesFull diff: https://github.com/llvm/llvm-project/pull/159099.diff 1 Files Affected:
diff --git a/llvm/utils/TableGen/DecoderEmitter.cpp b/llvm/utils/TableGen/DecoderEmitter.cpp
index 43e1299563762..159f9a781356f 100644
--- a/llvm/utils/TableGen/DecoderEmitter.cpp
+++ b/llvm/utils/TableGen/DecoderEmitter.cpp
@@ -1063,8 +1063,11 @@ static void emitBinaryParser(raw_ostream &OS, indent Indent,
}
}
-static void emitDecoder(raw_ostream &OS, indent Indent,
- const InstructionEncoding &Encoding) {
+static std::string getDecoderString(const InstructionEncoding &Encoding) {
+ std::string Decoder;
+ raw_string_ostream OS(Decoder);
+ indent Indent(UseFnTableInDecodeToMCInst ? 2 : 4);
+
// If a custom instruction decoder was specified, use that.
StringRef DecoderMethod = Encoding.getDecoderMethod();
if (!DecoderMethod.empty()) {
@@ -1072,73 +1075,45 @@ static void emitDecoder(raw_ostream &OS, indent Indent,
<< "(MI, insn, Address, Decoder))) { "
<< (Encoding.hasCompleteDecoder() ? "" : "DecodeComplete = false; ")
<< "return MCDisassembler::Fail; }\n";
- return;
+ } else {
+ for (const OperandInfo &Op : Encoding.getOperands())
+ emitBinaryParser(OS, Indent, Encoding, Op);
}
-
- for (const OperandInfo &Op : Encoding.getOperands())
- emitBinaryParser(OS, Indent, Encoding, Op);
+ return Decoder;
}
-static unsigned getDecoderIndex(const InstructionEncoding &Encoding,
- DecoderTableInfo &TableInfo) {
- // Build up the predicate string.
- SmallString<256> Decoder;
- // FIXME: emitDecoder() function can take a buffer directly rather than
- // a stream.
- raw_svector_ostream S(Decoder);
- indent Indent(UseFnTableInDecodeToMCInst ? 2 : 4);
- emitDecoder(S, Indent, Encoding);
-
- // Using the full decoder string as the key value here is a bit
- // heavyweight, but is effective. If the string comparisons become a
- // performance concern, we can implement a mangling of the predicate
- // data easily enough with a map back to the actual string. That's
- // overkill for now, though.
- TableInfo.insertDecoder(Decoder);
- return TableInfo.getDecoderIndex(Decoder);
-}
-
-// Returns true if there was any predicate emitted.
-static bool emitPredicateMatch(raw_ostream &OS,
- const InstructionEncoding &Encoding,
- StringRef TargetName) {
+static std::string getPredicateString(const InstructionEncoding &Encoding,
+ StringRef TargetName) {
std::vector<const Record *> Predicates =
Encoding.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;
+ if (It == Predicates.end())
+ return std::string();
+
+ std::string Predicate;
+ raw_string_ostream OS(Predicate);
SubtargetFeatureInfo::emitMCPredicateCheck(OS, TargetName, Predicates);
- return true;
+ return Predicate;
}
-static unsigned getPredicateIndex(StringRef Predicate,
- DecoderTableInfo &TableInfo) {
+void DecoderTableBuilder::emitPredicateTableEntry(unsigned EncodingID) const {
+ const InstructionEncoding &Encoding = Encodings[EncodingID];
+ std::string Predicate = getPredicateString(Encoding, Target.getName());
+ if (Predicate.empty())
+ return;
+
// Using the full predicate string as the key value here is a bit
// heavyweight, but is effective. If the string comparisons become a
// performance concern, we can implement a mangling of the predicate
// data easily enough with a map back to the actual string. That's
// overkill for now, though.
TableInfo.insertPredicate(Predicate);
- return TableInfo.getPredicateIndex(Predicate);
-}
-
-void DecoderTableBuilder::emitPredicateTableEntry(unsigned EncodingID) const {
- const InstructionEncoding &Encoding = Encodings[EncodingID];
- // Build up the predicate string.
- SmallString<256> Predicate;
- raw_svector_ostream PS(Predicate);
- if (!emitPredicateMatch(PS, Encoding, Target.getName()))
- return;
-
- // Figure out the index into the predicate table for the predicate just
- // computed.
- unsigned PIdx = getPredicateIndex(PS.str(), TableInfo);
+ unsigned PredicateIndex = TableInfo.getPredicateIndex(Predicate);
TableInfo.Table.insertOpcode(OPC_CheckPredicate);
- TableInfo.Table.insertULEB128(PIdx);
+ TableInfo.Table.insertULEB128(PredicateIndex);
}
void DecoderTableBuilder::emitSoftFailTableEntry(unsigned EncodingID) const {
@@ -1181,7 +1156,14 @@ void DecoderTableBuilder::emitSingletonTableEntry(
// Check for soft failure of the match.
emitSoftFailTableEntry(EncodingID);
- unsigned DIdx = getDecoderIndex(Encoding, TableInfo);
+ // Using the full decoder string as the key value here is a bit
+ // heavyweight, but is effective. If the string comparisons become a
+ // performance concern, we can implement a mangling of the predicate
+ // data easily enough with a map back to the actual string. That's
+ // overkill for now, though.
+ std::string Decoder = getDecoderString(Encoding);
+ TableInfo.insertDecoder(Decoder);
+ unsigned DecoderIndex = TableInfo.getDecoderIndex(Decoder);
// Produce OPC_Decode or OPC_TryDecode opcode based on the information
// whether the instruction decoder is complete or not. If it is complete
@@ -1197,7 +1179,7 @@ void DecoderTableBuilder::emitSingletonTableEntry(
TableInfo.Table.insertOpcode(DecoderOp);
const Record *InstDef = Encodings[EncodingID].getInstruction()->TheDef;
TableInfo.Table.insertULEB128(Target.getInstrIntValue(InstDef));
- TableInfo.Table.insertULEB128(DIdx);
+ TableInfo.Table.insertULEB128(DecoderIndex);
}
std::unique_ptr<Filter>
|
6f8b10f to
04e0ee8
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.