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 
9 #include "mlir/Interfaces/CallInterfaces.h"
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 *
resolveCallable(SymbolTableCollection * symbolTable)22 CallOpInterface::resolveCallable(SymbolTableCollection *symbolTable) {
23   CallInterfaceCallable callable = getCallableForCallee();
24   if (auto symbolVal = callable.dyn_cast<Value>())
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"
39