CIRCT 21.0.0git
Loading...
Searching...
No Matches
HierPathCache.cpp
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// Implementation of a utility for creating Hierarchical Path operations.
10//
11//===----------------------------------------------------------------------===//
12
15
16namespace circt {
17namespace hw {
18
19HierPathOp HierPathCache::getOrCreatePath(ArrayAttr pathArray, Location loc,
20 StringRef nameHint) {
21 return getOrCreatePath(pathArray, loc, pathInsertPoint, nameHint);
22}
23
24HierPathOp HierPathCache::getOrCreatePath(ArrayAttr pathArray, Location loc,
25 OpBuilder::InsertPoint &insertPoint,
26 StringRef nameHint) {
27
28 assert(pathArray && !pathArray.empty());
29 // Return an existing HierPathOp if one exists with the same path. Add
30 // location information to the existing HierPathOp if it is being reused.
31 auto pathIter = pathCache.find(pathArray);
32 if (pathIter != pathCache.end()) {
33 auto &hierPathOp = pathIter->getSecond();
34 auto oldLoc = hierPathOp->getLoc();
35 // Fuse the location of all old locations and the new location.
36 SmallVector<Location> locations;
37 if (auto fusedLoc = dyn_cast<FusedLoc>(oldLoc)) {
38 auto oldLocs = fusedLoc.getLocations();
39 locations.append(oldLocs.begin(), oldLocs.end());
40 } else {
41 locations.push_back(oldLoc);
42 }
43 locations.push_back(loc);
44 // Update the location on the original HierPathOp.
45 hierPathOp->setLoc(FusedLoc::get(loc.getContext(), locations));
46 return hierPathOp;
47 }
48
49 // Create a builder and move its insertion point to the original insertion
50 // point.
51 OpBuilder builder(insertPoint.getBlock(), insertPoint.getPoint());
52
53 // Create the new HierPathOp and insert it into the pathCache.
54 hw::HierPathOp path =
56 .insert({pathArray, builder.create<hw::HierPathOp>(
57 loc, ns->newName(nameHint), pathArray)})
58 .first->second;
59 path.setVisibility(SymbolTable::Visibility::Private);
60
61 // Save the insertion point so other unique HierPathOps will be created
62 // after this one.
63 insertPoint = builder.saveInsertionPoint();
64
65 // Return the new path.
66 return path;
67}
68
69} // namespace hw
70} // namespace circt
assert(baseType &&"element must be base type")
StringRef newName(const Twine &name)
Return a unique name, derived from the input name, and add the new name to the internal namespace.
Definition Namespace.h:87
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