Skip to content

Commit 9c36de9

Browse files
committed
[mips] Pass "xgot" flag as a subtarget feature
We need "xgot" flag in the MipsAsmParser to implement correct expansion of some pseudo instructions in case of using 32-bit GOT (XGOT). MipsAsmParser does not have reference to MipsSubtarget but has a reference to "feature bit set". llvm-svn: 372220
1 parent 1ebdbad commit 9c36de9

File tree

10 files changed

+46
-27
lines changed

10 files changed

+46
-27
lines changed

clang/lib/Driver/ToolChains/Arch/Mips.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,13 @@ void mips::getMIPSTargetFeatures(const Driver &D, const llvm::Triple &Triple,
267267
D.Diag(diag::warn_drv_unsupported_longcalls) << (ABICallsArg ? 0 : 1);
268268
}
269269

270+
if (Arg *A = Args.getLastArg(options::OPT_mxgot, options::OPT_mno_xgot)) {
271+
if (A->getOption().matches(options::OPT_mxgot))
272+
Features.push_back("+xgot");
273+
else
274+
Features.push_back("-xgot");
275+
}
276+
270277
mips::FloatABI FloatABI = mips::getMipsFloatABI(D, Args);
271278
if (FloatABI == mips::FloatABI::Soft) {
272279
// FIXME: Note, this is a hack. We need to pass the selected float

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1675,13 +1675,6 @@ void Clang::AddMIPSTargetArgs(const ArgList &Args,
16751675
CmdArgs.push_back("hard");
16761676
}
16771677

1678-
if (Arg *A = Args.getLastArg(options::OPT_mxgot, options::OPT_mno_xgot)) {
1679-
if (A->getOption().matches(options::OPT_mxgot)) {
1680-
CmdArgs.push_back("-mllvm");
1681-
CmdArgs.push_back("-mxgot");
1682-
}
1683-
}
1684-
16851678
if (Arg *A = Args.getLastArg(options::OPT_mldc1_sdc1,
16861679
options::OPT_mno_ldc1_sdc1)) {
16871680
if (A->getOption().matches(options::OPT_mno_ldc1_sdc1)) {

clang/test/Driver/mips-features.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,13 +268,13 @@
268268
// RUN: %clang -target mips-linux-gnu -### -c %s \
269269
// RUN: -mno-xgot -mxgot 2>&1 \
270270
// RUN: | FileCheck --check-prefix=CHECK-XGOT %s
271-
// CHECK-XGOT: "-mllvm" "-mxgot"
271+
// CHECK-XGOT: "-target-feature" "+xgot"
272272
//
273273
// -mno-xgot
274274
// RUN: %clang -target mips-linux-gnu -### -c %s \
275275
// RUN: -mxgot -mno-xgot 2>&1 \
276276
// RUN: | FileCheck --check-prefix=CHECK-NOXGOT %s
277-
// CHECK-NOXGOT-NOT: "-mllvm" "-mxgot"
277+
// CHECK-NOXGOT: "-target-feature" "-xgot"
278278
//
279279
// -mldc1-sdc1
280280
// RUN: %clang -target mips-linux-gnu -### -c %s \

clang/test/Driver/mips-integrated-as.s

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,3 +293,13 @@
293293
// IMG-SINGLEFLOAT-EXPLICIT-FPXX: "-target-feature" "+single-float"
294294
// IMG-SINGLEFLOAT-EXPLICIT-FPXX: "-target-feature" "+fpxx"
295295
// IMG-SINGLEFLOAT-EXPLICIT-FPXX: "-target-feature" "+nooddspreg"
296+
297+
// RUN: %clang -target mips-linux-gnu -### -fintegrated-as -mxgot -c %s 2>&1 | \
298+
// RUN: FileCheck -check-prefix=XGOT %s
299+
// XGOT: -cc1as
300+
// XGOT: "-target-feature" "+xgot"
301+
302+
// RUN: %clang -target mips-linux-gnu -### -fintegrated-as -mno-xgot -c %s 2>&1 | \
303+
// RUN: FileCheck -check-prefix=NOXGOT %s
304+
// NOXGOT: -cc1as
305+
// NOXGOT: "-target-feature" "-xgot"

llvm/lib/Target/Mips/Mips.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ def FeatureMT : SubtargetFeature<"mt", "HasMT", "true", "Mips MT ASE">;
209209
def FeatureLongCalls : SubtargetFeature<"long-calls", "UseLongCalls", "true",
210210
"Disable use of the jal instruction">;
211211

212+
def FeatureXGOT
213+
: SubtargetFeature<"xgot", "UseXGOT", "true", "Assume 32-bit GOT">;
214+
212215
def FeatureUseIndirectJumpsHazard : SubtargetFeature<"use-indirect-jump-hazard",
213216
"UseIndirectJumpsHazard",
214217
"true", "Use indirect jump"

llvm/lib/Target/Mips/MipsISelLowering.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,6 @@ using namespace llvm;
8282

8383
STATISTIC(NumTailCalls, "Number of tail calls");
8484

85-
static cl::opt<bool>
86-
LargeGOT("mxgot", cl::Hidden,
87-
cl::desc("MIPS: Enable GOT larger than 64k."), cl::init(false));
88-
8985
static cl::opt<bool>
9086
NoZeroDivCheck("mno-check-zero-division", cl::Hidden,
9187
cl::desc("MIPS: Don't trap on integer division by zero."),
@@ -554,8 +550,9 @@ MipsTargetLowering::createFastISel(FunctionLoweringInfo &funcInfo,
554550
!Subtarget.inMicroMipsMode();
555551

556552
// Disable if either of the following is true:
557-
// We do not generate PIC, the ABI is not O32, LargeGOT is being used.
558-
if (!TM.isPositionIndependent() || !TM.getABI().IsO32() || LargeGOT)
553+
// We do not generate PIC, the ABI is not O32, XGOT is being used.
554+
if (!TM.isPositionIndependent() || !TM.getABI().IsO32() ||
555+
Subtarget.useXGOT())
559556
UseFastISel = false;
560557

561558
return UseFastISel ? Mips::createFastISel(funcInfo, libInfo) : nullptr;
@@ -1989,7 +1986,7 @@ SDValue MipsTargetLowering::lowerGlobalAddress(SDValue Op,
19891986
if (GV->hasLocalLinkage())
19901987
return getAddrLocal(N, SDLoc(N), Ty, DAG, ABI.IsN32() || ABI.IsN64());
19911988

1992-
if (LargeGOT)
1989+
if (Subtarget.useXGOT())
19931990
return getAddrGlobalLargeGOT(
19941991
N, SDLoc(N), Ty, DAG, MipsII::MO_GOT_HI16, MipsII::MO_GOT_LO16,
19951992
DAG.getEntryNode(),
@@ -3272,7 +3269,7 @@ MipsTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
32723269

32733270
if (InternalLinkage)
32743271
Callee = getAddrLocal(G, DL, Ty, DAG, ABI.IsN32() || ABI.IsN64());
3275-
else if (LargeGOT) {
3272+
else if (Subtarget.useXGOT()) {
32763273
Callee = getAddrGlobalLargeGOT(G, DL, Ty, DAG, MipsII::MO_CALL_HI16,
32773274
MipsII::MO_CALL_LO16, Chain,
32783275
FuncInfo->callPtrInfo(Val));
@@ -3294,7 +3291,7 @@ MipsTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
32943291
if (!IsPIC) // static
32953292
Callee = DAG.getTargetExternalSymbol(
32963293
Sym, getPointerTy(DAG.getDataLayout()), MipsII::MO_NO_FLAG);
3297-
else if (LargeGOT) {
3294+
else if (Subtarget.useXGOT()) {
32983295
Callee = getAddrGlobalLargeGOT(S, DL, Ty, DAG, MipsII::MO_CALL_HI16,
32993296
MipsII::MO_CALL_LO16, Chain,
33003297
FuncInfo->callPtrInfo(Sym));

llvm/lib/Target/Mips/MipsSubtarget.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ class MipsSubtarget : public MipsGenSubtargetInfo {
189189
// Disable use of the `jal` instruction.
190190
bool UseLongCalls = false;
191191

192+
// Assume 32-bit GOT.
193+
bool UseXGOT = false;
194+
192195
/// The minimum alignment known to hold of the stack frame on
193196
/// entry to the function and which must be maintained by every function.
194197
unsigned stackAlignment;
@@ -323,6 +326,8 @@ class MipsSubtarget : public MipsGenSubtargetInfo {
323326

324327
bool useLongCalls() const { return UseLongCalls; }
325328

329+
bool useXGOT() const { return UseXGOT; }
330+
326331
bool enableLongBranchPass() const {
327332
return hasStandardEncoding() || inMicroMipsMode() || allowMixed16_32();
328333
}

llvm/test/CodeGen/Mips/address-selection.ll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
; RUN: llc -march=mips < %s -debug 2>&1 | FileCheck %s --check-prefix=MIPS
2-
; RUN: llc -march=mips -relocation-model=pic -mxgot < %s -debug 2>&1 | FileCheck %s --check-prefix=MIPS-XGOT
2+
; RUN: llc -march=mips -relocation-model=pic -mattr=+xgot < %s \
3+
; RUN: -debug 2>&1 | FileCheck %s --check-prefix=MIPS-XGOT
34

45
; RUN: llc -march=mips -mattr=+micromips < %s -debug 2>&1 | FileCheck %s --check-prefix=MM
5-
; RUN: llc -march=mips -relocation-model=pic -mxgot -mattr=+micromips < %s -debug 2>&1 | FileCheck %s --check-prefix=MM-XGOT
6+
; RUN: llc -march=mips -relocation-model=pic -mattr=+xgot,+micromips < %s \
7+
; RUN: -debug 2>&1 | FileCheck %s --check-prefix=MM-XGOT
68

79
; REQUIRES: asserts
810

llvm/test/CodeGen/Mips/biggot.ll

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
; RUN: llc -march=mipsel -mxgot -relocation-model=pic < %s | FileCheck %s -check-prefix=O32
2-
; RUN: llc -march=mips64el -mcpu=mips64r2 -mxgot -relocation-model=pic < %s | \
3-
; RUN: FileCheck %s -check-prefix=N64
4-
; RUN: llc -march=mipsel -mxgot -relocation-model=pic -fast-isel < %s | FileCheck %s -check-prefix=O32
5-
; RUN: llc -march=mips64el -mcpu=mips64r2 -mxgot -relocation-model=pic -fast-isel < %s | \
6-
; RUN: FileCheck %s -check-prefix=N64
1+
; RUN: llc -march=mipsel -mattr=+xgot \
2+
; RUN: -relocation-model=pic < %s | FileCheck %s -check-prefix=O32
3+
; RUN: llc -march=mips64el -mcpu=mips64r2 -mattr=+xgot \
4+
; RUN: -relocation-model=pic < %s | FileCheck %s -check-prefix=N64
5+
; RUN: llc -march=mipsel -mattr=+xgot -fast-isel \
6+
; RUN: -relocation-model=pic < %s | FileCheck %s -check-prefix=O32
7+
; RUN: llc -march=mips64el -mcpu=mips64r2 -mattr=+xgot -fast-isel \
8+
; RUN: -relocation-model=pic < %s | FileCheck %s -check-prefix=N64
79

810
@v0 = external global i32
911

llvm/test/CodeGen/Mips/mirparser/target-flags-pic-mxgot-tls.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# RUN: llc -march=mips64 -target-abi n64 -start-before=finalize-isel \
2-
# RUN: -stop-after=finalize-isel -relocation-model=pic -mxgot \
2+
# RUN: -stop-after=finalize-isel -relocation-model=pic -mattr=+xgot \
33
# RUN: -o /dev/null %s
44

55
# A simple test to show that we can parse the target specific flags: gpoff-hi,

0 commit comments

Comments
 (0)