MLIR  19.0.0git
Utils.cpp
Go to the documentation of this file.
1 //===- Utils.cpp - Transform dialect utilities ----------------------------===//
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 
10 
11 #include "mlir/IR/OpDefinition.h"
13 
14 using namespace mlir;
15 using namespace mlir::transform;
16 
18  OpAsmPrinter &printer, Operation *op, Value packed, Type packedType,
19  OperandRange values, TypeRange valueTypes, DenseI64ArrayAttr integers) {
20  if (packed) {
21  assert(values.empty() && (!integers || integers.empty()) &&
22  "expected no values/integers");
23  printer << "*(" << packed << " : " << packedType << ")";
24  return;
25  }
26  printDynamicIndexList(printer, op, values, integers, valueTypes);
27 }
28 
30  OpAsmParser &parser, std::optional<OpAsmParser::UnresolvedOperand> &packed,
32  SmallVectorImpl<Type> &valueTypes, DenseI64ArrayAttr &integers) {
33  OpAsmParser::UnresolvedOperand packedOperand;
34  if (parser.parseOptionalStar().succeeded()) {
35  if (parser.parseLParen().failed() ||
36  parser.parseOperand(packedOperand).failed() ||
37  parser.parseColonType(packedType).failed() ||
38  parser.parseRParen().failed()) {
39  return failure();
40  }
41  packed.emplace(packedOperand);
42  integers = parser.getBuilder().getDenseI64ArrayAttr({});
43  return success();
44  }
45 
46  return parseDynamicIndexList(parser, values, integers, &valueTypes);
47 }
virtual Builder & getBuilder() const =0
Return a builder which provides useful access to MLIRContext, global objects like types and attribute...
virtual ParseResult parseRParen()=0
Parse a ) token.
virtual ParseResult parseColonType(Type &result)=0
Parse a colon followed by a type.
virtual ParseResult parseOptionalStar()=0
Parse a '*' token if present.
virtual ParseResult parseLParen()=0
Parse a ( token.
DenseI64ArrayAttr getDenseI64ArrayAttr(ArrayRef< int64_t > values)
Definition: Builders.cpp:183
The OpAsmParser has methods for interacting with the asm parser: parsing things from it,...
virtual ParseResult parseOperand(UnresolvedOperand &result, bool allowResultNumber=true)=0
Parse a single SSA value operand name along with a result number if allowResultNumber is true.
This is a pure-virtual base class that exposes the asmprinter hooks necessary to implement a custom p...
This class implements the operand iterators for the Operation class.
Definition: ValueRange.h:42
Operation is the basic unit of execution within MLIR.
Definition: Operation.h:88
This class represents success/failure for parsing-like operations that find it important to chain tog...
This class provides an abstraction over the various different ranges of value types.
Definition: TypeRange.h:36
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition: Types.h:74
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition: Value.h:96
Base class for DenseArrayAttr that is instantiated and specialized for each supported element type be...
void printPackedOrDynamicIndexList(OpAsmPrinter &printer, Operation *op, Value packed, Type packedType, OperandRange values, TypeRange valueTypes, DenseI64ArrayAttr integers)
Printer hook for custom directive in assemblyFormat.
Definition: Utils.cpp:17
ParseResult parsePackedOrDynamicIndexList(OpAsmParser &parser, std::optional< OpAsmParser::UnresolvedOperand > &packed, Type &packedType, SmallVectorImpl< OpAsmParser::UnresolvedOperand > &values, SmallVectorImpl< Type > &valueTypes, DenseI64ArrayAttr &integers)
Parser hook for custom directive in assemblyFormat.
Definition: Utils.cpp:29
Include the generated interface declarations.
LogicalResult failure(bool isFailure=true)
Utility function to generate a LogicalResult.
Definition: LogicalResult.h:62
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
Definition: LogicalResult.h:56
void printDynamicIndexList(OpAsmPrinter &printer, Operation *op, OperandRange values, ArrayRef< int64_t > integers, TypeRange valueTypes=TypeRange(), ArrayRef< bool > scalables={}, AsmParser::Delimiter delimiter=AsmParser::Delimiter::Square)
Printer hook for custom directive in assemblyFormat.
ParseResult parseDynamicIndexList(OpAsmParser &parser, SmallVectorImpl< OpAsmParser::UnresolvedOperand > &values, DenseI64ArrayAttr &integers, DenseBoolArrayAttr &scalableVals, SmallVectorImpl< Type > *valueTypes=nullptr, AsmParser::Delimiter delimiter=AsmParser::Delimiter::Square)
Parser hook for custom directive in assemblyFormat.
bool succeeded() const
Returns true if the provided LogicalResult corresponds to a success value.
Definition: LogicalResult.h:41
bool failed() const
Returns true if the provided LogicalResult corresponds to a failure value.
Definition: LogicalResult.h:44
This is the representation of an operand reference.