@@ -129,6 +129,38 @@ struct OperandInfo {
129
129
const_iterator end () const { return Fields.end (); }
130
130
};
131
131
132
+ // / Represents a parsed InstructionEncoding record or a record derived from it.
133
+ class InstructionEncoding {
134
+ // / The Record this encoding originates from.
135
+ const Record *EncodingDef;
136
+
137
+ // / The instruction this encoding is for.
138
+ const CodeGenInstruction *Inst;
139
+
140
+ // / The name of this encoding (for debugging purposes).
141
+ std::string Name;
142
+
143
+ public:
144
+ InstructionEncoding (const Record *EncodingDef, const CodeGenInstruction *Inst)
145
+ : EncodingDef(EncodingDef), Inst(Inst) {
146
+ const Record *InstDef = Inst->TheDef ;
147
+
148
+ // Give this encoding a name.
149
+ if (EncodingDef != InstDef)
150
+ Name = (EncodingDef->getName () + Twine (' :' )).str ();
151
+ Name.append (InstDef->getName ());
152
+ }
153
+
154
+ // / Returns the Record this encoding originates from.
155
+ const Record *getRecord () const { return EncodingDef; }
156
+
157
+ // / Returns the instruction this encoding is for.
158
+ const CodeGenInstruction *getInstruction () const { return Inst; }
159
+
160
+ // / Returns the name of this encoding, for debugging purposes.
161
+ StringRef getName () const { return Name; }
162
+ };
163
+
132
164
typedef std::vector<uint32_t > FixupList;
133
165
typedef std::vector<FixupList> FixupScopeList;
134
166
typedef SmallSetVector<CachedHashString, 16 > PredicateSet;
@@ -205,14 +237,6 @@ struct DecoderTableInfo {
205
237
}
206
238
};
207
239
208
- struct EncodingAndInst {
209
- const Record *EncodingDef;
210
- const CodeGenInstruction *Inst;
211
-
212
- EncodingAndInst (const Record *EncodingDef, const CodeGenInstruction *Inst)
213
- : EncodingDef(EncodingDef), Inst(Inst) {}
214
- };
215
-
216
240
using NamespacesHwModesMap = std::map<std::string, std::set<unsigned >>;
217
241
218
242
class DecoderEmitter {
@@ -221,7 +245,7 @@ class DecoderEmitter {
221
245
const CodeGenHwModes &CGH;
222
246
223
247
// / All parsed encodings.
224
- std::vector<EncodingAndInst > Encodings;
248
+ std::vector<InstructionEncoding > Encodings;
225
249
226
250
// / Encodings IDs for each HwMode. An ID is an index into Encodings.
227
251
SmallDenseMap<unsigned , std::vector<unsigned >> EncodingIDsByHwMode;
@@ -316,13 +340,6 @@ struct BitValue {
316
340
317
341
} // end anonymous namespace
318
342
319
- static raw_ostream &operator <<(raw_ostream &OS, const EncodingAndInst &Value) {
320
- if (Value.EncodingDef != Value.Inst ->TheDef )
321
- OS << Value.EncodingDef ->getName () << " :" ;
322
- OS << Value.Inst ->TheDef ->getName ();
323
- return OS;
324
- }
325
-
326
343
// Prints the bit value for each position.
327
344
static void dumpBits (raw_ostream &OS, const BitsInit &Bits, unsigned BitWidth) {
328
345
for (const Init *Bit : reverse (Bits.getBits ().take_front (BitWidth)))
@@ -500,7 +517,7 @@ class FilterChooser {
500
517
friend class Filter ;
501
518
502
519
// Vector of encodings to choose our filter.
503
- ArrayRef<EncodingAndInst > Encodings;
520
+ ArrayRef<InstructionEncoding > Encodings;
504
521
505
522
// Vector of encoding IDs for this filter chooser to work on.
506
523
ArrayRef<unsigned > EncodingIDs;
@@ -531,7 +548,7 @@ class FilterChooser {
531
548
};
532
549
533
550
public:
534
- FilterChooser (ArrayRef<EncodingAndInst > Encodings,
551
+ FilterChooser (ArrayRef<InstructionEncoding > Encodings,
535
552
ArrayRef<unsigned > EncodingIDs,
536
553
const std::map<unsigned , std::vector<OperandInfo>> &Ops,
537
554
unsigned BW, const DecoderEmitter *E)
@@ -541,7 +558,7 @@ class FilterChooser {
541
558
doFilter ();
542
559
}
543
560
544
- FilterChooser (ArrayRef<EncodingAndInst > Encodings,
561
+ FilterChooser (ArrayRef<InstructionEncoding > Encodings,
545
562
ArrayRef<unsigned > EncodingIDs,
546
563
const std::map<unsigned , std::vector<OperandInfo>> &Ops,
547
564
const std::vector<BitValue> &ParentFilterBitValues,
@@ -560,7 +577,7 @@ class FilterChooser {
560
577
protected:
561
578
// Populates the insn given the uid.
562
579
insn_t insnWithID (unsigned EncodingID) const {
563
- const Record *EncodingDef = Encodings[EncodingID].EncodingDef ;
580
+ const Record *EncodingDef = Encodings[EncodingID].getRecord () ;
564
581
const BitsInit &Bits = getBitsField (*EncodingDef, " Inst" );
565
582
insn_t Insn (std::max (BitWidth, Bits.getNumBits ()), BitValue::BIT_UNSET);
566
583
// We may have a SoftFail bitmask, which specifies a mask where an encoding
@@ -827,7 +844,7 @@ unsigned DecoderEmitter::emitTable(formatted_raw_ostream &OS,
827
844
DenseMap<unsigned , unsigned > OpcodeToEncodingID;
828
845
OpcodeToEncodingID.reserve (EncodingIDs.size ());
829
846
for (unsigned EncodingID : EncodingIDs) {
830
- const Record *InstDef = Encodings[EncodingID].Inst ->TheDef ;
847
+ const Record *InstDef = Encodings[EncodingID].getInstruction () ->TheDef ;
831
848
OpcodeToEncodingID[Target.getInstrIntValue (InstDef)] = EncodingID;
832
849
}
833
850
@@ -978,15 +995,15 @@ unsigned DecoderEmitter::emitTable(formatted_raw_ostream &OS,
978
995
auto EncodingID = EncI->second ;
979
996
980
997
if (!IsTry) {
981
- OS << " // Opcode: " << Encodings[EncodingID]
998
+ OS << " // Opcode: " << Encodings[EncodingID]. getName ()
982
999
<< " , DecodeIdx: " << DecodeIdx << ' \n ' ;
983
1000
break ;
984
1001
}
985
1002
986
1003
// Fallthrough for OPC_TryDecode.
987
1004
if (!IsFail) {
988
1005
uint32_t NumToSkip = emitNumToSkip (I, OS);
989
- OS << " // Opcode: " << Encodings[EncodingID]
1006
+ OS << " // Opcode: " << Encodings[EncodingID]. getName ()
990
1007
<< " , DecodeIdx: " << DecodeIdx;
991
1008
emitNumToSkipComment (NumToSkip, /* InComment=*/ true );
992
1009
}
@@ -1295,7 +1312,7 @@ bool FilterChooser::emitPredicateMatchAux(const Init &Val, bool ParenIfBinOp,
1295
1312
bool FilterChooser::emitPredicateMatch (raw_ostream &OS,
1296
1313
unsigned EncodingID) const {
1297
1314
const ListInit *Predicates =
1298
- Encodings[EncodingID].EncodingDef ->getValueAsListInit (" Predicates" );
1315
+ Encodings[EncodingID].getRecord () ->getValueAsListInit (" Predicates" );
1299
1316
bool IsFirstEmission = true ;
1300
1317
for (unsigned i = 0 ; i < Predicates->size (); ++i) {
1301
1318
const Record *Pred = Predicates->getElementAsRecord (i);
@@ -1317,7 +1334,7 @@ bool FilterChooser::emitPredicateMatch(raw_ostream &OS,
1317
1334
1318
1335
bool FilterChooser::doesOpcodeNeedPredicate (unsigned EncodingID) const {
1319
1336
const ListInit *Predicates =
1320
- Encodings[EncodingID].EncodingDef ->getValueAsListInit (" Predicates" );
1337
+ Encodings[EncodingID].getRecord () ->getValueAsListInit (" Predicates" );
1321
1338
for (unsigned i = 0 ; i < Predicates->size (); ++i) {
1322
1339
const Record *Pred = Predicates->getElementAsRecord (i);
1323
1340
if (!Pred->getValue (" AssemblerMatcherPredicate" ))
@@ -1374,7 +1391,7 @@ void FilterChooser::emitPredicateTableEntry(DecoderTableInfo &TableInfo,
1374
1391
1375
1392
void FilterChooser::emitSoftFailTableEntry (DecoderTableInfo &TableInfo,
1376
1393
unsigned EncodingID) const {
1377
- const Record *EncodingDef = Encodings[EncodingID].EncodingDef ;
1394
+ const Record *EncodingDef = Encodings[EncodingID].getRecord () ;
1378
1395
const RecordVal *RV = EncodingDef->getValue (" SoftFail" );
1379
1396
const BitsInit *SFBits = RV ? dyn_cast<BitsInit>(RV->getValue ()) : nullptr ;
1380
1397
@@ -1400,7 +1417,7 @@ void FilterChooser::emitSoftFailTableEntry(DecoderTableInfo &TableInfo,
1400
1417
} else {
1401
1418
// The bit is not set; this must be an error!
1402
1419
errs () << " SoftFail Conflict: bit SoftFail{" << i << " } in "
1403
- << Encodings[EncodingID] << " is set but Inst{" << i
1420
+ << Encodings[EncodingID]. getName () << " is set but Inst{" << i
1404
1421
<< " } is unset!\n "
1405
1422
<< " - You can only mark a bit as SoftFail if it is fully defined"
1406
1423
<< " (1/0 - not '?') in Inst\n " ;
@@ -1473,7 +1490,7 @@ void FilterChooser::emitSingletonTableEntry(DecoderTableInfo &TableInfo,
1473
1490
: MCD::OPC_TryDecode);
1474
1491
TableInfo.Table .push_back (DecoderOp);
1475
1492
NumEncodingsSupported++;
1476
- const Record *InstDef = Encodings[EncodingID].Inst ->TheDef ;
1493
+ const Record *InstDef = Encodings[EncodingID].getInstruction () ->TheDef ;
1477
1494
TableInfo.Table .insertULEB128 (Emitter->getTarget ().getInstrIntValue (InstDef));
1478
1495
TableInfo.Table .insertULEB128 (DIdx);
1479
1496
@@ -1768,10 +1785,10 @@ void FilterChooser::doFilter() {
1768
1785
1769
1786
// Dump encodings.
1770
1787
for (unsigned EncodingID : EncodingIDs) {
1771
- const EncodingAndInst &Enc = Encodings[EncodingID];
1788
+ const InstructionEncoding &Enc = Encodings[EncodingID];
1772
1789
errs () << Indent;
1773
- dumpBits (errs (), getBitsField (*Enc.EncodingDef , " Inst" ), BitWidth);
1774
- errs () << " " << Enc << ' \n ' ;
1790
+ dumpBits (errs (), getBitsField (*Enc.getRecord () , " Inst" ), BitWidth);
1791
+ errs () << " " << Enc. getName () << ' \n ' ;
1775
1792
}
1776
1793
PrintFatalError (" Decoding conflict encountered" );
1777
1794
}
@@ -2437,7 +2454,7 @@ void DecoderEmitter::handleHwModesUnrelatedEncodings(
2437
2454
break ;
2438
2455
}
2439
2456
case SUPPRESSION_LEVEL1: {
2440
- const Record *InstDef = Encodings[EncodingID].Inst ->TheDef ;
2457
+ const Record *InstDef = Encodings[EncodingID].getInstruction () ->TheDef ;
2441
2458
std::string DecoderNamespace =
2442
2459
InstDef->getValueAsString (" DecoderNamespace" ).str ();
2443
2460
auto It = NamespacesWithHwModes.find (DecoderNamespace);
@@ -2540,9 +2557,9 @@ namespace {
2540
2557
2541
2558
for (const auto &[HwModeID, EncodingIDs] : EncodingIDsByHwMode) {
2542
2559
for (unsigned EncodingID : EncodingIDs) {
2543
- const EncodingAndInst &Encoding = Encodings[EncodingID];
2544
- const Record *EncodingDef = Encoding.EncodingDef ;
2545
- const CodeGenInstruction *Inst = Encoding.Inst ;
2560
+ const InstructionEncoding &Encoding = Encodings[EncodingID];
2561
+ const Record *EncodingDef = Encoding.getRecord () ;
2562
+ const CodeGenInstruction *Inst = Encoding.getInstruction () ;
2546
2563
const Record *Def = Inst->TheDef ;
2547
2564
unsigned Size = EncodingDef->getValueAsInt (" Size" );
2548
2565
if (Def->getValueAsString (" Namespace" ) == " TargetOpcode" ||
0 commit comments