MLIR 24.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
21namespace 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.
24struct CallInterfaceCallable : public PointerUnion<SymbolRefAttr, Value> {
25 using PointerUnion<SymbolRefAttr, Value>::PointerUnion;
26};
27
28class CallableOpInterface;
29class CallOpInterface;
30
32
33/// Resolve the callable operation for given callee to a CallableOpInterface, or
34/// nullptr if a valid callable was not resolved. `symbolTable` is an optional
35/// parameter that will allow for using a cached symbol table for symbol lookups
36/// instead of performing an O(N) scan.
37Operation *resolveCallable(CallOpInterface call,
38 SymbolTableCollection *symbolTable = nullptr);
39
40/// Verify that the forwarded operands and results of `call` are in a 1:1
41/// relationship with the given argument and result types of its callee: the
42/// numbers must match and corresponding types must be equal.
43///
44/// This overload is for call operations whose callee does not necessarily
45/// implement `CallableOpInterface`, e.g., `llvm.call`, which can also call an
46/// `llvm.mlir.alias` or an `llvm.mlir.ifunc`.
47LogicalResult verifyCallOpInterface(CallOpInterface call,
48 TypeRange argumentTypes,
49 TypeRange resultTypes);
50
51/// Same as above, taking the argument and result types from `callable`.
52LogicalResult verifyCallOpInterface(CallOpInterface call,
53 CallableOpInterface callable);
54
55/// Same as above, but resolve the callee of `call` first. Returns success if
56/// the callee cannot be resolved or does not implement `CallableOpInterface`.
57LogicalResult verifyCallOpInterface(CallOpInterface call,
58 SymbolTableCollection &symbolTable);
59LogicalResult verifyCallOpInterface(CallOpInterface call);
60
61/// Parse a function or call result list.
62///
63/// function-result-list ::= function-result-list-parens
64/// | non-function-type
65/// function-result-list-parens ::= `(` `)`
66/// | `(` function-result-list-no-parens `)`
67/// function-result-list-no-parens ::= function-result (`,` function-result)*
68/// function-result ::= type attribute-dict?
69///
70ParseResult
73
74/// Parses a function signature using `parser`. This does not deal with function
75/// signatures containing SSA region arguments (to parse these signatures, use
76/// function_interface_impl::parseFunctionSignature). When
77/// `mustParseEmptyResult`, `-> ()` is expected when there is no result type.
78///
79/// no-ssa-function-signature ::= `(` no-ssa-function-arg-list `)`
80/// -> function-result-list
81/// no-ssa-function-arg-list ::= no-ssa-function-arg
82/// (`,` no-ssa-function-arg)*
83/// no-ssa-function-arg ::= type attribute-dict?
84ParseResult parseFunctionSignature(OpAsmParser &parser,
85 SmallVectorImpl<Type> &argTypes,
87 SmallVectorImpl<Type> &resultTypes,
89 bool mustParseEmptyResult = true);
90
91/// Print a function signature for a call or callable operation. If a body
92/// region is provided, the SSA arguments are printed in the signature. When
93/// `printEmptyResult` is false, `-> function-result-list` is omitted when
94/// `resultTypes` is empty.
95///
96/// function-signature ::= ssa-function-signature
97/// | no-ssa-function-signature
98/// ssa-function-signature ::= `(` ssa-function-arg-list `)`
99/// -> function-result-list
100/// ssa-function-arg-list ::= ssa-function-arg (`,` ssa-function-arg)*
101/// ssa-function-arg ::= `%`name `:` type attribute-dict?
103 ArrayAttr argAttrs, bool isVariadic,
104 TypeRange resultTypes, ArrayAttr resultAttrs,
105 Region *body = nullptr,
106 bool printEmptyResult = true);
107
108/// Adds argument and result attributes, provided as `argAttrs` and
109/// `resultAttrs` arguments, to the list of operation attributes in `result`.
110/// Internally, argument and result attributes are stored as dict attributes
111/// with special names given by getResultAttrName, getArgumentAttrName.
114 ArrayRef<DictionaryAttr> resultAttrs,
115 StringAttr argAttrsName, StringAttr resAttrsName);
118 ArrayRef<DictionaryAttr> resultAttrs,
119 StringAttr argAttrsName, StringAttr resAttrsName);
120
121} // namespace call_interface_impl
122
123} // namespace mlir
124
125namespace llvm {
126
127// Allow llvm::cast style functions.
128template <typename To>
129struct CastInfo<To, mlir::CallInterfaceCallable>
130 : public CastInfo<To, mlir::CallInterfaceCallable::PointerUnion> {};
131
132template <typename To>
133struct CastInfo<To, const mlir::CallInterfaceCallable>
134 : public CastInfo<To, const mlir::CallInterfaceCallable::PointerUnion> {};
135
136} // namespace llvm
137
138/// Include the generated interface declarations.
139#include "mlir/Interfaces/CallInterfaces.h.inc"
140
141#endif // MLIR_INTERFACES_CALLINTERFACES_H
ArrayAttr()
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:87
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.
This class provides an abstraction over the various different ranges of value types.
Definition TypeRange.h:40
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition Value.h:96
The OpAsmOpInterface, see OpAsmInterface.td for more details.
Definition CallGraph.h:227
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.
LogicalResult verifyCallOpInterface(CallOpInterface call, TypeRange argumentTypes, TypeRange resultTypes)
Verify that the forwarded operands and results of call are in a 1:1 relationship with the given argum...
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.