6
6
//
7
7
// ===----------------------------------------------------------------------===//
8
8
//
9
- // This header is not part of the public API. It is placed in the
10
- // includes directory only because that's required by the implementations
11
- // of template-classes.
12
- //
13
- // This file is part of the lightweight runtime support library for sparse
14
- // tensor manipulations. The functionality of the support library is meant
15
- // to simplify benchmarking, testing, and debugging MLIR code operating on
16
- // sparse tensors. However, the provided functionality is **not** part of
17
- // core MLIR itself.
9
+ // A collection of "safe" arithmetic helper methods.
18
10
//
19
11
// ===----------------------------------------------------------------------===//
20
12
21
13
#ifndef MLIR_EXECUTIONENGINE_SPARSETENSOR_ARITHMETICUTILS_H
22
14
#define MLIR_EXECUTIONENGINE_SPARSETENSOR_ARITHMETICUTILS_H
23
15
24
- #include " mlir/ExecutionEngine/SparseTensor/Attributes.h"
25
-
26
16
#include < cassert>
27
17
#include < cinttypes>
28
18
#include < limits>
@@ -108,12 +98,6 @@ constexpr bool safelyGE(T t, U u) noexcept {
108
98
//
109
99
// ===----------------------------------------------------------------------===//
110
100
111
- // TODO: we would like to be able to pass in custom error messages, to
112
- // improve the user experience. We should be able to use something like
113
- // `assert(((void)(msg ? msg : defaultMsg), cond))`; but I'm not entirely
114
- // sure that'll work as intended when done within a function-definition
115
- // rather than within a macro-definition.
116
-
117
101
// / A version of `static_cast<To>` which checks for overflow/underflow.
118
102
// / The implementation avoids performing runtime assertions whenever
119
103
// / the types alone are sufficient to statically prove that overflow
@@ -140,7 +124,8 @@ inline uint64_t checkedMul(uint64_t lhs, uint64_t rhs) {
140
124
// If assertions are enabled and we have the intrinsic, then use it to
141
125
// avoid the expensive division. If assertions are disabled, then don't
142
126
// bother with intrinsics (to avoid any possible slowdown vs `operator*`).
143
- #if !defined(NDEBUG) && MLIR_SPARSETENSOR_HAS_BUILTIN(__builtin_mul_overflow)
127
+ #if !defined(NDEBUG) && defined(__has_builtin) && \
128
+ __has_builtin (__builtin_mul_overflow)
144
129
uint64_t result;
145
130
bool overflowed = __builtin_mul_overflow (lhs, rhs, &result);
146
131
assert (!overflowed && " Integer overflow" );
0 commit comments