Skip to content

Commit ec79b1b

Browse files
authored
[hw] Convert HW Passes to use ODS constructors (#8703)
Change all HW passes to use ODS consturctors as opposed to hand-rolling them. The hand-rolled constructors aren't necessary and add a bunch of boilerplate. Note: a number of these passes do not have users and hence may break out of tree users. The out of tree users are likely @teqdruid and @mortbopet. Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
1 parent 8fa6b23 commit ec79b1b

File tree

14 files changed

+19
-86
lines changed

14 files changed

+19
-86
lines changed

include/circt/Dialect/HW/HWPasses.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,13 @@
1515

1616
#include "mlir/Pass/Pass.h"
1717
#include "mlir/Pass/PassRegistry.h"
18-
#include <memory>
19-
#include <optional>
2018

2119
namespace circt {
2220
namespace hw {
2321

2422
#define GEN_PASS_DECL
2523
#include "circt/Dialect/HW/Passes.h.inc"
2624

27-
std::unique_ptr<mlir::Pass> createPrintInstanceGraphPass();
28-
std::unique_ptr<mlir::Pass> createHWSpecializePass();
29-
std::unique_ptr<mlir::Pass> createPrintHWModuleGraphPass();
30-
std::unique_ptr<mlir::Pass> createFlattenIOPass(bool recursiveFlag = true,
31-
bool flattenExternFlag = false,
32-
char joinChar = '.');
33-
std::unique_ptr<mlir::Pass> createVerifyInnerRefNamespacePass();
34-
std::unique_ptr<mlir::Pass> createFlattenModulesPass();
35-
std::unique_ptr<mlir::Pass> createFooWiresPass();
36-
std::unique_ptr<mlir::Pass> createHWAggregateToCombPass();
37-
3825
/// Generate the code for registering passes.
3926
#define GEN_PASS_REGISTRATION
4027
#include "circt/Dialect/HW/Passes.h.inc"

include/circt/Dialect/HW/Passes.td

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,10 @@ include "mlir/Pass/PassBase.td"
1717

1818
def PrintInstanceGraph : Pass<"hw-print-instance-graph", "mlir::ModuleOp"> {
1919
let summary = "Print a DOT graph of the module hierarchy.";
20-
let constructor = "circt::hw::createPrintInstanceGraphPass()";
2120
}
2221

2322
def PrintHWModuleGraph : Pass<"hw-print-module-graph", "mlir::ModuleOp"> {
2423
let summary = "Print a DOT graph of the HWModule's within a top-level module.";
25-
let constructor = "circt::hw::createPrintHWModuleGraphPass()";
26-
2724
let options = [
2825
Option<"verboseEdges", "verbose-edges", "bool", "false",
2926
"Print information on SSA edges (types, operand #, ...)">,
@@ -32,8 +29,6 @@ def PrintHWModuleGraph : Pass<"hw-print-module-graph", "mlir::ModuleOp"> {
3229

3330
def FlattenIO : Pass<"hw-flatten-io", "mlir::ModuleOp"> {
3431
let summary = "Flattens hw::Structure typed in- and output ports.";
35-
let constructor = "circt::hw::createFlattenIOPass()";
36-
3732
let options = [
3833
Option<"recursive", "recursive", "bool", "true",
3934
"Recursively flatten nested structs.">,
@@ -48,18 +43,16 @@ def FlattenModules : Pass<"hw-flatten-modules", "mlir::ModuleOp"> {
4843
let summary = "Eagerly inline private modules";
4944
let description = [{
5045
This pass eagerly inlines private HW modules into their instantiation sites.
51-
This is necessary for verification purposes, as model checking backends do not
52-
require or support the use of module hierarchy. For simulation, module hierarchies
46+
This is necessary for verification purposes, as model checking backends do not
47+
require or support the use of module hierarchy. For simulation, module hierarchies
5348
degenerate into a purely cosmetic construct, at which point it is beneficial
54-
to fully flatten the module hierarchy to simplify further analysis and
49+
to fully flatten the module hierarchy to simplify further analysis and
5550
optimization of state transfer arcs.
5651
}];
57-
let constructor = "circt::hw::createFlattenModulesPass()";
5852
}
5953

6054
def HWSpecialize : Pass<"hw-specialize", "mlir::ModuleOp"> {
6155
let summary = "Specializes instances of parametric hw.modules";
62-
let constructor = "circt::hw::createHWSpecializePass()";
6356
let description = [{
6457
Any `hw.instance` operation instantiating a parametric `hw.module` will
6558
trigger a specialization procedure which resolves all parametric types and
@@ -72,7 +65,6 @@ def HWSpecialize : Pass<"hw-specialize", "mlir::ModuleOp"> {
7265

7366
def VerifyInnerRefNamespace : Pass<"hw-verify-irn"> {
7467
let summary = "Verify InnerRefNamespaceLike operations, if not self-verifying.";
75-
let constructor = "circt::hw::createVerifyInnerRefNamespacePass()";
7668
}
7769

7870
/**
@@ -84,13 +76,10 @@ def FooWires : Pass<"hw-foo-wires", "hw::HWModuleOp"> {
8476
Very basic pass that numbers all of the wires in a given module.
8577
The wires' names are then all converte to foo_<that number>.
8678
}];
87-
let constructor = "circt::hw::createFooWiresPass()";
8879
}
8980

9081
def HWAggregateToComb : Pass<"hw-aggregate-to-comb", "hw::HWModuleOp"> {
9182
let summary = "Lower aggregate operations to comb operations";
92-
let constructor = "circt::hw::createHWAggregateToCombPass()";
93-
9483
let description = [{
9584
This pass lowers aggregate *operations* to comb operations within modules.
9685
Note that this pass does not lower ports. Ports lowering is handled

lib/Dialect/HW/Transforms/FlattenIO.cpp

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -544,13 +544,9 @@ static bool flattenIO(ModuleOp module, bool recursive,
544544
namespace {
545545

546546
class FlattenIOPass : public circt::hw::impl::FlattenIOBase<FlattenIOPass> {
547-
public:
548-
FlattenIOPass(bool recursiveFlag, bool flattenExternFlag, char join) {
549-
recursive = recursiveFlag;
550-
flattenExtern = flattenExternFlag;
551-
joinChar = join;
552-
}
547+
using Base::Base;
553548

549+
public:
554550
void runOnOperation() override {
555551
ModuleOp module = getOperation();
556552
if (!flattenExtern) {
@@ -573,14 +569,3 @@ class FlattenIOPass : public circt::hw::impl::FlattenIOBase<FlattenIOPass> {
573569
StringSet<> externModules;
574570
};
575571
} // namespace
576-
577-
//===----------------------------------------------------------------------===//
578-
// Pass initialization
579-
//===----------------------------------------------------------------------===//
580-
581-
std::unique_ptr<Pass> circt::hw::createFlattenIOPass(bool recursiveFlag,
582-
bool flattenExternFlag,
583-
char joinChar) {
584-
return std::make_unique<FlattenIOPass>(recursiveFlag, flattenExternFlag,
585-
joinChar);
586-
}

lib/Dialect/HW/Transforms/FlattenModules.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,3 @@ void FlattenModulesPass::runOnOperation() {
151151
}
152152
}
153153
}
154-
155-
std::unique_ptr<Pass> circt::hw::createFlattenModulesPass() {
156-
return std::make_unique<FlattenModulesPass>();
157-
}

lib/Dialect/HW/Transforms/FooWires.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,3 @@ void FooWiresPass::runOnOperation() {
3838
wire.setName("foo_" + std::to_string(nWires++)); // Rename said wire
3939
});
4040
}
41-
42-
std::unique_ptr<mlir::Pass> circt::hw::createFooWiresPass() {
43-
return std::make_unique<FooWiresPass>();
44-
}

lib/Dialect/HW/Transforms/HWAggregateToComb.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,3 @@ void HWAggregateToCombPass::runOnOperation() {
181181
std::move(patterns))))
182182
return signalPassFailure();
183183
}
184-
185-
std::unique_ptr<Pass> circt::hw::createHWAggregateToCombPass() {
186-
return std::make_unique<HWAggregateToCombPass>();
187-
}

lib/Dialect/HW/Transforms/HWPrintInstanceGraph.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ using namespace hw;
2929
namespace {
3030
struct PrintInstanceGraphPass
3131
: public circt::hw::impl::PrintInstanceGraphBase<PrintInstanceGraphPass> {
32-
PrintInstanceGraphPass(raw_ostream &os) : os(os) {}
32+
PrintInstanceGraphPass() : os(llvm::errs()) {}
3333
void runOnOperation() override {
3434
InstanceGraph &instanceGraph = getAnalysis<InstanceGraph>();
3535
llvm::WriteGraph(os, &instanceGraph, /*ShortNames=*/false);
@@ -38,7 +38,3 @@ struct PrintInstanceGraphPass
3838
raw_ostream &os;
3939
};
4040
} // end anonymous namespace
41-
42-
std::unique_ptr<mlir::Pass> circt::hw::createPrintInstanceGraphPass() {
43-
return std::make_unique<PrintInstanceGraphPass>(llvm::errs());
44-
}

lib/Dialect/HW/Transforms/HWSpecialize.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,3 @@ void HWSpecializePass::runOnOperation() {
434434
}
435435

436436
} // namespace
437-
438-
std::unique_ptr<Pass> circt::hw::createHWSpecializePass() {
439-
return std::make_unique<HWSpecializePass>();
440-
}

lib/Dialect/HW/Transforms/PrintHWModuleGraph.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ using namespace hw;
2929
namespace {
3030
struct PrintHWModuleGraphPass
3131
: public circt::hw::impl::PrintHWModuleGraphBase<PrintHWModuleGraphPass> {
32-
PrintHWModuleGraphPass(raw_ostream &os) : os(os) {}
32+
using Base::Base;
33+
3334
void runOnOperation() override {
3435
getOperation().walk([&](hw::HWModuleOp module) {
3536
// We don't really have any other way of forwarding draw arguments to the
@@ -38,13 +39,8 @@ struct PrintHWModuleGraphPass
3839
module->setAttr("dot_verboseEdges",
3940
BoolAttr::get(module.getContext(), verboseEdges));
4041

41-
llvm::WriteGraph(os, module, /*ShortNames=*/false);
42+
llvm::WriteGraph(llvm::errs(), module, /*ShortNames=*/false);
4243
});
4344
}
44-
raw_ostream &os;
4545
};
4646
} // end anonymous namespace
47-
48-
std::unique_ptr<mlir::Pass> circt::hw::createPrintHWModuleGraphPass() {
49-
return std::make_unique<PrintHWModuleGraphPass>(llvm::errs());
50-
}

lib/Dialect/HW/Transforms/VerifyInnerRefNamespace.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,3 @@ class VerifyInnerRefNamespacePass
4646
};
4747

4848
} // namespace
49-
50-
std::unique_ptr<mlir::Pass> circt::hw::createVerifyInnerRefNamespacePass() {
51-
return std::make_unique<VerifyInnerRefNamespacePass>();
52-
}

0 commit comments

Comments
 (0)