Skip to content

Commit ab87484

Browse files
author
Djordje Todorovic
committed
[clang] Verify NanoMips target features
1 parent cf5782d commit ab87484

File tree

7 files changed

+81
-13
lines changed

7 files changed

+81
-13
lines changed

clang/include/clang/Basic/DiagnosticCommonKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,8 @@ def err_opt_not_valid_without_opt : Error<
306306
"option '%0' cannot be specified without '%1'">;
307307
def err_opt_not_valid_on_target : Error<
308308
"option '%0' cannot be specified on this target">;
309+
def err_feature_not_valid_on_target : Error<
310+
"feature '%0' cannot be specified on this target">;
309311

310312
// Source manager
311313
def err_cannot_open_file : Error<"cannot open file '%0': %1">, DefaultFatal;

clang/lib/Basic/Targets/Mips.cpp

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,62 @@ bool MipsTargetInfo::validateTarget(DiagnosticsEngine &Diags) const {
309309
// P32 ABI is only supported on NanoMIPS
310310
if (getTriple().isNanoMips() != (ABI == "p32")) {
311311
Diags.Report(diag::err_target_unsupported_abi_for_triple)
312-
<< ABI << getTriple().str();
312+
<< ABI << getTriple().str();
313+
return false;
314+
}
315+
316+
// Validate NanoMips target features.
317+
if (getTriple().isNanoMips()) {
318+
// NanoMips supports LE only.
319+
if (BigEndian) {
320+
Diags.Report(diag::err_opt_not_valid_on_target) << "-BE" << CPU;
321+
return false;
322+
}
323+
324+
// NanoMips supports soft float only.
325+
if (FloatABI == HardFloat) {
326+
Diags.Report(diag::err_target_unsupported_abi_for_triple)
327+
<< "hard-float" << getTriple().str();
328+
return false;
329+
}
330+
331+
// NanoMips supports p32 ABI only.
332+
if (ABI != "p32") {
333+
Diags.Report(diag::err_target_unsupported_abi_for_triple)
334+
<< ABI << getTriple().str();
335+
return false;
336+
}
337+
338+
// NanoMips does not support dsp.
339+
if (DspRev != NoDSP) {
340+
Diags.Report(diag::err_opt_not_valid_on_target) << "-mdsp/-mdspr2" << CPU;
341+
return false;
342+
}
343+
344+
// NanoMips does not support MSA.
345+
if (HasMSA) {
346+
Diags.Report(diag::err_opt_not_valid_on_target) << "-mmsa" << CPU;
347+
return false;
348+
}
349+
350+
// NanoMips does not support mips16.
351+
if (IsMips16) {
352+
Diags.Report(diag::err_opt_not_valid_on_target) << "-mips16" << CPU;
353+
return false;
354+
}
355+
356+
// NanoMips does not support micromips.
357+
if (IsMicromips) {
358+
Diags.Report(diag::err_target_unsupported_cpu_for_micromips) << CPU;
359+
return false;
360+
}
361+
362+
// NanoMips does not support indirect jump hazards.
363+
if (UseIndirectJumpHazard) {
364+
Diags.Report(diag::err_feature_not_valid_on_target)
365+
<< "use-indirect-jump-hazard" << CPU;
366+
return false;
367+
}
313368
}
314369

315370
return true;

clang/lib/Basic/Targets/Mips.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,18 @@ class LLVM_LIBRARY_VISIBILITY MipsTargetInfo : public TargetInfo {
6767
IsSingleFloat(false), IsNoABICalls(false), CanUseBSDABICalls(false),
6868
FloatABI(HardFloat), DspRev(NoDSP), HasMSA(false), DisableMadd4(false),
6969
UseIndirectJumpHazard(false), FPMode(FPXX) {
70-
7170
TheCXXABI.set(TargetCXXABI::GenericMIPS);
7271

73-
if (Triple.isMIPS32())
72+
if (Triple.isMIPS32()) {
7473
setABI("o32");
75-
else if (Triple.isNanoMips())
74+
} else if (Triple.isNanoMips()) {
7675
setABI("p32");
77-
else if (Triple.getEnvironment() == llvm::Triple::GNUABIN32)
76+
IsNanoMips = true;
77+
} else if (Triple.getEnvironment() == llvm::Triple::GNUABIN32) {
7878
setABI("n32");
79-
else
79+
} else {
8080
setABI("n64");
81+
}
8182

8283
CPU = ABI == "p32" ? "nanomips" : ABI == "o32" ? "mips32r2" : "mips64r2";
8384

@@ -338,10 +339,7 @@ class LLVM_LIBRARY_VISIBILITY MipsTargetInfo : public TargetInfo {
338339
IsNan2008 = isIEEE754_2008Default();
339340
IsAbs2008 = isIEEE754_2008Default();
340341
IsSingleFloat = false;
341-
if (IsNanoMips)
342-
FloatABI = SoftFloat;
343-
else
344-
FloatABI = HardFloat;
342+
FloatABI = IsNanoMips ? SoftFloat : HardFloat;
345343
DspRev = NoDSP;
346344
FPMode = isFP64Default() ? FP64 : FPXX;
347345
for (const auto &Feature : Features) {

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2001,6 +2001,16 @@ void Clang::AddMIPSTargetArgs(const ArgList &Args,
20012001
}
20022002
}
20032003
}
2004+
2005+
// NanoMips does not support SmallData, so force it to 0, since the default is
2006+
// 8 for Mips architectures.
2007+
if (Triple.isNanoMips()) {
2008+
CmdArgs.push_back("-msmall-data-limit");
2009+
CmdArgs.push_back("0");
2010+
2011+
CmdArgs.push_back("-mllvm");
2012+
CmdArgs.push_back("-mips-ssection-threshold=0");
2013+
}
20042014
}
20052015

20062016
void Clang::AddPPCTargetArgs(const ArgList &Args,

llvm/lib/Target/Mips/MipsSubtarget.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ class MipsSubtarget : public MipsGenSubtargetInfo {
335335
bool useIndirectJumpsHazard() const {
336336
return UseIndirectJumpsHazard && hasMips32r2();
337337
}
338-
bool useSmallSection() const { return UseSmallSection; }
338+
bool useSmallSection() const { return UseSmallSection && !hasNanoMips(); }
339339

340340
bool hasStandardEncoding() const { return !InMips16Mode && !InMicroMipsMode; }
341341

llvm/lib/Target/Mips/MipsTargetObjectFile.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ IsGlobalInSmallSectionImpl(const GlobalObject *GO,
100100
if (!Subtarget.useSmallSection())
101101
return false;
102102

103+
assert(!Subtarget.hasNanoMips() &&
104+
"NanoMips does not support small data section");
105+
103106
// Only global variables, not functions.
104107
const GlobalVariable *GVA = dyn_cast<GlobalVariable>(GO);
105108
if (!GVA)

llvm/test/CodeGen/Mips/nanomips/globaladdr.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ define i32 @load_global_val() {
77
; CHECK-LABEL: load_global_val
88
; CHECK: lwpc $a0, single
99
; CHECK-GP-LABEL: load_global_val
10-
; CHECK-GP: lw $a0, %gp_rel(single)($gp)
10+
; CHECK-GP: lwpc $a0, single
1111
%r = load i32, i32* @single
1212
ret i32 %r
1313
}
@@ -16,7 +16,7 @@ define i32* @load_global_addr() {
1616
; CHECK-LABEL: load_global_addr
1717
; CHECK: la $a0, single
1818
; CHECK-GP-LABEL: load_global_addr
19-
; CHECK-GP: addiu $a0, $gp, %gp_rel(single)
19+
; CHECK-GP: la $a0, single
2020
ret i32* @single
2121
}
2222

0 commit comments

Comments
 (0)