MLIR 24.0.0git
TilingInterface.cpp
Go to the documentation of this file.
1//===- TilingInterface.cpp - Tiling interface -------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file contains the definitions of the interface in `TilingInterface.td`.
10//
11//===----------------------------------------------------------------------===//
12
14
15#include "llvm/ADT/STLExtras.h"
16#include "llvm/ADT/SmallVectorExtras.h"
17#include "llvm/ADT/StringSwitch.h"
18
19using namespace mlir;
20
22 ArrayRef<int64_t> alignments) {
23 for (int64_t a : alignments)
25 return op->emitOpError()
26 << "expected inner_tile_alignments entries to be one of 0 "
27 "(Unknown), 1 (Multiple) or 2 (Equal), but got "
28 << a;
29 return success();
30}
31
34 return llvm::map_to_vector(alignments, [](int64_t v) {
35 assert(isValidInnerTileAlignment(v) &&
36 "invalid InnerTileAlignment; should be rejected by the verifier");
37 return static_cast<InnerTileAlignment>(v);
38 });
39}
40
42 switch (alignment) {
44 return "Unknown";
46 return "Multiple";
48 return "Equal";
49 }
50 llvm_unreachable("unknown InnerTileAlignment");
51}
52
53std::optional<InnerTileAlignment>
56 .Case("Unknown", InnerTileAlignment::Unknown)
57 .Case("Multiple", InnerTileAlignment::Multiple)
58 .Case("Equal", InnerTileAlignment::Equal)
59 .Default(std::nullopt);
60}
61
63 DenseI64ArrayAttr &alignments) {
65 auto parseEntry = [&]() -> ParseResult {
66 StringRef keyword;
67 llvm::SMLoc loc = parser.getCurrentLocation();
68 if (parser.parseKeyword(&keyword))
69 return failure();
70 std::optional<InnerTileAlignment> alignment =
72 if (!alignment)
73 return parser.emitError(loc)
74 << "expected one of 'Unknown', 'Multiple' or 'Equal', but got '"
75 << keyword << "'";
76 values.push_back(static_cast<int64_t>(*alignment));
77 return success();
78 };
80 return failure();
81 alignments = DenseI64ArrayAttr::get(parser.getContext(), values);
82 return success();
83}
84
86 DenseI64ArrayAttr alignments) {
87 printer << "[";
88 llvm::interleaveComma(alignments.asArrayRef(), printer, [&](int64_t value) {
89 printer << stringifyInnerTileAlignment(
90 static_cast<InnerTileAlignment>(value));
91 });
92 printer << "]";
93}
94
95#include "mlir/Interfaces/TilingInterface.cpp.inc"
return success()
static LogicalResult parseEntry(EncodingReader &reader, RangeT &entries, T &entry, StringRef entryStr)
Parse and resolve an index into the given entry list.
@ Square
Square brackets surrounding zero or more operands.
virtual ParseResult parseCommaSeparatedList(Delimiter delimiter, function_ref< ParseResult()> parseElementFn, StringRef contextMessage=StringRef())=0
Parse a list of comma-separated items with an optional delimiter.
MLIRContext * getContext() const
virtual InFlightDiagnostic emitError(SMLoc loc, const Twine &message={})=0
Emit a diagnostic at the specified location and return failure.
virtual SMLoc getCurrentLocation()=0
Get the location of the next token and store it into the argument.
ParseResult parseKeyword(StringRef keyword)
Parse a given keyword.
The OpAsmParser has methods for interacting with the asm parser: parsing things from it,...
This is a pure-virtual base class that exposes the asmprinter hooks necessary to implement a custom p...
Operation is the basic unit of execution within MLIR.
Definition Operation.h:87
InFlightDiagnostic emitOpError(const Twine &message={})
Emit an error with the op name prefixed, like "'dim' op " which is convenient for verifiers.
static DenseArrayAttrImpl get(MLIRContext *context, ArrayRef< int64_t > content)
Include the generated interface declarations.
bool isValidInnerTileAlignment(int64_t value)
Returns true iff value is a valid InnerTileAlignment enumerator.
detail::DenseArrayAttrImpl< int64_t > DenseI64ArrayAttr
void printInnerTileAlignmentArray(OpAsmPrinter &printer, Operation *op, DenseI64ArrayAttr alignments)
ParseResult parseInnerTileAlignmentArray(OpAsmParser &parser, DenseI64ArrayAttr &alignments)
Custom directive parser/printer for an inner_tile_alignments attribute, rendering the DenseI64ArrayAt...
std::optional< InnerTileAlignment > symbolizeInnerTileAlignment(StringRef keyword)
Returns the InnerTileAlignment for a keyword spelling, or std::nullopt if keyword is not one of Unkno...
StringRef stringifyInnerTileAlignment(InnerTileAlignment alignment)
Returns the keyword spelling of an InnerTileAlignment (Unknown, Multiple or Equal) used by the inner_...
SmallVector< InnerTileAlignment > convertInnerTileAlignments(ArrayRef< int64_t > alignments)
Maps a validated inner_tile_alignments integer array onto the per-dimension InnerTileAlignment hints ...
LogicalResult verifyInnerTileAlignments(Operation *op, ArrayRef< int64_t > alignments)
Verifies that every entry of a raw inner_tile_alignments integer array is a valid InnerTileAlignment,...
InnerTileAlignment
Per-dimension alignment of a loop tile size to a linalg.pack / linalg.unpack inner tile size,...