Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FreezePaths] Add an optional argument, to get the operation name #7549

Merged
merged 2 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion include/circt/Dialect/OM/OMPasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#ifndef CIRCT_DIALECT_OM_OMPASSES_H
#define CIRCT_DIALECT_OM_OMPASSES_H

#include "circt/Support/LLVM.h"
#include "mlir/Pass/Pass.h"
#include <memory>

Expand All @@ -20,7 +21,8 @@ namespace circt {
namespace om {

std::unique_ptr<mlir::Pass> createOMLinkModulesPass();
std::unique_ptr<mlir::Pass> createFreezePathsPass();
std::unique_ptr<mlir::Pass> createFreezePathsPass(
std::function<StringAttr(Operation *)> getOpNameFallback = {});
std::unique_ptr<mlir::Pass> createVerifyObjectFieldsPass();

#define GEN_PASS_REGISTRATION
Expand Down
21 changes: 16 additions & 5 deletions lib/Dialect/OM/Transforms/FreezePaths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ using namespace om;

namespace {
struct PathVisitor {
PathVisitor(hw::InstanceGraph &instanceGraph, hw::InnerRefNamespace &irn)
: instanceGraph(instanceGraph), irn(irn) {}
PathVisitor(hw::InstanceGraph &instanceGraph, hw::InnerRefNamespace &irn,
std::function<StringAttr(Operation *)> &getOpName)
: instanceGraph(instanceGraph), irn(irn), getOpNameFallback(getOpName) {}

StringAttr field;
LogicalResult processPath(Location loc, hw::HierPathOp hierPathOp,
Expand All @@ -44,6 +45,7 @@ struct PathVisitor {
LogicalResult run(ModuleOp module);
hw::InstanceGraph &instanceGraph;
hw::InnerRefNamespace &irn;
std::function<StringAttr(Operation *)> getOpNameFallback;
};
} // namespace

Expand Down Expand Up @@ -118,6 +120,8 @@ LogicalResult PathVisitor::processPath(Location loc, hw::HierPathOp hierPathOp,
auto *op = target.getOp();
// Get the verilog name of the target.
auto verilogName = op->getAttrOfType<StringAttr>("hw.verilogName");
if (!verilogName && getOpNameFallback)
verilogName = getOpNameFallback(op);
if (!verilogName) {
auto diag = emitError(loc, "component does not have verilog name");
diag.attachNote(op->getLoc()) << "component here";
Expand Down Expand Up @@ -147,6 +151,8 @@ LogicalResult PathVisitor::processPath(Location loc, hw::HierPathOp hierPathOp,
auto currentModule = innerRef.getModule();
// Get the verilog name of the target.
auto verilogName = op->getAttrOfType<StringAttr>("hw.verilogName");
if (!verilogName && getOpNameFallback)
verilogName = getOpNameFallback(op);
if (!verilogName) {
auto diag = emitError(loc, "component does not have verilog name");
diag.attachNote(op->getLoc()) << "component here";
Expand Down Expand Up @@ -299,7 +305,11 @@ LogicalResult PathVisitor::run(ModuleOp module) {
namespace {
struct FreezePathsPass
: public circt::om::impl::FreezePathsBase<FreezePathsPass> {
FreezePathsPass(std::function<StringAttr(Operation *)> getOpName)
: getOpName(std::move(getOpName)) {}
void runOnOperation() override;

std::function<StringAttr(Operation *)> getOpName;
};
} // namespace

Expand All @@ -310,10 +320,11 @@ void FreezePathsPass::runOnOperation() {
auto &symbolTable = getAnalysis<SymbolTable>();
hw::InnerSymbolTableCollection collection(module);
hw::InnerRefNamespace irn{symbolTable, collection};
if (failed(PathVisitor(instanceGraph, irn).run(module)))
if (failed(PathVisitor(instanceGraph, irn, getOpName).run(module)))
signalPassFailure();
}

std::unique_ptr<mlir::Pass> circt::om::createFreezePathsPass() {
return std::make_unique<FreezePathsPass>();
std::unique_ptr<mlir::Pass> circt::om::createFreezePathsPass(
std::function<StringAttr(Operation *)> getOpName) {
return std::make_unique<FreezePathsPass>(getOpName);
}
Loading