summaryrefslogtreecommitdiffstats
path: root/llvm/tools/opt/opt.cpp
diff options
context:
space:
mode:
authorCraig Topper <craig.topper@gmail.com>2015-04-01 05:32:04 +0000
committerCraig Topper <craig.topper@gmail.com>2015-04-01 05:32:04 +0000
commitd675e11c2aba4d36dccb7866615dbdb5cf56e232 (patch)
treeb57fc71d24f89f9470abca6623fbe8bc7f95efda /llvm/tools/opt/opt.cpp
parente8eb9e6de3b75890c83b6a9f83de9cc8ed60f073 (diff)
downloadbcm5719-llvm-d675e11c2aba4d36dccb7866615dbdb5cf56e232.tar.gz
bcm5719-llvm-d675e11c2aba4d36dccb7866615dbdb5cf56e232.zip
Add -mcpu=native support to opt.
llvm-svn: 233789
Diffstat (limited to 'llvm/tools/opt/opt.cpp')
-rw-r--r--llvm/tools/opt/opt.cpp18
1 files changed, 17 insertions, 1 deletions
diff --git a/llvm/tools/opt/opt.cpp b/llvm/tools/opt/opt.cpp
index c64e907af22..af86e2dbd60 100644
--- a/llvm/tools/opt/opt.cpp
+++ b/llvm/tools/opt/opt.cpp
@@ -39,6 +39,7 @@
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Host.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/PluginLoader.h"
#include "llvm/Support/PrettyStackTrace.h"
@@ -266,13 +267,28 @@ static TargetMachine* GetTargetMachine(Triple TheTriple) {
// Package up features to be passed to target/subtarget
std::string FeaturesStr;
- if (MAttrs.size()) {
+ if (MAttrs.size() || MCPU == "native") {
SubtargetFeatures Features;
+
+ // If user asked for the 'native' CPU, we need to autodetect features.
+ // This is necessary for x86 where the CPU might not support all the
+ // features the autodetected CPU name lists in the target. For example,
+ // not all Sandybridge processors support AVX.
+ if (MCPU == "native") {
+ StringMap<bool> HostFeatures;
+ if (sys::getHostCPUFeatures(HostFeatures))
+ for (auto &F : HostFeatures)
+ Features.AddFeature(F.first(), F.second);
+ }
+
for (unsigned i = 0; i != MAttrs.size(); ++i)
Features.AddFeature(MAttrs[i]);
FeaturesStr = Features.getString();
}
+ if (MCPU == "native")
+ MCPU = sys::getHostCPUName();
+
return TheTarget->createTargetMachine(TheTriple.getTriple(),
MCPU, FeaturesStr,
InitTargetOptionsFromCodeGenFlags(),
OpenPOWER on IntegriCloud