If compiling for PPC on an i386 box, the LTO wouldn't get the altivec (and
other) feature information. The workaround is inelegant and could be cleaned up
if this information were available some other way (say, in the IR).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@52447 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/lto2/LTOModule.cpp b/tools/lto2/LTOModule.cpp
index a68fa6c..45c5e2b 100644
--- a/tools/lto2/LTOModule.cpp
+++ b/tools/lto2/LTOModule.cpp
@@ -24,11 +24,11 @@
#include "llvm/Support/MathExtras.h"
#include "llvm/System/Path.h"
#include "llvm/System/Process.h"
+#include "llvm/Target/SubtargetFeature.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetMachineRegistry.h"
#include "llvm/Target/TargetAsmInfo.h"
-
#include <fstream>
using namespace llvm;
@@ -125,11 +125,27 @@
// find machine architecture for this module
const TargetMachineRegistry::entry* march =
TargetMachineRegistry::getClosestStaticTargetForModule(*m, errMsg);
+
if ( march == NULL )
return NULL;
+
// construct LTModule, hand over ownership of module and target
- std::string features;
- TargetMachine* target = march->CtorFn(*m, features);
+ //
+ // FIXME: This is an inelegant way of specifying the features of a
+ // subtarget. It would be better if we could encode this information into
+ // the IR. See <rdar://5972456>.
+ SubtargetFeatures Features;
+ std::string FeatureStr;
+ const char *TargetTriple = m->getTargetTriple().c_str();
+
+ if (strncmp(TargetTriple, "powerpc-apple-", 14) == 0) {
+ Features.AddFeature("altivec", true);
+ } else if (strncmp(TargetTriple, "powerpc64-apple-", 16) == 0) {
+ Features.AddFeature("64bit", true);
+ Features.AddFeature("altivec", true);
+ }
+
+ TargetMachine* target = march->CtorFn(*m, Features.getString());
return new LTOModule(m.take(), target);
}