[LLVM] Fix Maintainers.md formatting (NFC)
[llvm-project.git] / mlir / lib / IR / Types.cpp
blobe190902b2e489859d88798ec5f2d1c28a49b6e9b
1 //===- Types.cpp - MLIR Type Classes --------------------------------------===//
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 //===----------------------------------------------------------------------===//
9 #include "mlir/IR/BuiltinTypes.h"
10 #include "mlir/IR/Dialect.h"
12 using namespace mlir;
13 using namespace mlir::detail;
15 //===----------------------------------------------------------------------===//
16 // AbstractType
17 //===----------------------------------------------------------------------===//
19 void AbstractType::walkImmediateSubElements(
20 Type type, function_ref<void(Attribute)> walkAttrsFn,
21 function_ref<void(Type)> walkTypesFn) const {
22 walkImmediateSubElementsFn(type, walkAttrsFn, walkTypesFn);
25 Type AbstractType::replaceImmediateSubElements(Type type,
26 ArrayRef<Attribute> replAttrs,
27 ArrayRef<Type> replTypes) const {
28 return replaceImmediateSubElementsFn(type, replAttrs, replTypes);
31 //===----------------------------------------------------------------------===//
32 // Type
33 //===----------------------------------------------------------------------===//
35 MLIRContext *Type::getContext() const { return getDialect().getContext(); }
37 bool Type::isFloat4E2M1FN() const { return llvm::isa<Float4E2M1FNType>(*this); }
38 bool Type::isFloat6E2M3FN() const { return llvm::isa<Float6E2M3FNType>(*this); }
39 bool Type::isFloat6E3M2FN() const { return llvm::isa<Float6E3M2FNType>(*this); }
40 bool Type::isFloat8E5M2() const { return llvm::isa<Float8E5M2Type>(*this); }
41 bool Type::isFloat8E4M3() const { return llvm::isa<Float8E4M3Type>(*this); }
42 bool Type::isFloat8E4M3FN() const { return llvm::isa<Float8E4M3FNType>(*this); }
43 bool Type::isFloat8E5M2FNUZ() const {
44 return llvm::isa<Float8E5M2FNUZType>(*this);
46 bool Type::isFloat8E4M3FNUZ() const {
47 return llvm::isa<Float8E4M3FNUZType>(*this);
49 bool Type::isFloat8E4M3B11FNUZ() const {
50 return llvm::isa<Float8E4M3B11FNUZType>(*this);
52 bool Type::isFloat8E8M0FNU() const {
53 return llvm::isa<Float8E8M0FNUType>(*this);
55 bool Type::isFloat8E3M4() const { return llvm::isa<Float8E3M4Type>(*this); }
56 bool Type::isBF16() const { return llvm::isa<BFloat16Type>(*this); }
57 bool Type::isF16() const { return llvm::isa<Float16Type>(*this); }
58 bool Type::isTF32() const { return llvm::isa<FloatTF32Type>(*this); }
59 bool Type::isF32() const { return llvm::isa<Float32Type>(*this); }
60 bool Type::isF64() const { return llvm::isa<Float64Type>(*this); }
61 bool Type::isF80() const { return llvm::isa<Float80Type>(*this); }
62 bool Type::isF128() const { return llvm::isa<Float128Type>(*this); }
64 bool Type::isIndex() const { return llvm::isa<IndexType>(*this); }
66 bool Type::isInteger() const { return llvm::isa<IntegerType>(*this); }
68 /// Return true if this is an integer type with the specified width.
69 bool Type::isInteger(unsigned width) const {
70 if (auto intTy = llvm::dyn_cast<IntegerType>(*this))
71 return intTy.getWidth() == width;
72 return false;
75 bool Type::isSignlessInteger() const {
76 if (auto intTy = llvm::dyn_cast<IntegerType>(*this))
77 return intTy.isSignless();
78 return false;
81 bool Type::isSignlessInteger(unsigned width) const {
82 if (auto intTy = llvm::dyn_cast<IntegerType>(*this))
83 return intTy.isSignless() && intTy.getWidth() == width;
84 return false;
87 bool Type::isSignedInteger() const {
88 if (auto intTy = llvm::dyn_cast<IntegerType>(*this))
89 return intTy.isSigned();
90 return false;
93 bool Type::isSignedInteger(unsigned width) const {
94 if (auto intTy = llvm::dyn_cast<IntegerType>(*this))
95 return intTy.isSigned() && intTy.getWidth() == width;
96 return false;
99 bool Type::isUnsignedInteger() const {
100 if (auto intTy = llvm::dyn_cast<IntegerType>(*this))
101 return intTy.isUnsigned();
102 return false;
105 bool Type::isUnsignedInteger(unsigned width) const {
106 if (auto intTy = llvm::dyn_cast<IntegerType>(*this))
107 return intTy.isUnsigned() && intTy.getWidth() == width;
108 return false;
111 bool Type::isSignlessIntOrIndex() const {
112 return isSignlessInteger() || llvm::isa<IndexType>(*this);
115 bool Type::isSignlessIntOrIndexOrFloat() const {
116 return isSignlessInteger() || llvm::isa<IndexType, FloatType>(*this);
119 bool Type::isSignlessIntOrFloat() const {
120 return isSignlessInteger() || llvm::isa<FloatType>(*this);
123 bool Type::isIntOrIndex() const {
124 return llvm::isa<IntegerType>(*this) || isIndex();
127 bool Type::isIntOrFloat() const {
128 return llvm::isa<IntegerType, FloatType>(*this);
131 bool Type::isIntOrIndexOrFloat() const { return isIntOrFloat() || isIndex(); }
133 unsigned Type::getIntOrFloatBitWidth() const {
134 assert(isIntOrFloat() && "only integers and floats have a bitwidth");
135 if (auto intType = llvm::dyn_cast<IntegerType>(*this))
136 return intType.getWidth();
137 return llvm::cast<FloatType>(*this).getWidth();