14#include <mlir/Interfaces/CallInterfaces.h>
35llvm::SmallVector<mlir::StringRef>
getNames(mlir::SymbolRefAttr ref);
36llvm::SmallVector<mlir::FlatSymbolRefAttr>
getPieces(mlir::SymbolRefAttr ref);
39inline mlir::FlatSymbolRefAttr
41 return mlir::FlatSymbolRefAttr::get(mlir::StringAttr::get(context, twine));
45inline mlir::SymbolRefAttr
asSymbolRefAttr(mlir::StringAttr root, mlir::SymbolRefAttr tail) {
46 return mlir::SymbolRefAttr::get(root,
getPieces(tail));
50inline mlir::SymbolRefAttr
asSymbolRefAttr(llvm::ArrayRef<mlir::FlatSymbolRefAttr> path) {
51 return mlir::SymbolRefAttr::get(path.front().getAttr(), path.drop_front());
55inline mlir::SymbolRefAttr
asSymbolRefAttr(
const std::vector<mlir::FlatSymbolRefAttr> &path) {
66 return mlir::SymbolRefAttr::get(
67 symbol.getRootReference(), symbol.getNestedReferences().drop_back()
72mlir::SymbolRefAttr
replaceLeaf(mlir::SymbolRefAttr orig, mlir::FlatSymbolRefAttr newLeaf);
73inline mlir::SymbolRefAttr
replaceLeaf(mlir::SymbolRefAttr orig, mlir::StringAttr newLeaf) {
74 return replaceLeaf(orig, mlir::FlatSymbolRefAttr::get(newLeaf));
76inline mlir::SymbolRefAttr
replaceLeaf(mlir::SymbolRefAttr orig,
const mlir::Twine &newLeaf) {
77 return replaceLeaf(orig, mlir::StringAttr::get(orig.getContext(), newLeaf));
81mlir::SymbolRefAttr
appendLeaf(mlir::SymbolRefAttr orig, mlir::FlatSymbolRefAttr newLeaf);
82inline mlir::SymbolRefAttr
appendLeaf(mlir::SymbolRefAttr orig, mlir::StringAttr newLeaf) {
83 return appendLeaf(orig, mlir::FlatSymbolRefAttr::get(newLeaf));
85inline mlir::SymbolRefAttr
appendLeaf(mlir::SymbolRefAttr orig,
const mlir::Twine &newLeaf) {
86 return appendLeaf(orig, mlir::StringAttr::get(orig.getContext(), newLeaf));
91mlir::SymbolRefAttr
appendLeafName(mlir::SymbolRefAttr orig,
const mlir::Twine &newLeafSuffix);
96mlir::FailureOr<mlir::SymbolRefAttr>
98mlir::FailureOr<mlir::SymbolRefAttr>
100mlir::FailureOr<mlir::SymbolRefAttr>
102mlir::FailureOr<mlir::SymbolRefAttr>
108inline mlir::SymbolRefAttr
110 if (!requireParent && symbol.getOperation()->getParentOp() ==
nullptr) {
111 return mlir::SymbolRefAttr::get(symbol.getOperation());
114 assert(mlir::succeeded(res));
121mlir::FailureOr<mlir::SymbolRefAttr>
123mlir::FailureOr<mlir::SymbolRefAttr>
125mlir::FailureOr<mlir::SymbolRefAttr>
127mlir::FailureOr<mlir::SymbolRefAttr>
140mlir::FailureOr<SymbolLookupResult<llzk::component::StructDefOp>>
149inline mlir::FailureOr<SymbolLookupResult<T>>
150resolveCallable(mlir::SymbolTableCollection &symbolTable, mlir::CallOpInterface call) {
151 mlir::CallInterfaceCallable callable = call.getCallableForCallee();
152 if (
auto symbolVal = llvm::dyn_cast<mlir::Value>(callable)) {
160 auto symbolRef = llvm::cast<mlir::SymbolRefAttr>(callable);
161 mlir::Operation *op = symbolTable.lookupNearestSymbolFrom(call.getOperation(), symbolRef);
175inline mlir::FailureOr<SymbolLookupResult<T>>
177 mlir::CallInterfaceCallable callable = call.getCallableForCallee();
178 if (
auto symbolVal = llvm::dyn_cast<mlir::Value>(callable)) {
181 return mlir::failure();
186 auto symbolRef = llvm::cast<mlir::SymbolRefAttr>(callable);
187 if (mlir::Operation *op = symbolTable.lookupNearestSymbolFrom(call.getOperation(), symbolRef)) {
190 return mlir::failure();
195 symbolTable, symbolRef, call.getOperation(),
false
200inline mlir::FailureOr<SymbolLookupResult<T>>
resolveCallable(mlir::CallOpInterface call) {
201 mlir::SymbolTableCollection symbolTable;
210mlir::FailureOr<polymorphic::TemplateOp>
216 mlir::SymbolTableCollection &tables, mlir::SymbolRefAttr param, mlir::Type structOrArrayType,
217 mlir::Operation *origin, std::optional<mlir::Type> requiredParamType = std::nullopt
224 mlir::SymbolTableCollection &tables, mlir::ArrayRef<mlir::Attribute> tyParams,
225 mlir::Type structOrArrayType, mlir::Operation *origin,
226 std::optional<mlir::Type> requiredParamType = std::nullopt
239template <std::ranges::input_range Range>
241 mlir::SymbolTableCollection &tables, mlir::Operation *origin,
const Range &types
245 for (
const auto &t : types) {
248 return mlir::LogicalResult::failure(failed);
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for and distribution as defined by Sections through of this document Licensor shall mean the copyright owner or entity authorized by the copyright owner that is granting the License Legal Entity shall mean the union of the acting entity and all other entities that control are controlled by or are under common control with that entity For the purposes of this definition control direct or to cause the direction or management of such whether by contract or including but not limited to software source documentation and configuration files Object form shall mean any form resulting from mechanical transformation or translation of a Source including but not limited to compiled object generated and conversions to other media types Work shall mean the work of whether in Source or Object made available under the as indicated by a copyright notice that is included in or attached to the whether in Source or Object that is based or other modifications as a an original work of authorship For the purposes of this Derivative Works shall not include works that remain separable from
This file defines methods symbol lookup across LLZK operations and included files.
mlir::SymbolRefAttr getPrefixAsSymbolRefAttr(mlir::SymbolRefAttr symbol)
Return SymbolRefAttr like the one given but with the leaf/final element removed.
SymbolRefAttr appendLeafName(SymbolRefAttr orig, const Twine &newLeafSuffix)
mlir::FlatSymbolRefAttr getFlatSymbolRefAttr(mlir::MLIRContext *context, const mlir::Twine &twine)
Construct a FlatSymbolRefAttr with the given content.
mlir::FailureOr< SymbolLookupResultUntyped > lookupTopLevelSymbol(mlir::SymbolTableCollection &tables, mlir::SymbolRefAttr symbol, mlir::Operation *origin, bool reportMissing=true)
FailureOr< StructType > getMainInstanceType(Operation *lookupFrom)
llvm::SmallVector< StringRef > getNames(SymbolRefAttr ref)
FailureOr< ModuleOp > getRootModule(Operation *from)
FailureOr< TemplateOp > getConstResolutionTemplate(SymbolTableCollection &tables, Operation *origin)
SymbolRefAttr appendLeaf(SymbolRefAttr orig, FlatSymbolRefAttr newLeaf)
SymbolRefAttr replaceLeaf(SymbolRefAttr orig, FlatSymbolRefAttr newLeaf)
FailureOr< StructDefOp > verifyStructTypeResolution(SymbolTableCollection &tables, StructType ty, Operation *origin)
mlir::FailureOr< SymbolLookupResult< T > > resolveCallable(mlir::SymbolTableCollection &symbolTable, mlir::CallOpInterface call)
Based on mlir::CallOpInterface::resolveCallable, but using LLZK lookup helpers.
FailureOr< ModuleOp > getTopRootModule(Operation *from)
LogicalResult verifyParamsOfType(SymbolTableCollection &tables, ArrayRef< Attribute > tyParams, Type parameterizedType, Operation *origin, std::optional< Type > requiredParamType)
LogicalResult verifyTypeResolution(SymbolTableCollection &tables, Operation *origin, Type ty)
mlir::FailureOr< SymbolLookupResult< T > > resolveCallableSilently(mlir::SymbolTableCollection &symbolTable, mlir::CallOpInterface call)
Resolve a callable without emitting a diagnostic for missing top-level symbols.
mlir::SymbolRefAttr asSymbolRefAttr(mlir::StringAttr root, mlir::SymbolRefAttr tail)
Build a SymbolRefAttr that prepends tail with root, i.e., root::tail.
mlir::SymbolRefAttr getFullyQualifiedName(mlir::SymbolOpInterface symbol, bool requireParent=true)
Return the full name for this symbol from the root module, including any surrounding symbol table nam...
mlir::SymbolRefAttr getTailAsSymbolRefAttr(mlir::SymbolRefAttr symbol)
Return SymbolRefAttr like the one given but with the root/head element removed.
FailureOr< SymbolLookupResult< StructDefOp > > getMainInstanceDef(SymbolTableCollection &symbolTable, Operation *lookupFrom)
FailureOr< SymbolRefAttr > getPathFromTopRoot(SymbolOpInterface to, ModuleOp *foundRoot)
llvm::SmallVector< FlatSymbolRefAttr > getPieces(SymbolRefAttr ref)
FailureOr< SymbolRefAttr > getPathFromRoot(SymbolOpInterface to, ModuleOp *foundRoot)
LogicalResult verifyParamOfType(SymbolTableCollection &tables, SymbolRefAttr param, Type parameterizedType, Operation *origin, std::optional< Type > requiredParamType)