[Mlir-commits] [mlir] c3082e2 - [mlir][sparse] Adding wrapper for `__has_builtin`

wren romano llvmlistbot at llvm.org
Wed Nov 16 17:46:50 PST 2022


Author: wren romano
Date: 2022-11-16T17:46:42-08:00
New Revision: c3082e2ca281390b3c72e5b99381b6e524023ac5

URL: https://github.com/llvm/llvm-project/commit/c3082e2ca281390b3c72e5b99381b6e524023ac5
DIFF: https://github.com/llvm/llvm-project/commit/c3082e2ca281390b3c72e5b99381b6e524023ac5.diff

LOG: [mlir][sparse] Adding wrapper for `__has_builtin`

This is a followup to D138154 and should resolve build issues on Windows.

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D138167

Added: 
    

Modified: 
    mlir/include/mlir/ExecutionEngine/SparseTensor/ArithmeticUtils.h
    mlir/include/mlir/ExecutionEngine/SparseTensor/Attributes.h

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/ExecutionEngine/SparseTensor/ArithmeticUtils.h b/mlir/include/mlir/ExecutionEngine/SparseTensor/ArithmeticUtils.h
index ab5764c6b1e5..f36da5f3b745 100644
--- a/mlir/include/mlir/ExecutionEngine/SparseTensor/ArithmeticUtils.h
+++ b/mlir/include/mlir/ExecutionEngine/SparseTensor/ArithmeticUtils.h
@@ -21,6 +21,8 @@
 #ifndef MLIR_EXECUTIONENGINE_SPARSETENSOR_ARITHMETICUTILS_H
 #define MLIR_EXECUTIONENGINE_SPARSETENSOR_ARITHMETICUTILS_H
 
+#include "mlir/ExecutionEngine/SparseTensor/Attributes.h"
+
 #include <cassert>
 #include <cinttypes>
 #include <limits>
@@ -137,7 +139,7 @@ inline uint64_t checkedMul(uint64_t lhs, uint64_t rhs) {
   // If assertions are enabled and we have the intrinsic, then use it to
   // avoid the expensive division.  If assertions are disabled, then don't
   // bother with intrinsics (to avoid any possible slowdown vs `operator*`).
-#if !defined(NDEBUG) && __has_builtin(__builtin_mul_overflow)
+#if !defined(NDEBUG) && MLIR_SPARSETENSOR_HAS_BUILTIN(__builtin_mul_overflow)
   uint64_t result;
   bool overflowed = __builtin_mul_overflow(lhs, rhs, &result);
   assert(!overflowed && "Integer overflow");

diff  --git a/mlir/include/mlir/ExecutionEngine/SparseTensor/Attributes.h b/mlir/include/mlir/ExecutionEngine/SparseTensor/Attributes.h
index 4fb30f9494bc..681eba60d2c9 100644
--- a/mlir/include/mlir/ExecutionEngine/SparseTensor/Attributes.h
+++ b/mlir/include/mlir/ExecutionEngine/SparseTensor/Attributes.h
@@ -44,6 +44,16 @@
 #define MLIR_SPARSETENSOR_HAS_ATTRIBUTE(x) 0
 #endif
 
+// A wrapper around `__has_builtin`, which is defined by GCC and Clang
+// but is missing on some versions of MSVC.
+// GCC: <https://gcc.gnu.org/onlinedocs/cpp/_005f_005fhas_005fbuiltin.html>
+// Clang: <https://clang.llvm.org/docs/LanguageExtensions.html#has-builtin>
+#ifdef __has_builtin
+#define MLIR_SPARSETENSOR_HAS_BUILTIN(x) __has_builtin(x)
+#else
+#define MLIR_SPARSETENSOR_HAS_BUILTIN(x) 0
+#endif
+
 // An attribute for non-owning classes (like `PermutationRef`) to enable
 // lifetime warnings.
 #if MLIR_SPARSETENSOR_HAS_CPP_ATTRIBUTE(gsl::Pointer)


        


More information about the Mlir-commits mailing list