Skip to content

Commit 80f7a11

Browse files
author
git apple-llvm automerger
committed
Merge commit 'c8c2218c001e' from llvm.org/main into next
2 parents f93033e + c8c2218 commit 80f7a11

File tree

3 files changed

+39
-41
lines changed

3 files changed

+39
-41
lines changed

llvm/test/TableGen/HwModeEncodeDecode2.td

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,26 +93,26 @@ let OutOperandList = (outs) in {
9393
}
9494
}
9595

96-
// DECODER-LABEL: DecoderTableAlt_ModeA32[] =
97-
// DECODER-DAG: Opcode: unrelated
98-
// DECODER-LABEL: DecoderTableAlt_ModeB32[] =
99-
// DECODER-DAG: Opcode: unrelated
10096
// DECODER-LABEL: DecoderTable_ModeA32[] =
10197
// DECODER-DAG: Opcode: fooTypeEncA:foo
10298
// DECODER-DAG: Opcode: bar
10399
// DECODER-LABEL: DecoderTable_ModeB32[] =
104100
// DECODER-DAG: Opcode: fooTypeEncB:foo
105101
// DECODER-DAG: Opcode: fooTypeEncA:baz
106102
// DECODER-DAG: Opcode: bar
103+
// DECODER-LABEL: DecoderTableAlt_ModeA32[] =
104+
// DECODER-DAG: Opcode: unrelated
105+
// DECODER-LABEL: DecoderTableAlt_ModeB32[] =
106+
// DECODER-DAG: Opcode: unrelated
107107

108108
// DECODER-SUPPRESS-LABEL: DecoderTable32[] =
109109
// DECODER-SUPPRESS-DAG: Opcode: bar
110-
// DECODER-SUPPRESS-LABEL: DecoderTableAlt32[] =
111-
// DECODER-SUPPRESS-DAG: Opcode: unrelated
112110
// DECODER-SUPPRESS-LABEL: DecoderTable_ModeA32[] =
113111
// DECODER-SUPPRESS-DAG: Opcode: fooTypeEncA:foo
114112
// DECODER-SUPPRESS-NOT: Opcode: bar
115113
// DECODER-SUPPRESS-LABEL: DecoderTable_ModeB32[] =
116114
// DECODER-SUPPRESS-DAG: Opcode: fooTypeEncB:foo
117115
// DECODER-SUPPRESS-DAG: Opcode: fooTypeEncA:baz
118116
// DECODER-SUPPRESS-NOT: Opcode: bar
117+
// DECODER-SUPPRESS-LABEL: DecoderTableAlt32[] =
118+
// DECODER-SUPPRESS-DAG: Opcode: unrelated

llvm/test/TableGen/HwModeEncodeDecode3.td

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,6 @@ def unrelated: Instruction {
120120
// DECODER-DAG: Opcode: bar
121121
// DECODER-LABEL: DecoderTable64[] =
122122
// DECODER-DAG: Opcode: fooTypeEncDefault:foo
123-
// DECODER-LABEL: DecoderTableAlt32[] =
124-
// DECODER-DAG: Opcode: unrelated
125-
// DECODER-LABEL: DecoderTableAlt_ModeA32[] =
126-
// DECODER-DAG: Opcode: unrelated
127-
// DECODER-LABEL: DecoderTableAlt_ModeB32[] =
128-
// DECODER-DAG: Opcode: unrelated
129-
// DECODER-LABEL: DecoderTableAlt_ModeC32[] =
130-
// DECODER-DAG: Opcode: unrelated
131123
// DECODER-LABEL: DecoderTable_ModeA32[] =
132124
// DECODER-DAG: Opcode: fooTypeEncA:foo
133125
// DECODER-DAG: Opcode: bar
@@ -138,15 +130,21 @@ def unrelated: Instruction {
138130
// DECODER-LABEL: DecoderTable_ModeC32[] =
139131
// DECODER-DAG: Opcode: fooTypeEncC:foo
140132
// DECODER-DAG: Opcode: bar
133+
// DECODER-LABEL: DecoderTableAlt32[] =
134+
// DECODER-DAG: Opcode: unrelated
135+
// DECODER-LABEL: DecoderTableAlt_ModeA32[] =
136+
// DECODER-DAG: Opcode: unrelated
137+
// DECODER-LABEL: DecoderTableAlt_ModeB32[] =
138+
// DECODER-DAG: Opcode: unrelated
139+
// DECODER-LABEL: DecoderTableAlt_ModeC32[] =
140+
// DECODER-DAG: Opcode: unrelated
141141

142142
// Under the 'O1' optimization level, unnecessary duplicate tables will be eliminated,
143143
// reducing the four ‘Alt’ tables down to just one.
144144
// DECODER-SUPPRESS-O1-LABEL: DecoderTable32[] =
145145
// DECODER-SUPPRESS-O1-DAG: Opcode: bar
146146
// DECODER-SUPPRESS-O1-LABEL: DecoderTable64[] =
147147
// DECODER-SUPPRESS-O1-DAG: Opcode: fooTypeEncDefault:foo
148-
// DECODER-SUPPRESS-O1-LABEL: DecoderTableAlt32[] =
149-
// DECODER-SUPPRESS-O1-DAG: Opcode: unrelated
150148
// DECODER-SUPPRESS-O1-LABEL: DecoderTable_ModeA32[] =
151149
// DECODER-SUPPRESS-O1-DAG: Opcode: fooTypeEncA:foo
152150
// DECODER-SUPPRESS-O1-DAG: Opcode: bar
@@ -157,6 +155,8 @@ def unrelated: Instruction {
157155
// DECODER-SUPPRESS-O1-LABEL: DecoderTable_ModeC32[] =
158156
// DECODER-SUPPRESS-O1-DAG: Opcode: fooTypeEncC:foo
159157
// DECODER-SUPPRESS-O1-DAG: Opcode: bar
158+
// DECODER-SUPPRESS-O1-LABEL: DecoderTableAlt32[] =
159+
// DECODER-SUPPRESS-O1-DAG: Opcode: unrelated
160160

161161
// Under the 'O2' optimization condition, instructions possessing the 'EncodingByHwMode'
162162
// attribute will be extracted from their original DecoderNamespace and placed into their
@@ -169,8 +169,6 @@ def unrelated: Instruction {
169169
// DECODER-SUPPRESS-O2-LABEL: DecoderTable64[] =
170170
// DECODER-SUPPRESS-O2-NOT: Opcode: bar
171171
// DECODER-SUPPRESS-O2-DAG: Opcode: fooTypeEncDefault:foo
172-
// DECODER-SUPPRESS-O2-LABEL: DecoderTableAlt32[] =
173-
// DECODER-SUPPRESS-O2-DAG: Opcode: unrelated
174172
// DECODER-SUPPRESS-O2-LABEL: DecoderTable_ModeA32[] =
175173
// DECODER-SUPPRESS-O2-DAG: Opcode: fooTypeEncA:foo
176174
// DECODER-SUPPRESS-O2-NOT: Opcode: bar
@@ -181,6 +179,8 @@ def unrelated: Instruction {
181179
// DECODER-SUPPRESS-O2-LABEL: DecoderTable_ModeC32[] =
182180
// DECODER-SUPPRESS-O2-DAG: Opcode: fooTypeEncC:foo
183181
// DECODER-SUPPRESS-O2-NOT: Opcode: bar
182+
// DECODER-SUPPRESS-O2-LABEL: DecoderTableAlt32[] =
183+
// DECODER-SUPPRESS-O2-DAG: Opcode: unrelated
184184

185185
// For 'bar' and 'unrelated', we didn't assign any HwModes for them,
186186
// they should keep the same in the following four tables.

llvm/utils/TableGen/DecoderEmitter.cpp

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ class DecoderEmitter {
230230
// Emit the decoder state machine table. Returns a mask of MCD decoder ops
231231
// that were emitted.
232232
unsigned emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
233-
unsigned BitWidth, StringRef Namespace,
233+
StringRef Namespace, unsigned HwModeID, unsigned BitWidth,
234234
ArrayRef<unsigned> EncodingIDs) const;
235235
void emitInstrLenTable(formatted_raw_ostream &OS,
236236
ArrayRef<unsigned> InstrLen) const;
@@ -805,8 +805,8 @@ unsigned Filter::usefulness() const {
805805
// Emit the decoder state machine table. Returns a mask of MCD decoder ops
806806
// that were emitted.
807807
unsigned DecoderEmitter::emitTable(formatted_raw_ostream &OS,
808-
DecoderTable &Table, unsigned BitWidth,
809-
StringRef Namespace,
808+
DecoderTable &Table, StringRef Namespace,
809+
unsigned HwModeID, unsigned BitWidth,
810810
ArrayRef<unsigned> EncodingIDs) const {
811811
// We'll need to be able to map from a decoded opcode into the corresponding
812812
// EncodingID for this specific combination of BitWidth and Namespace. This
@@ -818,8 +818,10 @@ unsigned DecoderEmitter::emitTable(formatted_raw_ostream &OS,
818818
OpcodeToEncodingID[Target.getInstrIntValue(InstDef)] = EncodingID;
819819
}
820820

821-
OS << "static const uint8_t DecoderTable" << Namespace << BitWidth
822-
<< "[] = {\n";
821+
OS << "static const uint8_t DecoderTable" << Namespace;
822+
if (HwModeID != DefaultMode)
823+
OS << '_' << Target.getHwModes().getModeName(HwModeID);
824+
OS << BitWidth << "[] = {\n";
823825

824826
// Emit ULEB128 encoded value to OS, returning the number of bytes emitted.
825827
auto emitULEB128 = [](DecoderTable::const_iterator &I,
@@ -2501,8 +2503,9 @@ namespace {
25012503
NumberedAlias,
25022504
&Target.getInstruction(NumberedAlias->getValueAsDef("AliasOf")));
25032505

2504-
// Map of (namespace, size) tuple to encoding IDs.
2505-
std::map<std::pair<std::string, unsigned>, std::vector<unsigned>> EncMap;
2506+
// Map of (namespace, hwmode, size) tuple to encoding IDs.
2507+
std::map<std::tuple<StringRef, unsigned, unsigned>, std::vector<unsigned>>
2508+
EncMap;
25062509
std::map<unsigned, std::vector<OperandInfo>> Operands;
25072510
std::vector<unsigned> InstrLen;
25082511
bool IsVarLenInst = Target.hasVariableLengthEncodings();
@@ -2537,27 +2540,22 @@ namespace {
25372540
MaxInstLen = std::max(MaxInstLen, Len);
25382541
InstrLen[NEI] = Len;
25392542
}
2540-
std::string DecoderNamespace =
2541-
EncodingDef->getValueAsString("DecoderNamespace").str();
2542-
// DecoderTables with DefaultMode should not have any suffix.
2543-
if (NumberedEncoding.HwModeID != DefaultMode) {
2544-
StringRef HwModeName = HWM.getModeName(NumberedEncoding.HwModeID);
2545-
DecoderNamespace += ("_" + HwModeName).str();
2546-
}
2547-
EncMap[{DecoderNamespace, Size}].push_back(NEI);
2543+
StringRef DecoderNamespace =
2544+
EncodingDef->getValueAsString("DecoderNamespace");
2545+
EncMap[{DecoderNamespace, NumberedEncoding.HwModeID, Size}].push_back(
2546+
NEI);
25482547
} else {
25492548
NumEncodingsOmitted++;
25502549
}
25512550
}
25522551

25532552
DecoderTableInfo TableInfo;
25542553
unsigned OpcodeMask = 0;
2555-
for (const auto &[NSAndByteSize, EncodingIDs] : EncMap) {
2556-
const std::string &DecoderNamespace = NSAndByteSize.first;
2557-
const unsigned BitWidth = 8 * NSAndByteSize.second;
2558-
// Emit the decoder for this namespace+width combination.
2559-
FilterChooser FC(NumberedEncodings, EncodingIDs, Operands,
2560-
IsVarLenInst ? MaxInstLen : BitWidth, this);
2554+
for (const auto &[Key, EncodingIDs] : EncMap) {
2555+
auto [DecoderNamespace, HwModeID, Size] = Key;
2556+
const unsigned BitWidth = IsVarLenInst ? MaxInstLen : 8 * Size;
2557+
// Emit the decoder for this (namespace, hwmode, width) combination.
2558+
FilterChooser FC(NumberedEncodings, EncodingIDs, Operands, BitWidth, this);
25612559

25622560
// The decode table is cleared for each top level decoder function. The
25632561
// predicates and decoders themselves, however, are shared across all
@@ -2573,8 +2571,8 @@ namespace {
25732571
TableInfo.Table.push_back(MCD::OPC_Fail);
25742572

25752573
// Print the table to the output stream.
2576-
OpcodeMask |= emitTable(OS, TableInfo.Table, FC.getBitWidth(),
2577-
DecoderNamespace, EncodingIDs);
2574+
OpcodeMask |= emitTable(OS, TableInfo.Table, DecoderNamespace, HwModeID,
2575+
BitWidth, EncodingIDs);
25782576
}
25792577

25802578
// For variable instruction, we emit a instruction length table

0 commit comments

Comments
 (0)