-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[TableGen][DecoderEmitter] Add a couple of helper methods (NFC) #155163
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/opcode-uint8-helpers
Aug 24, 2025
Merged
[TableGen][DecoderEmitter] Add a couple of helper methods (NFC) #155163
s-barannikov
merged 1 commit into
llvm:main
from
s-barannikov:tablegen/decoder/opcode-uint8-helpers
Aug 24, 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
Replace push_back with more specific insertOpcode/insertUInt8.
Member
|
@llvm/pr-subscribers-tablegen Author: Sergei Barannikov (s-barannikov) ChangesReplace push_back with more specific insertOpcode/insertUInt8. Full diff: https://github.com/llvm/llvm-project/pull/155163.diff 1 Files Affected:
diff --git a/llvm/utils/TableGen/DecoderEmitter.cpp b/llvm/utils/TableGen/DecoderEmitter.cpp
index 76dafca07e0d4..758cb8f6f808e 100644
--- a/llvm/utils/TableGen/DecoderEmitter.cpp
+++ b/llvm/utils/TableGen/DecoderEmitter.cpp
@@ -252,7 +252,6 @@ class DecoderTable {
DecoderTable() { Data.reserve(16384); }
void clear() { Data.clear(); }
- void push_back(uint8_t Item) { Data.push_back(Item); }
size_t size() const { return Data.size(); }
const uint8_t *data() const { return Data.data(); }
@@ -260,7 +259,16 @@ class DecoderTable {
const_iterator begin() const { return Data.begin(); }
const_iterator end() const { return Data.end(); }
- // Insert a ULEB128 encoded value into the table.
+ /// Inserts a state machine opcode into the table.
+ void insertOpcode(MCD::DecoderOps Opcode) { Data.push_back(Opcode); }
+
+ /// Inserts a uint8 encoded value into the table.
+ void insertUInt8(unsigned Value) {
+ assert(isUInt<8>(Value));
+ Data.push_back(Value);
+ }
+
+ /// Inserts a ULEB128 encoded value into the table.
void insertULEB128(uint64_t Value) {
// Encode and emit the value to filter against.
uint8_t Buffer[16];
@@ -1243,10 +1251,10 @@ void FilterChooser::emitPredicateTableEntry(DecoderTableInfo &TableInfo,
// computed.
unsigned PIdx = getPredicateIndex(TableInfo, PS.str());
- const uint8_t DecoderOp = TableInfo.isOutermostScope()
- ? MCD::OPC_CheckPredicateOrFail
- : MCD::OPC_CheckPredicate;
- TableInfo.Table.push_back(DecoderOp);
+ const MCD::DecoderOps DecoderOp = TableInfo.isOutermostScope()
+ ? MCD::OPC_CheckPredicateOrFail
+ : MCD::OPC_CheckPredicate;
+ TableInfo.Table.insertOpcode(DecoderOp);
TableInfo.Table.insertULEB128(PIdx);
if (DecoderOp == MCD::OPC_CheckPredicate) {
@@ -1286,7 +1294,7 @@ void FilterChooser::emitSoftFailTableEntry(DecoderTableInfo &TableInfo,
if (!NeedPositiveMask && !NeedNegativeMask)
return;
- TableInfo.Table.push_back(MCD::OPC_SoftFail);
+ TableInfo.Table.insertOpcode(MCD::OPC_SoftFail);
TableInfo.Table.insertULEB128(PositiveMask.getZExtValue());
TableInfo.Table.insertULEB128(NegativeMask.getZExtValue());
}
@@ -1305,14 +1313,12 @@ void FilterChooser::emitSingletonTableEntry(DecoderTableInfo &TableInfo,
// Check any additional encoding fields needed.
for (const Island &Ilnd : reverse(Islands)) {
- assert(isUInt<8>(Ilnd.NumBits) && "NumBits overflowed uint8 table entry!");
- const uint8_t DecoderOp = TableInfo.isOutermostScope()
- ? MCD::OPC_CheckFieldOrFail
- : MCD::OPC_CheckField;
- TableInfo.Table.push_back(DecoderOp);
-
+ const MCD::DecoderOps DecoderOp = TableInfo.isOutermostScope()
+ ? MCD::OPC_CheckFieldOrFail
+ : MCD::OPC_CheckField;
+ TableInfo.Table.insertOpcode(DecoderOp);
TableInfo.Table.insertULEB128(Ilnd.StartBit);
- TableInfo.Table.push_back(Ilnd.NumBits);
+ TableInfo.Table.insertUInt8(Ilnd.NumBits);
TableInfo.Table.insertULEB128(Ilnd.FieldVal);
if (DecoderOp == MCD::OPC_CheckField) {
@@ -1338,12 +1344,11 @@ void FilterChooser::emitSingletonTableEntry(DecoderTableInfo &TableInfo,
// decoder method indicates that additional processing should be done to see
// if there is any other instruction that also matches the bitpattern and
// can decode it.
- const uint8_t DecoderOp =
- Encoding.hasCompleteDecoder()
- ? MCD::OPC_Decode
- : (TableInfo.isOutermostScope() ? MCD::OPC_TryDecodeOrFail
- : MCD::OPC_TryDecode);
- TableInfo.Table.push_back(DecoderOp);
+ const MCD::DecoderOps DecoderOp =
+ Encoding.hasCompleteDecoder() ? MCD::OPC_Decode
+ : TableInfo.isOutermostScope() ? MCD::OPC_TryDecodeOrFail
+ : MCD::OPC_TryDecode;
+ TableInfo.Table.insertOpcode(DecoderOp);
const Record *InstDef = Encodings[EncodingID].getInstruction()->TheDef;
TableInfo.Table.insertULEB128(Emitter->getTarget().getInstrIntValue(InstDef));
TableInfo.Table.insertULEB128(DIdx);
@@ -1661,14 +1666,13 @@ void FilterChooser::emitTableEntries(DecoderTableInfo &TableInfo) const {
} else {
// The general case: emit a switch over the field value.
DecoderTable &Table = TableInfo.Table;
- Table.push_back(MCD::OPC_ExtractField);
+ Table.insertOpcode(MCD::OPC_ExtractField);
Table.insertULEB128(StartBit);
- assert(isUInt<8>(NumBits) && "NumBits overflowed uint8 table entry!");
- Table.push_back(NumBits);
+ Table.insertUInt8(NumBits);
// Emit switch cases for all but the last element.
for (const auto &[FilterVal, Delegate] : drop_end(FilterChooserMap)) {
- Table.push_back(MCD::OPC_FilterValue);
+ Table.insertOpcode(MCD::OPC_FilterValue);
Table.insertULEB128(FilterVal);
size_t FixupPos = Table.insertNumToSkip();
@@ -1682,8 +1686,9 @@ void FilterChooser::emitTableEntries(DecoderTableInfo &TableInfo) const {
// Emit a switch case for the last element. It never falls through;
// if it doesn't match, we leave the current scope.
const auto &[FilterVal, Delegate] = *FilterChooserMap.rbegin();
- Table.push_back(!TableInfo.isOutermostScope() ? MCD::OPC_FilterValue
- : MCD::OPC_FilterValueOrFail);
+ Table.insertOpcode(!TableInfo.isOutermostScope()
+ ? MCD::OPC_FilterValue
+ : MCD::OPC_FilterValueOrFail);
Table.insertULEB128(FilterVal);
if (!TableInfo.isOutermostScope())
TableInfo.FixupStack.back().push_back(Table.insertNumToSkip());
@@ -2519,7 +2524,7 @@ namespace {
assert(TableInfo.isOutermostScope() && "fixup stack phasing error!");
TableInfo.popScope();
- TableInfo.Table.push_back(MCD::OPC_Fail);
+ TableInfo.Table.insertOpcode(MCD::OPC_Fail);
// Print the table to the output stream.
OpcodeMask |= emitTable(OS, TableInfo.Table, DecoderNamespace, HwModeID,
|
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.
Replace push_back with more specific insertOpcode/insertUInt8.