CIRCT  20.0.0git
InnerSymbolNamespace.h
Go to the documentation of this file.
1 //===- InnerSymbolNamespace.h - Inner Symbol Table Namespace ----*- C++ -*-===//
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 // This file declares the InnerSymbolNamespace, which tracks the names
10 // used by inner symbols within an InnerSymbolTable.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef CIRCT_DIALECT_HW_INNERSYMBOLNAMESPACE_H
15 #define CIRCT_DIALECT_HW_INNERSYMBOLNAMESPACE_H
16 
19 
20 namespace circt {
21 namespace hw {
22 
24  InnerSymbolNamespace() = default;
25  InnerSymbolNamespace(Operation *module) { add(module); }
26 
27  /// Populate the namespace from a module-like operation. This namespace will
28  /// be composed of the `inner_sym`s of the module's ports and declarations.
29  void add(Operation *module) {
31  module, [&](StringAttr name, const InnerSymTarget &target) {
32  nextIndex.insert({name.getValue(), 0});
33  });
34  }
35 };
36 
38 
39  InnerSymbolNamespace &get(Operation *op) {
40  return collection.try_emplace(op, op).first->second;
41  }
42 
43  InnerSymbolNamespace &operator[](Operation *op) { return get(op); }
44 
45 private:
46  DenseMap<Operation *, InnerSymbolNamespace> collection;
47 };
48 
49 } // namespace hw
50 } // namespace circt
51 
52 #endif // CIRCT_DIALECT_HW_INNERSYMBOLNAMESPACE_H
A namespace that is used to store existing names and generate new names in some scope within the IR.
Definition: Namespace.h:30
llvm::StringMap< size_t > nextIndex
Definition: Namespace.h:159
The target of an inner symbol, the entity the symbol is a handle for.
static RetTy walkSymbols(Operation *op, FuncTy &&callback)
Walk the given IST operation and invoke the callback for all encountered inner symbols.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition: DebugAnalysis.h:21
Definition: hw.py:1
InnerSymbolNamespace & get(Operation *op)
DenseMap< Operation *, InnerSymbolNamespace > collection
InnerSymbolNamespace & operator[](Operation *op)
void add(Operation *module)
Populate the namespace from a module-like operation.