Skip to content

Commit 5306d86

Browse files
committed
[hw] Rename HierPathBuilder -> HierPathCache
Rename the `hw::HierPathBuilder` utility to `hw::HierPathCache`. This more accurately represents what it is, i.e., it is a cache of hierarchical path ops. h/t @rwy7 for the offline suggestion for the name change. Signed-off-by: Schuyler Eldridge <[email protected]>
1 parent 42c5610 commit 5306d86

File tree

4 files changed

+33
-29
lines changed

4 files changed

+33
-29
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
//===- HierPathBuilder.h - HierPathOp Builder Utility ---------------------===//
1+
//===- HierPathCache.h - HierPathOp Caching Utility -----------------------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
88
//
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.
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.
1717
//
1818
//===----------------------------------------------------------------------===//
1919

20-
#ifndef CIRCT_DIALECT_HW_HIERPATHBUILDER_H
21-
#define CIRCT_DIALECT_HW_HIERPATHBUILDER_H
20+
#ifndef CIRCT_DIALECT_HW_HIERPATHCACHE_H
21+
#define CIRCT_DIALECT_HW_HIERPATHCACHE_H
2222

2323
#include "circt/Dialect/HW/HWOps.h"
2424
#include "circt/Support/Namespace.h"
@@ -27,14 +27,18 @@
2727
namespace circt {
2828
namespace hw {
2929

30-
class HierPathBuilder {
30+
class HierPathCache {
3131
public:
32-
HierPathBuilder(Namespace *ns, OpBuilder::InsertPoint insertionPoint)
32+
HierPathCache(Namespace *ns, OpBuilder::InsertPoint insertionPoint)
3333
: ns(ns), pathInsertPoint(insertionPoint) {}
3434

35+
/// Get an existing `hw::HierPathOp` at the default location in the circuit.
3536
HierPathOp getOrCreatePath(ArrayAttr pathArray, Location loc,
3637
StringRef nameHint = "xmrPath");
3738

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.
3842
HierPathOp getOrCreatePath(ArrayAttr pathArray, Location loc,
3943
OpBuilder::InsertPoint &insertPoint,
4044
StringRef nameHint = "xmrPath");
@@ -54,4 +58,4 @@ class HierPathBuilder {
5458
} // namespace hw
5559
} // namespace circt
5660

57-
#endif // CIRCT_DIALECT_HW_HIERPATHBUILDER_H
61+
#endif // CIRCT_DIALECT_HW_HIERPATHCACHE_H

lib/Dialect/FIRRTL/Transforms/LowerXMR.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include "circt/Dialect/FIRRTL/FIRRTLUtils.h"
1717
#include "circt/Dialect/FIRRTL/Namespace.h"
1818
#include "circt/Dialect/FIRRTL/Passes.h"
19-
#include "circt/Dialect/HW/HierPathBuilder.h"
19+
#include "circt/Dialect/HW/HierPathCache.h"
2020
#include "circt/Dialect/HW/InnerSymbolNamespace.h"
2121
#include "circt/Dialect/SV/SVOps.h"
2222
#include "mlir/IR/ImplicitLocOpBuilder.h"
@@ -131,10 +131,10 @@ class LowerXMRPass : public circt::firrtl::impl::LowerXMRBase<LowerXMRPass> {
131131
CircuitNamespace ns(getOperation());
132132
circuitNamespace = &ns;
133133

134-
hw::HierPathBuilder pb(
134+
hw::HierPathCache pc(
135135
&ns, OpBuilder::InsertPoint(getOperation().getBodyBlock(),
136136
getOperation().getBodyBlock()->begin()));
137-
hierPathBuilder = &pb;
137+
hierPathCache = &pc;
138138

139139
llvm::EquivalenceClasses<Value> eq;
140140
dataFlowClasses = &eq;
@@ -414,7 +414,7 @@ class LowerXMRPass : public circt::firrtl::impl::LowerXMRBase<LowerXMRPass> {
414414
opsToRemove.clear();
415415
xmrPathSuffix.clear();
416416
circuitNamespace = nullptr;
417-
hierPathBuilder = nullptr;
417+
hierPathCache = nullptr;
418418
}
419419

420420
/// Generate the ABI ref_<module> prefix string into `prefix`.
@@ -501,7 +501,7 @@ class LowerXMRPass : public circt::firrtl::impl::LowerXMRBase<LowerXMRPass> {
501501
if (!refSendPath.empty())
502502
// Compute the HierPathOp that stores the path.
503503
ref = FlatSymbolRefAttr::get(
504-
hierPathBuilder
504+
hierPathCache
505505
->getOrCreatePath(builder.getArrayAttr(refSendPath),
506506
builder.getLoc())
507507
.getSymNameAttr());
@@ -869,7 +869,7 @@ class LowerXMRPass : public circt::firrtl::impl::LowerXMRBase<LowerXMRPass> {
869869

870870
/// Utility to create HerPathOps at a predefined location in the circuit.
871871
/// This handles caching and keeps the order consistent.
872-
hw::HierPathBuilder *hierPathBuilder;
872+
hw::HierPathCache *hierPathCache;
873873

874874
/// Per-module helpers for creating operations within modules.
875875
DenseMap<FModuleOp, ModuleState> moduleStates;

lib/Dialect/HW/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
set(CIRCT_HW_Sources
22
ConversionPatterns.cpp
33
CustomDirectiveImpl.cpp
4-
HierPathBuilder.cpp
4+
HierPathCache.cpp
55
HWAttributes.cpp
66
HWEnums.cpp
77
HWDialect.cpp

lib/Dialect/HW/HierPathBuilder.cpp renamed to lib/Dialect/HW/HierPathCache.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
//===- HierPathBuilder.cpp - HierPathOp Builder Utility -------------------===//
1+
//===- HierPathCache.h - HierPathOp Caching Utility -----------------------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
88
//
9-
// Implementation of a utility for creating Hierarchical Path operation.s
9+
// Implementation of a utility for creating Hierarchical Path operations.
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#include "circt/Dialect/HW/HierPathBuilder.h"
13+
#include "circt/Dialect/HW/HierPathCache.h"
1414
#include "circt/Dialect/HW/HWOps.h"
1515

1616
namespace circt {
1717
namespace hw {
1818

19-
HierPathOp HierPathBuilder::getOrCreatePath(ArrayAttr pathArray, Location loc,
20-
StringRef nameHint) {
19+
HierPathOp HierPathCache::getOrCreatePath(ArrayAttr pathArray, Location loc,
20+
StringRef nameHint) {
2121
return getOrCreatePath(pathArray, loc, pathInsertPoint, nameHint);
2222
}
2323

24-
HierPathOp HierPathBuilder::getOrCreatePath(ArrayAttr pathArray, Location loc,
25-
OpBuilder::InsertPoint &insertPoint,
26-
StringRef nameHint) {
24+
HierPathOp HierPathCache::getOrCreatePath(ArrayAttr pathArray, Location loc,
25+
OpBuilder::InsertPoint &insertPoint,
26+
StringRef nameHint) {
2727

2828
assert(pathArray && !pathArray.empty());
2929
// Return an existing HierPathOp if one exists with the same path. Add

0 commit comments

Comments
 (0)