Set default CPU for Darwin targets with LTO. <rdar://problem/12457841>

This is a temporary hack until Bill's project to record command line options
in the LLVM IR is ready. Clang currently sets a default CPU but that isn't
recorded anywhere and it doesn't get used in the final LTO compilation.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@165809 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Bob Wilson
2012-10-12 17:39:25 +00:00
parent 20ce6e6562
commit 47ed8a161c
2 changed files with 28 additions and 12 deletions

View File

@@ -218,12 +218,13 @@ bool LTOCodeGenerator::determineTarget(std::string& errMsg) {
if (_target != NULL)
return false;
std::string Triple = _linker.getModule()->getTargetTriple();
if (Triple.empty())
Triple = sys::getDefaultTargetTriple();
std::string TripleStr = _linker.getModule()->getTargetTriple();
if (TripleStr.empty())
TripleStr = sys::getDefaultTargetTriple();
llvm::Triple Triple(TripleStr);
// create target machine from info for merged modules
const Target *march = TargetRegistry::lookupTarget(Triple, errMsg);
const Target *march = TargetRegistry::lookupTarget(TripleStr, errMsg);
if (march == NULL)
return true;
@@ -244,11 +245,18 @@ bool LTOCodeGenerator::determineTarget(std::string& errMsg) {
// construct LTOModule, hand over ownership of module and target
SubtargetFeatures Features;
Features.getDefaultSubtargetFeatures(llvm::Triple(Triple));
Features.getDefaultSubtargetFeatures(Triple);
std::string FeatureStr = Features.getString();
// Set a default CPU for Darwin triples.
if (_mCpu.empty() && Triple.isOSDarwin()) {
if (Triple.getArch() == llvm::Triple::x86_64)
_mCpu = "core2";
else if (Triple.getArch() == llvm::Triple::x86)
_mCpu = "yonah";
}
TargetOptions Options;
LTOModule::getTargetOptions(Options);
_target = march->createTargetMachine(Triple, _mCpu, FeatureStr, Options,
_target = march->createTargetMachine(TripleStr, _mCpu, FeatureStr, Options,
RelocModel, CodeModel::Default,
CodeGenOpt::Aggressive);
return false;