diff --git a/include/llvm/ADT/Triple.h b/include/llvm/ADT/Triple.h index 76fe6d38f2d..5e4a0fed6f2 100644 --- a/include/llvm/ADT/Triple.h +++ b/include/llvm/ADT/Triple.h @@ -56,9 +56,9 @@ public: bpfeb, // eBPF or extended BPF or 64-bit BPF (big endian) hexagon, // Hexagon: hexagon mips, // MIPS: mips, mipsallegrex - mipsel, // MIPSEL: mipsel, mipsallegrexel - mips64, // MIPS64: mips64 - mips64el, // MIPS64EL: mips64el + mipsel, // MIPSEL: mipsel, mipsallegrexe + mips64, // MIPS64: mips64, mipsn32 + mips64el, // MIPS64EL: mips64el, mipsn32el msp430, // MSP430: msp430 nios2, // NIOSII: nios2 ppc, // PPC: powerpc diff --git a/lib/Support/Triple.cpp b/lib/Support/Triple.cpp index d1017fb2a28..b56d1d9eff2 100644 --- a/lib/Support/Triple.cpp +++ b/lib/Support/Triple.cpp @@ -401,8 +401,8 @@ static Triple::ArchType parseArch(StringRef ArchName) { .Case("msp430", Triple::msp430) .Cases("mips", "mipseb", "mipsallegrex", Triple::mips) .Cases("mipsel", "mipsallegrexel", Triple::mipsel) - .Cases("mips64", "mips64eb", Triple::mips64) - .Case("mips64el", Triple::mips64el) + .Cases("mips64", "mips64eb", "mipsn32", Triple::mips64) + .Cases("mips64el", "mipsn32el", Triple::mips64el) .Case("nios2", Triple::nios2) .Case("r600", Triple::r600) .Case("amdgcn", Triple::amdgcn) @@ -711,6 +711,14 @@ Triple::Triple(const Twine &Str) ObjectFormat = parseFormat(Components[3]); } } + } else { + Environment = StringSwitch(Components[0]) + .StartsWith("mipsn32", Triple::GNUABIN32) + .StartsWith("mips64", Triple::GNUABI64) + .StartsWith("mipsisa64", Triple::GNUABI64) + .StartsWith("mipsisa32", Triple::GNU) + .Cases("mips", "mipsel", Triple::GNU) + .Default(UnknownEnvironment); } } if (ObjectFormat == UnknownObjectFormat) diff --git a/lib/Target/Mips/MCTargetDesc/MipsABIInfo.cpp b/lib/Target/Mips/MCTargetDesc/MipsABIInfo.cpp index bf139088028..18d7dd99be3 100644 --- a/lib/Target/Mips/MCTargetDesc/MipsABIInfo.cpp +++ b/lib/Target/Mips/MCTargetDesc/MipsABIInfo.cpp @@ -55,6 +55,8 @@ MipsABIInfo MipsABIInfo::computeTargetABI(const Triple &TT, StringRef CPU, return MipsABIInfo::N32(); if (Options.getABIName().startswith("n64")) return MipsABIInfo::N64(); + if (TT.getEnvironment() == llvm::Triple::GNUABIN32) + return MipsABIInfo::N32(); assert(Options.getABIName().empty() && "Unknown ABI option for MIPS"); if (TT.isMIPS64()) diff --git a/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp b/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp index 4397c971d08..4544be9f27f 100644 --- a/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp +++ b/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp @@ -13,6 +13,7 @@ // #include "MCTargetDesc/MipsAsmBackend.h" +#include "MCTargetDesc/MipsABIInfo.h" #include "MCTargetDesc/MipsFixupKinds.h" #include "MCTargetDesc/MipsMCExpr.h" #include "MCTargetDesc/MipsMCTargetDesc.h" @@ -572,6 +573,6 @@ MCAsmBackend *llvm::createMipsAsmBackend(const Target &T, const MCSubtargetInfo &STI, const MCRegisterInfo &MRI, const MCTargetOptions &Options) { - return new MipsAsmBackend(T, MRI, STI.getTargetTriple(), STI.getCPU(), - Options.ABIName == "n32"); + MipsABIInfo ABI = MipsABIInfo::computeTargetABI(STI.getTargetTriple(), STI.getCPU(), Options); + return new MipsAsmBackend(T, MRI, STI.getTargetTriple(), STI.getCPU(), ABI.IsN32()); } diff --git a/lib/Target/Mips/MCTargetDesc/MipsMCAsmInfo.cpp b/lib/Target/Mips/MCTargetDesc/MipsMCAsmInfo.cpp index f498d830c8f..0a8d5677241 100644 --- a/lib/Target/Mips/MCTargetDesc/MipsMCAsmInfo.cpp +++ b/lib/Target/Mips/MCTargetDesc/MipsMCAsmInfo.cpp @@ -59,6 +59,10 @@ MipsMCAsmInfo::MipsMCAsmInfo(const Triple &TheTriple) { if (TheTriple.getEnvironment() == Triple::GNUABI64) UseIntegratedAssembler = true; + // Enable IAS by default for Debian mipsn32/mipsn32el. + if (TheTriple.getEnvironment() == Triple::GNUABIN32) + UseIntegratedAssembler = true; + // Enable IAS by default for Android mips64el that uses N64 ABI. if (TheTriple.getArch() == Triple::mips64el && TheTriple.isAndroid()) UseIntegratedAssembler = true; diff --git a/test/MC/Mips/elf-N32.s b/test/MC/Mips/elf-N32.s index 34a0cd0f8be..853973152b3 100644 --- a/test/MC/Mips/elf-N32.s +++ b/test/MC/Mips/elf-N32.s @@ -2,6 +2,10 @@ // RUN: llvm-mc -filetype=obj -triple=mips64-linux-gnu -mcpu=mips3 \ // RUN: -target-abi=n32 %s -o - | llvm-readobj -r | FileCheck %s +// RUN: llvm-mc -filetype=obj -triple=mips64-linux-gnuabin32 -mcpu=mips3 \ +// RUN: %s -o - | llvm-readobj -r | FileCheck %s +// RUN: llvm-mc -filetype=obj -triple=mipsn32 -mcpu=mips3 \ +// RUN: %s -o - | llvm-readobj -r | FileCheck %s // CHECK: Relocations [ // CHECK-NEXT: Section (3) .rela.text { diff --git a/unittests/ADT/TripleTest.cpp b/unittests/ADT/TripleTest.cpp index 7da8cffd422..7991f2a476e 100644 --- a/unittests/ADT/TripleTest.cpp +++ b/unittests/ADT/TripleTest.cpp @@ -366,6 +366,59 @@ TEST(TripleTest, ParsedIDs) { EXPECT_EQ(Triple::UnknownVendor, T.getVendor()); EXPECT_EQ(Triple::Linux, T.getOS()); EXPECT_EQ(Triple::GNUABI64, T.getEnvironment()); + T = Triple("mips64el"); + EXPECT_EQ(Triple::mips64el, T.getArch()); + EXPECT_EQ(Triple::UnknownVendor, T.getVendor()); + EXPECT_EQ(Triple::GNUABI64, T.getEnvironment()); + + T = Triple("mips64-unknown-linux-gnuabi64"); + EXPECT_EQ(Triple::mips64, T.getArch()); + EXPECT_EQ(Triple::UnknownVendor, T.getVendor()); + EXPECT_EQ(Triple::Linux, T.getOS()); + EXPECT_EQ(Triple::GNUABI64, T.getEnvironment()); + T = Triple("mips64"); + EXPECT_EQ(Triple::mips64, T.getArch()); + EXPECT_EQ(Triple::UnknownVendor, T.getVendor()); + EXPECT_EQ(Triple::GNUABI64, T.getEnvironment()); + + T = Triple("mips64el-unknown-linux-gnuabin32"); + EXPECT_EQ(Triple::mips64el, T.getArch()); + EXPECT_EQ(Triple::UnknownVendor, T.getVendor()); + EXPECT_EQ(Triple::Linux, T.getOS()); + EXPECT_EQ(Triple::GNUABIN32, T.getEnvironment()); + T = Triple("mipsn32el"); + EXPECT_EQ(Triple::mips64el, T.getArch()); + EXPECT_EQ(Triple::UnknownVendor, T.getVendor()); + EXPECT_EQ(Triple::GNUABIN32, T.getEnvironment()); + + T = Triple("mips64-unknown-linux-gnuabin32"); + EXPECT_EQ(Triple::mips64, T.getArch()); + EXPECT_EQ(Triple::UnknownVendor, T.getVendor()); + EXPECT_EQ(Triple::Linux, T.getOS()); + EXPECT_EQ(Triple::GNUABIN32, T.getEnvironment()); + T = Triple("mipsn32"); + EXPECT_EQ(Triple::mips64, T.getArch()); + EXPECT_EQ(Triple::UnknownVendor, T.getVendor()); + EXPECT_EQ(Triple::GNUABIN32, T.getEnvironment()); + + T = Triple("mipsel-unknown-linux-gnu"); + EXPECT_EQ(Triple::mipsel, T.getArch()); + EXPECT_EQ(Triple::UnknownVendor, T.getVendor()); + EXPECT_EQ(Triple::Linux, T.getOS()); + EXPECT_EQ(Triple::GNU, T.getEnvironment()); + T = Triple("mipsel"); + EXPECT_EQ(Triple::mipsel, T.getArch()); + EXPECT_EQ(Triple::UnknownVendor, T.getVendor()); + EXPECT_EQ(Triple::GNU, T.getEnvironment()); + + T = Triple("mips-unknown-linux-gnu"); + EXPECT_EQ(Triple::mips, T.getArch()); + EXPECT_EQ(Triple::UnknownVendor, T.getVendor()); + EXPECT_EQ(Triple::GNU, T.getEnvironment()); + T = Triple("mips"); + EXPECT_EQ(Triple::mips, T.getArch()); + EXPECT_EQ(Triple::UnknownVendor, T.getVendor()); + EXPECT_EQ(Triple::GNU, T.getEnvironment()); T = Triple("arm-oe-linux-gnueabi"); EXPECT_EQ(Triple::arm, T.getArch());