diff --git a/mlir/include/mlir/ExecutionEngine/SparseTensor/ArithmeticUtils.h b/mlir/include/mlir/ExecutionEngine/SparseTensor/ArithmeticUtils.h --- 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 #include #include @@ -137,7 +139,7 @@ // 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 --- 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: +// Clang: +#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)