[PATCH] D45060: Allow target to handle required features for TARGET_BUILTINs.

Artem Belevich via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 29 13:40:44 PDT 2018


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*)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45060.140320.patch
Type: text/x-patch
Size: 2044 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180329/b40e8c72/attachment.bin>


More information about the cfe-commits mailing list