diff options
| author | Akira Hatanaka <ahatanaka@apple.com> | 2015-05-06 23:49:24 +0000 |
|---|---|---|
| committer | Akira Hatanaka <ahatanaka@apple.com> | 2015-05-06 23:49:24 +0000 |
| commit | 32b3760cf3483f64475acf7d24f31ac3f1b66176 (patch) | |
| tree | 27321b774b2c99457ecf73650cb7d3c7e7ec6444 /llvm/tools/opt | |
| parent | e66a45fdb4ceb0ffab3ae1d5452583f9b064aecc (diff) | |
| download | bcm5719-llvm-32b3760cf3483f64475acf7d24f31ac3f1b66176.tar.gz bcm5719-llvm-32b3760cf3483f64475acf7d24f31ac3f1b66176.zip | |
Factor out a function which determines the cpu and feature strings based on
command line options -mcpu and -mattr. NFC.
llvm-svn: 236671
Diffstat (limited to 'llvm/tools/opt')
| -rw-r--r-- | llvm/tools/opt/opt.cpp | 38 |
1 files changed, 10 insertions, 28 deletions
diff --git a/llvm/tools/opt/opt.cpp b/llvm/tools/opt/opt.cpp index 80b1934366a..8f2b3f7a72b 100644 --- a/llvm/tools/opt/opt.cpp +++ b/llvm/tools/opt/opt.cpp @@ -264,7 +264,8 @@ static CodeGenOpt::Level GetCodeGenOptLevel() { } // Returns the TargetMachine instance or zero if no triple is provided. -static TargetMachine* GetTargetMachine(Triple TheTriple) { +static TargetMachine* GetTargetMachine(Triple TheTriple, StringRef CPUStr, + StringRef FeaturesStr) { std::string Error; const Target *TheTarget = TargetRegistry::lookupTarget(MArch, TheTriple, Error); @@ -273,32 +274,8 @@ static TargetMachine* GetTargetMachine(Triple TheTriple) { return nullptr; } - // Package up features to be passed to target/subtarget - std::string FeaturesStr; - 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, + CPUStr, FeaturesStr, InitTargetOptionsFromCodeGenFlags(), RelocModel, CMModel, GetCodeGenOptLevel()); @@ -407,9 +384,14 @@ int main(int argc, char **argv) { } Triple ModuleTriple(M->getTargetTriple()); + std::string CPUStr, FeaturesStr; TargetMachine *Machine = nullptr; - if (ModuleTriple.getArch()) - Machine = GetTargetMachine(ModuleTriple); + if (ModuleTriple.getArch()) { + CPUStr = getCPUStr(); + FeaturesStr = getFeaturesStr(); + Machine = GetTargetMachine(ModuleTriple, CPUStr, FeaturesStr); + } + std::unique_ptr<TargetMachine> TM(Machine); // If the output is set to be emitted to standard out, and standard out is a |

