Skip to content

Commit 008f9f3

Browse files
authored
[TableGen][DecoderEmitter] Turn some methods into static functions (NFC) (#158789)
DecoderTableBuilder will be removed. Move out the class the methods that will remain.
1 parent 85d2a46 commit 008f9f3

File tree

1 file changed

+19
-29
lines changed

1 file changed

+19
-29
lines changed

llvm/utils/TableGen/DecoderEmitter.cpp

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -525,18 +525,6 @@ class DecoderTableBuilder {
525525
}
526526

527527
private:
528-
void emitBinaryParser(raw_ostream &OS, indent Indent,
529-
const InstructionEncoding &Encoding,
530-
const OperandInfo &OpInfo) const;
531-
532-
void emitDecoder(raw_ostream &OS, indent Indent, unsigned EncodingID) const;
533-
534-
unsigned getDecoderIndex(unsigned EncodingID) const;
535-
536-
unsigned getPredicateIndex(StringRef P) const;
537-
538-
bool emitPredicateMatch(raw_ostream &OS, unsigned EncodingID) const;
539-
540528
void emitPredicateTableEntry(unsigned EncodingID) const;
541529

542530
void emitSoftFailTableEntry(unsigned EncodingID) const;
@@ -1013,9 +1001,9 @@ FilterChooser::getIslands(const KnownBits &EncodingBits) const {
10131001
return Islands;
10141002
}
10151003

1016-
void DecoderTableBuilder::emitBinaryParser(raw_ostream &OS, indent Indent,
1017-
const InstructionEncoding &Encoding,
1018-
const OperandInfo &OpInfo) const {
1004+
static void emitBinaryParser(raw_ostream &OS, indent Indent,
1005+
const InstructionEncoding &Encoding,
1006+
const OperandInfo &OpInfo) {
10191007
if (OpInfo.HasNoEncoding) {
10201008
// If an operand has no encoding, the old behavior is to not decode it
10211009
// automatically and let the target do it. This is error-prone, so the
@@ -1075,10 +1063,8 @@ void DecoderTableBuilder::emitBinaryParser(raw_ostream &OS, indent Indent,
10751063
}
10761064
}
10771065

1078-
void DecoderTableBuilder::emitDecoder(raw_ostream &OS, indent Indent,
1079-
unsigned EncodingID) const {
1080-
const InstructionEncoding &Encoding = Encodings[EncodingID];
1081-
1066+
static void emitDecoder(raw_ostream &OS, indent Indent,
1067+
const InstructionEncoding &Encoding) {
10821068
// If a custom instruction decoder was specified, use that.
10831069
StringRef DecoderMethod = Encoding.getDecoderMethod();
10841070
if (!DecoderMethod.empty()) {
@@ -1093,14 +1079,15 @@ void DecoderTableBuilder::emitDecoder(raw_ostream &OS, indent Indent,
10931079
emitBinaryParser(OS, Indent, Encoding, Op);
10941080
}
10951081

1096-
unsigned DecoderTableBuilder::getDecoderIndex(unsigned EncodingID) const {
1082+
static unsigned getDecoderIndex(const InstructionEncoding &Encoding,
1083+
DecoderTableInfo &TableInfo) {
10971084
// Build up the predicate string.
10981085
SmallString<256> Decoder;
10991086
// FIXME: emitDecoder() function can take a buffer directly rather than
11001087
// a stream.
11011088
raw_svector_ostream S(Decoder);
11021089
indent Indent(UseFnTableInDecodeToMCInst ? 2 : 4);
1103-
emitDecoder(S, Indent, EncodingID);
1090+
emitDecoder(S, Indent, Encoding);
11041091

11051092
// Using the full decoder string as the key value here is a bit
11061093
// heavyweight, but is effective. If the string comparisons become a
@@ -1112,21 +1099,23 @@ unsigned DecoderTableBuilder::getDecoderIndex(unsigned EncodingID) const {
11121099
}
11131100

11141101
// Returns true if there was any predicate emitted.
1115-
bool DecoderTableBuilder::emitPredicateMatch(raw_ostream &OS,
1116-
unsigned EncodingID) const {
1102+
static bool emitPredicateMatch(raw_ostream &OS,
1103+
const InstructionEncoding &Encoding,
1104+
StringRef TargetName) {
11171105
std::vector<const Record *> Predicates =
1118-
Encodings[EncodingID].getRecord()->getValueAsListOfDefs("Predicates");
1106+
Encoding.getRecord()->getValueAsListOfDefs("Predicates");
11191107
auto It = llvm::find_if(Predicates, [](const Record *R) {
11201108
return R->getValueAsBit("AssemblerMatcherPredicate");
11211109
});
11221110
bool AnyAsmPredicate = It != Predicates.end();
11231111
if (!AnyAsmPredicate)
11241112
return false;
1125-
SubtargetFeatureInfo::emitMCPredicateCheck(OS, Target.getName(), Predicates);
1113+
SubtargetFeatureInfo::emitMCPredicateCheck(OS, TargetName, Predicates);
11261114
return true;
11271115
}
11281116

1129-
unsigned DecoderTableBuilder::getPredicateIndex(StringRef Predicate) const {
1117+
static unsigned getPredicateIndex(StringRef Predicate,
1118+
DecoderTableInfo &TableInfo) {
11301119
// Using the full predicate string as the key value here is a bit
11311120
// heavyweight, but is effective. If the string comparisons become a
11321121
// performance concern, we can implement a mangling of the predicate
@@ -1137,15 +1126,16 @@ unsigned DecoderTableBuilder::getPredicateIndex(StringRef Predicate) const {
11371126
}
11381127

11391128
void DecoderTableBuilder::emitPredicateTableEntry(unsigned EncodingID) const {
1129+
const InstructionEncoding &Encoding = Encodings[EncodingID];
11401130
// Build up the predicate string.
11411131
SmallString<256> Predicate;
11421132
raw_svector_ostream PS(Predicate);
1143-
if (!emitPredicateMatch(PS, EncodingID))
1133+
if (!emitPredicateMatch(PS, Encoding, Target.getName()))
11441134
return;
11451135

11461136
// Figure out the index into the predicate table for the predicate just
11471137
// computed.
1148-
unsigned PIdx = getPredicateIndex(PS.str());
1138+
unsigned PIdx = getPredicateIndex(PS.str(), TableInfo);
11491139

11501140
TableInfo.Table.insertOpcode(OPC_CheckPredicate);
11511141
TableInfo.Table.insertULEB128(PIdx);
@@ -1191,7 +1181,7 @@ void DecoderTableBuilder::emitSingletonTableEntry(
11911181
// Check for soft failure of the match.
11921182
emitSoftFailTableEntry(EncodingID);
11931183

1194-
unsigned DIdx = getDecoderIndex(EncodingID);
1184+
unsigned DIdx = getDecoderIndex(Encoding, TableInfo);
11951185

11961186
// Produce OPC_Decode or OPC_TryDecode opcode based on the information
11971187
// whether the instruction decoder is complete or not. If it is complete

0 commit comments

Comments
 (0)