summaryrefslogtreecommitdiffstats
path: root/mlir/lib/Transforms
diff options
context:
space:
mode:
Diffstat (limited to 'mlir/lib/Transforms')
-rw-r--r--mlir/lib/Transforms/ComposeAffineMaps.cpp4
-rw-r--r--mlir/lib/Transforms/LoopUnroll.cpp12
-rw-r--r--mlir/lib/Transforms/LoopUnrollAndJam.cpp8
-rw-r--r--mlir/lib/Transforms/LoopUtils.cpp46
-rw-r--r--mlir/lib/Transforms/PipelineDataTransfer.cpp3
-rw-r--r--mlir/lib/Transforms/SimplifyAffineExpr.cpp6
-rw-r--r--mlir/lib/Transforms/Utils.cpp6
7 files changed, 43 insertions, 42 deletions
diff --git a/mlir/lib/Transforms/ComposeAffineMaps.cpp b/mlir/lib/Transforms/ComposeAffineMaps.cpp
index d95cbb38971..d2f24ba8de8 100644
--- a/mlir/lib/Transforms/ComposeAffineMaps.cpp
+++ b/mlir/lib/Transforms/ComposeAffineMaps.cpp
@@ -103,9 +103,9 @@ static void createComposedAffineApplyOp(
unsigned rank = memrefType->getRank();
assert(indices.size() == rank);
// Create identity map with same number of dimensions as 'memrefType'.
- auto *map = builder->getMultiDimIdentityMap(rank);
+ auto map = builder->getMultiDimIdentityMap(rank);
// Initialize AffineValueMap with identity map.
- AffineValueMap valueMap(map, indices, builder->getContext());
+ AffineValueMap valueMap(map, indices);
for (auto *opStmt : affineApplyOps) {
assert(opStmt->is<AffineApplyOp>());
diff --git a/mlir/lib/Transforms/LoopUnroll.cpp b/mlir/lib/Transforms/LoopUnroll.cpp
index 33d5d141f7b..8738d74acdd 100644
--- a/mlir/lib/Transforms/LoopUnroll.cpp
+++ b/mlir/lib/Transforms/LoopUnroll.cpp
@@ -201,14 +201,14 @@ bool mlir::loopUnrollByFactor(ForStmt *forStmt, uint64_t unrollFactor) {
if (unrollFactor == 1 || forStmt->getStatements().empty())
return false;
- auto *lbMap = forStmt->getLowerBoundMap();
- auto *ubMap = forStmt->getUpperBoundMap();
+ auto lbMap = forStmt->getLowerBoundMap();
+ auto ubMap = forStmt->getUpperBoundMap();
// Loops with max/min expressions won't be unrolled here (the output can't be
// expressed as an MLFunction in the general case). However, the right way to
// do such unrolling for an MLFunction would be to specialize the loop for the
// 'hotspot' case and unroll that hotspot.
- if (lbMap->getNumResults() != 1 || ubMap->getNumResults() != 1)
+ if (lbMap.getNumResults() != 1 || ubMap.getNumResults() != 1)
return false;
// Same operand list for lower and upper bound for now.
@@ -229,7 +229,7 @@ bool mlir::loopUnrollByFactor(ForStmt *forStmt, uint64_t unrollFactor) {
DenseMap<const MLValue *, MLValue *> operandMap;
MLFuncBuilder builder(forStmt->getBlock(), ++StmtBlock::iterator(forStmt));
auto *cleanupForStmt = cast<ForStmt>(builder.clone(*forStmt, operandMap));
- auto *clLbMap = getCleanupLoopLowerBound(*forStmt, unrollFactor, &builder);
+ auto clLbMap = getCleanupLoopLowerBound(*forStmt, unrollFactor, &builder);
assert(clLbMap &&
"cleanup loop lower bound map for single result bound maps can "
"always be determined");
@@ -238,7 +238,7 @@ bool mlir::loopUnrollByFactor(ForStmt *forStmt, uint64_t unrollFactor) {
promoteIfSingleIteration(cleanupForStmt);
// Adjust upper bound.
- auto *unrolledUbMap =
+ auto unrolledUbMap =
getUnrolledLoopUpperBound(*forStmt, unrollFactor, &builder);
assert(unrolledUbMap &&
"upper bound map can alwayys be determined for an unrolled loop "
@@ -267,7 +267,7 @@ bool mlir::loopUnrollByFactor(ForStmt *forStmt, uint64_t unrollFactor) {
if (!forStmt->use_empty()) {
// iv' = iv + 1/2/3...unrollFactor-1;
auto d0 = builder.getAffineDimExpr(0);
- auto *bumpMap = builder.getAffineMap(1, 0, {d0 + i * step}, {});
+ auto bumpMap = builder.getAffineMap(1, 0, {d0 + i * step}, {});
auto *ivUnroll =
builder.create<AffineApplyOp>(forStmt->getLoc(), bumpMap, forStmt)
->getResult(0);
diff --git a/mlir/lib/Transforms/LoopUnrollAndJam.cpp b/mlir/lib/Transforms/LoopUnrollAndJam.cpp
index f96ba19c512..80ea0f55ba7 100644
--- a/mlir/lib/Transforms/LoopUnrollAndJam.cpp
+++ b/mlir/lib/Transforms/LoopUnrollAndJam.cpp
@@ -156,14 +156,14 @@ bool mlir::loopUnrollJamByFactor(ForStmt *forStmt, uint64_t unrollJamFactor) {
getLargestDivisorOfTripCount(*forStmt) % unrollJamFactor != 0)
return false;
- auto *lbMap = forStmt->getLowerBoundMap();
- auto *ubMap = forStmt->getUpperBoundMap();
+ auto lbMap = forStmt->getLowerBoundMap();
+ auto ubMap = forStmt->getUpperBoundMap();
// Loops with max/min expressions won't be unrolled here (the output can't be
// expressed as an MLFunction in the general case). However, the right way to
// do such unrolling for an MLFunction would be to specialize the loop for the
// 'hotspot' case and unroll that hotspot.
- if (lbMap->getNumResults() != 1 || ubMap->getNumResults() != 1)
+ if (lbMap.getNumResults() != 1 || ubMap.getNumResults() != 1)
return false;
// Same operand list for lower and upper bound for now.
@@ -221,7 +221,7 @@ bool mlir::loopUnrollJamByFactor(ForStmt *forStmt, uint64_t unrollJamFactor) {
if (!forStmt->use_empty()) {
// iv' = iv + i, i = 1 to unrollJamFactor-1.
auto d0 = builder.getAffineDimExpr(0);
- auto *bumpMap = builder.getAffineMap(1, 0, {d0 + i * step}, {});
+ auto bumpMap = builder.getAffineMap(1, 0, {d0 + i * step}, {});
auto *ivUnroll =
builder.create<AffineApplyOp>(forStmt->getLoc(), bumpMap, forStmt)
->getResult(0);
diff --git a/mlir/lib/Transforms/LoopUtils.cpp b/mlir/lib/Transforms/LoopUtils.cpp
index 89e59fe40fb..95726653551 100644
--- a/mlir/lib/Transforms/LoopUtils.cpp
+++ b/mlir/lib/Transforms/LoopUtils.cpp
@@ -35,50 +35,50 @@ using namespace mlir;
/// Returns the upper bound of an unrolled loop with lower bound 'lb' and with
/// the specified trip count, stride, and unroll factor. Returns nullptr when
/// the trip count can't be expressed as an affine expression.
-AffineMap *mlir::getUnrolledLoopUpperBound(const ForStmt &forStmt,
- unsigned unrollFactor,
- MLFuncBuilder *builder) {
- auto *lbMap = forStmt.getLowerBoundMap();
+AffineMap mlir::getUnrolledLoopUpperBound(const ForStmt &forStmt,
+ unsigned unrollFactor,
+ MLFuncBuilder *builder) {
+ auto lbMap = forStmt.getLowerBoundMap();
// Single result lower bound map only.
- if (lbMap->getNumResults() != 1)
- return nullptr;
+ if (lbMap.getNumResults() != 1)
+ return AffineMap::Invalid();
// Sometimes, the trip count cannot be expressed as an affine expression.
auto tripCount = getTripCountExpr(forStmt);
if (!tripCount)
- return nullptr;
+ return AffineMap::Invalid();
- AffineExpr lb(lbMap->getResult(0));
+ AffineExpr lb(lbMap.getResult(0));
unsigned step = forStmt.getStep();
auto newUb = lb + (tripCount - tripCount % unrollFactor - 1) * step;
- return builder->getAffineMap(lbMap->getNumDims(), lbMap->getNumSymbols(),
+ return builder->getAffineMap(lbMap.getNumDims(), lbMap.getNumSymbols(),
{newUb}, {});
}
/// Returns the lower bound of the cleanup loop when unrolling a loop with lower
/// bound 'lb' and with the specified trip count, stride, and unroll factor.
-/// Returns nullptr when the trip count can't be expressed as an affine
-/// expression.
-AffineMap *mlir::getCleanupLoopLowerBound(const ForStmt &forStmt,
- unsigned unrollFactor,
- MLFuncBuilder *builder) {
- auto *lbMap = forStmt.getLowerBoundMap();
+/// Returns an AffinMap with nullptr storage (that evaluates to false)
+/// when the trip count can't be expressed as an affine expression.
+AffineMap mlir::getCleanupLoopLowerBound(const ForStmt &forStmt,
+ unsigned unrollFactor,
+ MLFuncBuilder *builder) {
+ auto lbMap = forStmt.getLowerBoundMap();
// Single result lower bound map only.
- if (lbMap->getNumResults() != 1)
- return nullptr;
+ if (lbMap.getNumResults() != 1)
+ return AffineMap::Invalid();
// Sometimes the trip count cannot be expressed as an affine expression.
AffineExpr tripCount(getTripCountExpr(forStmt));
if (!tripCount)
- return nullptr;
+ return AffineMap::Invalid();
- AffineExpr lb(lbMap->getResult(0));
+ AffineExpr lb(lbMap.getResult(0));
unsigned step = forStmt.getStep();
auto newLb = lb + (tripCount - tripCount % unrollFactor) * step;
- return builder->getAffineMap(lbMap->getNumDims(), lbMap->getNumSymbols(),
+ return builder->getAffineMap(lbMap.getNumDims(), lbMap.getNumSymbols(),
{newLb}, {});
}
@@ -91,7 +91,7 @@ bool mlir::promoteIfSingleIteration(ForStmt *forStmt) {
return false;
// TODO(mlir-team): there is no builder for a max.
- if (forStmt->getLowerBoundMap()->getNumResults() != 1)
+ if (forStmt->getLowerBoundMap().getNumResults() != 1)
return false;
// Replaces all IV uses to its single iteration value.
@@ -140,7 +140,7 @@ void mlir::promoteSingleIterationLoops(MLFunction *f) {
/// the pair specifies the delay applied to that group of statements. Returns
/// nullptr if the generated loop simplifies to a single iteration one.
static ForStmt *
-generateLoop(AffineMap *lb, AffineMap *ub,
+generateLoop(AffineMap lb, AffineMap ub,
const std::vector<std::pair<uint64_t, ArrayRef<Statement *>>>
&stmtGroupQueue,
unsigned offset, ForStmt *srcForStmt, MLFuncBuilder *b) {
@@ -296,7 +296,7 @@ UtilResult mlir::stmtBodySkew(ForStmt *forStmt, ArrayRef<uint64_t> delays,
// of statements is paired with its delay.
std::vector<std::pair<uint64_t, ArrayRef<Statement *>>> stmtGroupQueue;
- auto *origLbMap = forStmt->getLowerBoundMap();
+ auto origLbMap = forStmt->getLowerBoundMap();
uint64_t lbDelay = 0;
MLFuncBuilder b(forStmt);
for (uint64_t d = 0, e = sortedStmtGroups.size(); d < e; ++d) {
diff --git a/mlir/lib/Transforms/PipelineDataTransfer.cpp b/mlir/lib/Transforms/PipelineDataTransfer.cpp
index 0d025f5678f..87899564172 100644
--- a/mlir/lib/Transforms/PipelineDataTransfer.cpp
+++ b/mlir/lib/Transforms/PipelineDataTransfer.cpp
@@ -100,7 +100,8 @@ static bool doubleBuffer(MLValue *oldMemRef, ForStmt *forStmt) {
->getResult());
auto d0 = bInner.getAffineDimExpr(0);
- auto *modTwoMap = bInner.getAffineMap(1, 0, {d0 % 2}, {});
+ auto modTwoMap =
+ bInner.getAffineMap(/*dimCount=*/1, /*symbolCount=*/0, {d0 % 2}, {});
auto ivModTwoOp =
bInner.create<AffineApplyOp>(forStmt->getLoc(), modTwoMap, forStmt);
if (!replaceAllMemRefUsesWith(oldMemRef, newMemRef, ivModTwoOp->getResult(0)))
diff --git a/mlir/lib/Transforms/SimplifyAffineExpr.cpp b/mlir/lib/Transforms/SimplifyAffineExpr.cpp
index 30d3908ac33..a3b8ebf1ba8 100644
--- a/mlir/lib/Transforms/SimplifyAffineExpr.cpp
+++ b/mlir/lib/Transforms/SimplifyAffineExpr.cpp
@@ -59,10 +59,10 @@ PassResult SimplifyAffineExpr::runOnMLFunction(MLFunction *f) {
void visitOperationStmt(OperationStmt *opStmt) {
for (auto attr : opStmt->getAttrs()) {
if (auto *mapAttr = dyn_cast<AffineMapAttr>(attr.second)) {
- MutableAffineMap mMap(mapAttr->getValue(), context);
+ MutableAffineMap mMap(mapAttr->getValue());
mMap.simplify();
- auto *map = mMap.getAffineMap();
- opStmt->setAttr(attr.first, AffineMapAttr::get(map, context));
+ auto map = mMap.getAffineMap();
+ opStmt->setAttr(attr.first, AffineMapAttr::get(map));
}
}
}
diff --git a/mlir/lib/Transforms/Utils.cpp b/mlir/lib/Transforms/Utils.cpp
index 0262eb94bd7..e1601c4f75d 100644
--- a/mlir/lib/Transforms/Utils.cpp
+++ b/mlir/lib/Transforms/Utils.cpp
@@ -48,14 +48,14 @@ static bool isMemRefDereferencingOp(const Operation &op) {
// extended to add additional indices at any position.
bool mlir::replaceAllMemRefUsesWith(MLValue *oldMemRef, MLValue *newMemRef,
ArrayRef<SSAValue *> extraIndices,
- AffineMap *indexRemap) {
+ AffineMap indexRemap) {
unsigned newMemRefRank = cast<MemRefType>(newMemRef->getType())->getRank();
(void)newMemRefRank; // unused in opt mode
unsigned oldMemRefRank = cast<MemRefType>(oldMemRef->getType())->getRank();
(void)newMemRefRank;
if (indexRemap) {
- assert(indexRemap->getNumInputs() == oldMemRefRank);
- assert(indexRemap->getNumResults() + extraIndices.size() == newMemRefRank);
+ assert(indexRemap.getNumInputs() == oldMemRefRank);
+ assert(indexRemap.getNumResults() + extraIndices.size() == newMemRefRank);
} else {
assert(oldMemRefRank + extraIndices.size() == newMemRefRank);
}
OpenPOWER on IntegriCloud