From e823db8bae7fe42cd4f1fa861bec8c36a636702b Mon Sep 17 00:00:00 2001 From: Viktor Kutuzov Date: Wed, 18 Nov 2009 20:20:05 +0000 Subject: [PATCH] Added getDefaultSubtargetFeatures method to SubtargetFeatures class which returns a correct feature string for given triple. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@89236 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Target/SubtargetFeature.h | 5 +++++ lib/Target/SubtargetFeature.cpp | 27 +++++++++++++++++++++++++++ tools/lto/LTOCodeGenerator.cpp | 3 ++- tools/lto/LTOModule.cpp | 25 +++---------------------- tools/lto/LTOModule.h | 2 -- 5 files changed, 37 insertions(+), 25 deletions(-) diff --git a/include/llvm/Target/SubtargetFeature.h b/include/llvm/Target/SubtargetFeature.h index a709f523897..38a3cc2fefa 100644 --- a/include/llvm/Target/SubtargetFeature.h +++ b/include/llvm/Target/SubtargetFeature.h @@ -21,6 +21,7 @@ #include #include #include +#include "llvm/ADT/Triple.h" #include "llvm/System/DataTypes.h" namespace llvm { @@ -106,6 +107,10 @@ public: // Dump feature info. void dump() const; + + /// Retrieve a formatted string of the default features for + /// the specified target triple. + static std::string getDefaultSubtargetFeatures(const Triple &Triple); }; } // End namespace llvm diff --git a/lib/Target/SubtargetFeature.cpp b/lib/Target/SubtargetFeature.cpp index 664a43cbcca..590574ef398 100644 --- a/lib/Target/SubtargetFeature.cpp +++ b/lib/Target/SubtargetFeature.cpp @@ -357,3 +357,30 @@ void SubtargetFeatures::print(raw_ostream &OS) const { void SubtargetFeatures::dump() const { print(errs()); } + +/// getDefaultSubtargetFeatures - 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 . +/// +std::string SubtargetFeatures::getDefaultSubtargetFeatures( + const Triple& Triple) { + switch (Triple.getVendor()) { + case Triple::Apple: + switch (Triple.getArch()) { + case Triple::ppc: // powerpc-apple-* + return std::string("altivec"); + case Triple::ppc64: // powerpc64-apple-* + return std::string("64bit,altivec"); + default: + break; + } + break; + default: + break; + } + + return std::string(""); +} diff --git a/tools/lto/LTOCodeGenerator.cpp b/tools/lto/LTOCodeGenerator.cpp index eb82f984d7b..0b9cb2952e8 100644 --- a/tools/lto/LTOCodeGenerator.cpp +++ b/tools/lto/LTOCodeGenerator.cpp @@ -305,7 +305,8 @@ bool LTOCodeGenerator::determineTarget(std::string& errMsg) } // construct LTModule, hand over ownership of module and target - std::string FeatureStr = getFeatureString(Triple.c_str()); + const std::string FeatureStr = + SubtargetFeatures::getDefaultSubtargetFeatures(llvm::Triple(Triple)); _target = march->createTargetMachine(Triple, FeatureStr); } return false; diff --git a/tools/lto/LTOModule.cpp b/tools/lto/LTOModule.cpp index e1cf48d3c84..bce416207c4 100644 --- a/tools/lto/LTOModule.cpp +++ b/tools/lto/LTOModule.cpp @@ -19,6 +19,7 @@ #include "llvm/Module.h" #include "llvm/ModuleProvider.h" #include "llvm/ADT/OwningPtr.h" +#include "llvm/ADT/Triple.h" #include "llvm/Bitcode/ReaderWriter.h" #include "llvm/Support/SystemUtils.h" #include "llvm/Support/Mangler.h" @@ -120,27 +121,6 @@ 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 . -std::string getFeatureString(const char *TargetTriple) { - InitializeAllTargets(); - - 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) { @@ -161,7 +141,8 @@ LTOModule* LTOModule::makeLTOModule(MemoryBuffer* buffer, return NULL; // construct LTModule, hand over ownership of module and target - std::string FeatureStr = getFeatureString(Triple.c_str()); + const std::string FeatureStr = + SubtargetFeatures::getDefaultSubtargetFeatures(llvm::Triple(Triple)); TargetMachine* target = march->createTargetMachine(Triple, FeatureStr); return new LTOModule(m.take(), target); } diff --git a/tools/lto/LTOModule.h b/tools/lto/LTOModule.h index 8fd3915e28c..4019e015a5d 100644 --- a/tools/lto/LTOModule.h +++ b/tools/lto/LTOModule.h @@ -107,7 +107,5 @@ private: llvm::StringMap _undefines; }; -extern std::string getFeatureString(const char *TargetTriple); - #endif // LTO_MODULE_H -- 2.11.0