@@ -219,11 +219,12 @@ using NamespacesHwModesMap = std::map<std::string, std::set<unsigned>>;
219
219
220
220
class DecoderEmitter {
221
221
const RecordKeeper &RK;
222
+ CodeGenTarget Target;
223
+ const CodeGenHwModes &CGH;
222
224
std::vector<EncodingAndInst> Encodings;
223
225
224
226
public:
225
- DecoderEmitter (const RecordKeeper &R, StringRef PredicateNamespace)
226
- : RK(R), Target(R), PredicateNamespace(PredicateNamespace) {}
227
+ DecoderEmitter (const RecordKeeper &RK, StringRef PredicateNamespace);
227
228
228
229
const CodeGenTarget &getTarget () const { return Target; }
229
230
@@ -240,10 +241,19 @@ class DecoderEmitter {
240
241
DecoderSet &Decoders) const ;
241
242
242
243
// run - Output the code emitter
243
- void run (raw_ostream &o);
244
+ void run (raw_ostream &o) const ;
244
245
245
246
private:
246
- CodeGenTarget Target;
247
+ void collectHwModesReferencedForEncodings (
248
+ std::vector<unsigned > &HwModeIDs,
249
+ NamespacesHwModesMap &NamespacesWithHwModes) const ;
250
+
251
+ void
252
+ handleHwModesUnrelatedEncodings (const CodeGenInstruction *Instr,
253
+ ArrayRef<unsigned > HwModeIDs,
254
+ NamespacesHwModesMap &NamespacesWithHwModes);
255
+
256
+ void parseInstructionEncodings ();
247
257
248
258
public:
249
259
StringRef PredicateNamespace;
@@ -2393,12 +2403,12 @@ static bool Check(DecodeStatus &Out, DecodeStatus In) {
2393
2403
)" ;
2394
2404
}
2395
2405
2396
- // Collect all HwModes referenced by the target for encoding purposes.
2397
- static void collectHwModesReferencedForEncodings (
2398
- const CodeGenHwModes &HWM, std::vector<unsigned > &HwModeIDs,
2399
- NamespacesHwModesMap &NamespacesWithHwModes) {
2400
- SmallBitVector BV (HWM .getNumModeIds ());
2401
- for (const auto &MS : HWM .getHwModeSelects ()) {
2406
+ // / Collects all HwModes referenced by the target for encoding purposes.
2407
+ void DecoderEmitter:: collectHwModesReferencedForEncodings (
2408
+ std::vector<unsigned > &HwModeIDs,
2409
+ NamespacesHwModesMap &NamespacesWithHwModes) const {
2410
+ SmallBitVector BV (CGH .getNumModeIds ());
2411
+ for (const auto &MS : CGH .getHwModeSelects ()) {
2402
2412
for (auto [HwModeID, EncodingDef] : MS.second .Items ) {
2403
2413
if (EncodingDef->isSubClassOf (" InstructionEncoding" )) {
2404
2414
std::string DecoderNamespace =
@@ -2414,17 +2424,15 @@ static void collectHwModesReferencedForEncodings(
2414
2424
llvm::copy (BV.set_bits (), std::back_inserter (HwModeIDs));
2415
2425
}
2416
2426
2417
- static void
2418
- handleHwModesUnrelatedEncodings (const CodeGenInstruction *Instr,
2419
- ArrayRef<unsigned > HwModeIDs,
2420
- NamespacesHwModesMap &NamespacesWithHwModes,
2421
- std::vector<EncodingAndInst> &GlobalEncodings) {
2427
+ void DecoderEmitter::handleHwModesUnrelatedEncodings (
2428
+ const CodeGenInstruction *Instr, ArrayRef<unsigned > HwModeIDs,
2429
+ NamespacesHwModesMap &NamespacesWithHwModes) {
2422
2430
const Record *InstDef = Instr->TheDef ;
2423
2431
2424
2432
switch (DecoderEmitterSuppressDuplicates) {
2425
2433
case SUPPRESSION_DISABLE: {
2426
2434
for (unsigned HwModeID : HwModeIDs)
2427
- GlobalEncodings .emplace_back (InstDef, Instr, HwModeID);
2435
+ Encodings .emplace_back (InstDef, Instr, HwModeID);
2428
2436
break ;
2429
2437
}
2430
2438
case SUPPRESSION_LEVEL1: {
@@ -2433,51 +2441,28 @@ handleHwModesUnrelatedEncodings(const CodeGenInstruction *Instr,
2433
2441
auto It = NamespacesWithHwModes.find (DecoderNamespace);
2434
2442
if (It != NamespacesWithHwModes.end ()) {
2435
2443
for (unsigned HwModeID : It->second )
2436
- GlobalEncodings .emplace_back (InstDef, Instr, HwModeID);
2444
+ Encodings .emplace_back (InstDef, Instr, HwModeID);
2437
2445
} else {
2438
2446
// Only emit the encoding once, as it's DecoderNamespace doesn't
2439
2447
// contain any HwModes.
2440
- GlobalEncodings .emplace_back (InstDef, Instr, DefaultMode);
2448
+ Encodings .emplace_back (InstDef, Instr, DefaultMode);
2441
2449
}
2442
2450
break ;
2443
2451
}
2444
2452
case SUPPRESSION_LEVEL2:
2445
- GlobalEncodings .emplace_back (InstDef, Instr, DefaultMode);
2453
+ Encodings .emplace_back (InstDef, Instr, DefaultMode);
2446
2454
break ;
2447
2455
}
2448
2456
}
2449
2457
2450
- // Emits disassembler code for instruction decoding.
2451
- void DecoderEmitter::run (raw_ostream &o) {
2452
- formatted_raw_ostream OS (o);
2453
- OS << R"(
2454
- #include "llvm/MC/MCInst.h"
2455
- #include "llvm/MC/MCSubtargetInfo.h"
2456
- #include "llvm/Support/DataTypes.h"
2457
- #include "llvm/Support/Debug.h"
2458
- #include "llvm/Support/LEB128.h"
2459
- #include "llvm/Support/raw_ostream.h"
2460
- #include "llvm/TargetParser/SubtargetFeature.h"
2461
- #include <assert.h>
2462
-
2463
- namespace {
2464
- )" ;
2465
-
2466
- emitFieldFromInstruction (OS);
2467
- emitInsertBits (OS);
2468
- emitCheck (OS);
2469
-
2470
- Target.reverseBitsForLittleEndianEncoding ();
2471
-
2472
- // Parameterize the decoders based on namespace and instruction width.
2473
-
2458
+ // / Parses all InstructionEncoding instances and fills internal data structures.
2459
+ void DecoderEmitter::parseInstructionEncodings () {
2474
2460
// First, collect all encoding-related HwModes referenced by the target.
2475
2461
// And establish a mapping table between DecoderNamespace and HwMode.
2476
2462
// If HwModeNames is empty, add the default mode so we always have one HwMode.
2477
- const CodeGenHwModes &HWM = Target.getHwModes ();
2478
2463
std::vector<unsigned > HwModeIDs;
2479
2464
NamespacesHwModesMap NamespacesWithHwModes;
2480
- collectHwModesReferencedForEncodings (HWM, HwModeIDs, NamespacesWithHwModes);
2465
+ collectHwModesReferencedForEncodings (HwModeIDs, NamespacesWithHwModes);
2481
2466
if (HwModeIDs.empty ())
2482
2467
HwModeIDs.push_back (DefaultMode);
2483
2468
@@ -2488,22 +2473,50 @@ namespace {
2488
2473
for (const CodeGenInstruction *Inst : Instructions) {
2489
2474
const Record *InstDef = Inst->TheDef ;
2490
2475
if (const Record *RV = InstDef->getValueAsOptionalDef (" EncodingInfos" )) {
2491
- EncodingInfoByHwMode EBM (RV, HWM );
2476
+ EncodingInfoByHwMode EBM (RV, CGH );
2492
2477
for (auto [HwModeID, EncodingDef] : EBM)
2493
2478
Encodings.emplace_back (EncodingDef, Inst, HwModeID);
2494
2479
continue ;
2495
2480
}
2496
2481
// This instruction is encoded the same on all HwModes.
2497
2482
// According to user needs, provide varying degrees of suppression.
2498
- handleHwModesUnrelatedEncodings (Inst, HwModeIDs, NamespacesWithHwModes,
2499
- Encodings);
2483
+ handleHwModesUnrelatedEncodings (Inst, HwModeIDs, NamespacesWithHwModes);
2500
2484
}
2501
2485
2502
2486
for (const Record *EncodingDef :
2503
2487
RK.getAllDerivedDefinitions (" AdditionalEncoding" )) {
2504
2488
const Record *InstDef = EncodingDef->getValueAsDef (" AliasOf" );
2505
2489
Encodings.emplace_back (EncodingDef, &Target.getInstruction (InstDef));
2506
2490
}
2491
+ }
2492
+
2493
+ DecoderEmitter::DecoderEmitter (const RecordKeeper &RK,
2494
+ StringRef PredicateNamespace)
2495
+ : RK(RK), Target(RK), CGH(Target.getHwModes()),
2496
+ PredicateNamespace(PredicateNamespace) {
2497
+ Target.reverseBitsForLittleEndianEncoding ();
2498
+ parseInstructionEncodings ();
2499
+ }
2500
+
2501
+ // Emits disassembler code for instruction decoding.
2502
+ void DecoderEmitter::run (raw_ostream &o) const {
2503
+ formatted_raw_ostream OS (o);
2504
+ OS << R"(
2505
+ #include "llvm/MC/MCInst.h"
2506
+ #include "llvm/MC/MCSubtargetInfo.h"
2507
+ #include "llvm/Support/DataTypes.h"
2508
+ #include "llvm/Support/Debug.h"
2509
+ #include "llvm/Support/LEB128.h"
2510
+ #include "llvm/Support/raw_ostream.h"
2511
+ #include "llvm/TargetParser/SubtargetFeature.h"
2512
+ #include <assert.h>
2513
+
2514
+ namespace {
2515
+ )" ;
2516
+
2517
+ emitFieldFromInstruction (OS);
2518
+ emitInsertBits (OS);
2519
+ emitCheck (OS);
2507
2520
2508
2521
// Map of (namespace, hwmode, size) tuple to encoding IDs.
2509
2522
std::map<std::tuple<StringRef, unsigned , unsigned >, std::vector<unsigned >>
@@ -2512,7 +2525,7 @@ namespace {
2512
2525
std::vector<unsigned > InstrLen;
2513
2526
bool IsVarLenInst = Target.hasVariableLengthEncodings ();
2514
2527
if (IsVarLenInst)
2515
- InstrLen.resize (Instructions .size (), 0 );
2528
+ InstrLen.resize (Target. getInstructions () .size (), 0 );
2516
2529
unsigned MaxInstLen = 0 ;
2517
2530
2518
2531
for (const auto &[EncodingID, Encoding] : enumerate(Encodings)) {
0 commit comments