Refactor the way to get a string containing the features of the target.
authorBill Wendling <isanbard@gmail.com>
Wed, 18 Jun 2008 21:39:02 +0000 (21:39 +0000)
committerBill Wendling <isanbard@gmail.com>
Wed, 18 Jun 2008 21:39:02 +0000 (21:39 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@52470 91177308-0d34-0410-b5e6-96231b3b80d8

tools/lto2/LTOCodeGenerator.cpp
tools/lto2/LTOModule.cpp
tools/lto2/LTOModule.h

index 38ff49cc8c51051827451e5ec82d8e3382acf0e1..5b7a067b4c389cf4400cac14e12f5eedbc8f9781 100644 (file)
@@ -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;
 }
index 45c5e2bc1f92cd8f70a714a037383731b7623753..333e9ba103c337ffb23074548530e96ca0bbb39e 100644 (file)
@@ -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);
 }
 
index fa15850c629298bcea1e8cd8d2a4c9efe0ec6961..40f92f9816523bb2091d9ddecfea38e09ab7ff29 100644 (file)
@@ -99,5 +99,7 @@ private:
     StringSet                               _undefines; 
 };
 
+extern std::string getFeatureString(const char *TargetTriple);
+
 #endif // LTO_MODULE_H