@@ -785,6 +785,7 @@ SDValue LoongArchTargetLowering::getAddr(NodeTy *N, SelectionDAG &DAG,
785
785
SDLoc DL (N);
786
786
EVT Ty = getPointerTy (DAG.getDataLayout ());
787
787
SDValue Addr = getTargetNode (N, DL, Ty, DAG, 0 );
788
+ SDValue Load;
788
789
789
790
switch (M) {
790
791
default :
@@ -796,33 +797,48 @@ SDValue LoongArchTargetLowering::getAddr(NodeTy *N, SelectionDAG &DAG,
796
797
// This is not actually used, but is necessary for successfully matching
797
798
// the PseudoLA_*_LARGE nodes.
798
799
SDValue Tmp = DAG.getConstant (0 , DL, Ty);
799
- if (IsLocal)
800
+ if (IsLocal) {
800
801
// This generates the pattern (PseudoLA_PCREL_LARGE tmp sym), that
801
802
// eventually becomes the desired 5-insn code sequence.
802
- return SDValue (DAG.getMachineNode (LoongArch::PseudoLA_PCREL_LARGE, DL, Ty,
803
+ Load = SDValue (DAG.getMachineNode (LoongArch::PseudoLA_PCREL_LARGE, DL, Ty,
803
804
Tmp, Addr),
804
805
0 );
805
-
806
- // This generates the pattern (PseudoLA_GOT_LARGE tmp sym), that eventually
807
- // becomes the desired 5-insn code sequence.
808
- return SDValue (
809
- DAG.getMachineNode (LoongArch::PseudoLA_GOT_LARGE, DL, Ty, Tmp, Addr),
810
- 0 );
806
+ } else {
807
+ // This generates the pattern (PseudoLA_GOT_LARGE tmp sym), that
808
+ // eventually becomes the desired 5-insn code sequence.
809
+ Load = SDValue (
810
+ DAG.getMachineNode (LoongArch::PseudoLA_GOT_LARGE, DL, Ty, Tmp, Addr),
811
+ 0 );
812
+ }
813
+ break ;
811
814
}
812
815
813
816
case CodeModel::Small:
814
817
case CodeModel::Medium:
815
- if (IsLocal)
818
+ if (IsLocal) {
816
819
// This generates the pattern (PseudoLA_PCREL sym), which expands to
817
820
// (addi.w/d (pcalau12i %pc_hi20(sym)) %pc_lo12(sym)).
818
- return SDValue (
821
+ Load = SDValue (
819
822
DAG.getMachineNode (LoongArch::PseudoLA_PCREL, DL, Ty, Addr), 0 );
823
+ } else {
824
+ // This generates the pattern (PseudoLA_GOT sym), which expands to (ld.w/d
825
+ // (pcalau12i %got_pc_hi20(sym)) %got_pc_lo12(sym)).
826
+ Load =
827
+ SDValue (DAG.getMachineNode (LoongArch::PseudoLA_GOT, DL, Ty, Addr), 0 );
828
+ }
829
+ }
820
830
821
- // This generates the pattern (PseudoLA_GOT sym), which expands to (ld.w/d
822
- // (pcalau12i %got_pc_hi20(sym)) %got_pc_lo12(sym)).
823
- return SDValue (DAG.getMachineNode (LoongArch::PseudoLA_GOT, DL, Ty, Addr),
824
- 0 );
831
+ if (!IsLocal) {
832
+ MachineFunction &MF = DAG.getMachineFunction ();
833
+ MachineMemOperand *MemOp = MF.getMachineMemOperand (
834
+ MachinePointerInfo::getGOT (MF),
835
+ MachineMemOperand::MOLoad | MachineMemOperand::MODereferenceable |
836
+ MachineMemOperand::MOInvariant,
837
+ LLT (Ty.getSimpleVT ()), Align (Ty.getFixedSizeInBits () / 8 ));
838
+ DAG.setNodeMemRefs (cast<MachineSDNode>(Load.getNode ()), {MemOp});
825
839
}
840
+
841
+ return Load;
826
842
}
827
843
828
844
SDValue LoongArchTargetLowering::lowerBlockAddress (SDValue Op,
@@ -860,7 +876,7 @@ SDValue LoongArchTargetLowering::lowerGlobalAddress(SDValue Op,
860
876
861
877
SDValue LoongArchTargetLowering::getStaticTLSAddr (GlobalAddressSDNode *N,
862
878
SelectionDAG &DAG,
863
- unsigned Opc,
879
+ unsigned Opc, bool UseGOT,
864
880
bool Large) const {
865
881
SDLoc DL (N);
866
882
EVT Ty = getPointerTy (DAG.getDataLayout ());
@@ -873,6 +889,15 @@ SDValue LoongArchTargetLowering::getStaticTLSAddr(GlobalAddressSDNode *N,
873
889
SDValue Offset = Large
874
890
? SDValue (DAG.getMachineNode (Opc, DL, Ty, Tmp, Addr), 0 )
875
891
: SDValue (DAG.getMachineNode (Opc, DL, Ty, Addr), 0 );
892
+ if (UseGOT) {
893
+ MachineFunction &MF = DAG.getMachineFunction ();
894
+ MachineMemOperand *MemOp = MF.getMachineMemOperand (
895
+ MachinePointerInfo::getGOT (MF),
896
+ MachineMemOperand::MOLoad | MachineMemOperand::MODereferenceable |
897
+ MachineMemOperand::MOInvariant,
898
+ LLT (Ty.getSimpleVT ()), Align (Ty.getFixedSizeInBits () / 8 ));
899
+ DAG.setNodeMemRefs (cast<MachineSDNode>(Offset.getNode ()), {MemOp});
900
+ }
876
901
877
902
// Add the thread pointer.
878
903
return DAG.getNode (ISD::ADD, DL, Ty, Offset,
@@ -972,13 +997,14 @@ LoongArchTargetLowering::lowerGlobalTLSAddress(SDValue Op,
972
997
return getStaticTLSAddr (N, DAG,
973
998
Large ? LoongArch::PseudoLA_TLS_IE_LARGE
974
999
: LoongArch::PseudoLA_TLS_IE,
975
- Large);
1000
+ /* UseGOT= */ true , Large);
976
1001
case TLSModel::LocalExec:
977
1002
// This model is used when static linking as the TLS offsets are resolved
978
1003
// during program linking.
979
1004
//
980
1005
// This node doesn't need an extra argument for the large code model.
981
- return getStaticTLSAddr (N, DAG, LoongArch::PseudoLA_TLS_LE);
1006
+ return getStaticTLSAddr (N, DAG, LoongArch::PseudoLA_TLS_LE,
1007
+ /* UseGOT=*/ false );
982
1008
}
983
1009
984
1010
return getTLSDescAddr (N, DAG,
0 commit comments