Skip to content

Commit e3cf7c8

Browse files
[mlir][MemRef] NFC - Drop MemRef EDSC usage
Drop the MemRef dialect EDSC subdirectory and update all uses. Differential Revision: https://reviews.llvm.org/D102868
1 parent 3eb12b0 commit e3cf7c8

File tree

7 files changed

+71
-162
lines changed

7 files changed

+71
-162
lines changed

mlir/include/mlir/Dialect/Linalg/Utils/Utils.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include "mlir/Dialect/Affine/EDSC/Intrinsics.h"
1313
#include "mlir/Dialect/Linalg/Analysis/DependenceAnalysis.h"
1414
#include "mlir/Dialect/Linalg/IR/LinalgOps.h"
15-
#include "mlir/Dialect/MemRef/EDSC/Intrinsics.h"
1615
#include "mlir/Dialect/SCF/SCF.h"
1716
#include "mlir/Dialect/StandardOps/EDSC/Intrinsics.h"
1817
#include "mlir/Dialect/StandardOps/IR/Ops.h"

mlir/include/mlir/Dialect/MemRef/EDSC/Intrinsics.h

Lines changed: 0 additions & 86 deletions
This file was deleted.

mlir/include/mlir/IR/ImplicitLocOpBuilder.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,31 +63,31 @@ class ImplicitLocOpBuilder : public mlir::OpBuilder {
6363
/// Create an operation of specific op type at the current insertion point and
6464
/// location.
6565
template <typename OpTy, typename... Args>
66-
OpTy create(Args &&... args) {
66+
OpTy create(Args &&...args) {
6767
return OpBuilder::create<OpTy>(curLoc, std::forward<Args>(args)...);
6868
}
6969

7070
/// Create an operation of specific op type at the current insertion point,
7171
/// and immediately try to fold it. This functions populates 'results' with
7272
/// the results after folding the operation.
7373
template <typename OpTy, typename... Args>
74-
void createOrFold(llvm::SmallVectorImpl<Value> &results, Args &&... args) {
74+
void createOrFold(llvm::SmallVectorImpl<Value> &results, Args &&...args) {
7575
OpBuilder::createOrFold<OpTy>(results, curLoc, std::forward<Args>(args)...);
7676
}
7777

7878
/// Overload to create or fold a single result operation.
7979
template <typename OpTy, typename... Args>
8080
typename std::enable_if<OpTy::template hasTrait<mlir::OpTrait::OneResult>(),
8181
Value>::type
82-
createOrFold(Args &&... args) {
82+
createOrFold(Args &&...args) {
8383
return OpBuilder::createOrFold<OpTy>(curLoc, std::forward<Args>(args)...);
8484
}
8585

8686
/// Overload to create or fold a zero result operation.
8787
template <typename OpTy, typename... Args>
8888
typename std::enable_if<OpTy::template hasTrait<mlir::OpTrait::ZeroResult>(),
8989
OpTy>::type
90-
createOrFold(Args &&... args) {
90+
createOrFold(Args &&...args) {
9191
return OpBuilder::createOrFold<OpTy>(curLoc, std::forward<Args>(args)...);
9292
}
9393

mlir/lib/Dialect/GPU/Transforms/MemoryPromotion.cpp

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313

1414
#include "mlir/Dialect/GPU/MemoryPromotion.h"
1515
#include "mlir/Dialect/GPU/GPUDialect.h"
16-
#include "mlir/Dialect/MemRef/EDSC/Intrinsics.h"
1716
#include "mlir/Dialect/SCF/SCF.h"
1817
#include "mlir/Dialect/StandardOps/EDSC/Intrinsics.h"
18+
#include "mlir/IR/ImplicitLocOpBuilder.h"
1919
#include "mlir/Pass/Pass.h"
2020
#include "mlir/Transforms/LoopUtils.h"
2121

@@ -41,45 +41,46 @@ static StringRef getDimName(unsigned dim) {
4141
/// GPUDialect::getNumWorkgroupDimensions() loops, completing the nest with
4242
/// single-iteration loops. Maps the innermost loops to thread dimensions, in
4343
/// reverse order to enable access coalescing in the innermost loop.
44-
static void insertCopyLoops(OpBuilder &b, Location loc,
45-
MemRefBoundsCapture &bounds, Value from, Value to) {
46-
// Create EDSC handles for bounds.
47-
unsigned rank = bounds.rank();
44+
static void insertCopyLoops(ImplicitLocOpBuilder &b, Value from, Value to) {
45+
auto memRefType = from.getType().cast<MemRefType>();
46+
auto rank = memRefType.getRank();
47+
4848
SmallVector<Value, 4> lbs, ubs, steps;
49+
Value zero = b.create<ConstantIndexOp>(0);
50+
Value one = b.create<ConstantIndexOp>(1);
4951

5052
// Make sure we have enough loops to use all thread dimensions, these trivial
5153
// loops should be outermost and therefore inserted first.
5254
if (rank < GPUDialect::getNumWorkgroupDimensions()) {
5355
unsigned extraLoops = GPUDialect::getNumWorkgroupDimensions() - rank;
54-
Value zero = std_constant_index(0);
55-
Value one = std_constant_index(1);
5656
lbs.resize(extraLoops, zero);
5757
ubs.resize(extraLoops, one);
5858
steps.resize(extraLoops, one);
5959
}
6060

6161
// Add existing bounds.
62-
lbs.append(bounds.getLbs().begin(), bounds.getLbs().end());
63-
ubs.append(bounds.getUbs().begin(), bounds.getUbs().end());
64-
65-
// Emit constant operations for steps.
62+
lbs.append(rank, zero);
63+
ubs.reserve(lbs.size());
6664
steps.reserve(lbs.size());
67-
llvm::transform(bounds.getSteps(), std::back_inserter(steps),
68-
[](int64_t step) { return std_constant_index(step); });
65+
for (auto idx = 0; idx < rank; ++idx) {
66+
ubs.push_back(
67+
b.createOrFold<memref::DimOp>(from, b.create<ConstantIndexOp>(idx)));
68+
steps.push_back(one);
69+
}
6970

7071
// Obtain thread identifiers and block sizes, necessary to map to them.
7172
auto indexType = b.getIndexType();
7273
SmallVector<Value, 3> threadIds, blockDims;
7374
for (unsigned i = 0; i < 3; ++i) {
7475
auto dimName = b.getStringAttr(getDimName(i));
75-
threadIds.push_back(b.create<gpu::ThreadIdOp>(loc, indexType, dimName));
76-
blockDims.push_back(b.create<gpu::BlockDimOp>(loc, indexType, dimName));
76+
threadIds.push_back(b.create<gpu::ThreadIdOp>(indexType, dimName));
77+
blockDims.push_back(b.create<gpu::BlockDimOp>(indexType, dimName));
7778
}
7879

7980
// Produce the loop nest with copies.
8081
SmallVector<Value, 8> ivs(lbs.size());
8182
mlir::scf::buildLoopNest(
82-
b, loc, lbs, ubs, steps,
83+
b, b.getLoc(), lbs, ubs, steps,
8384
[&](OpBuilder &b, Location loc, ValueRange loopIvs) {
8485
ivs.assign(loopIvs.begin(), loopIvs.end());
8586
auto activeIvs = llvm::makeArrayRef(ivs).take_back(rank);
@@ -142,17 +143,13 @@ static void insertCopies(Region &region, Location loc, Value from, Value to) {
142143
assert(llvm::hasSingleElement(region) &&
143144
"unstructured control flow not supported");
144145

145-
OpBuilder b(region.getContext());
146-
b.setInsertionPointToStart(&region.front());
147-
148-
ScopedContext edscContext(b, loc);
149-
MemRefBoundsCapture fromBoundsCapture(from);
150-
insertCopyLoops(b, loc, fromBoundsCapture, from, to);
151-
b.create<gpu::BarrierOp>(loc);
146+
auto b = ImplicitLocOpBuilder::atBlockBegin(loc, &region.front());
147+
insertCopyLoops(b, from, to);
148+
b.create<gpu::BarrierOp>();
152149

153150
b.setInsertionPoint(&region.front().back());
154-
b.create<gpu::BarrierOp>(loc);
155-
insertCopyLoops(b, loc, fromBoundsCapture, to, from);
151+
b.create<gpu::BarrierOp>();
152+
insertCopyLoops(b, to, from);
156153
}
157154

158155
/// Promotes a function argument to workgroup memory in the given function. The

0 commit comments

Comments
 (0)