Skip to content

Commit 133b24a

Browse files
committed
[NFC] Refactor X86TargetLowering::getGlobalWrapperKind()
To simplify D150297. We should be looking at OpFlags more. Reviewed By: rnk Differential Revision: https://reviews.llvm.org/D157907
1 parent 7ba4896 commit 133b24a

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18204,15 +18204,17 @@ unsigned X86TargetLowering::getGlobalWrapperKind(
1820418204
if (GV && GV->isAbsoluteSymbolRef())
1820518205
return X86ISD::Wrapper;
1820618206

18207-
CodeModel::Model M = getTargetMachine().getCodeModel();
18207+
// The following OpFlags under RIP-rel PIC use RIP.
1820818208
if (Subtarget.isPICStyleRIPRel() &&
18209-
(M == CodeModel::Small || M == CodeModel::Kernel))
18209+
(OpFlags == X86II::MO_NO_FLAG || OpFlags == X86II::MO_COFFSTUB ||
18210+
OpFlags == X86II::MO_DLLIMPORT))
1821018211
return X86ISD::WrapperRIP;
1821118212

1821218213
// In the medium model, functions can always be referenced RIP-relatively,
1821318214
// since they must be within 2GiB. This is also possible in non-PIC mode, and
1821418215
// shorter than the 64-bit absolute immediate that would otherwise be emitted.
18215-
if (M == CodeModel::Medium && isa_and_nonnull<Function>(GV))
18216+
if (getTargetMachine().getCodeModel() == CodeModel::Medium &&
18217+
isa_and_nonnull<Function>(GV))
1821618218
return X86ISD::WrapperRIP;
1821718219

1821818220
// GOTPCREL references must always use RIP.
@@ -18240,7 +18242,8 @@ X86TargetLowering::LowerConstantPool(SDValue Op, SelectionDAG &DAG) const {
1824018242
SDValue Result = DAG.getTargetConstantPool(
1824118243
CP->getConstVal(), PtrVT, CP->getAlign(), CP->getOffset(), OpFlag);
1824218244
SDLoc DL(CP);
18243-
Result = DAG.getNode(getGlobalWrapperKind(), DL, PtrVT, Result);
18245+
Result =
18246+
DAG.getNode(getGlobalWrapperKind(nullptr, OpFlag), DL, PtrVT, Result);
1824418247
// With PIC, the address is actually $g + Offset.
1824518248
if (OpFlag) {
1824618249
Result =
@@ -18261,7 +18264,8 @@ SDValue X86TargetLowering::LowerJumpTable(SDValue Op, SelectionDAG &DAG) const {
1826118264
auto PtrVT = getPointerTy(DAG.getDataLayout());
1826218265
SDValue Result = DAG.getTargetJumpTable(JT->getIndex(), PtrVT, OpFlag);
1826318266
SDLoc DL(JT);
18264-
Result = DAG.getNode(getGlobalWrapperKind(), DL, PtrVT, Result);
18267+
Result =
18268+
DAG.getNode(getGlobalWrapperKind(nullptr, OpFlag), DL, PtrVT, Result);
1826518269

1826618270
// With PIC, the address is actually $g + Offset.
1826718271
if (OpFlag)
@@ -18287,7 +18291,8 @@ X86TargetLowering::LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const {
1828718291
SDLoc dl(Op);
1828818292
auto PtrVT = getPointerTy(DAG.getDataLayout());
1828918293
SDValue Result = DAG.getTargetBlockAddress(BA, PtrVT, Offset, OpFlags);
18290-
Result = DAG.getNode(getGlobalWrapperKind(), dl, PtrVT, Result);
18294+
Result =
18295+
DAG.getNode(getGlobalWrapperKind(nullptr, OpFlags), dl, PtrVT, Result);
1829118296

1829218297
// With PIC, the address is actually $g + Offset.
1829318298
if (isGlobalRelativeToPICBase(OpFlags)) {
@@ -25975,7 +25980,7 @@ SDValue X86TargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op,
2597525980
auto &Context = MF.getMMI().getContext();
2597625981
MCSymbol *S = Context.getOrCreateSymbol(Twine("GCC_except_table") +
2597725982
Twine(MF.getFunctionNumber()));
25978-
return DAG.getNode(getGlobalWrapperKind(), dl, VT,
25983+
return DAG.getNode(getGlobalWrapperKind(nullptr, /*OpFlags=*/0), dl, VT,
2597925984
DAG.getMCSymbol(S, PtrVT));
2598025985
}
2598125986

llvm/lib/Target/X86/X86ISelLowering.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,8 +1637,8 @@ namespace llvm {
16371637
SDValue LowerEXTRACT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) const;
16381638
SDValue LowerINSERT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) const;
16391639

1640-
unsigned getGlobalWrapperKind(const GlobalValue *GV = nullptr,
1641-
const unsigned char OpFlags = 0) const;
1640+
unsigned getGlobalWrapperKind(const GlobalValue *GV,
1641+
const unsigned char OpFlags) const;
16421642
SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const;
16431643
SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;
16441644
SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;

llvm/lib/Target/X86/X86Subtarget.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,9 @@ X86Subtarget::X86Subtarget(const Triple &TT, StringRef CPU, StringRef TuneCPU,
323323
InstrInfo(initializeSubtargetDependencies(CPU, TuneCPU, FS)),
324324
TLInfo(TM, *this), FrameLowering(*this, getStackAlignment()) {
325325
// Determine the PICStyle based on the target selected.
326-
if (!isPositionIndependent())
326+
if (!isPositionIndependent() || TM.getCodeModel() == CodeModel::Large)
327+
// With the large code model, None forces all memory accesses to be indirect
328+
// rather than RIP-relative.
327329
setPICStyle(PICStyles::Style::None);
328330
else if (is64Bit())
329331
setPICStyle(PICStyles::Style::RIPRel);

0 commit comments

Comments
 (0)