@@ -290,55 +290,52 @@ CodeEmitterGen::getInstructionCases(const Record *R,
290
290
BitOffsetCase += S;
291
291
};
292
292
293
- if (const RecordVal *RV = R->getValue (" EncodingInfos" )) {
294
- if (const auto *DI = dyn_cast_or_null<DefInit>(RV->getValue ())) {
295
- const CodeGenHwModes &HWM = Target.getHwModes ();
296
- EncodingInfoByHwMode EBM (DI->getDef (), HWM);
297
-
298
- // Invoke the interface to obtain the HwMode ID controlling the
299
- // EncodingInfo for the current subtarget. This interface will
300
- // mask off irrelevant HwMode IDs.
301
- Append (" unsigned HwMode = "
302
- " STI.getHwMode(MCSubtargetInfo::HwMode_EncodingInfo);\n " );
303
- Case += " switch (HwMode) {\n " ;
304
- Case += " default: llvm_unreachable(\" Unknown hardware mode!\" ); "
305
- " break;\n " ;
306
- for (auto &[ModeId, Encoding] : EBM) {
307
- if (ModeId == DefaultMode) {
308
- Case +=
309
- " case " + itostr (DefaultMode) + " : InstBitsByHw = InstBits" ;
310
- } else {
311
- Case += " case " + itostr (ModeId) +
312
- " : InstBitsByHw = InstBits_" + HWM.getMode (ModeId).Name .str ();
313
- }
314
- Case += " ; break;\n " ;
315
- }
316
- Case += " };\n " ;
317
-
318
- // We need to remodify the 'Inst' value from the table we found above.
319
- if (UseAPInt) {
320
- int NumWords = APInt::getNumWords (BitWidth);
321
- Case += " Inst = APInt(" + itostr (BitWidth);
322
- Case += " , ArrayRef(InstBitsByHw + opcode * " + itostr (NumWords) +
323
- " , " + itostr (NumWords);
324
- Case += " ));\n " ;
325
- Case += " Value = Inst;\n " ;
293
+ if (const Record *RV = R->getValueAsOptionalDef (" EncodingInfos" )) {
294
+ const CodeGenHwModes &HWM = Target.getHwModes ();
295
+ EncodingInfoByHwMode EBM (RV, HWM);
296
+
297
+ // Invoke the interface to obtain the HwMode ID controlling the
298
+ // EncodingInfo for the current subtarget. This interface will
299
+ // mask off irrelevant HwMode IDs.
300
+ Append (" unsigned HwMode = "
301
+ " STI.getHwMode(MCSubtargetInfo::HwMode_EncodingInfo);\n " );
302
+ Case += " switch (HwMode) {\n " ;
303
+ Case += " default: llvm_unreachable(\" Unknown hardware mode!\" ); "
304
+ " break;\n " ;
305
+ for (auto &[ModeId, Encoding] : EBM) {
306
+ if (ModeId == DefaultMode) {
307
+ Case +=
308
+ " case " + itostr (DefaultMode) + " : InstBitsByHw = InstBits" ;
326
309
} else {
327
- Case += " Value = InstBitsByHw[opcode];\n " ;
310
+ Case += " case " + itostr (ModeId) + " : InstBitsByHw = InstBits_" +
311
+ HWM.getMode (ModeId).Name .str ();
328
312
}
313
+ Case += " ; break;\n " ;
314
+ }
315
+ Case += " };\n " ;
329
316
330
- Append (" switch (HwMode) {\n " );
331
- Append (" default: llvm_unreachable(\" Unhandled HwMode\" );\n " );
332
- for (auto &[ModeId, Encoding] : EBM) {
333
- Append (" case " + itostr (ModeId) + " : {\n " );
334
- addInstructionCasesForEncoding (R, Encoding, Target, Case,
335
- BitOffsetCase);
336
- Append (" break;\n " );
337
- Append (" }\n " );
338
- }
317
+ // We need to remodify the 'Inst' value from the table we found above.
318
+ if (UseAPInt) {
319
+ int NumWords = APInt::getNumWords (BitWidth);
320
+ Case += " Inst = APInt(" + itostr (BitWidth);
321
+ Case += " , ArrayRef(InstBitsByHw + opcode * " + itostr (NumWords) + " , " +
322
+ itostr (NumWords);
323
+ Case += " ));\n " ;
324
+ Case += " Value = Inst;\n " ;
325
+ } else {
326
+ Case += " Value = InstBitsByHw[opcode];\n " ;
327
+ }
328
+
329
+ Append (" switch (HwMode) {\n " );
330
+ Append (" default: llvm_unreachable(\" Unhandled HwMode\" );\n " );
331
+ for (auto &[ModeId, Encoding] : EBM) {
332
+ Append (" case " + itostr (ModeId) + " : {\n " );
333
+ addInstructionCasesForEncoding (R, Encoding, Target, Case, BitOffsetCase);
334
+ Append (" break;\n " );
339
335
Append (" }\n " );
340
- return {std::move (Case), std::move (BitOffsetCase)};
341
336
}
337
+ Append (" }\n " );
338
+ return {std::move (Case), std::move (BitOffsetCase)};
342
339
}
343
340
addInstructionCasesForEncoding (R, R, Target, Case, BitOffsetCase);
344
341
return {std::move (Case), std::move (BitOffsetCase)};
@@ -417,20 +414,18 @@ void CodeEmitterGen::emitInstructionBaseValues(
417
414
}
418
415
419
416
const Record *EncodingDef = R;
420
- if (const RecordVal *RV = R->getValue (" EncodingInfos" )) {
421
- if (auto *DI = dyn_cast_or_null<DefInit>(RV->getValue ())) {
422
- EncodingInfoByHwMode EBM (DI->getDef (), HWM);
423
- if (EBM.hasMode (HwMode)) {
424
- EncodingDef = EBM.get (HwMode);
425
- } else {
426
- // If the HwMode does not match, then Encoding '0'
427
- // should be generated.
428
- APInt Value (BitWidth, 0 );
429
- O << " " ;
430
- emitInstBits (O, Value);
431
- O << " ," << ' \t ' << " // " << R->getName () << " \n " ;
432
- continue ;
433
- }
417
+ if (const Record *RV = R->getValueAsOptionalDef (" EncodingInfos" )) {
418
+ EncodingInfoByHwMode EBM (RV, HWM);
419
+ if (EBM.hasMode (HwMode)) {
420
+ EncodingDef = EBM.get (HwMode);
421
+ } else {
422
+ // If the HwMode does not match, then Encoding '0'
423
+ // should be generated.
424
+ APInt Value (BitWidth, 0 );
425
+ O << " " ;
426
+ emitInstBits (O, Value);
427
+ O << " ," << ' \t ' << " // " << R->getName () << " \n " ;
428
+ continue ;
434
429
}
435
430
}
436
431
const BitsInit *BI = EncodingDef->getValueAsBitsInit (" Inst" );
@@ -490,16 +485,14 @@ void CodeEmitterGen::run(raw_ostream &O) {
490
485
R->getValueAsBit (" isPseudo" ))
491
486
continue ;
492
487
493
- if (const RecordVal *RV = R->getValue (" EncodingInfos" )) {
494
- if (const DefInit *DI = dyn_cast_or_null<DefInit>(RV->getValue ())) {
495
- EncodingInfoByHwMode EBM (DI->getDef (), HWM);
496
- for (const auto &[Key, Value] : EBM) {
497
- const BitsInit *BI = Value->getValueAsBitsInit (" Inst" );
498
- BitWidth = std::max (BitWidth, BI->getNumBits ());
499
- HwModes.insert (Key);
500
- }
501
- continue ;
488
+ if (const Record *RV = R->getValueAsOptionalDef (" EncodingInfos" )) {
489
+ EncodingInfoByHwMode EBM (RV, HWM);
490
+ for (const auto &[Key, Value] : EBM) {
491
+ const BitsInit *BI = Value->getValueAsBitsInit (" Inst" );
492
+ BitWidth = std::max (BitWidth, BI->getNumBits ());
493
+ HwModes.insert (Key);
502
494
}
495
+ continue ;
503
496
}
504
497
const BitsInit *BI = R->getValueAsBitsInit (" Inst" );
505
498
BitWidth = std::max (BitWidth, BI->getNumBits ());
0 commit comments