Skip to content

Commit c3082e2

Browse files
committed
[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
1 parent 8255472 commit c3082e2

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

mlir/include/mlir/ExecutionEngine/SparseTensor/ArithmeticUtils.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#ifndef MLIR_EXECUTIONENGINE_SPARSETENSOR_ARITHMETICUTILS_H
2222
#define MLIR_EXECUTIONENGINE_SPARSETENSOR_ARITHMETICUTILS_H
2323

24+
#include "mlir/ExecutionEngine/SparseTensor/Attributes.h"
25+
2426
#include <cassert>
2527
#include <cinttypes>
2628
#include <limits>
@@ -137,7 +139,7 @@ inline uint64_t checkedMul(uint64_t lhs, uint64_t rhs) {
137139
// If assertions are enabled and we have the intrinsic, then use it to
138140
// avoid the expensive division. If assertions are disabled, then don't
139141
// bother with intrinsics (to avoid any possible slowdown vs `operator*`).
140-
#if !defined(NDEBUG) && __has_builtin(__builtin_mul_overflow)
142+
#if !defined(NDEBUG) && MLIR_SPARSETENSOR_HAS_BUILTIN(__builtin_mul_overflow)
141143
uint64_t result;
142144
bool overflowed = __builtin_mul_overflow(lhs, rhs, &result);
143145
assert(!overflowed && "Integer overflow");

mlir/include/mlir/ExecutionEngine/SparseTensor/Attributes.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@
4444
#define MLIR_SPARSETENSOR_HAS_ATTRIBUTE(x) 0
4545
#endif
4646

47+
// A wrapper around `__has_builtin`, which is defined by GCC and Clang
48+
// but is missing on some versions of MSVC.
49+
// GCC: <https://gcc.gnu.org/onlinedocs/cpp/_005f_005fhas_005fbuiltin.html>
50+
// Clang: <https://clang.llvm.org/docs/LanguageExtensions.html#has-builtin>
51+
#ifdef __has_builtin
52+
#define MLIR_SPARSETENSOR_HAS_BUILTIN(x) __has_builtin(x)
53+
#else
54+
#define MLIR_SPARSETENSOR_HAS_BUILTIN(x) 0
55+
#endif
56+
4757
// An attribute for non-owning classes (like `PermutationRef`) to enable
4858
// lifetime warnings.
4959
#if MLIR_SPARSETENSOR_HAS_CPP_ATTRIBUTE(gsl::Pointer)

0 commit comments

Comments
 (0)