Skip to content

Commit c04a05d

Browse files
committed
Reland [NFCI] Refactor X86TargetLowering::getGlobalWrapperKind()
To simplify D150297. We should be looking at OpFlags more. Relanding after fix in https://reviews.llvm.org/D159297, hopefully now this is actually NFC. Reviewed By: rnk Differential Revision: https://reviews.llvm.org/D157907
1 parent 35fdf8d commit c04a05d

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
@@ -18183,15 +18183,17 @@ unsigned X86TargetLowering::getGlobalWrapperKind(
1818318183
if (GV && GV->isAbsoluteSymbolRef())
1818418184
return X86ISD::Wrapper;
1818518185

18186-
CodeModel::Model M = getTargetMachine().getCodeModel();
18186+
// The following OpFlags under RIP-rel PIC use RIP.
1818718187
if (Subtarget.isPICStyleRIPRel() &&
18188-
(M == CodeModel::Small || M == CodeModel::Kernel))
18188+
(OpFlags == X86II::MO_NO_FLAG || OpFlags == X86II::MO_COFFSTUB ||
18189+
OpFlags == X86II::MO_DLLIMPORT))
1818918190
return X86ISD::WrapperRIP;
1819018191

1819118192
// In the medium model, functions can always be referenced RIP-relatively,
1819218193
// since they must be within 2GiB. This is also possible in non-PIC mode, and
1819318194
// shorter than the 64-bit absolute immediate that would otherwise be emitted.
18194-
if (M == CodeModel::Medium && isa_and_nonnull<Function>(GV))
18195+
if (getTargetMachine().getCodeModel() == CodeModel::Medium &&
18196+
isa_and_nonnull<Function>(GV))
1819518197
return X86ISD::WrapperRIP;
1819618198

1819718199
// GOTPCREL references must always use RIP.
@@ -18219,7 +18221,8 @@ X86TargetLowering::LowerConstantPool(SDValue Op, SelectionDAG &DAG) const {
1821918221
SDValue Result = DAG.getTargetConstantPool(
1822018222
CP->getConstVal(), PtrVT, CP->getAlign(), CP->getOffset(), OpFlag);
1822118223
SDLoc DL(CP);
18222-
Result = DAG.getNode(getGlobalWrapperKind(), DL, PtrVT, Result);
18224+
Result =
18225+
DAG.getNode(getGlobalWrapperKind(nullptr, OpFlag), DL, PtrVT, Result);
1822318226
// With PIC, the address is actually $g + Offset.
1822418227
if (OpFlag) {
1822518228
Result =
@@ -18240,7 +18243,8 @@ SDValue X86TargetLowering::LowerJumpTable(SDValue Op, SelectionDAG &DAG) const {
1824018243
auto PtrVT = getPointerTy(DAG.getDataLayout());
1824118244
SDValue Result = DAG.getTargetJumpTable(JT->getIndex(), PtrVT, OpFlag);
1824218245
SDLoc DL(JT);
18243-
Result = DAG.getNode(getGlobalWrapperKind(), DL, PtrVT, Result);
18246+
Result =
18247+
DAG.getNode(getGlobalWrapperKind(nullptr, OpFlag), DL, PtrVT, Result);
1824418248

1824518249
// With PIC, the address is actually $g + Offset.
1824618250
if (OpFlag)
@@ -18266,7 +18270,8 @@ X86TargetLowering::LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const {
1826618270
SDLoc dl(Op);
1826718271
auto PtrVT = getPointerTy(DAG.getDataLayout());
1826818272
SDValue Result = DAG.getTargetBlockAddress(BA, PtrVT, Offset, OpFlags);
18269-
Result = DAG.getNode(getGlobalWrapperKind(), dl, PtrVT, Result);
18273+
Result =
18274+
DAG.getNode(getGlobalWrapperKind(nullptr, OpFlags), dl, PtrVT, Result);
1827018275

1827118276
// With PIC, the address is actually $g + Offset.
1827218277
if (isGlobalRelativeToPICBase(OpFlags)) {
@@ -25982,7 +25987,7 @@ SDValue X86TargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op,
2598225987
auto &Context = MF.getMMI().getContext();
2598325988
MCSymbol *S = Context.getOrCreateSymbol(Twine("GCC_except_table") +
2598425989
Twine(MF.getFunctionNumber()));
25985-
return DAG.getNode(getGlobalWrapperKind(), dl, VT,
25990+
return DAG.getNode(getGlobalWrapperKind(nullptr, /*OpFlags=*/0), dl, VT,
2598625991
DAG.getMCSymbol(S, PtrVT));
2598725992
}
2598825993

llvm/lib/Target/X86/X86ISelLowering.h

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

1639-
unsigned getGlobalWrapperKind(const GlobalValue *GV = nullptr,
1640-
const unsigned char OpFlags = 0) const;
1639+
unsigned getGlobalWrapperKind(const GlobalValue *GV,
1640+
const unsigned char OpFlags) const;
16411641
SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const;
16421642
SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;
16431643
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)