CIRCT 21.0.0git
Loading...
Searching...
No Matches
HierPathCache.h
Go to the documentation of this file.
1//===- HierPathCache.h - HierPathOp Caching 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 HierPathCache is a utility for creating hierarchical paths at a
10// pre-defined location in a circuit. This exists to help with a common pattern
11// where you are running a transform and you need to build HierPathOps, but you
12// don't know when you are going to do it. You also don't want to create the
13// same HierPathOp multiple times. This utility will maintain a cache of
14// existing ops and only create new ones when necessary. Additionally, this
15// creates the ops in nice, predictable order. I.e., all the ops are inserted
16// into the IR in the order they are created, not in reverse order.
17//
18//===----------------------------------------------------------------------===//
19
20#ifndef CIRCT_DIALECT_HW_HIERPATHCACHE_H
21#define CIRCT_DIALECT_HW_HIERPATHCACHE_H
22
25#include <mlir/IR/Attributes.h>
26
27namespace circt {
28namespace hw {
29
31public:
32 HierPathCache(Namespace *ns, OpBuilder::InsertPoint insertionPoint)
33 : ns(ns), pathInsertPoint(insertionPoint) {}
34
35 /// Get an existing `hw::HierPathOp` at the default location in the circuit.
36 HierPathOp getOrCreatePath(ArrayAttr pathArray, Location loc,
37 StringRef nameHint = "xmrPath");
38
39 /// Get an existing `hw::HierPathOp` at a specific location in the circuit.
40 /// The insertion point will be updated to allow for this method to be used
41 /// repeatedly to create the ops predictably, one after the other.
42 HierPathOp getOrCreatePath(ArrayAttr pathArray, Location loc,
43 OpBuilder::InsertPoint &insertPoint,
44 StringRef nameHint = "xmrPath");
45
46private:
47 /// A namespace in which symbols for hierarchical path ops will be created.
49
50 /// A cache of already created HierPathOps. This is used to avoid repeatedly
51 /// creating the same HierPathOp.
52 DenseMap<mlir::Attribute, hw::HierPathOp> pathCache;
53
54 /// The insertion point where the pass inserts HierPathOps.
55 OpBuilder::InsertPoint pathInsertPoint;
56};
57
58} // namespace hw
59} // namespace circt
60
61#endif // CIRCT_DIALECT_HW_HIERPATHCACHE_H
A namespace that is used to store existing names and generate new names in some scope within the IR.
Definition Namespace.h:30
HierPathCache(Namespace *ns, OpBuilder::InsertPoint insertionPoint)
OpBuilder::InsertPoint pathInsertPoint
The insertion point where the pass inserts HierPathOps.
DenseMap< mlir::Attribute, hw::HierPathOp > pathCache
A cache of already created HierPathOps.
Namespace * ns
A namespace in which symbols for hierarchical path ops will be created.
HierPathOp getOrCreatePath(ArrayAttr pathArray, Location loc, StringRef nameHint="xmrPath")
Get an existing hw::HierPathOp at the default location in the circuit.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition hw.py:1