Skip to content

Commit b406f0c

Browse files
committed
[BPF] Refactor {LOAD,STORE}{,32} classes (NFC)
We will need different AsmString formats for load-acquire and store-release instructions. To make that easier, refactor {LOAD,STORE}{,32} classes to take AsmString as an argument directly. Add a BPFModeModifer parameter to STORE{,32} for similar reasons. No functional changes intended.
1 parent 425bead commit b406f0c

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

llvm/lib/Target/BPF/BPFInstrInfo.td

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -497,12 +497,11 @@ def LD_pseudo
497497
}
498498

499499
// STORE instructions
500-
class STORE<BPFWidthModifer SizeOp, string OpcodeStr, list<dag> Pattern>
501-
: TYPE_LD_ST<BPF_MEM.Value, SizeOp.Value,
500+
class STORE<BPFWidthModifer SizeOp, BPFModeModifer ModOp, string AsmString, list<dag> Pattern>
501+
: TYPE_LD_ST<ModOp.Value, SizeOp.Value,
502502
(outs),
503503
(ins GPR:$src, MEMri:$addr),
504-
"*("#OpcodeStr#" *)($addr) = $src",
505-
Pattern> {
504+
AsmString, Pattern> {
506505
bits<4> src;
507506
bits<20> addr;
508507

@@ -513,7 +512,7 @@ class STORE<BPFWidthModifer SizeOp, string OpcodeStr, list<dag> Pattern>
513512
}
514513

515514
class STOREi64<BPFWidthModifer Opc, string OpcodeStr, PatFrag OpNode>
516-
: STORE<Opc, OpcodeStr, [(OpNode GPR:$src, ADDRri:$addr)]>;
515+
: STORE<Opc, BPF_MEM, "*("#OpcodeStr#" *)($addr) = $src", [(OpNode GPR:$src, ADDRri:$addr)]>;
517516

518517
let Predicates = [BPFNoALU32] in {
519518
def STW : STOREi64<BPF_W, "u32", truncstorei32>;
@@ -567,12 +566,11 @@ let Predicates = [BPFHasALU32, BPFHasStoreImm] in {
567566
}
568567

569568
// LOAD instructions
570-
class LOAD<BPFWidthModifer SizeOp, BPFModeModifer ModOp, string OpcodeStr, list<dag> Pattern>
569+
class LOAD<BPFWidthModifer SizeOp, BPFModeModifer ModOp, string AsmString, list<dag> Pattern>
571570
: TYPE_LD_ST<ModOp.Value, SizeOp.Value,
572571
(outs GPR:$dst),
573572
(ins MEMri:$addr),
574-
"$dst = *("#OpcodeStr#" *)($addr)",
575-
Pattern> {
573+
AsmString, Pattern> {
576574
bits<4> dst;
577575
bits<20> addr;
578576

@@ -583,7 +581,8 @@ class LOAD<BPFWidthModifer SizeOp, BPFModeModifer ModOp, string OpcodeStr, list<
583581
}
584582

585583
class LOADi64<BPFWidthModifer SizeOp, BPFModeModifer ModOp, string OpcodeStr, PatFrag OpNode>
586-
: LOAD<SizeOp, ModOp, OpcodeStr, [(set i64:$dst, (OpNode ADDRri:$addr))]>;
584+
: LOAD<SizeOp, ModOp, "$dst = *("#OpcodeStr#" *)($addr)",
585+
[(set i64:$dst, (OpNode ADDRri:$addr))]>;
587586

588587
let isCodeGenOnly = 1 in {
589588
class CORE_LD<RegisterClass RegClass, string Sz>
@@ -1163,12 +1162,11 @@ def : Pat<(i32 (trunc GPR:$src)),
11631162
def : Pat<(i64 (anyext GPR32:$src)),
11641163
(INSERT_SUBREG (i64 (IMPLICIT_DEF)), GPR32:$src, sub_32)>;
11651164

1166-
class STORE32<BPFWidthModifer SizeOp, string OpcodeStr, list<dag> Pattern>
1167-
: TYPE_LD_ST<BPF_MEM.Value, SizeOp.Value,
1165+
class STORE32<BPFWidthModifer SizeOp, BPFModeModifer ModOp, string AsmString, list<dag> Pattern>
1166+
: TYPE_LD_ST<ModOp.Value, SizeOp.Value,
11681167
(outs),
11691168
(ins GPR32:$src, MEMri:$addr),
1170-
"*("#OpcodeStr#" *)($addr) = $src",
1171-
Pattern> {
1169+
AsmString, Pattern> {
11721170
bits<4> src;
11731171
bits<20> addr;
11741172

@@ -1179,20 +1177,20 @@ class STORE32<BPFWidthModifer SizeOp, string OpcodeStr, list<dag> Pattern>
11791177
}
11801178

11811179
class STOREi32<BPFWidthModifer Opc, string OpcodeStr, PatFrag OpNode>
1182-
: STORE32<Opc, OpcodeStr, [(OpNode GPR32:$src, ADDRri:$addr)]>;
1180+
: STORE32<Opc, BPF_MEM, "*("#OpcodeStr#" *)($addr) = $src",
1181+
[(OpNode GPR32:$src, ADDRri:$addr)]>;
11831182

11841183
let Predicates = [BPFHasALU32], DecoderNamespace = "BPFALU32" in {
11851184
def STW32 : STOREi32<BPF_W, "u32", store>;
11861185
def STH32 : STOREi32<BPF_H, "u16", truncstorei16>;
11871186
def STB32 : STOREi32<BPF_B, "u8", truncstorei8>;
11881187
}
11891188

1190-
class LOAD32<BPFWidthModifer SizeOp, BPFModeModifer ModOp, string OpcodeStr, list<dag> Pattern>
1189+
class LOAD32<BPFWidthModifer SizeOp, BPFModeModifer ModOp, string AsmString, list<dag> Pattern>
11911190
: TYPE_LD_ST<ModOp.Value, SizeOp.Value,
11921191
(outs GPR32:$dst),
11931192
(ins MEMri:$addr),
1194-
"$dst = *("#OpcodeStr#" *)($addr)",
1195-
Pattern> {
1193+
AsmString, Pattern> {
11961194
bits<4> dst;
11971195
bits<20> addr;
11981196

@@ -1203,7 +1201,8 @@ class LOAD32<BPFWidthModifer SizeOp, BPFModeModifer ModOp, string OpcodeStr, lis
12031201
}
12041202

12051203
class LOADi32<BPFWidthModifer SizeOp, BPFModeModifer ModOp, string OpcodeStr, PatFrag OpNode>
1206-
: LOAD32<SizeOp, ModOp, OpcodeStr, [(set i32:$dst, (OpNode ADDRri:$addr))]>;
1204+
: LOAD32<SizeOp, ModOp, "$dst = *("#OpcodeStr#" *)($addr)",
1205+
[(set i32:$dst, (OpNode ADDRri:$addr))]>;
12071206

12081207
let Predicates = [BPFHasALU32], DecoderNamespace = "BPFALU32" in {
12091208
def LDW32 : LOADi32<BPF_W, BPF_MEM, "u32", load>;

0 commit comments

Comments
 (0)