• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1//===- CallInterfaces.td - Call Interfaces for ops ---------*- tablegen -*-===//
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 a set of interfaces that can be used to define information
10// related to call-like and callable operations. Each of which are defined along
11// with the respective interface below.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef MLIR_INTERFACES_CALLINTERFACES
16#define MLIR_INTERFACES_CALLINTERFACES
17
18include "mlir/IR/OpBase.td"
19
20// `CallInterfaceCallable`: This is a type used to represent a single callable
21// region. A callable is either a symbol, or an SSA value, that is referenced by
22// a call-like operation. This represents the destination of the call.
23
24/// Interface for call-like operations.
25def CallOpInterface : OpInterface<"CallOpInterface"> {
26  let description = [{
27    A call-like operation is one that transfers control from one sub-routine to
28    another. These operations may be traditional direct calls `call @foo`, or
29    indirect calls to other operations `call_indirect %foo`. An operation that
30    uses this interface, must *not* also provide the `CallableOpInterface`.
31  }];
32  let cppNamespace = "::mlir";
33
34  let methods = [
35    InterfaceMethod<[{
36        Returns the callee of this call-like operation. A `callee` is either a
37        reference to a symbol, via SymbolRefAttr, or a reference to a defined
38        SSA value. If the reference is an SSA value, the SSA value corresponds
39        to a region of a lambda-like operation.
40      }],
41      "CallInterfaceCallable", "getCallableForCallee"
42    >,
43    InterfaceMethod<[{
44        Returns the operands within this call that are used as arguments to the
45        callee.
46      }],
47      "Operation::operand_range", "getArgOperands"
48    >,
49  ];
50
51  let extraClassDeclaration = [{
52    /// Resolve the callable operation for given callee to a
53    /// CallableOpInterface, or nullptr if a valid callable was not resolved.
54    /// `symbolTable` is an optional parameter that will allow for using a
55    /// cached symbol table for symbol lookups instead of performing an O(N)
56    /// scan.
57    Operation *resolveCallable(SymbolTableCollection *symbolTable = nullptr);
58  }];
59}
60
61/// Interface for callable operations.
62def CallableOpInterface : OpInterface<"CallableOpInterface"> {
63  let description = [{
64    A callable operation is one who represents a potential sub-routine, and may
65    be a target for a call-like operation (those providing the CallOpInterface
66    above). These operations may be traditional functional operation
67    `func @foo(...)`, as well as function producing operations
68    `%foo = dialect.create_function(...)`. These operations may only contain a
69    single region, or subroutine.
70  }];
71  let cppNamespace = "::mlir";
72
73  let methods = [
74    InterfaceMethod<[{
75        Returns the region on the current operation that is callable. This may
76        return null in the case of an external callable object, e.g. an external
77        function.
78      }],
79      "Region *", "getCallableRegion"
80    >,
81    InterfaceMethod<[{
82        Returns the results types that the callable region produces when
83        executed.
84      }],
85      "ArrayRef<Type>", "getCallableResults"
86    >,
87  ];
88}
89
90#endif // MLIR_INTERFACES_CALLINTERFACES
91