@@ -216,22 +216,6 @@ void mlir::tosa::printTypeOrAttr(OpAsmPrinter &p, Operation *op, TypeAttr type,
216
216
}
217
217
}
218
218
219
- // Create a pad-const const tensor with value of `val` of required data-type
220
- Value mlir::tosa::createPadConstTensor (OpBuilder &builder, Location loc,
221
- Value src, int32_t val) {
222
- const auto srcType = getElementTypeOrSelf (src);
223
- const auto srcElemType = getElementTypeOrSelf (src);
224
- const auto padConstType = mlir::RankedTensorType::get ({1 }, srcType);
225
- const auto padConstEType = mlir::RankedTensorType::get ({1 }, srcElemType);
226
- const auto padConstAttr{
227
- llvm::isa<FloatType>(srcElemType)
228
- ? DenseElementsAttr::get (padConstEType,
229
- builder.getFloatAttr (srcElemType, val))
230
- : DenseElementsAttr::get (padConstEType,
231
- builder.getIntegerAttr (srcElemType, val))};
232
- return builder.create <tosa::ConstOp>(loc, padConstType, padConstAttr);
233
- }
234
-
235
219
// ===----------------------------------------------------------------------===//
236
220
// Tosa utilities.
237
221
// ===----------------------------------------------------------------------===//
@@ -242,16 +226,15 @@ std::optional<int64_t> idivCheck(const int64_t lhs, const int64_t rhs) {
242
226
return lhs / rhs;
243
227
}
244
228
245
- // ===----------------------------------------------------------------------===//
246
- // Tosa utilities.
247
- // ===----------------------------------------------------------------------===//
248
-
249
- static Type getStorageElementTypeOrSelf (Type type) {
250
- auto elementType = getElementTypeOrSelf (type);
251
- if (auto quantType = llvm::dyn_cast<mlir::quant::QuantizedType>(elementType))
252
- elementType = quantType.getStorageType ();
229
+ Type getStorageElementTypeOrSelf (Type type) {
230
+ auto srcType = getElementTypeOrSelf (type);
231
+ if (auto quantType = llvm::dyn_cast<mlir::quant::QuantizedType>(srcType))
232
+ srcType = quantType.getStorageType ();
233
+ return srcType;
234
+ }
253
235
254
- return elementType;
236
+ Type getStorageElementTypeOrSelf (Value value) {
237
+ return getStorageElementTypeOrSelf (value.getType ());
255
238
}
256
239
257
240
static LogicalResult verifyRescaleValueAndZpTypes (Operation *op, Value val,
@@ -273,6 +256,22 @@ static LogicalResult verifyRescaleValueAndZpTypes(Operation *op, Value val,
273
256
return success ();
274
257
}
275
258
259
+ // Create a pad-const const tensor with value of `val` of required data-type
260
+ Value mlir::tosa::createPadConstTensor (OpBuilder &builder, Location loc,
261
+ Value src, int32_t val) {
262
+ const auto srcType = getElementTypeOrSelf (src);
263
+ const auto srcElemType = getStorageElementTypeOrSelf (src);
264
+ const auto padConstType = mlir::RankedTensorType::get ({1 }, srcType);
265
+ const auto padConstEType = mlir::RankedTensorType::get ({1 }, srcElemType);
266
+ const auto padConstAttr{
267
+ llvm::isa<FloatType>(srcElemType)
268
+ ? DenseElementsAttr::get (padConstEType,
269
+ builder.getFloatAttr (srcElemType, val))
270
+ : DenseElementsAttr::get (padConstEType,
271
+ builder.getIntegerAttr (srcElemType, val))};
272
+ return builder.create <tosa::ConstOp>(loc, padConstType, padConstAttr);
273
+ }
274
+
276
275
// ===----------------------------------------------------------------------===//
277
276
// TOSA Operator Verifiers.
278
277
// ===----------------------------------------------------------------------===//
0 commit comments