MLIR 22.0.0git
FunctionImplementation.h
Go to the documentation of this file.
1//===- FunctionImplementation.h - Function-like Op utilities ----*- 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 provides utility functions for implementing function-like
10// operations, in particular, parsing, printing and verification components
11// common to function-like operations.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef MLIR_IR_FUNCTIONIMPLEMENTATION_H_
16#define MLIR_IR_FUNCTIONIMPLEMENTATION_H_
17
20
21namespace mlir {
22
24
25/// A named class for passing around the variadic flag.
27public:
28 explicit VariadicFlag(bool variadic) : variadic(variadic) {}
29 bool isVariadic() const { return variadic; }
30
31private:
32 /// Underlying storage.
33 bool variadic;
34};
35
36/// Callback type for `parseFunctionOp`, the callback should produce the
37/// type that will be associated with a function-like operation from lists of
38/// function arguments and results, VariadicFlag indicates whether the function
39/// should have variadic arguments; in case of error, it may populate the last
40/// argument with a message.
43
44/// Parses a function signature using `parser`. The `allowVariadic` argument
45/// indicates whether functions with variadic arguments are supported. The
46/// trailing arguments are populated by this function with names, types,
47/// attributes and locations of the arguments and those of the results.
49 OpAsmParser &parser, bool allowVariadic,
50 SmallVectorImpl<OpAsmParser::Argument> &arguments, bool &isVariadic,
51 SmallVectorImpl<Type> &resultTypes,
53
54/// Parser implementation for function-like operations. Uses
55/// `funcTypeBuilder` to construct the custom function type given lists of
56/// input and output types. The parser sets the `typeAttrName` attribute to the
57/// resulting function type. If `allowVariadic` is set, the parser will accept
58/// trailing ellipsis in the function signature and indicate to the builder
59/// whether the function is variadic. If the builder returns a null type,
60/// `result` will not contain the `type` attribute. The caller can then add a
61/// type, report the error or delegate the reporting to the op's verifier.
63 bool allowVariadic, StringAttr typeAttrName,
64 FuncTypeBuilder funcTypeBuilder,
65 StringAttr argAttrsName, StringAttr resAttrsName);
66
67/// Printer implementation for function-like operations.
68void printFunctionOp(OpAsmPrinter &p, FunctionOpInterface op, bool isVariadic,
69 StringRef typeAttrName, StringAttr argAttrsName,
70 StringAttr resAttrsName);
71
72/// Prints the signature of the function-like operation `op`. Assumes `op` has
73/// is a FunctionOpInterface and has passed verification.
74inline void printFunctionSignature(OpAsmPrinter &p, FunctionOpInterface op,
75 ArrayRef<Type> argTypes, bool isVariadic,
76 ArrayRef<Type> resultTypes) {
78 p, argTypes, op.getArgAttrsAttr(), isVariadic, resultTypes,
79 op.getResAttrsAttr(), &op->getRegion(0),
80 /*printEmptyResult=*/false);
81}
82
83/// Prints the list of function prefixed with the "attributes" keyword. The
84/// attributes with names listed in "elided" as well as those used by the
85/// function-like operation internally are not printed. Nothing is printed
86/// if all attributes are elided. Assumes `op` is a FunctionOpInterface and
87/// has passed verification.
89 ArrayRef<StringRef> elided = {});
90
91} // namespace function_interface_impl
92
93} // namespace mlir
94
95#endif // MLIR_IR_FUNCTIONIMPLEMENTATION_H_
This class is a general helper class for creating context-global objects like types,...
Definition Builders.h:51
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:88
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition Types.h:74
A named class for passing around the variadic flag.
void printFunctionSignature(OpAsmPrinter &p, TypeRange argTypes, ArrayAttr argAttrs, bool isVariadic, TypeRange resultTypes, ArrayAttr resultAttrs, Region *body=nullptr, bool printEmptyResult=true)
Print a function signature for a call or callable operation.
function_ref< Type( Builder &, ArrayRef< Type >, ArrayRef< Type >, VariadicFlag, std::string &)> FuncTypeBuilder
Callback type for parseFunctionOp, the callback should produce the type that will be associated with ...
ParseResult parseFunctionSignatureWithArguments(OpAsmParser &parser, bool allowVariadic, SmallVectorImpl< OpAsmParser::Argument > &arguments, bool &isVariadic, SmallVectorImpl< Type > &resultTypes, SmallVectorImpl< DictionaryAttr > &resultAttrs)
Parses a function signature using parser.
void printFunctionOp(OpAsmPrinter &p, FunctionOpInterface op, bool isVariadic, StringRef typeAttrName, StringAttr argAttrsName, StringAttr resAttrsName)
Printer implementation for function-like operations.
ParseResult parseFunctionOp(OpAsmParser &parser, OperationState &result, bool allowVariadic, StringAttr typeAttrName, FuncTypeBuilder funcTypeBuilder, StringAttr argAttrsName, StringAttr resAttrsName)
Parser implementation for function-like operations.
void printFunctionAttributes(OpAsmPrinter &p, Operation *op, ArrayRef< StringRef > elided={})
Prints the list of function prefixed with the "attributes" keyword.
void printFunctionSignature(OpAsmPrinter &p, FunctionOpInterface op, ArrayRef< Type > argTypes, bool isVariadic, ArrayRef< Type > resultTypes)
Prints the signature of the function-like operation op.
Include the generated interface declarations.
llvm::function_ref< Fn > function_ref
Definition LLVM.h:152
This represents an operation in an abstracted form, suitable for use with the builder APIs.