tra created this revision.
tra added a reviewer: echristo.
Herald added subscribers: jlebar, sanjoy.

In some cases figuring out whether particular target builtin
should be enabled is a bit more complicated than current
implementation allow. This patch allows the target to override
what it considers for required feature to be enabled/disabled.

This will be used in the upcoming patch which needs to have some
NVPTX builtins enabled for a range of GPUs depending on detected
CUDA version.


https://reviews.llvm.org/D45060

Files:
  clang/include/clang/Basic/TargetInfo.h
  clang/lib/CodeGen/CodeGenFunction.cpp


Index: clang/lib/CodeGen/CodeGenFunction.cpp
===================================================================
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -2262,6 +2262,12 @@
         Feature.split(OrFeatures, "|");
         return std::any_of(OrFeatures.begin(), OrFeatures.end(),
                            [&](StringRef Feature) {
+                             // Check if the target wants to handle the 
feature.
+                             if (auto OR = CGM.getTarget().hasRequiredFeature(
+                                     CallerFeatureMap, Feature))
+                               return OR.getValue();
+                             // Otherwise just look for the feature
+                             // presence/absence in the CallerFeatureMap.
                              if (!CallerFeatureMap.lookup(Feature)) {
                                FirstMissing = Feature.str();
                                return false;
Index: clang/include/clang/Basic/TargetInfo.h
===================================================================
--- clang/include/clang/Basic/TargetInfo.h
+++ clang/include/clang/Basic/TargetInfo.h
@@ -928,8 +928,18 @@
     return false;
   }
 
-  /// \brief Identify whether this taret supports multiversioning of functions,
-  /// which requires support for cpu_supports and cpu_is functionality.
+  /// \brief Determine if ReqFeature is enabled given the features populated in
+  /// FeatureMap. Targets may override this to provide custom handling of
+  /// required features.
+  virtual Optional<bool>
+  hasRequiredFeature(const llvm::StringMap<bool> FeatureMap,
+                     const StringRef ReqFeature) const {
+    return {};
+  }
+
+  /// \brief Identify whether this taret supports multiversioning of
+  /// functions, which requires support for cpu_supports and cpu_is
+  /// functionality.
   virtual bool supportsMultiVersioning() const { return false; }
 
   // \brief Validate the contents of the __builtin_cpu_supports(const char*)


Index: clang/lib/CodeGen/CodeGenFunction.cpp
===================================================================
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -2262,6 +2262,12 @@
         Feature.split(OrFeatures, "|");
         return std::any_of(OrFeatures.begin(), OrFeatures.end(),
                            [&](StringRef Feature) {
+                             // Check if the target wants to handle the feature.
+                             if (auto OR = CGM.getTarget().hasRequiredFeature(
+                                     CallerFeatureMap, Feature))
+                               return OR.getValue();
+                             // Otherwise just look for the feature
+                             // presence/absence in the CallerFeatureMap.
                              if (!CallerFeatureMap.lookup(Feature)) {
                                FirstMissing = Feature.str();
                                return false;
Index: clang/include/clang/Basic/TargetInfo.h
===================================================================
--- clang/include/clang/Basic/TargetInfo.h
+++ clang/include/clang/Basic/TargetInfo.h
@@ -928,8 +928,18 @@
     return false;
   }
 
-  /// \brief Identify whether this taret supports multiversioning of functions,
-  /// which requires support for cpu_supports and cpu_is functionality.
+  /// \brief Determine if ReqFeature is enabled given the features populated in
+  /// FeatureMap. Targets may override this to provide custom handling of
+  /// required features.
+  virtual Optional<bool>
+  hasRequiredFeature(const llvm::StringMap<bool> FeatureMap,
+                     const StringRef ReqFeature) const {
+    return {};
+  }
+
+  /// \brief Identify whether this taret supports multiversioning of
+  /// functions, which requires support for cpu_supports and cpu_is
+  /// functionality.
   virtual bool supportsMultiVersioning() const { return false; }
 
   // \brief Validate the contents of the __builtin_cpu_supports(const char*)
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to