@@ -188,6 +188,20 @@ class CheriStore_r<bits<5> op, string opcodestr, RegisterClass rs2Class,
188
188
(ins rs2Class:$rs2, rs1Operand:$rs1),
189
189
opcodestr, "$rs2, $rs1">;
190
190
191
+ multiclass ExplicitCheriStore_r<bits<5> op, string opcodestr, RegisterClass rs2Class,
192
+ RegisterOperand rs1Operand,
193
+ list<Predicate> ExtraPreds = []> {
194
+ let Predicates = !listconcat([HasXCheriAll], ExtraPreds) in
195
+ def NAME: CheriStore_r<op, opcodestr, rs2Class, rs1Operand>;
196
+ // Adding a mode switch either side of the load expands to 3 instructions.
197
+ // The predicate here is HasCheriCommon, since in the xcheri case we can
198
+ // just expand this to an explicit mode load.
199
+ let hasSideEffects = 0, mayLoad = 0, mayStore = 1, Size = 12,
200
+ Predicates = !listconcat([HasCheriCommon], ExtraPreds) in
201
+ def Pseudo_#NAME : Pseudo<(outs), (ins rs2Class:$rs2, rs1Operand:$rs1), [],
202
+ "pseudo_"#opcodestr, "$rs2, $rs1">;
203
+ }
204
+
191
205
let hasSideEffects = 0, mayLoad = 0, mayStore = 1, Constraints = "$rd = $rs2" in
192
206
class CheriStoreCond_r<bits<5> op, string opcodestr, RegisterClass rs2Class,
193
207
RegisterOperand rs1Operand>
@@ -574,22 +588,13 @@ defm LC_64_DDC : ExplicitCheriLoad_r<0b00011, "lc.ddc", GPCR, GPRMemZeroOffset,
574
588
575
589
defm LC_128_DDC : ExplicitCheriLoad_r<0b10111, "lc.ddc", GPCR, GPRMemZeroOffset, [IsRV64]>;
576
590
577
- let Predicates = [HasXCheriAll] in {
578
- def SB_DDC : CheriStore_r<0b00000, "sb.ddc", GPR, GPRMemZeroOffset>;
579
- def SH_DDC : CheriStore_r<0b00001, "sh.ddc", GPR, GPRMemZeroOffset>;
580
- def SW_DDC : CheriStore_r<0b00010, "sw.ddc", GPR, GPRMemZeroOffset>;
581
- }
582
-
583
- let Predicates = [HasXCheriAll, IsRV64] in {
584
- def SD_DDC : CheriStore_r<0b00011, "sd.ddc", GPR, GPRMemZeroOffset>;
585
- }
586
-
587
- let DecoderNamespace = "RISCV32Only_",
588
- Predicates = [HasXCheriAll, IsRV32] in
589
- def SC_DDC_64 : CheriStore_r<0b00011, "sc.ddc", GPCR, GPRMemZeroOffset>;
590
-
591
- let Predicates = [HasXCheriAll, IsRV64] in
592
- def SC_DDC_128 : CheriStore_r<0b00100, "sc.ddc", GPCR, GPRMemZeroOffset>;
591
+ defm SB_DDC : ExplicitCheriStore_r<0b00000, "sb.ddc", GPR, GPRMemZeroOffset>;
592
+ defm SH_DDC : ExplicitCheriStore_r<0b00001, "sh.ddc", GPR, GPRMemZeroOffset>;
593
+ defm SW_DDC : ExplicitCheriStore_r<0b00010, "sw.ddc", GPR, GPRMemZeroOffset>;
594
+ defm SD_DDC : ExplicitCheriStore_r<0b00011, "sd.ddc", GPR, GPRMemZeroOffset, [IsRV64]>;
595
+ let DecoderNamespace = "RISCV32Only_" in
596
+ defm SC_64_DDC : ExplicitCheriStore_r<0b00011, "sc.ddc", GPCR, GPRMemZeroOffset, [IsRV32]>;
597
+ defm SC_128_DDC : ExplicitCheriStore_r<0b00100, "sc.ddc", GPCR, GPRMemZeroOffset, [IsRV64]>;
593
598
594
599
defm LB_CAP : ExplicitCheriLoad_r<0b01000, "lb.cap", GPR, GPCRMemZeroOffset>;
595
600
defm LH_CAP : ExplicitCheriLoad_r<0b01001, "lh.cap", GPR, GPCRMemZeroOffset>;
@@ -605,22 +610,13 @@ defm LC_64_CAP : ExplicitCheriLoad_r<0b01011, "lc.cap", GPCR, GPCRMemZeroOffset
605
610
606
611
defm LC_128_CAP : ExplicitCheriLoad_r<0b11111, "lc.cap", GPCR, GPCRMemZeroOffset, [IsRV64]>;
607
612
608
- let Predicates = [HasXCheriAll] in {
609
- def SB_CAP : CheriStore_r<0b01000, "sb.cap", GPR, GPCRMemZeroOffset>;
610
- def SH_CAP : CheriStore_r<0b01001, "sh.cap", GPR, GPCRMemZeroOffset>;
611
- def SW_CAP : CheriStore_r<0b01010, "sw.cap", GPR, GPCRMemZeroOffset>;
612
- }
613
-
614
- let Predicates = [HasXCheriAll, IsRV64] in {
615
- def SD_CAP : CheriStore_r<0b01011, "sd.cap", GPR, GPCRMemZeroOffset>;
616
- }
617
-
618
- let DecoderNamespace = "RISCV32Only_",
619
- Predicates = [HasXCheriAll, IsRV32] in
620
- def SC_CAP_64 : CheriStore_r<0b01011, "sc.cap", GPCR, GPCRMemZeroOffset>;
621
-
622
- let Predicates = [HasXCheriAll, IsRV64] in
623
- def SC_CAP_128 : CheriStore_r<0b01100, "sc.cap", GPCR, GPCRMemZeroOffset>;
613
+ defm SB_CAP : ExplicitCheriStore_r<0b01000, "sb.cap", GPR, GPCRMemZeroOffset>;
614
+ defm SH_CAP : ExplicitCheriStore_r<0b01001, "sh.cap", GPR, GPCRMemZeroOffset>;
615
+ defm SW_CAP : ExplicitCheriStore_r<0b01010, "sw.cap", GPR, GPCRMemZeroOffset>;
616
+ defm SD_CAP : ExplicitCheriStore_r<0b01011, "sd.cap", GPR, GPCRMemZeroOffset, [IsRV64]>;
617
+ let DecoderNamespace = "RISCV32Only_" in
618
+ defm SC_64_CAP : ExplicitCheriStore_r<0b01011, "sc.cap", GPCR, GPCRMemZeroOffset, [IsRV32]>;
619
+ defm SC_128_CAP : ExplicitCheriStore_r<0b01100, "sc.cap", GPCR, GPCRMemZeroOffset, [IsRV64]>;
624
620
625
621
let Predicates = [HasXCheriAll, HasStdExtA] in {
626
622
def LR_B_DDC : CheriLoad_r<0b10000, "lr.b.ddc", GPR, GPRMemZeroOffset>;
@@ -1525,7 +1521,8 @@ multiclass CheriExplicitStPat<PatFrag StoreOp, RVInst Inst,
1525
1521
RegisterClass StTy, RegisterClass AddrTy,
1526
1522
ValueType StoreVt = XLenVT,
1527
1523
ValueType AddrVt = XLenVT> {
1528
- def : Pat<(StoreOp (StoreVt StTy:$rs2), (AddrVt AddrTy:$rs1)), (Inst StTy:$rs2, AddrTy:$rs1)>;
1524
+ def : Pat<(StoreOp (StoreVt StTy:$rs2), (AddrVt AddrTy:$rs1)),
1525
+ (!cast<Pseudo>("Pseudo_"#Inst) StTy:$rs2, AddrTy:$rs1)>;
1529
1526
}
1530
1527
1531
1528
/// DDC-relative loads
@@ -1565,33 +1562,33 @@ def : Pat<(load (XLenVT GPR:$rs1)), (FMV_D_X (Pseudo_LD_DDC (XLenVT GPR:$rs1)))>
1565
1562
1566
1563
/// DDC-relative stores
1567
1564
1568
- let Predicates = [HasXCheriAll , IsCapMode] in {
1565
+ let Predicates = [HasCheriCommon , IsCapMode] in {
1569
1566
defm : CheriExplicitStPat<truncstorei8, SB_DDC, GPR, GPR>;
1570
1567
defm : CheriExplicitStPat<truncstorei16, SH_DDC, GPR, GPR>;
1571
1568
}
1572
1569
1573
- let Predicates = [HasXCheriAll , IsCapMode, IsRV32] in {
1570
+ let Predicates = [HasCheriCommon , IsCapMode, IsRV32] in {
1574
1571
defm : CheriExplicitStPat<store, SW_DDC, GPR, GPR>;
1575
- defm : CheriExplicitStPat<store, SC_DDC_64 , GPCR, GPR, CLenVT, XLenVT>;
1572
+ defm : CheriExplicitStPat<store, SC_64_DDC , GPCR, GPR, CLenVT, XLenVT>;
1576
1573
}
1577
1574
1578
- let Predicates = [HasXCheriAll , IsCapMode, IsRV64] in {
1575
+ let Predicates = [HasCheriCommon , IsCapMode, IsRV64] in {
1579
1576
defm : CheriExplicitStPat<truncstorei32, SW_DDC, GPR, GPR>;
1580
1577
defm : CheriExplicitStPat<store, SD_DDC, GPR, GPR>;
1581
- defm : CheriExplicitStPat<store, SC_DDC_128 , GPCR, GPR, CLenVT, XLenVT>;
1578
+ defm : CheriExplicitStPat<store, SC_128_DDC , GPCR, GPR, CLenVT, XLenVT>;
1582
1579
}
1583
1580
1584
- let Predicates = [HasXCheriAll , IsCapMode, HasStdExtF] in
1581
+ let Predicates = [HasCheriCommon , IsCapMode, HasStdExtF] in
1585
1582
def : Pat<(store FPR32:$rs2, (XLenVT GPR:$rs1)),
1586
- (SW_DDC (FMV_X_W FPR32:$rs2), (XLenVT GPR:$rs1))>;
1583
+ (Pseudo_SW_DDC (FMV_X_W FPR32:$rs2), (XLenVT GPR:$rs1))>;
1587
1584
1588
- let Predicates = [HasXCheriAll , IsCapMode, HasStdExtD, IsRV32] in
1585
+ let Predicates = [HasCheriCommon , IsCapMode, HasStdExtD, IsRV32] in
1589
1586
def : Pat<(store FPR64:$rs2, (XLenVT GPR:$rs1)),
1590
1587
(KILL (SplitStoreF64Pseudo FPR64:$rs2, (XLenVT GPR:$rs1)))>;
1591
1588
1592
- let Predicates = [HasXCheriAll , IsCapMode, HasStdExtD, IsRV64] in
1589
+ let Predicates = [HasCheriCommon , IsCapMode, HasStdExtD, IsRV64] in
1593
1590
def : Pat<(store FPR64:$rs2, (XLenVT GPR:$rs1)),
1594
- (SD_DDC (FMV_X_D FPR64:$rs2), (XLenVT GPR:$rs1))>;
1591
+ (Pseudo_SD_DDC (FMV_X_D FPR64:$rs2), (XLenVT GPR:$rs1))>;
1595
1592
1596
1593
/// Capability loads
1597
1594
@@ -1630,33 +1627,33 @@ def : Pat<(load GPCR:$rs1), (FMV_D_X (Pseudo_LD_CAP GPCR:$rs1))>;
1630
1627
1631
1628
/// Capability stores
1632
1629
1633
- let Predicates = [HasXCheriAll , NotCapMode] in {
1630
+ let Predicates = [HasCheriCommon , NotCapMode] in {
1634
1631
defm : CheriExplicitStPat<truncstorei8, SB_CAP, GPR, GPCR, XLenVT, CLenVT>;
1635
1632
defm : CheriExplicitStPat<truncstorei16, SH_CAP, GPR, GPCR, XLenVT, CLenVT>;
1636
1633
}
1637
1634
1638
- let Predicates = [HasXCheriAll , NotCapMode, IsRV32] in {
1635
+ let Predicates = [HasCheriCommon , NotCapMode, IsRV32] in {
1639
1636
defm : CheriExplicitStPat<store, SW_CAP, GPR, GPCR, XLenVT, CLenVT>;
1640
- defm : CheriExplicitStPat<store, SC_CAP_64 , GPCR, GPCR, CLenVT, CLenVT>;
1637
+ defm : CheriExplicitStPat<store, SC_64_CAP , GPCR, GPCR, CLenVT, CLenVT>;
1641
1638
}
1642
1639
1643
- let Predicates = [HasXCheriAll , NotCapMode, IsRV64] in {
1640
+ let Predicates = [HasCheriCommon , NotCapMode, IsRV64] in {
1644
1641
defm : CheriExplicitStPat<truncstorei32, SW_CAP, GPR, GPCR, XLenVT, CLenVT>;
1645
1642
defm : CheriExplicitStPat<store, SD_CAP, GPR, GPCR, XLenVT, CLenVT>;
1646
- defm : CheriExplicitStPat<store, SC_CAP_128 , GPCR, GPCR, CLenVT, CLenVT>;
1643
+ defm : CheriExplicitStPat<store, SC_128_CAP , GPCR, GPCR, CLenVT, CLenVT>;
1647
1644
}
1648
1645
1649
- let Predicates = [HasXCheriAll , NotCapMode, HasStdExtF] in
1646
+ let Predicates = [HasCheriCommon , NotCapMode, HasStdExtF] in
1650
1647
def : Pat<(store FPR32:$rs2, GPCR:$rs1),
1651
- (SW_CAP (FMV_X_W FPR32:$rs2), GPCR:$rs1)>;
1648
+ (Pseudo_SW_CAP (FMV_X_W FPR32:$rs2), GPCR:$rs1)>;
1652
1649
1653
- let Predicates = [HasXCheriAll , NotCapMode, HasStdExtD, IsRV32] in
1650
+ let Predicates = [HasCheriCommon , NotCapMode, HasStdExtD, IsRV32] in
1654
1651
def : Pat<(store FPR64:$rs2, GPCR:$rs1),
1655
1652
(KILL (CheriSplitStoreF64Pseudo FPR64:$rs2, GPCR:$rs1))>;
1656
1653
1657
- let Predicates = [HasXCheriAll , NotCapMode, HasStdExtD, IsRV64] in
1654
+ let Predicates = [HasCheriCommon , NotCapMode, HasStdExtD, IsRV64] in
1658
1655
def : Pat<(store FPR64:$rs2, GPCR:$rs1),
1659
- (SD_CAP (FMV_X_D FPR64:$rs2), GPCR:$rs1)>;
1656
+ (Pseudo_SD_CAP (FMV_X_D FPR64:$rs2), GPCR:$rs1)>;
1660
1657
1661
1658
/// Non-Capability Mode Instructions
1662
1659
0 commit comments