[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 17:14:52 PDT 2018


tra updated this revision to Diff 140371.
tra added a comment.

Updated description of hasRequiredFeature.
Set FirstMissing if target returns 'false' so diags still work.


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,16 @@
         Feature.split(OrFeatures, "|");
         return std::any_of(OrFeatures.begin(), OrFeatures.end(),
                            [&](StringRef Feature) {
+                             // Check if the target wants to handle the feature.
+                             if (Optional<bool> HasFeature =
+                                     CGM.getTarget().hasRequiredFeature(
+                                         CallerFeatureMap, Feature)) {
+                               if (*HasFeature == false)
+                                 FirstMissing = Feature.str();
+                               return *HasFeature;
+                             }
+                             // 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,20 @@
     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. Function returns None when the feature does not need
+  /// special handling by the target, or true/false to indicate whether the
+  /// feature is enabled.
+  virtual Optional<bool>
+  hasRequiredFeature(const llvm::StringMap<bool> FeatureMap,
+                     const StringRef ReqFeature) const {
+    return None;
+  }
+
+  /// \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.140371.patch
Type: text/x-patch
Size: 2417 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180330/c328a6de/attachment.bin>


More information about the cfe-commits mailing list