diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-11-14 22:04:54 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-11-14 22:04:54 +0000 |
commit | f86feddbd5b13d2c144132e35d608fa630784dbb (patch) | |
tree | 531a2233235d3485f15888c4cbeba2441cfa2dc5 | |
parent | 79cbc7dd2aacd85a28f469b5dc73c4ea296e7072 (diff) |
Add clang -mcpu=native support, patch by Roman Divacky, varioustweaks by me.
- We still need support for detecting the target features, since the name
doesn't actually do a good job of decribing what the CPU supports (for LLVM).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@88819 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Driver/Tools.cpp | 35 | ||||
-rw-r--r-- | test/Driver/clang-translation.c | 4 |
2 files changed, 27 insertions, 12 deletions
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index 7a77d56a52..657ebee924 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -26,6 +26,7 @@ #include "llvm/ADT/Twine.h" #include "llvm/Support/Format.h" #include "llvm/Support/raw_ostream.h" +#include "llvm/System/Host.h" #include "llvm/System/Process.h" #include "InputInfo.h" @@ -428,28 +429,42 @@ void Clang::AddX86TargetArgs(const ArgList &Args, false)) CmdArgs.push_back("--no-implicit-float"); + const char *CPUName = 0; if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) { - // FIXME: We may need some translation here from the options gcc takes to - // names the LLVM backend understand? - CmdArgs.push_back("-mcpu"); - CmdArgs.push_back(A->getValue(Args)); - } else { - // Select default CPU. + if (llvm::StringRef(A->getValue(Args)) == "native") { + // FIXME: Reject attempts to use -march=native unless the target matches + // the host. + // + // FIXME: We should also incorporate the detected target features for use + // with -native. + std::string CPU = llvm::sys::getHostCPUName(); + if (!CPU.empty()) + CPUName = Args.MakeArgString(CPU); + } else + CPUName = A->getValue(Args); + } + // Select the default CPU if none was given (or detection failed). + if (!CPUName) { // FIXME: Need target hooks. if (memcmp(getToolChain().getOS().c_str(), "darwin", 6) == 0) { if (getToolChain().getArchName() == "x86_64") - CmdArgs.push_back("--mcpu=core2"); + CPUName = "core2"; else if (getToolChain().getArchName() == "i386") - CmdArgs.push_back("--mcpu=yonah"); + CPUName = "yonah"; } else { if (getToolChain().getArchName() == "x86_64") - CmdArgs.push_back("--mcpu=x86-64"); + CPUName = "x86-64"; else if (getToolChain().getArchName() == "i386") - CmdArgs.push_back("--mcpu=pentium4"); + CPUName = "pentium4"; } } + if (CPUName) { + CmdArgs.push_back("--mcpu"); + CmdArgs.push_back(CPUName); + } + // FIXME: Use iterator. for (ArgList::const_iterator it = Args.begin(), ie = Args.end(); it != ie; ++it) { diff --git a/test/Driver/clang-translation.c b/test/Driver/clang-translation.c index e9ba10dd5d..c57a2b7624 100644 --- a/test/Driver/clang-translation.c +++ b/test/Driver/clang-translation.c @@ -10,6 +10,6 @@ // RUN: grep '"-o" .*clang-translation.*' %t.log // RUN: grep '"--asm-verbose"' %t.log // RUN: clang -ccc-host-triple i386-apple-darwin9 -### -S %s -o %t.s 2> %t.log -// RUN: grep '"--mcpu=yonah"' %t.log +// RUN: grep '"--mcpu" "yonah"' %t.log // RUN: clang -ccc-host-triple x86_64-apple-darwin9 -### -S %s -o %t.s 2> %t.log -// RUN: grep '"--mcpu=core2"' %t.log +// RUN: grep '"--mcpu" "core2"' %t.log |