From: Benjamin Kramer Date: Mon, 21 Oct 2013 12:33:55 +0000 (+0000) Subject: Driver: Various string-related cleanups. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=39e4b0fb309dc43d017d1b831a6b685c39bdedee;p=clang Driver: Various string-related cleanups. Also fixes some funky formatting. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@193079 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index 4592308e1a..3217525fba 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -1169,7 +1169,7 @@ static void getPPCTargetFeatures(const ArgList &Args, /// Get the (LLVM) name of the R600 gpu we are targeting. static std::string getR600TargetGPU(const ArgList &Args) { if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) { - std::string GPUName = A->getValue(); + const char *GPUName = A->getValue(); return llvm::StringSwitch(GPUName) .Cases("rv630", "rv635", "r600") .Cases("rv610", "rv620", "rs780", "rs880") @@ -1178,7 +1178,7 @@ static std::string getR600TargetGPU(const ArgList &Args) { .Cases("sumo", "sumo2", "sumo") .Case("hemlock", "cypress") .Case("aruba", "cayman") - .Default(GPUName.c_str()); + .Default(GPUName); } return ""; } @@ -1261,27 +1261,28 @@ static const char *getX86TargetCPU(const ArgList &Args, if (Triple.isOSDarwin()) return Is64Bit ? "core2" : "yonah"; + // All x86 devices running Android have core2 as their common + // denominator. This makes a better choice than pentium4. + if (Triple.getEnvironment() == llvm::Triple::Android) + return "core2"; + // Everything else goes to x86-64 in 64-bit mode. if (Is64Bit) return "x86-64"; - if (Triple.getOSName().startswith("haiku")) - return "i586"; - if (Triple.getOSName().startswith("openbsd")) + switch (Triple.getOS()) { + case llvm::Triple::FreeBSD: + case llvm::Triple::NetBSD: + case llvm::Triple::OpenBSD: return "i486"; - if (Triple.getOSName().startswith("bitrig")) + case llvm::Triple::Haiku: + return "i586"; + case llvm::Triple::Bitrig: return "i686"; - if (Triple.getOSName().startswith("freebsd")) - return "i486"; - if (Triple.getOSName().startswith("netbsd")) - return "i486"; - // All x86 devices running Android have core2 as their common - // denominator. This makes a better choice than pentium4. - if (Triple.getEnvironment() == llvm::Triple::Android) - return "core2"; - - // Fallback to p4. - return "pentium4"; + default: + // Fallback to p4. + return "pentium4"; + } } static std::string getCPUName(const ArgList &Args, const llvm::Triple &T) { @@ -4391,10 +4392,7 @@ void hexagon::Link::ConstructJob(Compilation &C, const JobAction &JA, } std::string Linker = ToolChain.GetProgramPath("hexagon-ld"); - C.addCommand( - new Command( - JA, *this, - Args.MakeArgString(Linker), CmdArgs)); + C.addCommand(new Command(JA, *this, Args.MakeArgString(Linker), CmdArgs)); } // Hexagon tools end. @@ -5056,18 +5054,17 @@ void solaris::Link::ConstructJob(Compilation &C, const JobAction &JA, std::string LibPath = "/usr/lib/"; llvm::Triple::ArchType Arch = T.getArch(); switch (Arch) { - case llvm::Triple::x86: - GCCLibPath += ("i386-" + T.getVendorName() + "-" + - T.getOSName()).str() + "/4.5.2/"; - break; - case llvm::Triple::x86_64: - GCCLibPath += ("i386-" + T.getVendorName() + "-" + - T.getOSName()).str(); - GCCLibPath += "/4.5.2/amd64/"; - LibPath += "amd64/"; - break; - default: - assert(0 && "Unsupported architecture"); + case llvm::Triple::x86: + GCCLibPath += + ("i386-" + T.getVendorName() + "-" + T.getOSName()).str() + "/4.5.2/"; + break; + case llvm::Triple::x86_64: + GCCLibPath += ("i386-" + T.getVendorName() + "-" + T.getOSName()).str(); + GCCLibPath += "/4.5.2/amd64/"; + LibPath += "amd64/"; + break; + default: + llvm_unreachable("Unsupported architecture"); } ArgStringList CmdArgs; @@ -5522,23 +5519,21 @@ void bitrig::Link::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back("-lc"); } - std::string myarch = "-lclang_rt."; - const llvm::Triple &T = getToolChain().getTriple(); - llvm::Triple::ArchType Arch = T.getArch(); - switch (Arch) { - case llvm::Triple::arm: - myarch += ("arm"); - break; - case llvm::Triple::x86: - myarch += ("i386"); - break; - case llvm::Triple::x86_64: - myarch += ("amd64"); - break; - default: - assert(0 && "Unsupported architecture"); - } - CmdArgs.push_back(Args.MakeArgString(myarch)); + StringRef MyArch; + switch (getToolChain().getTriple().getArch()) { + case llvm::Triple::arm: + MyArch = "arm"; + break; + case llvm::Triple::x86: + MyArch = "i386"; + break; + case llvm::Triple::x86_64: + MyArch = "amd64"; + break; + default: + llvm_unreachable("Unsupported architecture"); + } + CmdArgs.push_back(Args.MakeArgString("-lclang_rt." + MyArch)); } if (!Args.hasArg(options::OPT_nostdlib) &&