diff options
author | Simon Atanasyan <satanasyan@mips.com> | 2012-09-10 08:32:41 +0000 |
---|---|---|
committer | Simon Atanasyan <satanasyan@mips.com> | 2012-09-10 08:32:41 +0000 |
commit | 89d83ff23414240555f895d3dad736bd30f5af4e (patch) | |
tree | 8be7ff780057d3d12ed1ba0687417ed717d50bc3 /lib/Driver/Tools.cpp | |
parent | c265cddad7f9ca9eda1e7d08c2595ec73acec724 (diff) |
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
Diffstat (limited to 'lib/Driver/Tools.cpp')
-rw-r--r-- | lib/Driver/Tools.cpp | 94 |
1 files changed, 38 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<const char *>(ABIName) + .Cases("o32", "eabi", DefMips32CPU) + .Cases("n32", "n64", DefMips64CPU) + .Default(""); + } + else if (!CPUName.empty()) { + // Deduce ABI name from CPU name. + ABIName = llvm::StringSwitch<const char *>(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, |