@@ -36,6 +36,10 @@ static cl::opt<bool> BPFExpandMemcpyInOrder("bpf-expand-memcpy-in-order",
36
36
cl::Hidden, cl::init(false ),
37
37
cl::desc(" Expand memcpy into load/store pairs in order" ));
38
38
39
+ static cl::opt<unsigned > BPFMinimumJumpTableEntries (
40
+ " bpf-min-jump-table-entries" , cl::init(4 ), cl::Hidden,
41
+ cl::desc(" Set minimum number of entries to use a jump table on BPF" ));
42
+
39
43
static void fail (const SDLoc &DL, SelectionDAG &DAG, const Twine &Msg,
40
44
SDValue Val = {}) {
41
45
std::string Str;
@@ -65,10 +69,11 @@ BPFTargetLowering::BPFTargetLowering(const TargetMachine &TM,
65
69
66
70
setOperationAction (ISD::BR_CC, MVT::i64 , Custom);
67
71
setOperationAction (ISD::BR_JT, MVT::Other, Expand);
68
- setOperationAction (ISD::BRIND, MVT::Other, Expand);
69
72
setOperationAction (ISD::BRCOND, MVT::Other, Expand);
70
73
71
- setOperationAction ({ISD::GlobalAddress, ISD::ConstantPool}, MVT::i64 , Custom);
74
+ setOperationAction ({ISD::GlobalAddress, ISD::ConstantPool, ISD::JumpTable,
75
+ ISD::BlockAddress},
76
+ MVT::i64 , Custom);
72
77
73
78
setOperationAction (ISD::DYNAMIC_STACKALLOC, MVT::i64 , Custom);
74
79
setOperationAction (ISD::STACKSAVE, MVT::Other, Expand);
@@ -155,6 +160,7 @@ BPFTargetLowering::BPFTargetLowering(const TargetMachine &TM,
155
160
156
161
setBooleanContents (ZeroOrOneBooleanContent);
157
162
setMaxAtomicSizeInBitsSupported (64 );
163
+ setMinimumJumpTableEntries (BPFMinimumJumpTableEntries);
158
164
159
165
// Function alignments
160
166
setMinFunctionAlignment (Align (8 ));
@@ -312,10 +318,14 @@ SDValue BPFTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const {
312
318
report_fatal_error (" unimplemented opcode: " + Twine (Op.getOpcode ()));
313
319
case ISD::BR_CC:
314
320
return LowerBR_CC (Op, DAG);
321
+ case ISD::JumpTable:
322
+ return LowerJumpTable (Op, DAG);
315
323
case ISD::GlobalAddress:
316
324
return LowerGlobalAddress (Op, DAG);
317
325
case ISD::ConstantPool:
318
326
return LowerConstantPool (Op, DAG);
327
+ case ISD::BlockAddress:
328
+ return LowerBlockAddress (Op, DAG);
319
329
case ISD::SELECT_CC:
320
330
return LowerSELECT_CC (Op, DAG);
321
331
case ISD::SDIV:
@@ -726,6 +736,11 @@ SDValue BPFTargetLowering::LowerATOMIC_LOAD_STORE(SDValue Op,
726
736
return Op;
727
737
}
728
738
739
+ SDValue BPFTargetLowering::LowerJumpTable (SDValue Op, SelectionDAG &DAG) const {
740
+ JumpTableSDNode *N = cast<JumpTableSDNode>(Op);
741
+ return getAddr (N, DAG);
742
+ }
743
+
729
744
const char *BPFTargetLowering::getTargetNodeName (unsigned Opcode) const {
730
745
switch ((BPFISD::NodeType)Opcode) {
731
746
case BPFISD::FIRST_NUMBER:
@@ -757,6 +772,17 @@ static SDValue getTargetNode(ConstantPoolSDNode *N, const SDLoc &DL, EVT Ty,
757
772
N->getOffset (), Flags);
758
773
}
759
774
775
+ static SDValue getTargetNode (BlockAddressSDNode *N, const SDLoc &DL, EVT Ty,
776
+ SelectionDAG &DAG, unsigned Flags) {
777
+ return DAG.getTargetBlockAddress (N->getBlockAddress (), Ty, N->getOffset (),
778
+ Flags);
779
+ }
780
+
781
+ static SDValue getTargetNode (JumpTableSDNode *N, const SDLoc &DL, EVT Ty,
782
+ SelectionDAG &DAG, unsigned Flags) {
783
+ return DAG.getTargetJumpTable (N->getIndex (), Ty, Flags);
784
+ }
785
+
760
786
template <class NodeTy >
761
787
SDValue BPFTargetLowering::getAddr (NodeTy *N, SelectionDAG &DAG,
762
788
unsigned Flags) const {
@@ -783,6 +809,12 @@ SDValue BPFTargetLowering::LowerConstantPool(SDValue Op,
783
809
return getAddr (N, DAG);
784
810
}
785
811
812
+ SDValue BPFTargetLowering::LowerBlockAddress (SDValue Op,
813
+ SelectionDAG &DAG) const {
814
+ BlockAddressSDNode *N = cast<BlockAddressSDNode>(Op);
815
+ return getAddr (N, DAG);
816
+ }
817
+
786
818
unsigned
787
819
BPFTargetLowering::EmitSubregExt (MachineInstr &MI, MachineBasicBlock *BB,
788
820
unsigned Reg, bool isSigned) const {
0 commit comments