//===- SymbolTable.h - MLIR Symbol Table Class ------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #ifndef MLIR_IR_SYMBOLTABLE_H #define MLIR_IR_SYMBOLTABLE_H #include "mlir/IR/Attributes.h" #include "mlir/IR/OpDefinition.h" #include "llvm/ADT/SetVector.h" #include "llvm/ADT/StringMap.h" #include "llvm/Support/RWMutex.h" namespace mlir { /// This class allows for representing and managing the symbol table used by /// operations with the 'SymbolTable' trait. Inserting into and erasing from /// this SymbolTable will also insert and erase from the Operation given to it /// at construction. class SymbolTable { … }; raw_ostream &operator<<(raw_ostream &os, SymbolTable::Visibility visibility); //===----------------------------------------------------------------------===// // SymbolTableCollection //===----------------------------------------------------------------------===// /// This class represents a collection of `SymbolTable`s. This simplifies /// certain algorithms that run recursively on nested symbol tables. Symbol /// tables are constructed lazily to reduce the upfront cost of constructing /// unnecessary tables. class SymbolTableCollection { … }; //===----------------------------------------------------------------------===// // LockedSymbolTableCollection //===----------------------------------------------------------------------===// /// This class implements a lock-based shared wrapper around a symbol table /// collection that allows shared access to the collection of symbol tables. /// This class does not protect shared access to individual symbol tables. /// `SymbolTableCollection` lazily instantiates `SymbolTable` instances for /// symbol table operations, making read operations not thread-safe. This class /// provides a thread-safe `lookupSymbolIn` implementation by synchronizing the /// lazy `SymbolTable` lookup. class LockedSymbolTableCollection : public SymbolTableCollection { … }; //===----------------------------------------------------------------------===// // SymbolUserMap //===----------------------------------------------------------------------===// /// This class represents a map of symbols to users, and provides efficient /// implementations of symbol queries related to users; such as collecting the /// users of a symbol, replacing all uses, etc. class SymbolUserMap { … }; //===----------------------------------------------------------------------===// // SymbolTable Trait Types //===----------------------------------------------------------------------===// namespace detail { LogicalResult verifySymbolTable(Operation *op); LogicalResult verifySymbol(Operation *op); } // namespace detail namespace OpTrait { /// A trait used to provide symbol table functionalities to a region operation. /// This operation must hold exactly 1 region. Once attached, all operations /// that are directly within the region, i.e not including those within child /// regions, that contain a 'SymbolTable::getSymbolAttrName()' StringAttr will /// be verified to ensure that the names are uniqued. These operations must also /// adhere to the constraints defined by the `Symbol` trait, even if they do not /// inherit from it. template <typename ConcreteType> class SymbolTable : public TraitBase<ConcreteType, SymbolTable> { … }; } // namespace OpTrait //===----------------------------------------------------------------------===// // Visibility parsing implementation. //===----------------------------------------------------------------------===// namespace impl { /// Parse an optional visibility attribute keyword (i.e., public, private, or /// nested) without quotes in a string attribute named 'attrName'. ParseResult parseOptionalVisibilityKeyword(OpAsmParser &parser, NamedAttrList &attrs); } // namespace impl } // namespace mlir /// Include the generated symbol interfaces. #include "mlir/IR/SymbolInterfaces.h.inc" #endif // MLIR_IR_SYMBOLTABLE_H