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 "llvm/ADT/APFloat.h"
11
12using namespace mlir;
13using namespace mlir::detail;
14
15//===----------------------------------------------------------------------===//
16/// Tablegen Interface Definitions
17//===----------------------------------------------------------------------===//
18
19#include "mlir/IR/BuiltinTypeInterfaces.cpp.inc"
20
21//===----------------------------------------------------------------------===//
22// FloatType
23//===----------------------------------------------------------------------===//
24
25unsigned FloatType::getWidth() {
26 return APFloat::semanticsSizeInBits(getFloatSemantics());
27}
28
29unsigned FloatType::getFPMantissaWidth() {
30 return APFloat::semanticsPrecision(getFloatSemantics());
31}
32
33//===----------------------------------------------------------------------===//
34// ShapedType
35//===----------------------------------------------------------------------===//
36
37constexpr int64_t ShapedType::kDynamic;
38
39int64_t ShapedType::getNumElements(ArrayRef<int64_t> shape) {
40 int64_t num = 1;
41 for (int64_t dim : shape) {
42 num *= dim;
43 assert(num >= 0 && "integer overflow in element count computation");
44 }
45 return num;
46}
47

source code of mlir/lib/IR/BuiltinTypeInterfaces.cpp