18 #include "mlir/Interfaces/ViewLikeInterface.cpp.inc"
26 if (staticVals.size() != numElements)
27 return op->
emitError(
"expected ") << numElements <<
" " << name
28 <<
" values, got " << staticVals.size();
29 unsigned expectedNumDynamicEntries =
30 llvm::count_if(staticVals, ShapedType::isDynamic);
31 if (values.size() != expectedNumDynamicEntries)
33 << expectedNumDynamicEntries <<
" dynamic " << name <<
" values";
40 bool generateErrorMessage) {
43 for (int64_t i = 0, e = shape.size(); i < e; ++i) {
45 if (ShapedType::isDynamic(shape[i]))
48 if (ShapedType::isDynamic(staticOffsets[i]))
50 if (staticOffsets[i] >= shape[i]) {
52 std::string(
"offset ") + std::to_string(i) +
53 " is out-of-bounds: " + std::to_string(staticOffsets[i]) +
54 " >= " + std::to_string(shape[i]);
58 if (ShapedType::isDynamic(staticSizes[i]) ||
59 ShapedType::isDynamic(staticStrides[i]))
62 staticOffsets[i] + (staticSizes[i] - 1) * staticStrides[i];
63 if (lastPos >= shape[i]) {
64 result.
errorMessage = std::string(
"slice along dimension ") +
66 " runs out-of-bounds: " + std::to_string(lastPos) +
67 " >= " + std::to_string(shape[i]);
78 bool generateErrorMessage) {
82 if (
auto attr = dyn_cast<Attribute>(ofr)) {
83 staticValues.push_back(cast<IntegerAttr>(attr).getInt());
85 staticValues.push_back(ShapedType::kDynamic);
91 shape, getStaticValues(mixedOffsets), getStaticValues(mixedSizes),
92 getStaticValues(mixedStrides), generateErrorMessage);
97 std::array<unsigned, 3> maxRanks = op.getArrayAttrMaxRanks();
102 if (!(op.getMixedOffsets().size() == 1 && maxRanks[0] == 1) &&
103 op.getMixedOffsets().size() != op.getMixedSizes().size())
104 return op->emitError(
105 "expected mixed offsets rank to match mixed sizes rank (")
106 << op.getMixedOffsets().size() <<
" vs " << op.getMixedSizes().size()
107 <<
") so the rank of the result type is well-formed.";
110 if (op.getMixedSizes().size() != op.getMixedStrides().size())
111 return op->emitError(
112 "expected mixed sizes rank to match mixed strides rank (")
113 << op.getMixedSizes().size() <<
" vs " << op.getMixedStrides().size()
114 <<
") so the rank of the result type is well-formed.";
117 op,
"offset", maxRanks[0], op.getStaticOffsets(), op.getOffsets())))
120 op,
"size", maxRanks[1], op.getStaticSizes(), op.getSizes())))
123 op,
"stride", maxRanks[2], op.getStaticStrides(), op.getStrides())))
126 for (int64_t offset : op.getStaticOffsets()) {
127 if (offset < 0 && !ShapedType::isDynamic(offset))
128 return op->emitError(
"expected offsets to be non-negative, but got ")
131 for (int64_t size : op.getStaticSizes()) {
132 if (size < 0 && !ShapedType::isDynamic(size))
133 return op->emitError(
"expected sizes to be non-negative, but got ")
150 llvm_unreachable(
"unsupported delimiter");
165 llvm_unreachable(
"unsupported delimiter");
177 printer << leftDelimiter;
178 if (integers.empty()) {
179 printer << rightDelimiter;
183 unsigned dynamicValIdx = 0;
184 unsigned scalableIndexIdx = 0;
185 llvm::interleaveComma(integers, printer, [&](int64_t integer) {
186 if (!scalableFlags.empty() && scalableFlags[scalableIndexIdx])
188 if (ShapedType::isDynamic(integer)) {
189 printer << values[dynamicValIdx];
190 if (!valueTypes.empty())
191 printer <<
" : " << valueTypes[dynamicValIdx];
196 if (!scalableFlags.empty() && scalableFlags[scalableIndexIdx])
202 printer << rightDelimiter;
213 auto parseIntegerOrValue = [&]() {
220 if (res.has_value() && succeeded(res.value())) {
221 values.push_back(operand);
222 integerVals.push_back(ShapedType::kDynamic);
223 if (valueTypes && parser.
parseColonType(valueTypes->emplace_back()))
229 integerVals.push_back(integer);
239 " in dynamic index list"))
241 <<
"expected SSA value or integer";
248 OffsetSizeAndStrideOpInterface a, OffsetSizeAndStrideOpInterface b,
250 if (a.getStaticOffsets().size() != b.getStaticOffsets().size())
252 if (a.getStaticSizes().size() != b.getStaticSizes().size())
254 if (a.getStaticStrides().size() != b.getStaticStrides().size())
256 for (
auto it : llvm::zip(a.getMixedOffsets(), b.getMixedOffsets()))
257 if (!cmp(std::get<0>(it), std::get<1>(it)))
259 for (
auto it : llvm::zip(a.getMixedSizes(), b.getMixedSizes()))
260 if (!cmp(std::get<0>(it), std::get<1>(it)))
262 for (
auto it : llvm::zip(a.getMixedStrides(), b.getMixedStrides()))
263 if (!cmp(std::get<0>(it), std::get<1>(it)))
270 return std::count_if(staticVals.begin(), staticVals.begin() + idx,
271 ShapedType::isDynamic);
static char getLeftDelimiter(AsmParser::Delimiter delimiter)
static char getRightDelimiter(AsmParser::Delimiter delimiter)
Delimiter
These are the supported delimiters around operand lists and region argument lists,...
@ Paren
Parens surrounding zero or more operands.
@ Braces
{} brackets surrounding zero or more operands.
@ Square
Square brackets surrounding zero or more operands.
@ LessGreater
<> 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.
virtual Builder & getBuilder() const =0
Return a builder which provides useful access to MLIRContext, global objects like types and attribute...
virtual InFlightDiagnostic emitError(SMLoc loc, const Twine &message={})=0
Emit a diagnostic at the specified location and return failure.
ParseResult parseInteger(IntT &result)
Parse an integer value from the stream.
virtual ParseResult parseColonType(Type &result)=0
Parse a colon followed by a type.
virtual SMLoc getNameLoc() const =0
Return the location of the original name token.
virtual ParseResult parseOptionalRSquare()=0
Parse a ] token if present.
virtual ParseResult parseOptionalLSquare()=0
Parse a [ token if present.
DenseI64ArrayAttr getDenseI64ArrayAttr(ArrayRef< int64_t > values)
DenseBoolArrayAttr getDenseBoolArrayAttr(ArrayRef< bool > values)
Tensor-typed DenseArrayAttr getters.
The OpAsmParser has methods for interacting with the asm parser: parsing things from it,...
virtual OptionalParseResult parseOptionalOperand(UnresolvedOperand &result, bool allowResultNumber=true)=0
Parse a single operand if present.
This is a pure-virtual base class that exposes the asmprinter hooks necessary to implement a custom p...
This class represents a single result from folding an operation.
This class implements the operand iterators for the Operation class.
Operation is the basic unit of execution within MLIR.
InFlightDiagnostic emitError(const Twine &message={})
Emit an error about fatal conditions with this operation, reporting up to any diagnostic handlers tha...
This class provides an abstraction over the various different ranges of value types.
This class provides an abstraction over the different types of ranges over Values.
Base class for DenseArrayAttr that is instantiated and specialized for each supported element type be...
bool sameOffsetsSizesAndStrides(OffsetSizeAndStrideOpInterface a, OffsetSizeAndStrideOpInterface b, llvm::function_ref< bool(OpFoldResult, OpFoldResult)> cmp)
unsigned getNumDynamicEntriesUpToIdx(ArrayRef< int64_t > staticVals, unsigned idx)
Helper method to compute the number of dynamic entries of staticVals, up to idx.
LogicalResult verifyOffsetSizeAndStrideOp(OffsetSizeAndStrideOpInterface op)
Include the generated interface declarations.
ParseResult parseDynamicIndexList(OpAsmParser &parser, SmallVectorImpl< OpAsmParser::UnresolvedOperand > &values, DenseI64ArrayAttr &integers, DenseBoolArrayAttr &scalableFlags, SmallVectorImpl< Type > *valueTypes=nullptr, AsmParser::Delimiter delimiter=AsmParser::Delimiter::Square)
Parser hooks for custom directive in assemblyFormat.
SliceBoundsVerificationResult verifyInBoundsSlice(ArrayRef< int64_t > shape, ArrayRef< int64_t > staticOffsets, ArrayRef< int64_t > staticSizes, ArrayRef< int64_t > staticStrides, bool generateErrorMessage=false)
Verify that the offsets/sizes/strides-style access into the given shape is in-bounds.
LogicalResult verifyListOfOperandsOrIntegers(Operation *op, StringRef name, unsigned expectedNumElements, ArrayRef< int64_t > attr, ValueRange values)
Verify that a the values has as many elements as the number of entries in attr for which isDynamic ev...
void printDynamicIndexList(OpAsmPrinter &printer, Operation *op, OperandRange values, ArrayRef< int64_t > integers, ArrayRef< bool > scalableFlags, TypeRange valueTypes=TypeRange(), AsmParser::Delimiter delimiter=AsmParser::Delimiter::Square)
Printer hooks for custom directive in assemblyFormat.
This is the representation of an operand reference.
Result for slice bounds verification;.
bool isValid
If set to "true", the slice bounds verification was successful.
std::string errorMessage
An error message that can be printed during op verification.