MLIR  21.0.0git
BuiltinTypeInterfaces.cpp
Go to the documentation of this file.
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 
12 using namespace mlir;
13 using namespace mlir::detail;
14 
15 //===----------------------------------------------------------------------===//
16 /// Tablegen Interface Definitions
17 //===----------------------------------------------------------------------===//
18 
19 #include "mlir/IR/BuiltinTypeInterfaces.cpp.inc"
20 
21 //===----------------------------------------------------------------------===//
22 // FloatType
23 //===----------------------------------------------------------------------===//
24 
25 unsigned FloatType::getWidth() {
26  return APFloat::semanticsSizeInBits(getFloatSemantics());
27 }
28 
29 unsigned FloatType::getFPMantissaWidth() {
30  return APFloat::semanticsPrecision(getFloatSemantics());
31 }
32 
33 //===----------------------------------------------------------------------===//
34 // ShapedType
35 //===----------------------------------------------------------------------===//
36 
37 constexpr int64_t ShapedType::kDynamic;
38 
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 }
static int64_t getNumElements(Type t)
Compute the total number of elements in the given type, also taking into account nested types.
AttrTypeReplacer.
Include the generated interface declarations.