aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib
diff options
context:
space:
mode:
authorArthur Eubanks <aeubanks@google.com>2023-08-14 11:25:24 -0700
committerArthur Eubanks <aeubanks@google.com>2023-08-31 19:03:51 -0700
commitc04a05d898982614a2df80d928b97ed4f8c49b60 (patch)
tree528e49d31e6832afa005974860d0cd7e71d66b99 /llvm/lib
parent35fdf8d70329b2b067cb9433a5891f2a57e2f4ed (diff)
downloadllvm-c04a05d898982614a2df80d928b97ed4f8c49b60.zip
llvm-c04a05d898982614a2df80d928b97ed4f8c49b60.tar.gz
llvm-c04a05d898982614a2df80d928b97ed4f8c49b60.tar.bz2
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
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Target/X86/X86ISelLowering.cpp19
-rw-r--r--llvm/lib/Target/X86/X86ISelLowering.h4
-rw-r--r--llvm/lib/Target/X86/X86Subtarget.cpp4
3 files changed, 17 insertions, 10 deletions
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index 5a45629..ee8d268 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -18183,15 +18183,17 @@ unsigned X86TargetLowering::getGlobalWrapperKind(
if (GV && GV->isAbsoluteSymbolRef())
return X86ISD::Wrapper;
- CodeModel::Model M = getTargetMachine().getCodeModel();
+ // The following OpFlags under RIP-rel PIC use RIP.
if (Subtarget.isPICStyleRIPRel() &&
- (M == CodeModel::Small || M == CodeModel::Kernel))
+ (OpFlags == X86II::MO_NO_FLAG || OpFlags == X86II::MO_COFFSTUB ||
+ OpFlags == X86II::MO_DLLIMPORT))
return X86ISD::WrapperRIP;
// In the medium model, functions can always be referenced RIP-relatively,
// since they must be within 2GiB. This is also possible in non-PIC mode, and
// shorter than the 64-bit absolute immediate that would otherwise be emitted.
- if (M == CodeModel::Medium && isa_and_nonnull<Function>(GV))
+ if (getTargetMachine().getCodeModel() == CodeModel::Medium &&
+ isa_and_nonnull<Function>(GV))
return X86ISD::WrapperRIP;
// GOTPCREL references must always use RIP.
@@ -18219,7 +18221,8 @@ X86TargetLowering::LowerConstantPool(SDValue Op, SelectionDAG &DAG) const {
SDValue Result = DAG.getTargetConstantPool(
CP->getConstVal(), PtrVT, CP->getAlign(), CP->getOffset(), OpFlag);
SDLoc DL(CP);
- Result = DAG.getNode(getGlobalWrapperKind(), DL, PtrVT, Result);
+ Result =
+ DAG.getNode(getGlobalWrapperKind(nullptr, OpFlag), DL, PtrVT, Result);
// With PIC, the address is actually $g + Offset.
if (OpFlag) {
Result =
@@ -18240,7 +18243,8 @@ SDValue X86TargetLowering::LowerJumpTable(SDValue Op, SelectionDAG &DAG) const {
auto PtrVT = getPointerTy(DAG.getDataLayout());
SDValue Result = DAG.getTargetJumpTable(JT->getIndex(), PtrVT, OpFlag);
SDLoc DL(JT);
- Result = DAG.getNode(getGlobalWrapperKind(), DL, PtrVT, Result);
+ Result =
+ DAG.getNode(getGlobalWrapperKind(nullptr, OpFlag), DL, PtrVT, Result);
// With PIC, the address is actually $g + Offset.
if (OpFlag)
@@ -18266,7 +18270,8 @@ X86TargetLowering::LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const {
SDLoc dl(Op);
auto PtrVT = getPointerTy(DAG.getDataLayout());
SDValue Result = DAG.getTargetBlockAddress(BA, PtrVT, Offset, OpFlags);
- Result = DAG.getNode(getGlobalWrapperKind(), dl, PtrVT, Result);
+ Result =
+ DAG.getNode(getGlobalWrapperKind(nullptr, OpFlags), dl, PtrVT, Result);
// With PIC, the address is actually $g + Offset.
if (isGlobalRelativeToPICBase(OpFlags)) {
@@ -25982,7 +25987,7 @@ SDValue X86TargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op,
auto &Context = MF.getMMI().getContext();
MCSymbol *S = Context.getOrCreateSymbol(Twine("GCC_except_table") +
Twine(MF.getFunctionNumber()));
- return DAG.getNode(getGlobalWrapperKind(), dl, VT,
+ return DAG.getNode(getGlobalWrapperKind(nullptr, /*OpFlags=*/0), dl, VT,
DAG.getMCSymbol(S, PtrVT));
}
diff --git a/llvm/lib/Target/X86/X86ISelLowering.h b/llvm/lib/Target/X86/X86ISelLowering.h
index a7057ad..5689543 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.h
+++ b/llvm/lib/Target/X86/X86ISelLowering.h
@@ -1636,8 +1636,8 @@ namespace llvm {
SDValue LowerEXTRACT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) const;
SDValue LowerINSERT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) const;
- unsigned getGlobalWrapperKind(const GlobalValue *GV = nullptr,
- const unsigned char OpFlags = 0) const;
+ unsigned getGlobalWrapperKind(const GlobalValue *GV,
+ const unsigned char OpFlags) const;
SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const;
SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;
SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;
diff --git a/llvm/lib/Target/X86/X86Subtarget.cpp b/llvm/lib/Target/X86/X86Subtarget.cpp
index e9a6805..319b3c7 100644
--- a/llvm/lib/Target/X86/X86Subtarget.cpp
+++ b/llvm/lib/Target/X86/X86Subtarget.cpp
@@ -323,7 +323,9 @@ X86Subtarget::X86Subtarget(const Triple &TT, StringRef CPU, StringRef TuneCPU,
InstrInfo(initializeSubtargetDependencies(CPU, TuneCPU, FS)),
TLInfo(TM, *this), FrameLowering(*this, getStackAlignment()) {
// Determine the PICStyle based on the target selected.
- if (!isPositionIndependent())
+ if (!isPositionIndependent() || TM.getCodeModel() == CodeModel::Large)
+ // With the large code model, None forces all memory accesses to be indirect
+ // rather than RIP-relative.
setPICStyle(PICStyles::Style::None);
else if (is64Bit())
setPICStyle(PICStyles::Style::RIPRel);