|
| 1 | +//===- HierPathBuilder.h - HierPathOp Builder Utility ---------------------===// |
| 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 | +// The HierPathBuilder is a utility for creating hierarchical paths at some |
| 10 | +// location in a circuit. This exists to help with a common pattern where you |
| 11 | +// are running a transform and you need to build HierPathOps, but you don't know |
| 12 | +// when you are going to do it. You also don't want to create the same |
| 13 | +// HierPathOp multiple times. This utility will maintain a cache of existing |
| 14 | +// ops and only create new ones when necessary. Additionally, this creates the |
| 15 | +// ops in nice, predictable order. I.e., all the ops are inserted into the IR |
| 16 | +// in the order they are created, not in reverse order. |
| 17 | +// |
| 18 | +//===----------------------------------------------------------------------===// |
| 19 | + |
| 20 | +#ifndef CIRCT_DIALECT_HW_HIERPATHBUILDER_H |
| 21 | +#define CIRCT_DIALECT_HW_HIERPATHBUILDER_H |
| 22 | + |
| 23 | +#include "circt/Dialect/HW/HWOps.h" |
| 24 | +#include "circt/Support/Namespace.h" |
| 25 | +#include <mlir/IR/Attributes.h> |
| 26 | + |
| 27 | +namespace circt { |
| 28 | +namespace hw { |
| 29 | + |
| 30 | +class HierPathBuilder { |
| 31 | +public: |
| 32 | + HierPathBuilder(Namespace *ns, OpBuilder::InsertPoint insertionPoint) |
| 33 | + : ns(ns), pathInsertPoint(insertionPoint) {} |
| 34 | + |
| 35 | + HierPathOp getOrCreatePath(ArrayAttr pathArray, |
| 36 | + ImplicitLocOpBuilder &builder); |
| 37 | + |
| 38 | +private: |
| 39 | + /// A namespace in which symbols for hierarchical path ops will be created. |
| 40 | + Namespace *ns; |
| 41 | + |
| 42 | + /// A cache of already created HierPathOps. This is used to avoid repeatedly |
| 43 | + /// creating the same HierPathOp. |
| 44 | + DenseMap<mlir::Attribute, hw::HierPathOp> pathCache; |
| 45 | + |
| 46 | + /// The insertion point where the pass inserts HierPathOps. |
| 47 | + OpBuilder::InsertPoint pathInsertPoint; |
| 48 | +}; |
| 49 | + |
| 50 | +} // namespace hw |
| 51 | +} // namespace circt |
| 52 | + |
| 53 | +#endif // CIRCT_DIALECT_HW_HIERPATHBUILDER_H |
0 commit comments