Skip to content

Commit c2022dd

Browse files
author
Yonghong Song
committed
[BPF] Ensure GotoX only supported at CPU V4
This is temporary and it makes easy to run bpf selftests. Once kernel side is ready, we will implement CPU V5 which will support jump tables.
1 parent db20e46 commit c2022dd

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

llvm/lib/Target/BPF/BPFISelLowering.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,14 @@ BPFTargetLowering::BPFTargetLowering(const TargetMachine &TM,
7474
setOperationAction(ISD::BR_JT, MVT::Other, Expand);
7575
setOperationAction(ISD::BRCOND, MVT::Other, Expand);
7676

77+
if (!STI.hasGotox())
78+
setOperationAction(ISD::BRIND, MVT::Other, Expand);
79+
7780
setOperationAction(ISD::TRAP, MVT::Other, Custom);
7881

7982
setOperationAction({ISD::GlobalAddress, ISD::ConstantPool}, MVT::i64, Custom);
80-
setOperationAction({ISD::JumpTable, ISD::BlockAddress}, MVT::i64, Custom);
83+
if (STI.hasGotox())
84+
setOperationAction({ISD::JumpTable, ISD::BlockAddress}, MVT::i64, Custom);
8185

8286
setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i64, Custom);
8387
setOperationAction(ISD::STACKSAVE, MVT::Other, Expand);

llvm/lib/Target/BPF/BPFInstrInfo.td

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def BPFNoMovsx : Predicate<"!Subtarget->hasMovsx()">;
6161
def BPFNoBswap : Predicate<"!Subtarget->hasBswap()">;
6262
def BPFHasStoreImm : Predicate<"Subtarget->hasStoreImm()">;
6363
def BPFHasLoadAcqStoreRel : Predicate<"Subtarget->hasLoadAcqStoreRel()">;
64+
def BPFHasGotox : Predicate<"Subtarget->hasGotox()">;
6465

6566
class ImmediateAsmOperand<string name> : AsmOperandClass {
6667
let Name = name;
@@ -294,8 +295,10 @@ defm JSLE : J<BPF_JSLE, "s<=", BPF_CC_LE, BPF_CC_LE_32>;
294295
defm JSET : J<BPF_JSET, "&", NoCond, NoCond>;
295296
def JCOND : JMP_JCOND<BPF_JCOND, "may_goto", []>;
296297

297-
let isIndirectBranch = 1, isBarrier = 1 in {
298-
def JX : JMP_IND<BPF_JA, "gotox", [(brind i64:$dst)]>;
298+
let Predicates = [BPFHasGotox] in {
299+
let isIndirectBranch = 1, isBarrier = 1 in {
300+
def JX : JMP_IND<BPF_JA, "gotox", [(brind i64:$dst)]>;
301+
}
299302
}
300303
}
301304

llvm/lib/Target/BPF/BPFSubtarget.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ static cl::opt<bool>
4343
static cl::opt<bool> Disable_load_acq_store_rel(
4444
"disable-load-acq-store-rel", cl::Hidden, cl::init(false),
4545
cl::desc("Disable load-acquire and store-release insns"));
46+
static cl::opt<bool> Disable_gotox("disable-gotox", cl::Hidden, cl::init(false),
47+
cl::desc("Disable gotox insn"));
4648

4749
void BPFSubtarget::anchor() {}
4850

@@ -66,6 +68,7 @@ void BPFSubtarget::initializeEnvironment() {
6668
HasGotol = false;
6769
HasStoreImm = false;
6870
HasLoadAcqStoreRel = false;
71+
HasGotox = false;
6972
}
7073

7174
void BPFSubtarget::initSubtargetFeatures(StringRef CPU, StringRef FS) {
@@ -96,6 +99,7 @@ void BPFSubtarget::initSubtargetFeatures(StringRef CPU, StringRef FS) {
9699
HasGotol = !Disable_gotol;
97100
HasStoreImm = !Disable_StoreImm;
98101
HasLoadAcqStoreRel = !Disable_load_acq_store_rel;
102+
HasGotox = !Disable_gotox;
99103
return;
100104
}
101105
}

llvm/lib/Target/BPF/BPFSubtarget.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class BPFSubtarget : public BPFGenSubtargetInfo {
6565

6666
// whether cpu v4 insns are enabled.
6767
bool HasLdsx, HasMovsx, HasBswap, HasSdivSmod, HasGotol, HasStoreImm,
68-
HasLoadAcqStoreRel;
68+
HasLoadAcqStoreRel, HasGotox;
6969

7070
std::unique_ptr<CallLowering> CallLoweringInfo;
7171
std::unique_ptr<InstructionSelector> InstSelector;
@@ -94,6 +94,7 @@ class BPFSubtarget : public BPFGenSubtargetInfo {
9494
bool hasGotol() const { return HasGotol; }
9595
bool hasStoreImm() const { return HasStoreImm; }
9696
bool hasLoadAcqStoreRel() const { return HasLoadAcqStoreRel; }
97+
bool hasGotox() const { return HasGotox; }
9798

9899
bool isLittleEndian() const { return IsLittleEndian; }
99100

0 commit comments

Comments
 (0)