MLIR  19.0.0git
CallInterfaces.cpp
Go to the documentation of this file.
1 //===- CallInterfaces.cpp - ControlFlow Interfaces ------------------------===//
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 using namespace mlir;
12 
13 //===----------------------------------------------------------------------===//
14 // CallOpInterface
15 //===----------------------------------------------------------------------===//
16 
17 /// Resolve the callable operation for given callee to a CallableOpInterface, or
18 /// nullptr if a valid callable was not resolved. `symbolTable` is an optional
19 /// parameter that will allow for using a cached symbol table for symbol lookups
20 /// instead of performing an O(N) scan.
21 Operation *
22 CallOpInterface::resolveCallable(SymbolTableCollection *symbolTable) {
23  CallInterfaceCallable callable = getCallableForCallee();
24  if (auto symbolVal = dyn_cast<Value>(callable))
25  return symbolVal.getDefiningOp();
26 
27  // If the callable isn't a value, lookup the symbol reference.
28  auto symbolRef = callable.get<SymbolRefAttr>();
29  if (symbolTable)
30  return symbolTable->lookupNearestSymbolFrom(getOperation(), symbolRef);
31  return SymbolTable::lookupNearestSymbolFrom(getOperation(), symbolRef);
32 }
33 
34 //===----------------------------------------------------------------------===//
35 // CallInterfaces
36 //===----------------------------------------------------------------------===//
37 
38 #include "mlir/Interfaces/CallInterfaces.cpp.inc"
Operation is the basic unit of execution within MLIR.
Definition: Operation.h:88
This class represents a collection of SymbolTables.
Definition: SymbolTable.h:283
Operation * lookupNearestSymbolFrom(Operation *from, StringAttr symbol)
Returns the operation registered with the given symbol name within the closest parent operation of,...
static Operation * lookupNearestSymbolFrom(Operation *from, StringAttr symbol)
Returns the operation registered with the given symbol name within the closest parent operation of,...
Include the generated interface declarations.
A callable is either a symbol, or an SSA value, that is referenced by a call-like operation.