MLIR  21.0.0git
CallInterfaces.h
Go to the documentation of this file.
1 //===- CallInterfaces.h - Call Interfaces for MLIR --------------*- 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 call interfaces defined in
10 // `CallInterfaces.td`.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef MLIR_INTERFACES_CALLINTERFACES_H
15 #define MLIR_INTERFACES_CALLINTERFACES_H
16 
18 #include "mlir/IR/SymbolTable.h"
19 #include "llvm/ADT/PointerUnion.h"
20 
21 namespace mlir {
22 /// A callable is either a symbol, or an SSA value, that is referenced by a
23 /// call-like operation. This represents the destination of the call.
24 struct CallInterfaceCallable : public PointerUnion<SymbolRefAttr, Value> {
26 };
27 
28 class CallOpInterface;
29 
30 namespace call_interface_impl {
31 
32 /// Resolve the callable operation for given callee to a CallableOpInterface, or
33 /// nullptr if a valid callable was not resolved. `symbolTable` is an optional
34 /// parameter that will allow for using a cached symbol table for symbol lookups
35 /// instead of performing an O(N) scan.
36 Operation *resolveCallable(CallOpInterface call,
37  SymbolTableCollection *symbolTable = nullptr);
38 
39 /// Parse a function or call result list.
40 ///
41 /// function-result-list ::= function-result-list-parens
42 /// | non-function-type
43 /// function-result-list-parens ::= `(` `)`
44 /// | `(` function-result-list-no-parens `)`
45 /// function-result-list-no-parens ::= function-result (`,` function-result)*
46 /// function-result ::= type attribute-dict?
47 ///
48 ParseResult
50  SmallVectorImpl<DictionaryAttr> &resultAttrs);
51 
52 /// Parses a function signature using `parser`. This does not deal with function
53 /// signatures containing SSA region arguments (to parse these signatures, use
54 /// function_interface_impl::parseFunctionSignature). When
55 /// `mustParseEmptyResult`, `-> ()` is expected when there is no result type.
56 ///
57 /// no-ssa-function-signature ::= `(` no-ssa-function-arg-list `)`
58 /// -> function-result-list
59 /// no-ssa-function-arg-list ::= no-ssa-function-arg
60 /// (`,` no-ssa-function-arg)*
61 /// no-ssa-function-arg ::= type attribute-dict?
62 ParseResult parseFunctionSignature(OpAsmParser &parser,
63  SmallVectorImpl<Type> &argTypes,
65  SmallVectorImpl<Type> &resultTypes,
67  bool mustParseEmptyResult = true);
68 
69 /// Print a function signature for a call or callable operation. If a body
70 /// region is provided, the SSA arguments are printed in the signature. When
71 /// `printEmptyResult` is false, `-> function-result-list` is omitted when
72 /// `resultTypes` is empty.
73 ///
74 /// function-signature ::= ssa-function-signature
75 /// | no-ssa-function-signature
76 /// ssa-function-signature ::= `(` ssa-function-arg-list `)`
77 /// -> function-result-list
78 /// ssa-function-arg-list ::= ssa-function-arg (`,` ssa-function-arg)*
79 /// ssa-function-arg ::= `%`name `:` type attribute-dict?
81  ArrayAttr argAttrs, bool isVariadic,
82  TypeRange resultTypes, ArrayAttr resultAttrs,
83  Region *body = nullptr,
84  bool printEmptyResult = true);
85 
86 /// Adds argument and result attributes, provided as `argAttrs` and
87 /// `resultAttrs` arguments, to the list of operation attributes in `result`.
88 /// Internally, argument and result attributes are stored as dict attributes
89 /// with special names given by getResultAttrName, getArgumentAttrName.
90 void addArgAndResultAttrs(Builder &builder, OperationState &result,
91  ArrayRef<DictionaryAttr> argAttrs,
92  ArrayRef<DictionaryAttr> resultAttrs,
93  StringAttr argAttrsName, StringAttr resAttrsName);
94 void addArgAndResultAttrs(Builder &builder, OperationState &result,
96  ArrayRef<DictionaryAttr> resultAttrs,
97  StringAttr argAttrsName, StringAttr resAttrsName);
98 
99 } // namespace call_interface_impl
100 
101 } // namespace mlir
102 
103 namespace llvm {
104 
105 // Allow llvm::cast style functions.
106 template <typename To>
107 struct CastInfo<To, mlir::CallInterfaceCallable>
108  : public CastInfo<To, mlir::CallInterfaceCallable::PointerUnion> {};
109 
110 template <typename To>
111 struct CastInfo<To, const mlir::CallInterfaceCallable>
112  : public CastInfo<To, const mlir::CallInterfaceCallable::PointerUnion> {};
113 
114 } // namespace llvm
115 
116 /// Include the generated interface declarations.
117 #include "mlir/Interfaces/CallInterfaces.h.inc"
118 
119 #endif // MLIR_INTERFACES_CALLINTERFACES_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
This class contains a list of basic blocks and a link to the parent operation it is attached to.
Definition: Region.h:26
This class represents a collection of SymbolTables.
Definition: SymbolTable.h:283
This class provides an abstraction over the various different ranges of value types.
Definition: TypeRange.h:37
The OpAsmOpInterface, see OpAsmInterface.td for more details.
Definition: CallGraph.h:229
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.
Operation * resolveCallable(CallOpInterface call, SymbolTableCollection *symbolTable=nullptr)
Resolve the callable operation for given callee to a CallableOpInterface, or nullptr if a valid calla...
ParseResult parseFunctionResultList(OpAsmParser &parser, SmallVectorImpl< Type > &resultTypes, SmallVectorImpl< DictionaryAttr > &resultAttrs)
Parse a function or call result list.
ParseResult parseFunctionSignature(OpAsmParser &parser, SmallVectorImpl< Type > &argTypes, SmallVectorImpl< DictionaryAttr > &argAttrs, SmallVectorImpl< Type > &resultTypes, SmallVectorImpl< DictionaryAttr > &resultAttrs, bool mustParseEmptyResult=true)
Parses a function signature using parser.
void addArgAndResultAttrs(Builder &builder, OperationState &result, ArrayRef< DictionaryAttr > argAttrs, ArrayRef< DictionaryAttr > resultAttrs, StringAttr argAttrsName, StringAttr resAttrsName)
Adds argument and result attributes, provided as argAttrs and resultAttrs arguments,...
Include the generated interface declarations.
A callable is either a symbol, or an SSA value, that is referenced by a call-like operation.
This represents an operation in an abstracted form, suitable for use with the builder APIs.