r246259 - Merge the two feature map setting functions into a single function

Eric Christopher via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 27 19:13:58 PDT 2015


Author: echristo
Date: Thu Aug 27 21:13:58 2015
New Revision: 246259

URL: http://llvm.org/viewvc/llvm-project?rev=246259&view=rev
Log:
Merge the two feature map setting functions into a single function
and replace all callers.

Modified:
    cfe/trunk/include/clang/Basic/TargetInfo.h
    cfe/trunk/lib/Basic/Targets.cpp
    cfe/trunk/lib/CodeGen/CGCall.cpp

Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=246259&r1=246258&r2=246259&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
+++ cfe/trunk/include/clang/Basic/TargetInfo.h Thu Aug 27 21:13:58 2015
@@ -742,8 +742,13 @@ public:
 
   /// \brief Initialize the map with the default set of target features for the
   /// CPU this should include all legal feature strings on the target.
-  virtual void initDefaultFeatures(llvm::StringMap<bool> &Features,
-                                   StringRef CPU) const {}
+  ///
+  /// \return False on error (invalid features).
+  virtual bool initFeatureMap(llvm::StringMap<bool> &Features,
+                              DiagnosticsEngine &Diags, StringRef CPU,
+                              std::vector<std::string> &FAW) const {
+    return handleUserFeatures(Features, FAW, Diags);
+  }
 
   /// \brief Get the ABI currently in use.
   virtual StringRef getABI() const { return StringRef(); }

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=246259&r1=246258&r2=246259&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Thu Aug 27 21:13:58 2015
@@ -863,8 +863,9 @@ public:
   void getTargetDefines(const LangOptions &Opts,
                         MacroBuilder &Builder) const override;
 
-  void initDefaultFeatures(llvm::StringMap<bool> &Features,
-                           StringRef CPU) const override;
+  bool initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
+                      StringRef CPU,
+                      std::vector<std::string> &FAW) const override;
 
   bool handleTargetFeatures(std::vector<std::string> &Features,
                             DiagnosticsEngine &Diags) override;
@@ -1050,37 +1051,32 @@ bool PPCTargetInfo::handleTargetFeatures
 }
 
 bool PPCTargetInfo::handleUserFeatures(llvm::StringMap<bool> &Features,
-                                       std::vector<std::string> &UserFeatures,
+                                       std::vector<std::string> &FAW,
                                        DiagnosticsEngine &Diags) const {
-
   // Handle explicit options being passed to the compiler here: if we've
   // explicitly turned off vsx and turned on power8-vector or direct-move then
   // go ahead and error since the customer has expressed a somewhat incompatible
   // set of options.
-  if (std::find(UserFeatures.begin(), UserFeatures.end(), "-vsx") !=
-      UserFeatures.end()) {
-    if (std::find(UserFeatures.begin(), UserFeatures.end(), "+power8-vector") !=
-        UserFeatures.end()) {
+  if (std::find(FAW.begin(), FAW.end(), "-vsx") != FAW.end()) {
+    if (std::find(FAW.begin(), FAW.end(), "+power8-vector") != FAW.end()) {
       Diags.Report(diag::err_opt_not_valid_with_opt) << "-mpower8-vector"
                                                      << "-mno-vsx";
       return false;
     }
 
-    if (std::find(UserFeatures.begin(), UserFeatures.end(), "+direct-move") !=
-        UserFeatures.end()) {
+    if (std::find(FAW.begin(), FAW.end(), "+direct-move") != FAW.end()) {
       Diags.Report(diag::err_opt_not_valid_with_opt) << "-mdirect-move"
                                                      << "-mno-vsx";
       return false;
     }
   }
 
-  for (const auto &F : UserFeatures) {
+  for (const auto &F : FAW) {
     const char *Name = F.c_str();
     // Apply the feature via the target.
     bool Enabled = Name[0] == '+';
     setFeatureEnabled(Features, Name + 1, Enabled);
   }
-
   return true;
 }
 
@@ -1263,8 +1259,9 @@ void PPCTargetInfo::getTargetDefines(con
   //   __NO_FPRS__
 }
 
-void PPCTargetInfo::initDefaultFeatures(llvm::StringMap<bool> &Features,
-                                        StringRef CPU) const {
+bool PPCTargetInfo::initFeatureMap(llvm::StringMap<bool> &Features,
+                                   DiagnosticsEngine &Diags, StringRef CPU,
+                                   std::vector<std::string> &FAW) const {
   Features["altivec"] = llvm::StringSwitch<bool>(CPU)
     .Case("7400", true)
     .Case("g4", true)
@@ -1307,6 +1304,8 @@ void PPCTargetInfo::initDefaultFeatures(
     .Case("pwr8", true)
     .Case("pwr7", true)
     .Default(false);
+
+  return handleUserFeatures(Features, FAW, Diags);
 }
 
 bool PPCTargetInfo::hasFeature(StringRef Feature) const {
@@ -2371,11 +2370,12 @@ public:
     setFeatureEnabledImpl(Features, Name, Enabled);
   }
   // This exists purely to cut down on the number of virtual calls in
-  // initDefaultFeatures which calls this repeatedly.
+  // initFeatureMap which calls this repeatedly.
   static void setFeatureEnabledImpl(llvm::StringMap<bool> &Features,
                                     StringRef Name, bool Enabled);
-  void initDefaultFeatures(llvm::StringMap<bool> &Features,
-                           StringRef CPU) const override;
+  bool initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
+                      StringRef CPU,
+                      std::vector<std::string> &FAW) const override;
   bool hasFeature(StringRef Feature) const override;
   bool handleTargetFeatures(std::vector<std::string> &Features,
                             DiagnosticsEngine &Diags) override;
@@ -2501,8 +2501,9 @@ bool X86TargetInfo::setFPMath(StringRef
   return false;
 }
 
-void X86TargetInfo::initDefaultFeatures(llvm::StringMap<bool> &Features,
-                                        StringRef CPU) const {
+bool X86TargetInfo::initFeatureMap(llvm::StringMap<bool> &Features,
+                                   DiagnosticsEngine &Diags, StringRef CPU,
+                                   std::vector<std::string> &FAW) const {
   // FIXME: This *really* should not be here.
 
   // X86_64 always has SSE2.
@@ -2678,6 +2679,7 @@ void X86TargetInfo::initDefaultFeatures(
     setFeatureEnabledImpl(Features, "cx16", true);
     break;
   }
+  return handleUserFeatures(Features, FAW, Diags);
 }
 
 void X86TargetInfo::setSSELevel(llvm::StringMap<bool> &Features,
@@ -4397,8 +4399,9 @@ public:
   }
 
   // FIXME: This should be based on Arch attributes, not CPU names.
-  void initDefaultFeatures(llvm::StringMap<bool> &Features,
-                           StringRef CPU) const override {
+  bool initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
+                      StringRef CPU,
+                      std::vector<std::string> &FAW) const override {
     if (CPU == "arm1136jf-s" || CPU == "arm1176jzf-s" || CPU == "mpcore")
       Features["vfp2"] = true;
     else if (CPU == "cortex-a8" || CPU == "cortex-a9") {
@@ -4430,6 +4433,7 @@ public:
                CPU == "sc300" || CPU == "cortex-r4" || CPU == "cortex-r4f") {
       Features["hwdiv"] = true;
     }
+    return handleUserFeatures(Features, FAW, Diags);
   }
 
   bool handleTargetFeatures(std::vector<std::string> &Features,
@@ -5841,14 +5845,16 @@ public:
 
     return CPUKnown;
   }
-  void initDefaultFeatures(llvm::StringMap<bool> &Features,
-                           StringRef CPU) const override {
+  bool initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
+                    StringRef CPU,
+                    std::vector<std::string> &FAW) const override {
     if (CPU == "zEC12")
       Features["transactional-execution"] = true;
     if (CPU == "z13") {
       Features["transactional-execution"] = true;
       Features["vector"] = true;
     }
+    return handleUserFeatures(Features, FAW, Diags);
   }
 
   bool handleTargetFeatures(std::vector<std::string> &Features,
@@ -6209,12 +6215,14 @@ public:
         .Default(false);
   }
   const std::string& getCPU() const { return CPU; }
-  void initDefaultFeatures(llvm::StringMap<bool> &Features,
-                           StringRef CPU) const override {
+  bool initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
+                    StringRef CPU,
+                    std::vector<std::string> &FAW) const override {
     if (CPU == "octeon")
       Features["mips64r2"] = Features["cnmips"] = true;
     else
       Features[CPU] = true;
+    return handleUserFeatures(Features, FAW, Diags);
   }
 
   void getTargetDefines(const LangOptions &Opts,
@@ -7500,10 +7508,7 @@ TargetInfo::CreateTargetInfo(Diagnostics
   // Compute the default target features, we need the target to handle this
   // because features may have dependencies on one another.
   llvm::StringMap<bool> Features;
-  Target->initDefaultFeatures(Features, Opts->CPU);
-
-  // Apply the user specified deltas.
-  if (!Target->handleUserFeatures(Features, Opts->FeaturesAsWritten, Diags))
+  if (!Target->initFeatureMap(Features, Diags, Opts->CPU, Opts->FeaturesAsWritten))
       return nullptr;
 
   // Add the features to the compile options.

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=246259&r1=246258&r2=246259&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Thu Aug 27 21:13:58 2015
@@ -1538,8 +1538,7 @@ void CodeGenModule::ConstructAttributeLi
       // the default or a new one from the target attribute string. Then we'll
       // use the passed in features (FeaturesAsWritten) along with the new ones
       // from the attribute.
-      getTarget().initDefaultFeatures(FeatureMap, TargetCPU);
-      getTarget().handleUserFeatures(FeatureMap, FnFeatures, Diags);
+      getTarget().initFeatureMap(FeatureMap, Diags, TargetCPU, FnFeatures);
 
       // Produce the canonical string for this set of features.
       std::vector<std::string> Features;




More information about the cfe-commits mailing list