@@ -1410,46 +1410,6 @@ static SmallVector<int64_t> getTiledPackShape(tensor::PackOp packOp,
1410
1410
return applyPermutation (destShape, tensor::getPackInverseDestPerm (packOp));
1411
1411
}
1412
1412
1413
- // / Create a TransferReadOp from `source` with static shape `readShape`. If the
1414
- // / vector type for the read is not the same as the type of `source`, then a
1415
- // / mask is created on the read. If `doMasking` parameter is set to false we
1416
- // / update the `inBounds` attribute instead of masking.
1417
- static Value createReadOrMaskedRead (OpBuilder &builder, Location loc,
1418
- Value source, ArrayRef<int64_t > readShape,
1419
- Value padValue, bool doMasking = true ) {
1420
- assert (llvm::none_of (readShape,
1421
- [](int64_t s) { return s == ShapedType::kDynamic ; }));
1422
- auto sourceShape = dyn_cast<ShapedType>(source.getType ()).getShape ();
1423
- assert (sourceShape.size () == readShape.size ());
1424
- auto maskType = VectorType::get (readShape, builder.getI1Type ());
1425
- auto vectorType = VectorType::get (readShape, padValue.getType ());
1426
- int64_t readRank = readShape.size ();
1427
- auto zero = builder.create <arith::ConstantIndexOp>(loc, 0 );
1428
- SmallVector<bool > inBoundsVal (readRank, true );
1429
- if (!doMasking) {
1430
- // Update the inBounds attribute.
1431
- for (unsigned i = 0 ; i < readRank; i++)
1432
- inBoundsVal[i] = sourceShape[i] == readShape[i];
1433
- }
1434
- auto transferReadOp = builder.create <vector::TransferReadOp>(
1435
- loc,
1436
- /* vectorType=*/ vectorType,
1437
- /* source=*/ source,
1438
- /* indices=*/ SmallVector<Value>(readRank, zero),
1439
- /* padding=*/ padValue,
1440
- /* inBounds=*/ inBoundsVal);
1441
-
1442
- if (llvm::equal (readShape, sourceShape) || !doMasking) {
1443
- return transferReadOp;
1444
- }
1445
- SmallVector<OpFoldResult> mixedSourceDims =
1446
- tensor::getMixedSizes (builder, loc, source);
1447
- Value mask =
1448
- builder.create <vector::CreateMaskOp>(loc, maskType, mixedSourceDims);
1449
- return mlir::vector::maskOperation (builder, transferReadOp, mask)
1450
- ->getResult (0 );
1451
- }
1452
-
1453
1413
// / Given an input, the mixed destSizes, and the vector sizes for vectorization,
1454
1414
// / create an empty destination tensor and create a TransferWriteOp from the
1455
1415
// / input to the empty tensor. If the destination shape is not the same as the
@@ -1539,11 +1499,11 @@ vectorizeAsTensorPackOp(RewriterBase &rewriter, tensor::PackOp packOp,
1539
1499
// If the input vector sizes are not provided, then the vector sizes are
1540
1500
// determined by the result tensor shape. In case the vector sizes aren't
1541
1501
// provided, we update the inBounds attribute instead of masking.
1542
- bool doMasking = true ;
1502
+ bool useInBoundsInsteadOfMasking = true ;
1543
1503
if (inputVectorSizes.empty ()) {
1544
1504
ArrayRef<int64_t > resultTensorShape = packOp.getDestType ().getShape ();
1545
1505
inputVectorSizes = resultTensorShape.take_front (packOp.getSourceRank ());
1546
- doMasking = false ;
1506
+ useInBoundsInsteadOfMasking = false ;
1547
1507
}
1548
1508
1549
1509
// Create masked TransferReadOp.
@@ -1556,8 +1516,9 @@ vectorizeAsTensorPackOp(RewriterBase &rewriter, tensor::PackOp packOp,
1556
1516
invertPermutationVector (outerDimsPerm));
1557
1517
for (auto [idx, size] : enumerate(innerTiles))
1558
1518
inputShape[innerDimsPos[idx]] *= size;
1559
- auto maskedRead = createReadOrMaskedRead (rewriter, loc, packOp.getSource (),
1560
- inputShape, padValue, doMasking);
1519
+ auto maskedRead = vector::createReadOrMaskedRead (
1520
+ rewriter, loc, packOp.getSource (), inputShape, padValue,
1521
+ useInBoundsInsteadOfMasking);
1561
1522
1562
1523
// Create ShapeCastOp.
1563
1524
SmallVector<int64_t > destShape (inputVectorSizes);
@@ -1649,7 +1610,7 @@ vectorizeAsTensorUnpackOp(RewriterBase &rewriter, tensor::UnPackOp unpackOp,
1649
1610
1650
1611
// Read result, mask if necessary. If transferReadOp shape is not equal
1651
1612
// to shape of source, then a mask is necessary.
1652
- Value readResult = createReadOrMaskedRead (
1613
+ Value readResult = vector:: createReadOrMaskedRead (
1653
1614
rewriter, loc, unpackOp.getSource (),
1654
1615
ArrayRef<int64_t >(readMaskShape.begin (), readMaskShape.end ()), padValue);
1655
1616
@@ -1707,8 +1668,8 @@ vectorizeAsTensorPadOp(RewriterBase &rewriter, tensor::PadOp padOp,
1707
1668
.reifyResultShapes (rewriter, reifiedReturnShapes);
1708
1669
(void )status; // prevent unused variable warning on non-assert builds
1709
1670
assert (succeeded (status) && " failed to reify result shapes" );
1710
- auto maskedRead = createReadOrMaskedRead (rewriter, loc, padOp. getSource (),
1711
- inputVectorSizes, padValue);
1671
+ auto maskedRead = vector:: createReadOrMaskedRead (
1672
+ rewriter, loc, padOp. getSource (), inputVectorSizes, padValue);
1712
1673
Operation *write = createWriteOrMaskedWrite (
1713
1674
rewriter, loc, maskedRead, reifiedReturnShapes[0 ], inputVectorSizes);
1714
1675
newResults.push_back (write->getResult (0 ));
@@ -1781,41 +1742,6 @@ vectorizeDynamicLinalgOpPrecondition(linalg::LinalgOp op,
1781
1742
return success ();
1782
1743
}
1783
1744
1784
- // / Returns success if `inputVectorSizes` is a valid masking configuraion for
1785
- // / given `shape`, i.e., it meets:
1786
- // / 1. The numbers of elements in both array are equal.
1787
- // / 2. `inputVectorSizes` does not have dynamic dimensions.
1788
- // / 3. All the values in `inputVectorSizes` are greater than or equal to
1789
- // / static sizes in `shape`.
1790
- static LogicalResult
1791
- isValidMaskedInputVector (ArrayRef<int64_t > shape,
1792
- ArrayRef<int64_t > inputVectorSizes) {
1793
- LDBG (" Iteration space static sizes:" );
1794
- LLVM_DEBUG (llvm::interleaveComma (shape, llvm::dbgs ()));
1795
- LLVM_DEBUG (llvm::dbgs () << " \n " );
1796
-
1797
- if (inputVectorSizes.size () != shape.size ()) {
1798
- LDBG (" Input vector sizes don't match the number of loops" );
1799
- return failure ();
1800
- }
1801
- if (ShapedType::isDynamicShape (inputVectorSizes)) {
1802
- LDBG (" Input vector sizes can't have dynamic dimensions" );
1803
- return failure ();
1804
- }
1805
- if (!llvm::all_of (llvm::zip (shape, inputVectorSizes),
1806
- [](std::tuple<int64_t , int64_t > sizePair) {
1807
- int64_t staticSize = std::get<0 >(sizePair);
1808
- int64_t inputSize = std::get<1 >(sizePair);
1809
- return ShapedType::isDynamic (staticSize) ||
1810
- staticSize <= inputSize;
1811
- })) {
1812
- LDBG (" Input vector sizes must be greater than or equal to iteration space "
1813
- " static sizes" );
1814
- return failure ();
1815
- }
1816
- return success ();
1817
- }
1818
-
1819
1745
// / Need to check if the inner-tiles are static/constant.
1820
1746
static LogicalResult
1821
1747
vectorizeUnPackOpPrecondition (tensor::UnPackOp unpackOp,
@@ -1829,7 +1755,7 @@ vectorizeUnPackOpPrecondition(tensor::UnPackOp unpackOp,
1829
1755
}
1830
1756
llvm::ArrayRef<int64_t > resultShape = unpackOp.getDestType ().getShape ();
1831
1757
if (!inputVectorSizes.empty () &&
1832
- failed (isValidMaskedInputVector (resultShape, inputVectorSizes)))
1758
+ failed (vector:: isValidMaskedInputVector (resultShape, inputVectorSizes)))
1833
1759
return failure ();
1834
1760
1835
1761
return success ();
@@ -1843,8 +1769,8 @@ static LogicalResult vectorizeLinalgOpPrecondition(
1843
1769
return failure ();
1844
1770
// Check API contract for input vector sizes.
1845
1771
if (!inputVectorSizes.empty () &&
1846
- failed (isValidMaskedInputVector (linalgOp.getStaticLoopRanges (),
1847
- inputVectorSizes)))
1772
+ failed (vector:: isValidMaskedInputVector (linalgOp.getStaticLoopRanges (),
1773
+ inputVectorSizes)))
1848
1774
return failure ();
1849
1775
1850
1776
if (linalgOp.hasDynamicShape () && failed (vectorizeDynamicLinalgOpPrecondition (
@@ -1920,7 +1846,7 @@ vectorizePackOpPrecondition(tensor::PackOp packOp,
1920
1846
}
1921
1847
1922
1848
if (!satisfyEmptyCond &&
1923
- failed (isValidMaskedInputVector (
1849
+ failed (vector:: isValidMaskedInputVector (
1924
1850
resultTensorShape.take_front (packOp.getSourceRank ()),
1925
1851
inputVectorSizes)))
1926
1852
return failure ();
@@ -1945,7 +1871,8 @@ vectorizePadOpPrecondition(tensor::PadOp padOp,
1945
1871
}
1946
1872
1947
1873
ArrayRef<int64_t > resultTensorShape = padOp.getResultType ().getShape ();
1948
- if (failed (isValidMaskedInputVector (resultTensorShape, inputVectorSizes)))
1874
+ if (failed (vector::isValidMaskedInputVector (resultTensorShape,
1875
+ inputVectorSizes)))
1949
1876
return failure ();
1950
1877
1951
1878
if (llvm::any_of (padOp.getLow (), [](Value v) {
0 commit comments