aboutsummaryrefslogtreecommitdiffstats
path: root/tools/lto2
diff options
context:
space:
mode:
authorBill Wendling <isanbard@gmail.com>2008-06-18 21:39:02 +0000
committerBill Wendling <isanbard@gmail.com>2008-06-18 21:39:02 +0000
commite4242548976c04183a532695666803fb6a40ba06 (patch)
tree54df6526ea94733177b2f8394f497b11cdd7be51 /tools/lto2
parentf7acf8f288a3e012df363f18aeca788300ddb416 (diff)
downloadexternal_llvm-e4242548976c04183a532695666803fb6a40ba06.zip
external_llvm-e4242548976c04183a532695666803fb6a40ba06.tar.gz
external_llvm-e4242548976c04183a532695666803fb6a40ba06.tar.bz2
Refactor the way to get a string containing the features of the target.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@52470 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/lto2')
-rw-r--r--tools/lto2/LTOCodeGenerator.cpp19
-rw-r--r--tools/lto2/LTOModule.cpp37
-rw-r--r--tools/lto2/LTOModule.h2
3 files changed, 26 insertions, 32 deletions
diff --git a/tools/lto2/LTOCodeGenerator.cpp b/tools/lto2/LTOCodeGenerator.cpp
index 38ff49c..5b7a067 100644
--- a/tools/lto2/LTOCodeGenerator.cpp
+++ b/tools/lto2/LTOCodeGenerator.cpp
@@ -264,22 +264,9 @@ bool LTOCodeGenerator::determineTarget(std::string& errMsg)
return true;
// construct LTModule, hand over ownership of module and target
- //
- // 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;
- std::string TargetTriple = _linker.getModule()->getTargetTriple();
-
- if (strncmp(TargetTriple.c_str(), "powerpc-apple-", 14) == 0) {
- Features.AddFeature("altivec", true);
- } else if (strncmp(TargetTriple.c_str(), "powerpc64-apple-", 16) == 0) {
- Features.AddFeature("64bit", true);
- Features.AddFeature("altivec", true);
- }
-
- _target = march->CtorFn(*mergedModule, Features.getString());
+ std::string FeatureStr =
+ getFeatureString(_linker.getModule()->getTargetTriple().c_str());
+ _target = march->CtorFn(*mergedModule, FeatureStr.c_str());
}
return false;
}
diff --git a/tools/lto2/LTOModule.cpp b/tools/lto2/LTOModule.cpp
index 45c5e2b..333e9ba 100644
--- a/tools/lto2/LTOModule.cpp
+++ b/tools/lto2/LTOModule.cpp
@@ -116,6 +116,25 @@ LTOModule* LTOModule::makeLTOModule(const void* mem, size_t length,
return makeLTOModule(buffer.get(), errMsg);
}
+/// getFeatureString - Return a string listing the features associated with the
+/// target triple.
+///
+/// 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>.
+std::string getFeatureString(const char *TargetTriple) {
+ SubtargetFeatures Features;
+
+ 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);
+ }
+
+ return Features.getString();
+}
+
LTOModule* LTOModule::makeLTOModule(MemoryBuffer* buffer, std::string& errMsg)
{
// parse bitcode buffer
@@ -130,22 +149,8 @@ LTOModule* LTOModule::makeLTOModule(MemoryBuffer* buffer, std::string& errMsg)
return NULL;
// construct LTModule, hand over ownership of module and target
- //
- // 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());
+ std::string FeatureStr = getFeatureString(m->getTargetTriple().c_str());
+ TargetMachine* target = march->CtorFn(*m, FeatureStr);
return new LTOModule(m.take(), target);
}
diff --git a/tools/lto2/LTOModule.h b/tools/lto2/LTOModule.h
index fa15850..40f92f9 100644
--- a/tools/lto2/LTOModule.h
+++ b/tools/lto2/LTOModule.h
@@ -99,5 +99,7 @@ private:
StringSet _undefines;
};
+extern std::string getFeatureString(const char *TargetTriple);
+
#endif // LTO_MODULE_H