Skip to content

Commit

Permalink
Added comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Kavitha Madhu committed Feb 20, 2024
1 parent 9a53b74 commit bcc320d
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions lib/TPP/Transforms/SCFParallelLoopTiling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
//
//===----------------------------------------------------------------------===//

#include "mlir/Pass/Pass.h"
#include "mlir/Dialect/Affine/IR/AffineOps.h"
#include "mlir/Dialect/Arith/IR/Arith.h"
#include "mlir/Dialect/SCF/IR/SCF.h"
#include "mlir/Dialect/SCF/Utils/Utils.h"
#include "mlir/Pass/Pass.h"
namespace mlir {
namespace tpp {
#define GEN_PASS_DECL_SCFPARALLELLOOPTILING
Expand Down Expand Up @@ -54,9 +54,8 @@ using namespace mlir::scf;
/// %i0 + j0 and %i1 + %j1.
///
/// The old loop is replaced with the new one.
void tileParallelLoop(ParallelOp op,
ArrayRef<int64_t> tileSizes,
bool noMinMaxBounds) {
void tileParallelLoop(ParallelOp op, ArrayRef<int64_t> tileSizes,
bool noMinMaxBounds) {
bool useParallelOp = false;
/* TODO, need to implement this case */
if (!useParallelOp && noMinMaxBounds) {
Expand All @@ -80,7 +79,7 @@ void tileParallelLoop(ParallelOp op,
// Create the outer loop with adjusted steps.
SmallVector<Value, 2> newSteps;
newSteps.reserve(op.getStep().size());
for (auto step : llvm::zip(op.getStep(), tileSizeConstants)) {
for (auto step : llvm::zip_equal(op.getStep(), tileSizeConstants)) {
newSteps.push_back(b.create<arith::MulIOp>(op.getLoc(), std::get<0>(step),
std::get<1>(step)));
}
Expand Down Expand Up @@ -191,9 +190,6 @@ void tileParallelLoop(ParallelOp op,
.replaceAllUsesExcept(newIndex, newIndex);
}
thenBlock.eraseArguments(0, thenBlock.getNumArguments());
#if 0
} else if (!useParallelOp && noMinMaxBounds && needInboundCheck) {
#endif
} else {

if (useParallelOp) {
Expand All @@ -211,6 +207,7 @@ void tileParallelLoop(ParallelOp op,
else {
b.setInsertionPointToStart(innerLoops[innerLoops.size() - 1].getBody());
IRMapping mapper;
// Copy instruction by instruction and replace uses
for (auto opItr = op.getRegion().op_begin();
opItr != op.getRegion().op_end(); opItr++) {
if (!dyn_cast<scf::ReduceOp>(*opItr)) {
Expand All @@ -225,12 +222,14 @@ void tileParallelLoop(ParallelOp op,
Value innerIndex = innerLoops[index].getInductionVar();
auto newIndex = b.create<arith::AddIOp>(
op.getLoc(), innerIndex, outerLoop.getInductionVars()[index]);
// Cache the newly created index variables
indices.push_back(newIndex);
}

auto inductionVars =
dyn_cast<ParallelOp>(op.getRegion().getParentOp()).getInductionVars();

// Replace induction variables with newly created index variables
for (size_t i = 0; i < inductionVars.size(); i++) {
auto inductionVar = inductionVars[i];
inductionVar.replaceAllUsesWith(indices[i]);
Expand All @@ -245,7 +244,8 @@ namespace {
struct SCFParallelLoopTiling
: public tpp::impl::SCFParallelLoopTilingBase<SCFParallelLoopTiling> {
SCFParallelLoopTiling(){};
SCFParallelLoopTiling(ArrayRef<int64_t> tileSizes, bool noMinMaxBounds = false) {
SCFParallelLoopTiling(ArrayRef<int64_t> tileSizes,
bool noMinMaxBounds = false) {
this->tileSizes = tileSizes;
this->noMinMaxBounds = noMinMaxBounds;
};
Expand Down Expand Up @@ -273,4 +273,3 @@ struct SCFParallelLoopTiling
}
};
} // namespace

0 comments on commit bcc320d

Please sign in to comment.