| 1 | //===- BuiltinTypeInterfaces.cpp ------------------------------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "mlir/IR/BuiltinTypes.h" |
| 10 | #include "mlir/IR/Diagnostics.h" |
| 11 | #include "llvm/ADT/APFloat.h" |
| 12 | #include "llvm/ADT/Sequence.h" |
| 13 | |
| 14 | using namespace mlir; |
| 15 | using namespace mlir::detail; |
| 16 | |
| 17 | //===----------------------------------------------------------------------===// |
| 18 | /// Tablegen Interface Definitions |
| 19 | //===----------------------------------------------------------------------===// |
| 20 | |
| 21 | #include "mlir/IR/BuiltinTypeInterfaces.cpp.inc" |
| 22 | |
| 23 | //===----------------------------------------------------------------------===// |
| 24 | // FloatType |
| 25 | //===----------------------------------------------------------------------===// |
| 26 | |
| 27 | unsigned FloatType::getWidth() { |
| 28 | return APFloat::semanticsSizeInBits(getFloatSemantics()); |
| 29 | } |
| 30 | |
| 31 | unsigned FloatType::getFPMantissaWidth() { |
| 32 | return APFloat::semanticsPrecision(getFloatSemantics()); |
| 33 | } |
| 34 | |
| 35 | //===----------------------------------------------------------------------===// |
| 36 | // ShapedType |
| 37 | //===----------------------------------------------------------------------===// |
| 38 | |
| 39 | constexpr int64_t ShapedType::kDynamic; |
| 40 | |
| 41 | int64_t ShapedType::getNumElements(ArrayRef<int64_t> shape) { |
| 42 | int64_t num = 1; |
| 43 | for (int64_t dim : shape) { |
| 44 | num *= dim; |
| 45 | assert(num >= 0 && "integer overflow in element count computation" ); |
| 46 | } |
| 47 | return num; |
| 48 | } |
| 49 | |