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;
24  if (packedType) {
25  printer << " : " << packedType;
26  }
27  printer << ")";
28  return;
29  }
30  printDynamicIndexList(printer, op, values, integers, valueTypes);
31 }
32 
34  OpAsmParser &parser, std::optional<OpAsmParser::UnresolvedOperand> &packed,
36  SmallVectorImpl<Type> *valueTypes, DenseI64ArrayAttr &integers) {
37  OpAsmParser::UnresolvedOperand packedOperand;
38  if (parser.parseOptionalStar().succeeded()) {
39  if (parser.parseLParen().failed() ||
40  parser.parseOperand(packedOperand).failed())
41  return failure();
42  if (packedType && (parser.parseColonType(packedType).failed()))
43  return failure();
44  if (parser.parseRParen().failed())
45  return failure();
46  packed.emplace(packedOperand);
47  integers = parser.getBuilder().getDenseI64ArrayAttr({});
48  return success();
49  }
50 
51  return parseDynamicIndexList(parser, values, integers, valueTypes);
52 }
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...
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:33
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
Include the generated interface declarations.
LogicalResult failure(bool isFailure=true)
Utility function to generate a LogicalResult.
Definition: LogicalResult.h:62
void printDynamicIndexList(OpAsmPrinter &printer, Operation *op, OperandRange values, ArrayRef< int64_t > integers, ArrayRef< bool > scalables, TypeRange valueTypes=TypeRange(), AsmParser::Delimiter delimiter=AsmParser::Delimiter::Square)
Printer hook for custom directive in assemblyFormat.
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
Definition: LogicalResult.h:56
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.