@@ -36,6 +36,10 @@ static cl::opt<bool> BPFExpandMemcpyInOrder("bpf-expand-memcpy-in-order",
3636 cl::Hidden, cl::init(false ),
3737 cl::desc(" Expand memcpy into load/store pairs in order" ));
3838
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+
3943static void fail (const SDLoc &DL, SelectionDAG &DAG, const Twine &Msg,
4044 SDValue Val = {}) {
4145 std::string Str;
@@ -65,10 +69,11 @@ BPFTargetLowering::BPFTargetLowering(const TargetMachine &TM,
6569
6670 setOperationAction (ISD::BR_CC, MVT::i64 , Custom);
6771 setOperationAction (ISD::BR_JT, MVT::Other, Expand);
68- setOperationAction (ISD::BRIND, MVT::Other, Expand);
6972 setOperationAction (ISD::BRCOND, MVT::Other, Expand);
7073
71- setOperationAction ({ISD::GlobalAddress, ISD::ConstantPool}, MVT::i64 , Custom);
74+ setOperationAction ({ISD::GlobalAddress, ISD::ConstantPool, ISD::JumpTable,
75+ ISD::BlockAddress},
76+ MVT::i64 , Custom);
7277
7378 setOperationAction (ISD::DYNAMIC_STACKALLOC, MVT::i64 , Custom);
7479 setOperationAction (ISD::STACKSAVE, MVT::Other, Expand);
@@ -155,6 +160,7 @@ BPFTargetLowering::BPFTargetLowering(const TargetMachine &TM,
155160
156161 setBooleanContents (ZeroOrOneBooleanContent);
157162 setMaxAtomicSizeInBitsSupported (64 );
163+ setMinimumJumpTableEntries (BPFMinimumJumpTableEntries);
158164
159165 // Function alignments
160166 setMinFunctionAlignment (Align (8 ));
@@ -312,10 +318,14 @@ SDValue BPFTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const {
312318 report_fatal_error (" unimplemented opcode: " + Twine (Op.getOpcode ()));
313319 case ISD::BR_CC:
314320 return LowerBR_CC (Op, DAG);
321+ case ISD::JumpTable:
322+ return LowerJumpTable (Op, DAG);
315323 case ISD::GlobalAddress:
316324 return LowerGlobalAddress (Op, DAG);
317325 case ISD::ConstantPool:
318326 return LowerConstantPool (Op, DAG);
327+ case ISD::BlockAddress:
328+ return LowerBlockAddress (Op, DAG);
319329 case ISD::SELECT_CC:
320330 return LowerSELECT_CC (Op, DAG);
321331 case ISD::SDIV:
@@ -726,6 +736,11 @@ SDValue BPFTargetLowering::LowerATOMIC_LOAD_STORE(SDValue Op,
726736 return Op;
727737}
728738
739+ SDValue BPFTargetLowering::LowerJumpTable (SDValue Op, SelectionDAG &DAG) const {
740+ JumpTableSDNode *N = cast<JumpTableSDNode>(Op);
741+ return getAddr (N, DAG);
742+ }
743+
729744const char *BPFTargetLowering::getTargetNodeName (unsigned Opcode) const {
730745 switch ((BPFISD::NodeType)Opcode) {
731746 case BPFISD::FIRST_NUMBER:
@@ -757,6 +772,17 @@ static SDValue getTargetNode(ConstantPoolSDNode *N, const SDLoc &DL, EVT Ty,
757772 N->getOffset (), Flags);
758773}
759774
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+
760786template <class NodeTy >
761787SDValue BPFTargetLowering::getAddr (NodeTy *N, SelectionDAG &DAG,
762788 unsigned Flags) const {
@@ -783,6 +809,12 @@ SDValue BPFTargetLowering::LowerConstantPool(SDValue Op,
783809 return getAddr (N, DAG);
784810}
785811
812+ SDValue BPFTargetLowering::LowerBlockAddress (SDValue Op,
813+ SelectionDAG &DAG) const {
814+ BlockAddressSDNode *N = cast<BlockAddressSDNode>(Op);
815+ return getAddr (N, DAG);
816+ }
817+
786818unsigned
787819BPFTargetLowering::EmitSubregExt (MachineInstr &MI, MachineBasicBlock *BB,
788820 unsigned Reg, bool isSigned) const {
0 commit comments