mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-26 23:24:34 +00:00
Factor out a function which determines the cpu and feature strings based on
command line options -mcpu and -mattr. NFC. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@236671 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user