@@ -38,6 +38,10 @@ static cl::opt<bool> BPFExpandMemcpyInOrder("bpf-expand-memcpy-in-order",
3838 cl::Hidden, cl::init(false ),
3939 cl::desc(" Expand memcpy into load/store pairs in order" ));
4040
41+ static cl::opt<unsigned > BPFMinimumJumpTableEntries (
42+ " bpf-min-jump-table-entries" , cl::init(5 ), cl::Hidden,
43+ cl::desc(" Set minimum number of entries to use a jump table on BPF" ));
44+
4145static void fail (const SDLoc &DL, SelectionDAG &DAG, const Twine &Msg,
4246 SDValue Val = {}) {
4347 std::string Str;
@@ -67,12 +71,13 @@ BPFTargetLowering::BPFTargetLowering(const TargetMachine &TM,
6771
6872 setOperationAction (ISD::BR_CC, MVT::i64 , Custom);
6973 setOperationAction (ISD::BR_JT, MVT::Other, Expand);
70- setOperationAction (ISD::BRIND, MVT::Other, Expand);
7174 setOperationAction (ISD::BRCOND, MVT::Other, Expand);
7275
7376 setOperationAction (ISD::TRAP, MVT::Other, Custom);
7477
75- setOperationAction ({ISD::GlobalAddress, ISD::ConstantPool}, MVT::i64 , Custom);
78+ setOperationAction ({ISD::GlobalAddress, ISD::ConstantPool, ISD::JumpTable,
79+ ISD::BlockAddress},
80+ MVT::i64 , Custom);
7681
7782 setOperationAction (ISD::DYNAMIC_STACKALLOC, MVT::i64 , Custom);
7883 setOperationAction (ISD::STACKSAVE, MVT::Other, Expand);
@@ -159,6 +164,7 @@ BPFTargetLowering::BPFTargetLowering(const TargetMachine &TM,
159164
160165 setBooleanContents (ZeroOrOneBooleanContent);
161166 setMaxAtomicSizeInBitsSupported (64 );
167+ setMinimumJumpTableEntries (BPFMinimumJumpTableEntries);
162168
163169 // Function alignments
164170 setMinFunctionAlignment (Align (8 ));
@@ -316,10 +322,14 @@ SDValue BPFTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const {
316322 report_fatal_error (" unimplemented opcode: " + Twine (Op.getOpcode ()));
317323 case ISD::BR_CC:
318324 return LowerBR_CC (Op, DAG);
325+ case ISD::JumpTable:
326+ return LowerJumpTable (Op, DAG);
319327 case ISD::GlobalAddress:
320328 return LowerGlobalAddress (Op, DAG);
321329 case ISD::ConstantPool:
322330 return LowerConstantPool (Op, DAG);
331+ case ISD::BlockAddress:
332+ return LowerBlockAddress (Op, DAG);
323333 case ISD::SELECT_CC:
324334 return LowerSELECT_CC (Op, DAG);
325335 case ISD::SDIV:
@@ -780,6 +790,11 @@ SDValue BPFTargetLowering::LowerTRAP(SDValue Op, SelectionDAG &DAG) const {
780790 return LowerCall (CLI, InVals);
781791}
782792
793+ SDValue BPFTargetLowering::LowerJumpTable (SDValue Op, SelectionDAG &DAG) const {
794+ JumpTableSDNode *N = cast<JumpTableSDNode>(Op);
795+ return getAddr (N, DAG);
796+ }
797+
783798const char *BPFTargetLowering::getTargetNodeName (unsigned Opcode) const {
784799 switch ((BPFISD::NodeType)Opcode) {
785800 case BPFISD::FIRST_NUMBER:
@@ -811,6 +826,17 @@ static SDValue getTargetNode(ConstantPoolSDNode *N, const SDLoc &DL, EVT Ty,
811826 N->getOffset (), Flags);
812827}
813828
829+ static SDValue getTargetNode (BlockAddressSDNode *N, const SDLoc &DL, EVT Ty,
830+ SelectionDAG &DAG, unsigned Flags) {
831+ return DAG.getTargetBlockAddress (N->getBlockAddress (), Ty, N->getOffset (),
832+ Flags);
833+ }
834+
835+ static SDValue getTargetNode (JumpTableSDNode *N, const SDLoc &DL, EVT Ty,
836+ SelectionDAG &DAG, unsigned Flags) {
837+ return DAG.getTargetJumpTable (N->getIndex (), Ty, Flags);
838+ }
839+
814840template <class NodeTy >
815841SDValue BPFTargetLowering::getAddr (NodeTy *N, SelectionDAG &DAG,
816842 unsigned Flags) const {
@@ -837,6 +863,12 @@ SDValue BPFTargetLowering::LowerConstantPool(SDValue Op,
837863 return getAddr (N, DAG);
838864}
839865
866+ SDValue BPFTargetLowering::LowerBlockAddress (SDValue Op,
867+ SelectionDAG &DAG) const {
868+ BlockAddressSDNode *N = cast<BlockAddressSDNode>(Op);
869+ return getAddr (N, DAG);
870+ }
871+
840872unsigned
841873BPFTargetLowering::EmitSubregExt (MachineInstr &MI, MachineBasicBlock *BB,
842874 unsigned Reg, bool isSigned) const {
0 commit comments