Files
clang-p2996/mlir/lib/Dialect/StandardOps/EDSC/Builders.cpp
Nicolas Vasilache 75394e1301 [mlir][EDSC] Almost NFC - Refactor and untangle EDSC dependencies
This CL refactors EDSCs to layer them better and break unnecessary
dependencies. After this refactoring, the top-level EDSC target only
depends on IR but not on Dialects anymore and each dialect has its
own EDSC directory.

This simplifies the layering and breaks cyclic dependencies.
In particular, the declarative builder + folder are made explicit and
are now confined to Linalg.

As the refactoring occurred, certain classes and abstractions that were not
paying for themselves have been removed.

Differential Revision: https://reviews.llvm.org/D74302
2020-02-10 12:10:41 -05:00

50 lines
1.6 KiB
C++

//===- Builders.cpp - MLIR Declarative Builder Classes --------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "mlir/Dialect/StandardOps/EDSC/Intrinsics.h"
#include "mlir/IR/AffineExpr.h"
#include "mlir/IR/AffineMap.h"
using namespace mlir;
using namespace mlir::edsc;
using namespace mlir::edsc::intrinsics;
static SmallVector<ValueHandle, 8> getMemRefSizes(Value memRef) {
MemRefType memRefType = memRef.getType().cast<MemRefType>();
assert(isStrided(memRefType) && "Expected strided MemRef type");
SmallVector<ValueHandle, 8> res;
res.reserve(memRefType.getShape().size());
const auto &shape = memRefType.getShape();
for (unsigned idx = 0, n = shape.size(); idx < n; ++idx) {
if (shape[idx] == -1)
res.push_back(std_dim(memRef, idx));
else
res.push_back(std_constant_index(shape[idx]));
}
return res;
}
mlir::edsc::MemRefBoundsCapture::MemRefBoundsCapture(Value v) : base(v) {
auto memrefSizeValues = getMemRefSizes(v);
for (auto s : memrefSizeValues) {
lbs.push_back(std_constant_index(0));
ubs.push_back(s);
steps.push_back(1);
}
}
mlir::edsc::VectorBoundsCapture::VectorBoundsCapture(Value v) : base(v) {
auto vectorType = v.getType().cast<VectorType>();
for (auto s : vectorType.getShape()) {
lbs.push_back(std_constant_index(0));
ubs.push_back(std_constant_index(s));
steps.push_back(1);
}
}