From 89d83ff23414240555f895d3dad736bd30f5af4e Mon Sep 17 00:00:00 2001 From: Simon Atanasyan Date: Mon, 10 Sep 2012 08:32:41 +0000 Subject: [PATCH] MIPS: Use -march=arch option to select either generic MIPS ISA, or the name of a particular processor. The patch reviewed by Douglas Gregor. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@163492 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Driver/Tools.cpp | 94 ++++++++++++++--------------------- test/Driver/freebsd-mips-as.c | 5 ++ test/Driver/mips-as.c | 5 ++ 3 files changed, 48 insertions(+), 56 deletions(-) diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index 1117202f93..b7ee6ab955 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -777,72 +777,54 @@ void Clang::AddARMTargetArgs(const ArgList &Args, CmdArgs.push_back("-no-implicit-float"); } -// Get default architecture. -static const char* getMipsArchFromCPU(StringRef CPUName) { - if (CPUName == "mips32" || CPUName == "mips32r2") - return "mips"; - - assert((CPUName == "mips64" || CPUName == "mips64r2") && - "Unexpected cpu name."); - - return "mips64"; -} - -// Check that ArchName is a known Mips architecture name. -static bool checkMipsArchName(StringRef ArchName) { - return ArchName == "mips" || - ArchName == "mipsel" || - ArchName == "mips64" || - ArchName == "mips64el"; -} - -// Get default target cpu. -static const char* getMipsCPUFromArch(StringRef ArchName) { - if (ArchName == "mips" || ArchName == "mipsel") - return "mips32"; - - assert((ArchName == "mips64" || ArchName == "mips64el") && - "Unexpected arch name."); - - return "mips64"; -} - -// Get default ABI. -static const char* getMipsABIFromArch(StringRef ArchName) { - if (ArchName == "mips" || ArchName == "mipsel") - return "o32"; - - assert((ArchName == "mips64" || ArchName == "mips64el") && - "Unexpected arch name."); - return "n64"; -} - // Get CPU and ABI names. They are not independent // so we have to calculate them together. static void getMipsCPUAndABI(const ArgList &Args, const ToolChain &TC, StringRef &CPUName, StringRef &ABIName) { - StringRef ArchName; + const char *DefMips32CPU = "mips32"; + const char *DefMips64CPU = "mips64"; - // Select target cpu and architecture. - if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) { + if (Arg *A = Args.getLastArg(options::OPT_march_EQ, + options::OPT_mcpu_EQ)) CPUName = A->getValue(Args); - ArchName = getMipsArchFromCPU(CPUName); - } - else { - ArchName = Args.MakeArgString(TC.getArchName()); - if (!checkMipsArchName(ArchName)) - TC.getDriver().Diag(diag::err_drv_invalid_arch_name) << ArchName; - else - CPUName = getMipsCPUFromArch(ArchName); - } - - // Select the ABI to use. + if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ)) ABIName = A->getValue(Args); - else - ABIName = getMipsABIFromArch(ArchName); + + // Setup default CPU and ABI names. + if (CPUName.empty() && ABIName.empty()) { + switch (TC.getTriple().getArch()) { + default: + llvm_unreachable("Unexpected triple arch name"); + case llvm::Triple::mips: + case llvm::Triple::mipsel: + CPUName = DefMips32CPU; + break; + case llvm::Triple::mips64: + case llvm::Triple::mips64el: + CPUName = DefMips64CPU; + break; + } + } + + if (!ABIName.empty()) { + // Deduce CPU name from ABI name. + CPUName = llvm::StringSwitch(ABIName) + .Cases("o32", "eabi", DefMips32CPU) + .Cases("n32", "n64", DefMips64CPU) + .Default(""); + } + else if (!CPUName.empty()) { + // Deduce ABI name from CPU name. + ABIName = llvm::StringSwitch(CPUName) + .Cases("mips32", "mips32r2", "o32") + .Cases("mips64", "mips64r2", "n64") + .Default(""); + } + + // FIXME: Warn on inconsistent cpu and abi usage. } // Select the MIPS float ABI as determined by -msoft-float, -mhard-float, diff --git a/test/Driver/freebsd-mips-as.c b/test/Driver/freebsd-mips-as.c index 6e7fea31f7..4131caba7e 100644 --- a/test/Driver/freebsd-mips-as.c +++ b/test/Driver/freebsd-mips-as.c @@ -54,3 +54,8 @@ // RUN: -no-integrated-as -c %s 2>&1 \ // RUN: | FileCheck -check-prefix=MIPS-N32 %s // MIPS-N32: as{{(.exe)?}}" "-march" "mips64" "-mabi" "n32" "-EB" +// +// RUN: %clang -target mips-linux-freebsd -march=mips32r2 -### \ +// RUN: -no-integrated-as -c %s 2>&1 \ +// RUN: | FileCheck -check-prefix=MIPS-32R2 %s +// MIPS-32R2: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-EB" diff --git a/test/Driver/mips-as.c b/test/Driver/mips-as.c index da6b777e1a..95b93b791c 100644 --- a/test/Driver/mips-as.c +++ b/test/Driver/mips-as.c @@ -38,3 +38,8 @@ // RUN: -no-integrated-as -c %s 2>&1 \ // RUN: | FileCheck -check-prefix=MIPS-N32 %s // MIPS-N32: as{{(.exe)?}}" "-march" "mips64" "-mabi" "n32" "-EB" +// +// RUN: %clang -target mips-linux-gnu -march=mips32r2 -### \ +// RUN: -no-integrated-as -c %s 2>&1 \ +// RUN: | FileCheck -check-prefix=MIPS-32R2 %s +// MIPS-32R2: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-EB" -- 2.40.0