|
10 | 10 | #include "AttributeDetail.h"
|
11 | 11 | #include "mlir/IR/AffineMap.h"
|
12 | 12 | #include "mlir/IR/BuiltinDialect.h"
|
| 13 | +#include "mlir/IR/BuiltinTypeInterfaces.h" |
13 | 14 | #include "mlir/IR/Dialect.h"
|
14 | 15 | #include "mlir/IR/DialectResourceBlobManager.h"
|
15 | 16 | #include "mlir/IR/IntegerSet.h"
|
@@ -379,22 +380,20 @@ APSInt IntegerAttr::getAPSInt() const {
|
379 | 380 |
|
380 | 381 | LogicalResult IntegerAttr::verify(function_ref<InFlightDiagnostic()> emitError,
|
381 | 382 | Type type, APInt value) {
|
382 |
| - if (IntegerType integerType = llvm::dyn_cast<IntegerType>(type)) { |
383 |
| - if (integerType.getWidth() != value.getBitWidth()) |
384 |
| - return emitError() << "integer type bit width (" << integerType.getWidth() |
385 |
| - << ") doesn't match value bit width (" |
386 |
| - << value.getBitWidth() << ")"; |
387 |
| - return success(); |
| 383 | + unsigned width; |
| 384 | + if (auto intLikeType = dyn_cast<IntegerLikeTypeInterface>(type)) { |
| 385 | + width = intLikeType.getStorageBitWidth(); |
| 386 | + } else { |
| 387 | + return emitError() << "expected integer-like type"; |
388 | 388 | }
|
389 |
| - if (llvm::isa<IndexType>(type)) { |
390 |
| - if (value.getBitWidth() != IndexType::kInternalStorageBitWidth) |
391 |
| - return emitError() |
392 |
| - << "value bit width (" << value.getBitWidth() |
393 |
| - << ") doesn't match index type internal storage bit width (" |
394 |
| - << IndexType::kInternalStorageBitWidth << ")"; |
395 |
| - return success(); |
| 389 | + |
| 390 | + if (width != value.getBitWidth()) { |
| 391 | + return emitError() << "integer-like type bit width (" << width |
| 392 | + << ") doesn't match value bit width (" |
| 393 | + << value.getBitWidth() << ")"; |
396 | 394 | }
|
397 |
| - return emitError() << "expected integer or index type"; |
| 395 | + |
| 396 | + return success(); |
398 | 397 | }
|
399 | 398 |
|
400 | 399 | BoolAttr IntegerAttr::getBoolAttrUnchecked(IntegerType type, bool value) {
|
@@ -1019,7 +1018,7 @@ DenseElementsAttr DenseElementsAttr::get(ShapedType type,
|
1019 | 1018 | /// element type of 'type'.
|
1020 | 1019 | DenseElementsAttr DenseElementsAttr::get(ShapedType type,
|
1021 | 1020 | ArrayRef<APInt> values) {
|
1022 |
| - assert(type.getElementType().isIntOrIndex()); |
| 1021 | + assert(isa<IntegerLikeTypeInterface>(type.getElementType())); |
1023 | 1022 | assert(hasSameNumElementsOrSplat(type, values));
|
1024 | 1023 | size_t storageBitWidth = getDenseElementStorageWidth(type.getElementType());
|
1025 | 1024 | return DenseIntOrFPElementsAttr::getRaw(type, storageBitWidth, values);
|
@@ -1130,11 +1129,11 @@ static bool isValidIntOrFloat(Type type, int64_t dataEltSize, bool isInt,
|
1130 | 1129 | if (type.isIndex())
|
1131 | 1130 | return true;
|
1132 | 1131 |
|
1133 |
| - auto intType = llvm::dyn_cast<IntegerType>(type); |
| 1132 | + auto intType = llvm::dyn_cast<IntegerLikeTypeInterface>(type); |
1134 | 1133 | if (!intType) {
|
1135 | 1134 | LLVM_DEBUG(llvm::dbgs()
|
1136 |
| - << "expected integer type when isInt is true, but found " << type |
1137 |
| - << "\n"); |
| 1135 | + << "expected integer-like type when isInt is true, but found " |
| 1136 | + << type << "\n"); |
1138 | 1137 | return false;
|
1139 | 1138 | }
|
1140 | 1139 |
|
|
0 commit comments