Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AffineVectorLoadOp/AffineVectorStoreOp builders #24

Merged
merged 1 commit into from
Aug 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions mlir/include/mlir/Dialect/Affine/IR/AffineOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,19 @@ def AffineVectorLoadOp : AffineLoadOpBase<"vector_load"> {

let results = (outs AnyVector:$result);

let builders = [
/// Builds an affine vector load op with the specified map and operands.
OpBuilder<"OpBuilder &builder, OperationState &result, "
"VectorType resultType, AffineMap map, ValueRange operands">,
/// Builds an affine vector load op with an identity map and operands.
OpBuilder<"OpBuilder &builder, OperationState &result, "
"VectorType resultType, Value memref, ValueRange indices = {}">,
/// Builds an affine vector load op with the specified map and its operands.
OpBuilder<"OpBuilder &builder, OperationState &result, "
"VectorType resultType, Value memref, AffineMap map, "
"ValueRange mapOperands">
];

let extraClassDeclaration = extraClassDeclarationBase # [{
VectorType getVectorType() {
return result().getType().cast<VectorType>();
Expand Down Expand Up @@ -920,6 +933,15 @@ def AffineVectorStoreOp : AffineStoreOpBase<"vector_store"> {
[MemWrite]>:$memref,
Variadic<Index>:$indices);

let skipDefaultBuilders = 1;
let builders = [
OpBuilder<"OpBuilder &builder, OperationState &result, "
"Value valueToStore, Value memref, ValueRange indices">,
OpBuilder<"OpBuilder &builder, OperationState &result, "
"Value valueToStore, Value memref, AffineMap map, "
"ValueRange mapOperands">
];

let extraClassDeclaration = extraClassDeclarationBase # [{
VectorType getVectorType() {
return value().getType().cast<VectorType>();
Expand Down
55 changes: 55 additions & 0 deletions mlir/lib/Dialect/Affine/IR/AffineOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2966,6 +2966,38 @@ static LogicalResult verify(AffineYieldOp op) {
// AffineVectorLoadOp
//===----------------------------------------------------------------------===//

void AffineVectorLoadOp::build(OpBuilder &builder, OperationState &result,
VectorType resultType, AffineMap map,
ValueRange operands) {
assert(operands.size() == 1 + map.getNumInputs() && "inconsistent operands");
result.addOperands(operands);
if (map)
result.addAttribute(getMapAttrName(), AffineMapAttr::get(map));
result.types.push_back(resultType);
}

void AffineVectorLoadOp::build(OpBuilder &builder, OperationState &result,
VectorType resultType, Value memref,
AffineMap map, ValueRange mapOperands) {
assert(map.getNumInputs() == mapOperands.size() && "inconsistent index info");
result.addOperands(memref);
result.addOperands(mapOperands);
result.addAttribute(getMapAttrName(), AffineMapAttr::get(map));
result.types.push_back(resultType);
}

void AffineVectorLoadOp::build(OpBuilder &builder, OperationState &result,
VectorType resultType, Value memref,
ValueRange indices) {
auto memrefType = memref.getType().cast<MemRefType>();
auto rank = memrefType.getRank();
// Create identity map for memrefs with at least one dimension or () -> ()
// for zero-dimensional memrefs.
auto map =
rank ? builder.getMultiDimIdentityMap(rank) : builder.getEmptyAffineMap();
build(builder, result, resultType, memref, map, indices);
}

static ParseResult parseAffineVectorLoadOp(OpAsmParser &parser,
OperationState &result) {
auto &builder = parser.getBuilder();
Expand Down Expand Up @@ -3029,6 +3061,29 @@ static LogicalResult verify(AffineVectorLoadOp op) {
// AffineVectorStoreOp
//===----------------------------------------------------------------------===//

void AffineVectorStoreOp::build(OpBuilder &builder, OperationState &result,
Value valueToStore, Value memref, AffineMap map,
ValueRange mapOperands) {
assert(map.getNumInputs() == mapOperands.size() && "inconsistent index info");
result.addOperands(valueToStore);
result.addOperands(memref);
result.addOperands(mapOperands);
result.addAttribute(getMapAttrName(), AffineMapAttr::get(map));
}

// Use identity map.
void AffineVectorStoreOp::build(OpBuilder &builder, OperationState &result,
Value valueToStore, Value memref,
ValueRange indices) {
auto memrefType = memref.getType().cast<MemRefType>();
auto rank = memrefType.getRank();
// Create identity map for memrefs with at least one dimension or () -> ()
// for zero-dimensional memrefs.
auto map =
rank ? builder.getMultiDimIdentityMap(rank) : builder.getEmptyAffineMap();
build(builder, result, valueToStore, memref, map, indices);
}

static ParseResult parseAffineVectorStoreOp(OpAsmParser &parser,
OperationState &result) {
auto indexTy = parser.getBuilder().getIndexType();
Expand Down