[llvm-commits] [llvm] r52470 - in /llvm/trunk/tools/lto2: LTOCodeGenerator.cpp LTOModule.cpp LTOModule.h

Bill Wendling isanbard at gmail.com
Wed Jun 18 14:39:02 PDT 2008


Author: void
Date: Wed Jun 18 16:39:02 2008
New Revision: 52470

URL: http://llvm.org/viewvc/llvm-project?rev=52470&view=rev
Log:
Refactor the way to get a string containing the features of the target.

Modified:
    llvm/trunk/tools/lto2/LTOCodeGenerator.cpp
    llvm/trunk/tools/lto2/LTOModule.cpp
    llvm/trunk/tools/lto2/LTOModule.h

Modified: llvm/trunk/tools/lto2/LTOCodeGenerator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lto2/LTOCodeGenerator.cpp?rev=52470&r1=52469&r2=52470&view=diff

==============================================================================
--- llvm/trunk/tools/lto2/LTOCodeGenerator.cpp (original)
+++ llvm/trunk/tools/lto2/LTOCodeGenerator.cpp Wed Jun 18 16:39:02 2008
@@ -264,22 +264,9 @@
             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;
 }

Modified: llvm/trunk/tools/lto2/LTOModule.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lto2/LTOModule.cpp?rev=52470&r1=52469&r2=52470&view=diff

==============================================================================
--- llvm/trunk/tools/lto2/LTOModule.cpp (original)
+++ llvm/trunk/tools/lto2/LTOModule.cpp Wed Jun 18 16:39:02 2008
@@ -116,6 +116,25 @@
     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 @@
         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);
 }
 

Modified: llvm/trunk/tools/lto2/LTOModule.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lto2/LTOModule.h?rev=52470&r1=52469&r2=52470&view=diff

==============================================================================
--- llvm/trunk/tools/lto2/LTOModule.h (original)
+++ llvm/trunk/tools/lto2/LTOModule.h Wed Jun 18 16:39:02 2008
@@ -99,5 +99,7 @@
     StringSet                               _undefines; 
 };
 
+extern std::string getFeatureString(const char *TargetTriple);
+
 #endif // LTO_MODULE_H
 





More information about the llvm-commits mailing list