blob: c7bcb7a9609928081715336330b4734749638f66 [file] [log] [blame]
River Riddle7ce1e7a2020-03-10 19:20:241//===- 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
11using namespace mlir;
12
13//===----------------------------------------------------------------------===//
River Riddlea5ea6042020-10-16 18:57:1014// 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.
21Operation *
22CallOpInterface::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//===----------------------------------------------------------------------===//
River Riddle7ce1e7a2020-03-10 19:20:2435// CallInterfaces
36//===----------------------------------------------------------------------===//
37
38#include "mlir/Interfaces/CallInterfaces.cpp.inc"