1818#include " llvm/CodeGen/MachineFrameInfo.h"
1919#include " llvm/CodeGen/MachineFunction.h"
2020#include " llvm/CodeGen/MachineInstrBuilder.h"
21+ #include " llvm/CodeGen/MachineJumpTableInfo.h"
2122#include " llvm/CodeGen/MachineRegisterInfo.h"
2223#include " llvm/CodeGen/TargetLoweringObjectFileImpl.h"
2324#include " llvm/CodeGen/ValueTypes.h"
@@ -38,6 +39,10 @@ static cl::opt<bool> BPFExpandMemcpyInOrder("bpf-expand-memcpy-in-order",
3839 cl::Hidden, cl::init(false ),
3940 cl::desc(" Expand memcpy into load/store pairs in order" ));
4041
42+ static cl::opt<unsigned > BPFMinimumJumpTableEntries (
43+ " bpf-min-jump-table-entries" , cl::init(5 ), cl::Hidden,
44+ cl::desc(" Set minimum number of entries to use a jump table on BPF" ));
45+
4146static void fail (const SDLoc &DL, SelectionDAG &DAG, const Twine &Msg,
4247 SDValue Val = {}) {
4348 std::string Str;
@@ -67,12 +72,13 @@ BPFTargetLowering::BPFTargetLowering(const TargetMachine &TM,
6772
6873 setOperationAction (ISD::BR_CC, MVT::i64 , Custom);
6974 setOperationAction (ISD::BR_JT, MVT::Other, Expand);
70- setOperationAction (ISD::BRIND, MVT::Other, Expand);
7175 setOperationAction (ISD::BRCOND, MVT::Other, Expand);
7276
7377 setOperationAction (ISD::TRAP, MVT::Other, Custom);
7478
75- setOperationAction ({ISD::GlobalAddress, ISD::ConstantPool}, MVT::i64 , Custom);
79+ setOperationAction ({ISD::GlobalAddress, ISD::ConstantPool, ISD::JumpTable,
80+ ISD::BlockAddress},
81+ MVT::i64 , Custom);
7682
7783 setOperationAction (ISD::DYNAMIC_STACKALLOC, MVT::i64 , Custom);
7884 setOperationAction (ISD::STACKSAVE, MVT::Other, Expand);
@@ -159,6 +165,7 @@ BPFTargetLowering::BPFTargetLowering(const TargetMachine &TM,
159165
160166 setBooleanContents (ZeroOrOneBooleanContent);
161167 setMaxAtomicSizeInBitsSupported (64 );
168+ setMinimumJumpTableEntries (BPFMinimumJumpTableEntries);
162169
163170 // Function alignments
164171 setMinFunctionAlignment (Align (8 ));
@@ -246,6 +253,10 @@ bool BPFTargetLowering::isZExtFree(SDValue Val, EVT VT2) const {
246253 return TargetLoweringBase::isZExtFree (Val, VT2);
247254}
248255
256+ unsigned BPFTargetLowering::getJumpTableEncoding () const {
257+ return MachineJumpTableInfo::EK_LabelDifference32;
258+ }
259+
249260BPFTargetLowering::ConstraintType
250261BPFTargetLowering::getConstraintType (StringRef Constraint) const {
251262 if (Constraint.size () == 1 ) {
@@ -316,10 +327,14 @@ SDValue BPFTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const {
316327 report_fatal_error (" unimplemented opcode: " + Twine (Op.getOpcode ()));
317328 case ISD::BR_CC:
318329 return LowerBR_CC (Op, DAG);
330+ case ISD::JumpTable:
331+ return LowerJumpTable (Op, DAG);
319332 case ISD::GlobalAddress:
320333 return LowerGlobalAddress (Op, DAG);
321334 case ISD::ConstantPool:
322335 return LowerConstantPool (Op, DAG);
336+ case ISD::BlockAddress:
337+ return LowerBlockAddress (Op, DAG);
323338 case ISD::SELECT_CC:
324339 return LowerSELECT_CC (Op, DAG);
325340 case ISD::SDIV:
@@ -780,6 +795,11 @@ SDValue BPFTargetLowering::LowerTRAP(SDValue Op, SelectionDAG &DAG) const {
780795 return LowerCall (CLI, InVals);
781796}
782797
798+ SDValue BPFTargetLowering::LowerJumpTable (SDValue Op, SelectionDAG &DAG) const {
799+ JumpTableSDNode *N = cast<JumpTableSDNode>(Op);
800+ return getAddr (N, DAG);
801+ }
802+
783803const char *BPFTargetLowering::getTargetNodeName (unsigned Opcode) const {
784804 switch ((BPFISD::NodeType)Opcode) {
785805 case BPFISD::FIRST_NUMBER:
@@ -811,6 +831,17 @@ static SDValue getTargetNode(ConstantPoolSDNode *N, const SDLoc &DL, EVT Ty,
811831 N->getOffset (), Flags);
812832}
813833
834+ static SDValue getTargetNode (BlockAddressSDNode *N, const SDLoc &DL, EVT Ty,
835+ SelectionDAG &DAG, unsigned Flags) {
836+ return DAG.getTargetBlockAddress (N->getBlockAddress (), Ty, N->getOffset (),
837+ Flags);
838+ }
839+
840+ static SDValue getTargetNode (JumpTableSDNode *N, const SDLoc &DL, EVT Ty,
841+ SelectionDAG &DAG, unsigned Flags) {
842+ return DAG.getTargetJumpTable (N->getIndex (), Ty, Flags);
843+ }
844+
814845template <class NodeTy >
815846SDValue BPFTargetLowering::getAddr (NodeTy *N, SelectionDAG &DAG,
816847 unsigned Flags) const {
@@ -837,6 +868,12 @@ SDValue BPFTargetLowering::LowerConstantPool(SDValue Op,
837868 return getAddr (N, DAG);
838869}
839870
871+ SDValue BPFTargetLowering::LowerBlockAddress (SDValue Op,
872+ SelectionDAG &DAG) const {
873+ BlockAddressSDNode *N = cast<BlockAddressSDNode>(Op);
874+ return getAddr (N, DAG);
875+ }
876+
840877unsigned
841878BPFTargetLowering::EmitSubregExt (MachineInstr &MI, MachineBasicBlock *BB,
842879 unsigned Reg, bool isSigned) const {
0 commit comments