1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 03:02:36 +01:00

Add -mcpu=native support to opt.

llvm-svn: 233789
This commit is contained in:
Craig Topper 2015-04-01 05:32:04 +00:00
parent 228c1dbd4c
commit ab9b206e4a

View File

@ -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(),