diff --git a/mlir/include/mlir/IR/Types.h b/mlir/include/mlir/IR/Types.h --- a/mlir/include/mlir/IR/Types.h +++ b/mlir/include/mlir/IR/Types.h @@ -126,43 +126,43 @@ // Convenience predicates. This is only for floating point types, // derived types should use isa/dyn_cast. - bool isIndex(); - bool isBF16(); - bool isF16(); - bool isF32(); - bool isF64(); + bool isIndex() const; + bool isBF16() const; + bool isF16() const; + bool isF32() const; + bool isF64() const; /// Return true if this is an integer type with the specified width. - bool isInteger(unsigned width); + bool isInteger(unsigned width) const; /// Return true if this is a signless integer type (with the specified width). - bool isSignlessInteger(); - bool isSignlessInteger(unsigned width); + bool isSignlessInteger() const; + bool isSignlessInteger(unsigned width) const; /// Return true if this is a signed integer type (with the specified width). - bool isSignedInteger(); - bool isSignedInteger(unsigned width); + bool isSignedInteger() const; + bool isSignedInteger(unsigned width) const; /// Return true if this is an unsigned integer type (with the specified /// width). - bool isUnsignedInteger(); - bool isUnsignedInteger(unsigned width); + bool isUnsignedInteger() const; + bool isUnsignedInteger(unsigned width) const; /// Return the bit width of an integer or a float type, assert failure on /// other types. - unsigned getIntOrFloatBitWidth(); + unsigned getIntOrFloatBitWidth() const; /// Return true if this is a signless integer or index type. - bool isSignlessIntOrIndex(); + bool isSignlessIntOrIndex() const; /// Return true if this is a signless integer, index, or float type. - bool isSignlessIntOrIndexOrFloat(); + bool isSignlessIntOrIndexOrFloat() const; /// Return true of this is a signless integer or a float type. - bool isSignlessIntOrFloat(); + bool isSignlessIntOrFloat() const; /// Return true if this is an integer (of any signedness) or an index type. - bool isIntOrIndex(); + bool isIntOrIndex() const; /// Return true if this is an integer (of any signedness) or a float type. - bool isIntOrFloat(); + bool isIntOrFloat() const; /// Return true if this is an integer (of any signedness), index, or float /// type. - bool isIntOrIndexOrFloat(); + bool isIntOrIndexOrFloat() const; /// Print the current type. void print(raw_ostream &os); diff --git a/mlir/lib/IR/StandardTypes.cpp b/mlir/lib/IR/StandardTypes.cpp --- a/mlir/lib/IR/StandardTypes.cpp +++ b/mlir/lib/IR/StandardTypes.cpp @@ -22,75 +22,75 @@ // Type //===----------------------------------------------------------------------===// -bool Type::isBF16() { return isa(); } -bool Type::isF16() { return isa(); } -bool Type::isF32() { return isa(); } -bool Type::isF64() { return isa(); } +bool Type::isBF16() const { return isa(); } +bool Type::isF16() const { return isa(); } +bool Type::isF32() const { return isa(); } +bool Type::isF64() const { return isa(); } -bool Type::isIndex() { return isa(); } +bool Type::isIndex() const { return isa(); } /// Return true if this is an integer type with the specified width. -bool Type::isInteger(unsigned width) { +bool Type::isInteger(unsigned width) const { if (auto intTy = dyn_cast()) return intTy.getWidth() == width; return false; } -bool Type::isSignlessInteger() { +bool Type::isSignlessInteger() const { if (auto intTy = dyn_cast()) return intTy.isSignless(); return false; } -bool Type::isSignlessInteger(unsigned width) { +bool Type::isSignlessInteger(unsigned width) const { if (auto intTy = dyn_cast()) return intTy.isSignless() && intTy.getWidth() == width; return false; } -bool Type::isSignedInteger() { +bool Type::isSignedInteger() const { if (auto intTy = dyn_cast()) return intTy.isSigned(); return false; } -bool Type::isSignedInteger(unsigned width) { +bool Type::isSignedInteger(unsigned width) const { if (auto intTy = dyn_cast()) return intTy.isSigned() && intTy.getWidth() == width; return false; } -bool Type::isUnsignedInteger() { +bool Type::isUnsignedInteger() const { if (auto intTy = dyn_cast()) return intTy.isUnsigned(); return false; } -bool Type::isUnsignedInteger(unsigned width) { +bool Type::isUnsignedInteger(unsigned width) const { if (auto intTy = dyn_cast()) return intTy.isUnsigned() && intTy.getWidth() == width; return false; } -bool Type::isSignlessIntOrIndex() { +bool Type::isSignlessIntOrIndex() const { return isSignlessInteger() || isa(); } -bool Type::isSignlessIntOrIndexOrFloat() { +bool Type::isSignlessIntOrIndexOrFloat() const { return isSignlessInteger() || isa(); } -bool Type::isSignlessIntOrFloat() { +bool Type::isSignlessIntOrFloat() const { return isSignlessInteger() || isa(); } -bool Type::isIntOrIndex() { return isa() || isIndex(); } +bool Type::isIntOrIndex() const { return isa() || isIndex(); } -bool Type::isIntOrFloat() { return isa(); } +bool Type::isIntOrFloat() const { return isa(); } -bool Type::isIntOrIndexOrFloat() { return isIntOrFloat() || isIndex(); } +bool Type::isIntOrIndexOrFloat() const { return isIntOrFloat() || isIndex(); } -unsigned Type::getIntOrFloatBitWidth() { +unsigned Type::getIntOrFloatBitWidth() const { assert(isIntOrFloat() && "only integers and floats have a bitwidth"); if (auto intType = dyn_cast()) return intType.getWidth();