MLIR  16.0.0git
Types.cpp
Go to the documentation of this file.
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 //===----------------------------------------------------------------------===//
8 
9 #include "mlir/IR/BuiltinTypes.h"
10 #include "mlir/IR/Dialect.h"
11 
12 using namespace mlir;
13 using namespace mlir::detail;
14 
15 //===----------------------------------------------------------------------===//
16 // Type
17 //===----------------------------------------------------------------------===//
18 
19 MLIRContext *Type::getContext() const { return getDialect().getContext(); }
20 
21 bool Type::isBF16() const { return isa<BFloat16Type>(); }
22 bool Type::isF16() const { return isa<Float16Type>(); }
23 bool Type::isF32() const { return isa<Float32Type>(); }
24 bool Type::isF64() const { return isa<Float64Type>(); }
25 bool Type::isF80() const { return isa<Float80Type>(); }
26 bool Type::isF128() const { return isa<Float128Type>(); }
27 
28 bool Type::isIndex() const { return isa<IndexType>(); }
29 
30 /// Return true if this is an integer type with the specified width.
31 bool Type::isInteger(unsigned width) const {
32  if (auto intTy = dyn_cast<IntegerType>())
33  return intTy.getWidth() == width;
34  return false;
35 }
36 
38  if (auto intTy = dyn_cast<IntegerType>())
39  return intTy.isSignless();
40  return false;
41 }
42 
43 bool Type::isSignlessInteger(unsigned width) const {
44  if (auto intTy = dyn_cast<IntegerType>())
45  return intTy.isSignless() && intTy.getWidth() == width;
46  return false;
47 }
48 
49 bool Type::isSignedInteger() const {
50  if (auto intTy = dyn_cast<IntegerType>())
51  return intTy.isSigned();
52  return false;
53 }
54 
55 bool Type::isSignedInteger(unsigned width) const {
56  if (auto intTy = dyn_cast<IntegerType>())
57  return intTy.isSigned() && intTy.getWidth() == width;
58  return false;
59 }
60 
62  if (auto intTy = dyn_cast<IntegerType>())
63  return intTy.isUnsigned();
64  return false;
65 }
66 
67 bool Type::isUnsignedInteger(unsigned width) const {
68  if (auto intTy = dyn_cast<IntegerType>())
69  return intTy.isUnsigned() && intTy.getWidth() == width;
70  return false;
71 }
72 
74  return isSignlessInteger() || isa<IndexType>();
75 }
76 
78  return isSignlessInteger() || isa<IndexType, FloatType>();
79 }
80 
82  return isSignlessInteger() || isa<FloatType>();
83 }
84 
85 bool Type::isIntOrIndex() const { return isa<IntegerType>() || isIndex(); }
86 
87 bool Type::isIntOrFloat() const { return isa<IntegerType, FloatType>(); }
88 
89 bool Type::isIntOrIndexOrFloat() const { return isIntOrFloat() || isIndex(); }
90 
91 unsigned Type::getIntOrFloatBitWidth() const {
92  assert(isIntOrFloat() && "only integers and floats have a bitwidth");
93  if (auto intType = dyn_cast<IntegerType>())
94  return intType.getWidth();
95  return cast<FloatType>().getWidth();
96 }
Include the generated interface declarations.
bool isF32() const
Definition: Types.cpp:23
bool isIntOrIndexOrFloat() const
Return true if this is an integer (of any signedness), index, or float type.
Definition: Types.cpp:89
bool isInteger(unsigned width) const
Return true if this is an integer type with the specified width.
Definition: Types.cpp:31
bool isIntOrFloat() const
Return true if this is an integer (of any signedness) or a float type.
Definition: Types.cpp:87
bool isUnsignedInteger() const
Return true if this is an unsigned integer type (with the specified width).
Definition: Types.cpp:61
bool isSignlessIntOrIndexOrFloat() const
Return true if this is a signless integer, index, or float type.
Definition: Types.cpp:77
bool isF80() const
Definition: Types.cpp:25
bool isF16() const
Definition: Types.cpp:22
bool isSignlessIntOrIndex() const
Return true if this is a signless integer or index type.
Definition: Types.cpp:73
bool isIndex() const
Definition: Types.cpp:28
bool isSignlessInteger() const
Return true if this is a signless integer type (with the specified width).
Definition: Types.cpp:37
bool isF128() const
Definition: Types.cpp:26
bool isSignedInteger() const
Return true if this is a signed integer type (with the specified width).
Definition: Types.cpp:49
MLIRContext * getContext() const
Return the MLIRContext in which this type was uniqued.
Definition: Types.cpp:19
bool isF64() const
Definition: Types.cpp:24
MLIRContext is the top-level object for a collection of MLIR operations.
Definition: MLIRContext.h:56
unsigned getIntOrFloatBitWidth() const
Return the bit width of an integer or a float type, assert failure on other types.
Definition: Types.cpp:91
bool isIntOrIndex() const
Return true if this is an integer (of any signedness) or an index type.
Definition: Types.cpp:85
bool isSignlessIntOrFloat() const
Return true of this is a signless integer or a float type.
Definition: Types.cpp:81
bool isBF16() const
Definition: Types.cpp:21