@@ -69,7 +69,9 @@ BPFTargetLowering::BPFTargetLowering(const TargetMachine &TM,
69
69
setOperationAction (ISD::BRIND, MVT::Other, Expand);
70
70
setOperationAction (ISD::BRCOND, MVT::Other, Expand);
71
71
72
- setOperationAction (ISD::GlobalAddress, MVT::i64 , Custom);
72
+ setOperationAction ({ISD::GlobalAddress, ISD::BlockAddress, ISD::ConstantPool,
73
+ ISD::JumpTable},
74
+ MVT::i64 , Custom);
73
75
74
76
setOperationAction (ISD::DYNAMIC_STACKALLOC, MVT::i64 , Custom);
75
77
setOperationAction (ISD::STACKSAVE, MVT::Other, Expand);
@@ -305,6 +307,12 @@ SDValue BPFTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const {
305
307
return LowerBR_CC (Op, DAG);
306
308
case ISD::GlobalAddress:
307
309
return LowerGlobalAddress (Op, DAG);
310
+ case ISD::BlockAddress:
311
+ return LowerBlockAddress (Op, DAG);
312
+ case ISD::ConstantPool:
313
+ return LowerConstantPool (Op, DAG);
314
+ case ISD::JumpTable:
315
+ return LowerJumpTable (Op, DAG);
308
316
case ISD::SELECT_CC:
309
317
return LowerSELECT_CC (Op, DAG);
310
318
case ISD::DYNAMIC_STACKALLOC:
@@ -670,18 +678,65 @@ const char *BPFTargetLowering::getTargetNodeName(unsigned Opcode) const {
670
678
return nullptr ;
671
679
}
672
680
681
+ static SDValue getTargetNode (GlobalAddressSDNode *N, const SDLoc &DL, EVT Ty,
682
+ SelectionDAG &DAG, unsigned Flags) {
683
+ return DAG.getTargetGlobalAddress (N->getGlobal (), DL, Ty, 0 , Flags);
684
+ }
685
+
686
+ static SDValue getTargetNode (BlockAddressSDNode *N, const SDLoc &DL, EVT Ty,
687
+ SelectionDAG &DAG, unsigned Flags) {
688
+ return DAG.getTargetBlockAddress (N->getBlockAddress (), Ty, N->getOffset (),
689
+ Flags);
690
+ }
691
+
692
+ static SDValue getTargetNode (ConstantPoolSDNode *N, const SDLoc &DL, EVT Ty,
693
+ SelectionDAG &DAG, unsigned Flags) {
694
+ return DAG.getTargetConstantPool (N->getConstVal (), Ty, N->getAlign (),
695
+ N->getOffset (), Flags);
696
+ }
697
+
698
+ static SDValue getTargetNode (JumpTableSDNode *N, const SDLoc &DL, EVT Ty,
699
+ SelectionDAG &DAG, unsigned Flags) {
700
+ return DAG.getTargetJumpTable (N->getIndex (), Ty, Flags);
701
+ }
702
+
703
+ template <class NodeTy >
704
+ SDValue BPFTargetLowering::getAddr (NodeTy *N, SelectionDAG &DAG,
705
+ unsigned Flags) const {
706
+ SDLoc DL (N);
707
+
708
+ SDValue GA = getTargetNode (N, DL, MVT::i64 , DAG, Flags);
709
+
710
+ return DAG.getNode (BPFISD::Wrapper, DL, MVT::i64 , GA);
711
+ }
712
+
673
713
SDValue BPFTargetLowering::LowerGlobalAddress (SDValue Op,
674
714
SelectionDAG &DAG) const {
675
- auto *N = cast<GlobalAddressSDNode>(Op);
715
+ GlobalAddressSDNode *N = cast<GlobalAddressSDNode>(Op);
676
716
if (N->getOffset () != 0 )
677
717
report_fatal_error (" invalid offset for global address: " +
678
718
Twine (N->getOffset ()));
719
+ return getAddr (N, DAG);
720
+ }
679
721
680
- SDLoc DL (Op);
681
- const GlobalValue *GV = N-> getGlobal ();
682
- SDValue GA = DAG. getTargetGlobalAddress (GV, DL, MVT:: i64 );
722
+ SDValue BPFTargetLowering::LowerBlockAddress (SDValue Op,
723
+ SelectionDAG &DAG) const {
724
+ BlockAddressSDNode *N = cast<BlockAddressSDNode>(Op );
683
725
684
- return DAG.getNode (BPFISD::Wrapper, DL, MVT::i64 , GA);
726
+ return getAddr (N, DAG);
727
+ }
728
+
729
+ SDValue BPFTargetLowering::LowerConstantPool (SDValue Op,
730
+ SelectionDAG &DAG) const {
731
+ ConstantPoolSDNode *N = cast<ConstantPoolSDNode>(Op);
732
+
733
+ return getAddr (N, DAG);
734
+ }
735
+
736
+ SDValue BPFTargetLowering::LowerJumpTable (SDValue Op, SelectionDAG &DAG) const {
737
+ JumpTableSDNode *N = cast<JumpTableSDNode>(Op);
738
+
739
+ return getAddr (N, DAG);
685
740
}
686
741
687
742
unsigned
0 commit comments