20#include <mlir/IR/BuiltinOps.h>
21#include <mlir/IR/Operation.h>
22#include <mlir/IR/OwningOpRef.h>
24#include <llvm/ADT/ArrayRef.h>
25#include <llvm/ADT/StringRef.h>
35 std::shared_ptr<std::pair<mlir::OwningOpRef<mlir::ModuleOp>, mlir::SymbolTableCollection>>;
43 : op(other.op), managedResources(other.managedResources),
44 includeSymNameStack(other.includeSymNameStack), namespaceStack(other.namespaceStack) {}
52 this->managedResources = other.managedResources;
53 this->includeSymNameStack = other.includeSymNameStack;
54 this->namespaceStack = other.namespaceStack;
60 : op(other.op), managedResources(std::move(other.managedResources)),
61 includeSymNameStack(std::move(other.includeSymNameStack)),
62 namespaceStack(std::move(other.namespaceStack)) {
71 this->managedResources = std::move(other.managedResources);
72 this->includeSymNameStack = std::move(other.includeSymNameStack);
73 this->namespaceStack = std::move(other.namespaceStack);
83 mlir::Operation *
get();
84 mlir::Operation *
get()
const;
87 operator bool()
const;
94 llvm::ArrayRef<llvm::StringRef>
getNamespace()
const {
return namespaceStack; }
97 bool viaInclude()
const {
return !includeSymNameStack.empty(); }
100 if (managedResources) {
101 return &managedResources->second;
108 bool isManaged()
const {
return managedResources !=
nullptr; }
111 void manage(mlir::OwningOpRef<mlir::ModuleOp> &&ptr, mlir::SymbolTableCollection &&tables);
130 std::vector<llvm::StringRef> includeSymNameStack;
133 std::vector<llvm::StringRef> namespaceStack;
146 const T
operator*()
const {
return llvm::dyn_cast<T>(*inner); }
147 T
get() {
return llvm::dyn_cast<T>(inner.get()); }
148 T
get()
const {
return llvm::dyn_cast<T>(inner.get()); }
150 operator bool()
const {
return inner && llvm::isa<T>(*inner); }
157 llvm::ArrayRef<llvm::StringRef>
getNamespace()
const {
return inner.getNamespace(); }
196 *
this = std::move(other.inner);
205 Within(mlir::Operation *op) : from(op) { assert(op &&
"cannot lookup within nullptr"); }
218 mlir::FailureOr<SymbolLookupResultUntyped>
lookup(
219 mlir::SymbolTableCollection &tables, mlir::SymbolRefAttr symbol, mlir::Operation *origin,
220 bool reportMissing =
true
224 std::variant<mlir::Operation *, SymbolLookupResultUntyped>
from;
228 mlir::SymbolTableCollection &tables, mlir::SymbolRefAttr symbol,
Within &&lookupWithin,
229 mlir::Operation *origin,
bool reportMissing =
true
231 return std::move(lookupWithin).lookup(tables, symbol, origin, reportMissing);
235 mlir::SymbolTableCollection &tables, mlir::SymbolRefAttr symbol, mlir::Operation *origin,
236 bool reportMissing =
true
238 return Within().
lookup(tables, symbol, origin, reportMissing);
243 mlir::SymbolTableCollection &tables, mlir::SymbolRefAttr symbol,
Within &&lookupWithin,
244 mlir::Operation *origin,
bool reportMissing =
true
246 auto found =
lookupSymbolIn(tables, symbol, std::move(lookupWithin), origin, reportMissing);
247 if (mlir::failed(found)) {
248 return mlir::failure();
251 mlir::Operation *op = found->get();
256 return origin->emitError() <<
"symbol \"" << symbol <<
"\" references a '" << op->getName()
257 <<
"' but expected a '" << T::getOperationName() <<
'\'';
259 return mlir::failure();
267 mlir::SymbolTableCollection &tables, mlir::SymbolRefAttr symbol, mlir::Operation *origin,
268 bool reportMissing =
true
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
mlir::SymbolTableCollection * getSymbolTableCache()
bool viaInclude() const
Return 'true' if at least one IncludeOp was traversed to load this result.
void manage(mlir::OwningOpRef< mlir::ModuleOp > &&ptr, mlir::SymbolTableCollection &&tables)
Adds a pointer to the set of resources the result has to manage the lifetime of.
std::vector< llvm::StringRef > getIncludeSymNames() const
Return the stack of symbol names from the IncludeOp that were traversed to load this result.
SymbolLookupResultUntyped()
SymbolLookupResultUntyped(SymbolLookupResultUntyped &&other) noexcept
void prependNamespace(llvm::ArrayRef< llvm::StringRef > ns)
Adds the given namespace to the beginning of this result's namespace.
void trackIncludeAsName(llvm::StringRef includeOpSymName)
Adds the symbol name from the IncludeOp that caused the module to be loaded.
SymbolLookupResultUntyped(const SymbolLookupResultUntyped &other)
llvm::ArrayRef< llvm::StringRef > getNamespace() const
Return the stack of symbol names from either IncludeOp or ModuleOp that were traversed to load this r...
bool operator==(const SymbolLookupResultUntyped &rhs) const
bool isManaged() const
True iff the symbol is managed (i.e., loaded via an IncludeOp).
SymbolLookupResultUntyped(mlir::Operation *opPtr)
mlir::Operation & operator*()
SymbolLookupResultUntyped & operator=(const SymbolLookupResultUntyped &other)
void pushNamespace(llvm::StringRef symName)
Adds the symbol name from an IncludeOp or ModuleOp where the op is contained.
mlir::Operation * operator->()
Access the internal operation.
SymbolLookupResultUntyped & operator=(SymbolLookupResultUntyped &&other) noexcept
void prependNamespace(llvm::ArrayRef< llvm::StringRef > ns)
Adds the given namespace to the beginning of this result's namespace.
llvm::ArrayRef< llvm::StringRef > getNamespace() const
Return the stack of symbol names from either IncludeOp or ModuleOp that were traversed to load this r...
std::vector< llvm::StringRef > getIncludeSymNames() const
Return the stack of symbol names from the IncludeOp that were traversed to load this result.
const T operator*() const
SymbolLookupResult(SymbolLookupResultUntyped &&innerRes)
bool viaInclude() const
Return 'true' if at least one IncludeOp was traversed to load this result.
friend class SymbolLookupResultUntyped
bool isManaged() const
Return 'true' if the inner resource is managed (i.e., loaded via an IncludeOp).
bool operator==(const SymbolLookupResult< T > &rhs) const
T operator->()
Access the internal operation as type T.
mlir::FailureOr< SymbolLookupResultUntyped > lookup(mlir::SymbolTableCollection &tables, mlir::SymbolRefAttr symbol, mlir::Operation *origin, bool reportMissing=true) &&
Within(const Within &)=delete
Within()
Lookup within the top-level (root) module.
Within(SymbolLookupResultUntyped &&res)
Lookup within the Operation of the given result and transfer managed resources.
Within(Within &&other) noexcept
Within & operator=(const Within &)=delete
Within(mlir::Operation *op)
Lookup within the given Operation (cannot be nullptr)
Within(SymbolLookupResult< T > &&res)
Lookup within the Operation of the given result and transfer managed resources.
mlir::FailureOr< SymbolLookupResultUntyped > lookupTopLevelSymbol(mlir::SymbolTableCollection &tables, mlir::SymbolRefAttr symbol, mlir::Operation *origin, bool reportMissing=true)
std::shared_ptr< std::pair< mlir::OwningOpRef< mlir::ModuleOp >, mlir::SymbolTableCollection > > ManagedResources
mlir::FailureOr< SymbolLookupResultUntyped > lookupSymbolIn(mlir::SymbolTableCollection &tables, mlir::SymbolRefAttr symbol, Within &&lookupWithin, mlir::Operation *origin, bool reportMissing=true)