Skip to content

Commit f22291c

Browse files
authored
[RISCV][NFC] Merge Xqci Decoder Tables (llvm#128140)
RISC-V has multiple decoder tables because there is no guarantee that non-standard extensions do not overlap with each other. Qualcomm's Xqci family of extensions are intended to be implemented together, and therefore we want a single decode table for this group of extensions. This should be more efficient overall, and allows us to use tablegen's existing mechanism that finds overlapping encodings within the group. To implement this, the key addition is `TRY_TO_DECODE_FEATURE_ANY`, which will use the provided decoder table if any of the features from the FeatureBitset (first argument) are enabled, rather than if all are enabled.
1 parent c8136da commit f22291c

File tree

2 files changed

+47
-50
lines changed

2 files changed

+47
-50
lines changed

llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,17 @@ void RISCVDisassembler::addSPOperands(MCInst &MI) const {
619619
(void)nullptr)
620620
#define TRY_TO_DECODE_FEATURE(FEATURE, DECODER_TABLE, DESC) \
621621
TRY_TO_DECODE(STI.hasFeature(FEATURE), DECODER_TABLE, DESC)
622+
#define TRY_TO_DECODE_FEATURE_ANY(FEATURES, DECODER_TABLE, DESC) \
623+
TRY_TO_DECODE((STI.getFeatureBits() & (FEATURES)).any(), DECODER_TABLE, DESC)
624+
625+
static constexpr FeatureBitset XqciFeatureGroup = {
626+
RISCV::FeatureVendorXqcia, RISCV::FeatureVendorXqciac,
627+
RISCV::FeatureVendorXqcicli, RISCV::FeatureVendorXqcicm,
628+
RISCV::FeatureVendorXqcics, RISCV::FeatureVendorXqcicsr,
629+
RISCV::FeatureVendorXqciint, RISCV::FeatureVendorXqcilia,
630+
RISCV::FeatureVendorXqcilo, RISCV::FeatureVendorXqcilsm,
631+
RISCV::FeatureVendorXqcisls,
632+
};
622633

623634
DecodeStatus RISCVDisassembler::getInstruction32(MCInst &MI, uint64_t &Size,
624635
ArrayRef<uint8_t> Bytes,
@@ -706,24 +717,10 @@ DecodeStatus RISCVDisassembler::getInstruction32(MCInst &MI, uint64_t &Size,
706717
"CORE-V SIMD extensions");
707718
TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXCVbi, DecoderTableXCVbi32,
708719
"CORE-V Immediate Branching");
709-
TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXqcicsr, DecoderTableXqcicsr32,
710-
"Qualcomm uC CSR");
711-
TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXqcisls, DecoderTableXqcisls32,
712-
"Qualcomm uC Scaled Load Store");
713-
TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXqcia, DecoderTableXqcia32,
714-
"Qualcomm uC Arithmetic");
715-
TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXqcics, DecoderTableXqcics32,
716-
"Qualcomm uC Conditional Select");
717-
TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXqcilsm, DecoderTableXqcilsm32,
718-
"Qualcomm uC Load Store Multiple");
719-
TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXqciac, DecoderTableXqciac32,
720-
"Qualcomm uC Load-Store Address Calculation");
721-
TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXqcicli, DecoderTableXqcicli32,
722-
"Qualcomm uC Conditional Load Immediate");
723-
TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXqcicm, DecoderTableXqcicm32,
724-
"Qualcomm uC Conditional Move");
725-
TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXqciint, DecoderTableXqciint32,
726-
"Qualcomm uC Interrupts");
720+
721+
TRY_TO_DECODE_FEATURE_ANY(XqciFeatureGroup, DecoderTableXqci32,
722+
"Qualcomm uC Extensions");
723+
727724
TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXRivosVizip, DecoderTableXRivos32,
728725
"Rivos");
729726

@@ -752,12 +749,10 @@ DecodeStatus RISCVDisassembler::getInstruction16(MCInst &MI, uint64_t &Size,
752749
"Zcmt (16-bit Table Jump Instructions)");
753750
TRY_TO_DECODE_FEATURE(RISCV::FeatureStdExtZcmp, DecoderTableRVZcmp16,
754751
"Zcmp (16-bit Push/Pop & Double Move Instructions)");
755-
TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXqciac, DecoderTableXqciac16,
756-
"Qualcomm uC Load-Store Address Calculation 16bit");
757-
TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXqcicm, DecoderTableXqcicm16,
758-
"Qualcomm uC Conditional Move 16bit");
759-
TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXqciint, DecoderTableXqciint16,
760-
"Qualcomm uC Interrupts 16bit");
752+
753+
TRY_TO_DECODE_FEATURE_ANY(XqciFeatureGroup, DecoderTableXqci16,
754+
"Qualcomm uC 16bit");
755+
761756
TRY_TO_DECODE_AND_ADD_SP(STI.hasFeature(RISCV::FeatureVendorXwchc),
762757
DecoderTableXwchc16, "WCH QingKe XW");
763758
TRY_TO_DECODE_AND_ADD_SP(true, DecoderTable16,
@@ -780,10 +775,8 @@ DecodeStatus RISCVDisassembler::getInstruction48(MCInst &MI, uint64_t &Size,
780775
for (size_t i = Size; i-- != 0;) {
781776
Insn += (static_cast<uint64_t>(Bytes[i]) << 8 * i);
782777
}
783-
TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXqcilia, DecoderTableXqcilia48,
784-
"Qualcomm uC Large Immediate Arithmetic 48bit");
785-
TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXqcilo, DecoderTableXqcilo48,
786-
"Qualcomm uC Large Offset Load Store 48bit");
778+
TRY_TO_DECODE_FEATURE_ANY(XqciFeatureGroup, DecoderTableXqci48,
779+
"Qualcomm uC 48bit");
787780

788781
return MCDisassembler::Fail;
789782
}

llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,9 @@ class QCIRVInstEI<bits<3> funct3, bits<2> funct2, string opcodestr>
283283
// Instructions
284284
//===----------------------------------------------------------------------===//
285285

286-
let Predicates = [HasVendorXqcicsr, IsRV32], DecoderNamespace = "Xqcicsr" in {
286+
let DecoderNamespace = "Xqci" in {
287+
288+
let Predicates = [HasVendorXqcicsr, IsRV32] in {
287289
let hasSideEffects = 1, mayLoad = 0, mayStore = 0 in {
288290
def QC_CSRRWR : RVInstR<0b1000110, 0b000, OPC_SYSTEM, (outs GPR:$rd),
289291
(ins GPR:$rs1, GPRNoX0:$rs2), "qc.csrrwr",
@@ -293,9 +295,9 @@ let hasSideEffects = 1, mayLoad = 0, mayStore = 0 in {
293295
(ins uimm5:$rs1, GPRNoX0:$rs2), "qc.csrrwri",
294296
"$rd, $rs1, $rs2">;
295297
} // hasSideEffects = 1, mayLoad = 0, mayStore = 0
296-
} // Predicates = [HasVendorXqcicsr, IsRV32], DecoderNamespace = "Xqcicsr"
298+
} // Predicates = [HasVendorXqcicsr, IsRV32]
297299

298-
let Predicates = [HasVendorXqcisls, IsRV32], DecoderNamespace = "Xqcisls" in {
300+
let Predicates = [HasVendorXqcisls, IsRV32] in {
299301
def QC_LRB : QCILoad_ScaleIdx<0b1000, "qc.lrb">;
300302
def QC_LRH : QCILoad_ScaleIdx<0b1001, "qc.lrh">;
301303
def QC_LRW : QCILoad_ScaleIdx<0b1010, "qc.lrw">;
@@ -305,9 +307,9 @@ let Predicates = [HasVendorXqcisls, IsRV32], DecoderNamespace = "Xqcisls" in {
305307
def QC_SRB : QCIStore_ScaleIdx<0b1101, "qc.srb">;
306308
def QC_SRH : QCIStore_ScaleIdx<0b1110, "qc.srh">;
307309
def QC_SRW : QCIStore_ScaleIdx<0b1111, "qc.srw">;
308-
} // Predicates = [HasVendorXqcisls, IsRV32], DecoderNamespace = "Xqcisls"
310+
} // Predicates = [HasVendorXqcisls, IsRV32]
309311

310-
let Predicates = [HasVendorXqcia, IsRV32], DecoderNamespace = "Xqcia" in {
312+
let Predicates = [HasVendorXqcia, IsRV32] in {
311313
let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in {
312314
def QC_SLASAT : QCIRVInstRR<0b01010, GPRNoX0, "qc.slasat">;
313315
def QC_SLLSAT : QCIRVInstRR<0b01100, GPRNoX0, "qc.sllsat">;
@@ -329,9 +331,9 @@ let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in {
329331
def QC_NORMU : QCIRVInstR<0b1000, "qc.normu">;
330332
def QC_NORMEU : QCIRVInstR<0b1001, "qc.normeu">;
331333
} // hasSideEffects = 0, mayLoad = 0, mayStore = 0
332-
} // Predicates = [HasVendorXqcia, IsRV32], DecoderNamespace = "Xqcia"
334+
} // Predicates = [HasVendorXqcia, IsRV32]
333335

334-
let Predicates = [HasVendorXqciac, IsRV32], DecoderNamespace = "Xqciac" in {
336+
let Predicates = [HasVendorXqciac, IsRV32] in {
335337
let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in {
336338
def QC_C_MULIADD : RVInst16CL<0b001, 0b10, (outs GPRC:$rd_wb),
337339
(ins GPRC:$rd, GPRC:$rs1, uimm5:$uimm),
@@ -360,9 +362,9 @@ let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in {
360362
}
361363

362364
} // hasSideEffects = 0, mayLoad = 0, mayStore = 0
363-
} // Predicates = [HasVendorXqciac, IsRV32], DecoderNamespace = "Xqciac"
365+
} // Predicates = [HasVendorXqciac, IsRV32]
364366

365-
let Predicates = [HasVendorXqcics, IsRV32], DecoderNamespace = "Xqcics" in {
367+
let Predicates = [HasVendorXqcics, IsRV32] in {
366368
def QC_SELECTIIEQ : QCISELECTIICC <0b010, "qc.selectiieq">;
367369
def QC_SELECTIINE : QCISELECTIICC <0b011, "qc.selectiine">;
368370
def QC_SELECTIEQ : QCISELECTICC <0b010, "qc.selectieq">;
@@ -371,19 +373,19 @@ let Predicates = [HasVendorXqcics, IsRV32], DecoderNamespace = "Xqcics" in {
371373
def QC_SELECTNEI : QCISELECTCCI <0b011, "qc.selectnei">;
372374
def QC_SELECTIEQI : QCISELECTICCI <0b010, "qc.selectieqi">;
373375
def QC_SELECTINEI : QCISELECTICCI <0b011, "qc.selectinei">;
374-
} // Predicates = [HasVendorXqcics, IsRV32], DecoderNamespace = "Xqcics"
376+
} // Predicates = [HasVendorXqcics, IsRV32]
375377

376-
let Predicates = [HasVendorXqcilsm, IsRV32], DecoderNamespace = "Xqcilsm" in {
378+
let Predicates = [HasVendorXqcilsm, IsRV32] in {
377379
def QC_SWM : QCIStoreMultiple<0b00, GPRNoX0, "qc.swm">;
378380
def QC_SWMI : QCIStoreMultiple<0b01, uimm5nonzero, "qc.swmi">;
379381
def QC_SETWM : QCIStoreMultiple<0b10, GPRNoX0, "qc.setwm">;
380382
def QC_SETWMI : QCIStoreMultiple<0b11, uimm5nonzero, "qc.setwmi">;
381383

382384
def QC_LWM : QCILoadMultiple<0b00, GPRNoX0, "qc.lwm">;
383385
def QC_LWMI : QCILoadMultiple<0b01, uimm5nonzero, "qc.lwmi">;
384-
} // Predicates = [HasVendorXqcilsm, IsRV32], DecoderNamespace = "Xqcilsm"
386+
} // Predicates = [HasVendorXqcilsm, IsRV32]
385387

386-
let Predicates = [HasVendorXqcicli, IsRV32], DecoderNamespace = "Xqcicli" in {
388+
let Predicates = [HasVendorXqcicli, IsRV32] in {
387389
def QC_LIEQ : QCILICC<0b000, 0b01, GPRNoX0, "qc.lieq">;
388390
def QC_LINE : QCILICC<0b001, 0b01, GPRNoX0, "qc.line">;
389391
def QC_LILT : QCILICC<0b100, 0b01, GPRNoX0, "qc.lilt">;
@@ -397,9 +399,9 @@ let Predicates = [HasVendorXqcicli, IsRV32], DecoderNamespace = "Xqcicli" in {
397399
def QC_LIGEI : QCILICC<0b101, 0b11, simm5, "qc.ligei">;
398400
def QC_LILTUI : QCILICC<0b110, 0b11, uimm5, "qc.liltui">;
399401
def QC_LIGEUI : QCILICC<0b111, 0b11, uimm5, "qc.ligeui">;
400-
} // Predicates = [HasVendorXqcicli, IsRV32], DecoderNamespace = "Xqcicli"
402+
} // Predicates = [HasVendorXqcicli, IsRV32]
401403

402-
let Predicates = [HasVendorXqcicm, IsRV32], DecoderNamespace = "Xqcicm" in {
404+
let Predicates = [HasVendorXqcicm, IsRV32] in {
403405
let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in
404406
def QC_C_MVEQZ : RVInst16CL<0b101, 0b10, (outs GPRC:$rd_wb),
405407
(ins GPRC:$rd, GPRC:$rs1),
@@ -423,9 +425,9 @@ let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in
423425
def QC_MVGEI : QCIMVCCI<0b101, "qc.mvgei", simm5>;
424426
def QC_MVLTUI : QCIMVCCI<0b110, "qc.mvltui", uimm5>;
425427
def QC_MVGEUI : QCIMVCCI<0b111, "qc.mvgeui", uimm5>;
426-
} // Predicates = [HasVendorXqcicm, IsRV32], DecoderNamespace = "Xqcicm"
428+
} // Predicates = [HasVendorXqcicm, IsRV32]
427429

428-
let Predicates = [HasVendorXqciint, IsRV32], DecoderNamespace = "Xqciint" in {
430+
let Predicates = [HasVendorXqciint, IsRV32] in {
429431
let hasSideEffects = 1, mayLoad = 0, mayStore = 0 in
430432
def QC_C_DIR : RVInst16CI<0b000, 0b10, (outs GPRNoX0:$rd), (ins),
431433
"qc.c.dir", "$rd"> {
@@ -455,9 +457,9 @@ let Predicates = [HasVendorXqciint, IsRV32], DecoderNamespace = "Xqciint" in {
455457

456458
let mayLoad = 1, mayStore = 1, isReturn = 1, isTerminator = 1 in
457459
def QC_C_MILEAVERET : QCIRVInst16CI_NONE<0b10100, "qc.c.mileaveret">;
458-
} // Predicates = [HasVendorXqciint, IsRV32], DecoderNamespace = "Xqciint"
460+
} // Predicates = [HasVendorXqciint, IsRV32]
459461

460-
let Predicates = [HasVendorXqcilo, IsRV32], DecoderNamespace = "Xqcilo" in {
462+
let Predicates = [HasVendorXqcilo, IsRV32] in {
461463
def QC_E_LB : QCIRVInstEILoad<0b101, 0b00, "qc.e.lb">;
462464
def QC_E_LBU : QCIRVInstEILoad<0b101, 0b01, "qc.e.lbu">;
463465
def QC_E_LH : QCIRVInstEILoad<0b101, 0b10, "qc.e.lh">;
@@ -467,9 +469,9 @@ let Predicates = [HasVendorXqcilo, IsRV32], DecoderNamespace = "Xqcilo" in {
467469
def QC_E_SB : QCIRVInstESStore<0b110, 0b01, "qc.e.sb">;
468470
def QC_E_SH : QCIRVInstESStore<0b110, 0b10, "qc.e.sh">;
469471
def QC_E_SW : QCIRVInstESStore<0b110, 0b11, "qc.e.sw">;
470-
} // Predicates = [HasVendorXqcilo, IsRV32], DecoderNamespace = "Xqcilo"
472+
} // Predicates = [HasVendorXqcilo, IsRV32]
471473

472-
let Predicates = [HasVendorXqcilia, IsRV32], DecoderNamespace = "Xqcilia" in {
474+
let Predicates = [HasVendorXqcilia, IsRV32] in {
473475
let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in {
474476
def QC_E_XORAI : QCIRVInstEAI<0b001, 0b0, "qc.e.xorai">;
475477
def QC_E_ORAI : QCIRVInstEAI<0b001, 0b1, "qc.e.orai" >;
@@ -481,7 +483,9 @@ let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in {
481483
def QC_E_ADDI : QCIRVInstEI<0b011, 0b10, "qc.e.addi">;
482484
def QC_E_ANDI : QCIRVInstEI<0b011, 0b11, "qc.e.andi">;
483485
} // hasSideEffects = 0, mayLoad = 0, mayStore = 0
484-
} // Predicates = [HasVendorXqcilia, IsRV32], DecoderNamespace = "Xqcilia"
486+
} // Predicates = [HasVendorXqcilia, IsRV32]
487+
488+
} // DecoderNamespace = "Xqci"
485489

486490
//===----------------------------------------------------------------------===//
487491
// Aliases

0 commit comments

Comments
 (0)