Skip to content

Commit 85e200e

Browse files
committedJun 25, 2018
Add Triple::isMIPS()/isMIPS32()/isMIPS64(). NFC
There are quite a few if statements that enumerate all these cases. It gets even worse in our fork of LLVM where we also have a Triple::cheri (which is mips64 + CHERI instructions) and we had to update all if statements that check for Triple::mips64 to also handle Triple::cheri. This patch helps to reduce our diff to upstream and should also make some checks more readable. Reviewed By: atanasyan Differential Revision: https://reviews.llvm.org/D48548 llvm-svn: 335493
1 parent b4adc91 commit 85e200e

File tree

11 files changed

+28
-26
lines changed

11 files changed

+28
-26
lines changed
 

‎llvm/include/llvm/ADT/Triple.h

+15
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,21 @@ class Triple {
658658
return getArch() == Triple::aarch64 || getArch() == Triple::aarch64_be;
659659
}
660660

661+
/// Tests whether the target is MIPS 32-bit (little and big endian).
662+
bool isMIPS32() const {
663+
return getArch() == Triple::mips || getArch() == Triple::mipsel;
664+
}
665+
666+
/// Tests whether the target is MIPS 64-bit (little and big endian).
667+
bool isMIPS64() const {
668+
return getArch() == Triple::mips64 || getArch() == Triple::mips64el;
669+
}
670+
671+
/// Tests whether the target is MIPS (little and big endian, 32- or 64-bit).
672+
bool isMIPS() const {
673+
return isMIPS32() || isMIPS64();
674+
}
675+
661676
/// Tests whether the target supports comdat
662677
bool supportsCOMDAT() const {
663678
return !isOSBinFormatMachO();

‎llvm/lib/Analysis/TargetLibraryInfo.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T,
8585
}
8686
// Mips, on the other hand, needs signext on i32 parameters corresponding
8787
// to both signed and unsigned ints.
88-
if (T.getArch() == Triple::mips || T.getArch() == Triple::mipsel ||
89-
T.getArch() == Triple::mips64 || T.getArch() == Triple::mips64el) {
88+
if (T.isMIPS()) {
9089
ShouldSignExtI32Param = true;
9190
}
9291
TLI.setShouldExtI32Param(ShouldExtI32Param);

‎llvm/lib/MC/MCObjectFileInfo.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -529,8 +529,7 @@ void MCObjectFileInfo::initELFMCObjectFileInfo(const Triple &T, bool Large) {
529529
// MIPS .debug_* sections should have SHT_MIPS_DWARF section type
530530
// to distinguish among sections contain DWARF and ECOFF debug formats.
531531
// Sections with ECOFF debug format are obsoleted and marked by SHT_PROGBITS.
532-
if (T.getArch() == Triple::mips || T.getArch() == Triple::mipsel ||
533-
T.getArch() == Triple::mips64 || T.getArch() == Triple::mips64el)
532+
if (T.isMIPS())
534533
DebugSecType = ELF::SHT_MIPS_DWARF;
535534

536535
// Debug Info Sections.

‎llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp

+1-5
Original file line numberDiff line numberDiff line change
@@ -513,11 +513,7 @@ class MipsAsmParser : public MCTargetAsmParser {
513513
CpRestoreOffset = -1;
514514

515515
const Triple &TheTriple = sti.getTargetTriple();
516-
if ((TheTriple.getArch() == Triple::mips) ||
517-
(TheTriple.getArch() == Triple::mips64))
518-
IsLittleEndian = false;
519-
else
520-
IsLittleEndian = true;
516+
IsLittleEndian = TheTriple.isLittleEndian();
521517

522518
if (getSTI().getCPU() == "mips64r6" && inMicroMipsMode())
523519
report_fatal_error("microMIPS64R6 is not supported", false);

‎llvm/lib/Target/Mips/MCTargetDesc/MipsABIInfo.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ MipsABIInfo MipsABIInfo::computeTargetABI(const Triple &TT, StringRef CPU,
5757
return MipsABIInfo::N64();
5858
assert(Options.getABIName().empty() && "Unknown ABI option for MIPS");
5959

60-
if (TT.getArch() == Triple::mips64 || TT.getArch() == Triple::mips64el)
60+
if (TT.isMIPS64())
6161
return MipsABIInfo::N64();
6262
return MipsABIInfo::O32();
6363
}

‎llvm/lib/Target/Mips/MCTargetDesc/MipsMCAsmInfo.cpp

+3-6
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,14 @@ void MipsMCAsmInfo::anchor() { }
2121
MipsMCAsmInfo::MipsMCAsmInfo(const Triple &TheTriple) {
2222
IsLittleEndian = TheTriple.isLittleEndian();
2323

24-
if ((TheTriple.getArch() == Triple::mips64el) ||
25-
(TheTriple.getArch() == Triple::mips64)) {
24+
if (TheTriple.isMIPS64()) {
2625
CodePointerSize = CalleeSaveStackSlotSize = 8;
2726
}
2827

2928
// FIXME: This condition isn't quite right but it's the best we can do until
3029
// this object can identify the ABI. It will misbehave when using O32
3130
// on a mips64*-* triple.
32-
if ((TheTriple.getArch() == Triple::mipsel) ||
33-
(TheTriple.getArch() == Triple::mips)) {
31+
if (TheTriple.isMIPS32()) {
3432
PrivateGlobalPrefix = "$";
3533
PrivateLabelPrefix = "$";
3634
}
@@ -54,8 +52,7 @@ MipsMCAsmInfo::MipsMCAsmInfo(const Triple &TheTriple) {
5452
HasMipsExpressions = true;
5553

5654
// Enable IAS by default for O32.
57-
if (TheTriple.getArch() == Triple::mips ||
58-
TheTriple.getArch() == Triple::mipsel)
55+
if (TheTriple.isMIPS32())
5956
UseIntegratedAssembler = true;
6057

6158
// Enable IAS by default for Debian mips64/mips64el.

‎llvm/lib/Target/Mips/MCTargetDesc/MipsMCTargetDesc.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ using namespace llvm;
4747
/// FIXME: Merge with the copy in MipsSubtarget.cpp
4848
StringRef MIPS_MC::selectMipsCPU(const Triple &TT, StringRef CPU) {
4949
if (CPU.empty() || CPU == "generic") {
50-
if (TT.getArch() == Triple::mips || TT.getArch() == Triple::mipsel)
50+
if (TT.isMIPS32())
5151
CPU = "mips32";
5252
else
5353
CPU = "mips64";

‎llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -493,10 +493,8 @@ static ShadowMapping getShadowMapping(Triple &TargetTriple, int LongSize,
493493
bool IsSystemZ = TargetTriple.getArch() == Triple::systemz;
494494
bool IsX86 = TargetTriple.getArch() == Triple::x86;
495495
bool IsX86_64 = TargetTriple.getArch() == Triple::x86_64;
496-
bool IsMIPS32 = TargetTriple.getArch() == Triple::mips ||
497-
TargetTriple.getArch() == Triple::mipsel;
498-
bool IsMIPS64 = TargetTriple.getArch() == Triple::mips64 ||
499-
TargetTriple.getArch() == Triple::mips64el;
496+
bool IsMIPS32 = TargetTriple.isMIPS32();
497+
bool IsMIPS64 = TargetTriple.isMIPS64();
500498
bool IsArmOrThumb = TargetTriple.isARM() || TargetTriple.isThumb();
501499
bool IsAArch64 = TargetTriple.getArch() == Triple::aarch64;
502500
bool IsWindows = TargetTriple.isOSWindows();

‎llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -539,8 +539,7 @@ TransformedFunction DataFlowSanitizer::getCustomFunctionType(FunctionType *T) {
539539
bool DataFlowSanitizer::doInitialization(Module &M) {
540540
Triple TargetTriple(M.getTargetTriple());
541541
bool IsX86_64 = TargetTriple.getArch() == Triple::x86_64;
542-
bool IsMIPS64 = TargetTriple.getArch() == Triple::mips64 ||
543-
TargetTriple.getArch() == Triple::mips64el;
542+
bool IsMIPS64 = TargetTriple.isMIPS64();
544543
bool IsAArch64 = TargetTriple.getArch() == Triple::aarch64 ||
545544
TargetTriple.getArch() == Triple::aarch64_be;
546545

‎llvm/lib/Transforms/Instrumentation/EfficiencySanitizer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ void EfficiencySanitizer::createDestructor(Module &M, Constant *ToolInfoArg) {
537537
bool EfficiencySanitizer::initOnModule(Module &M) {
538538

539539
Triple TargetTriple(M.getTargetTriple());
540-
if (TargetTriple.getArch() == Triple::mips64 || TargetTriple.getArch() == Triple::mips64el)
540+
if (TargetTriple.isMIPS64())
541541
ShadowParams = ShadowParams40;
542542
else
543543
ShadowParams = ShadowParams47;

‎llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -3980,8 +3980,7 @@ static VarArgHelper *CreateVarArgHelper(Function &Func, MemorySanitizer &Msan,
39803980
Triple TargetTriple(Func.getParent()->getTargetTriple());
39813981
if (TargetTriple.getArch() == Triple::x86_64)
39823982
return new VarArgAMD64Helper(Func, Msan, Visitor);
3983-
else if (TargetTriple.getArch() == Triple::mips64 ||
3984-
TargetTriple.getArch() == Triple::mips64el)
3983+
else if (TargetTriple.isMIPS64())
39853984
return new VarArgMIPS64Helper(Func, Msan, Visitor);
39863985
else if (TargetTriple.getArch() == Triple::aarch64)
39873986
return new VarArgAArch64Helper(Func, Msan, Visitor);

0 commit comments

Comments
 (0)
Please sign in to comment.