Skip to content

Commit 9aec188

Browse files
eddyz87Yonghong Song
authored andcommitted
[BPF] generate gotox only for cpuv4
Coincidentally this fixes two test failures: - LLVM :: CodeGen/BPF/CORE/offset-reloc-fieldinfo-2-bpfeb.ll - LLVM :: CodeGen/BPF/CORE/offset-reloc-fieldinfo-2.ll These tests invoke llc with -mcpuv1 and have a switch statement in the IR. Both tests failed with assertion in SelectionDAGLegalize::LegalizeOp(): for (const SDValue &Op : Node->op_values()) assert((TLI.getTypeAction(*DAG.getContext(), Op.getValueType()) == TargetLowering::TypeLegal || Op.getOpcode() == ISD::TargetConstant || Op.getOpcode() == ISD::Register) && "Unexpected illegal type!"); At the moment of the failure: Op.getOpcode() == BPFISD::BPF_BR_JT The error happened because one of the BPFBrJt parameters has i32 type: def SDT_BPFBrJt : SDTypeProfile<0, 2, [SDTCisVT<0, i32>, // jump table SDTCisVT<1, i64>]>; // index def BPFBrJt : SDNode<"BPFISD::BPF_BR_JT", SDT_BPFBrJt, [SDNPHasChain]>;
1 parent a6fecc9 commit 9aec188

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

llvm/lib/Target/BPF/BPFISelLowering.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,10 @@ BPFTargetLowering::BPFTargetLowering(const TargetMachine &TM,
7272
setStackPointerRegisterToSaveRestore(BPF::R11);
7373

7474
setOperationAction(ISD::BR_CC, MVT::i64, Custom);
75-
setOperationAction(ISD::BR_JT, MVT::Other, Custom);
7675
setOperationAction(ISD::BRCOND, MVT::Other, Expand);
76+
LegalizeAction IndirectBrAction = STI.hasGotox() ? Custom : Expand;
77+
setOperationAction(ISD::BR_JT, MVT::Other, IndirectBrAction);
78+
setOperationAction(ISD::BRIND, MVT::Other, IndirectBrAction);
7779

7880
setOperationAction(ISD::TRAP, MVT::Other, Custom);
7981

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)