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

[firtool] Add option to disable layer sink #7981

Merged
merged 1 commit into from
Dec 13, 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
3 changes: 3 additions & 0 deletions include/circt-c/Firtool/Firtool.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ circtFirtoolOptionsSetEnableDebugInfo(CirctFirtoolFirtoolOptions options,
MLIR_CAPI_EXPORTED void
circtFirtoolOptionsSetBuildMode(CirctFirtoolFirtoolOptions options,
CirctFirtoolBuildMode value);
MLIR_CAPI_EXPORTED void
circtFirtoolOptionsSetDisableLayerSink(CirctFirtoolFirtoolOptions options,
bool value);

MLIR_CAPI_EXPORTED void
circtFirtoolOptionsSetDisableOptimization(CirctFirtoolFirtoolOptions options,
Expand Down
7 changes: 7 additions & 0 deletions include/circt/Firtool/Firtool.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class FirtoolOptions {
}
bool shouldConvertProbesToSignals() const { return probesToSignals; }
bool shouldReplaceSequentialMemories() const { return replSeqMem; }
bool shouldDisableLayerSink() const { return disableLayerSink; }
bool shouldDisableOptimization() const { return disableOptimization; }
bool shouldAdvancedLayerSink() const { return advancedLayerSink; }
bool shouldLowerMemories() const { return lowerMemories; }
Expand Down Expand Up @@ -189,6 +190,11 @@ class FirtoolOptions {
return *this;
}

FirtoolOptions &setDisableLayerSink(bool value) {
disableLayerSink = value;
return *this;
}

FirtoolOptions &setDisableOptimization(bool value) {
disableOptimization = value;
return *this;
Expand Down Expand Up @@ -381,6 +387,7 @@ class FirtoolOptions {
firrtl::PreserveValues::PreserveMode preserveMode;
bool enableDebugInfo;
BuildMode buildMode;
bool disableLayerSink;
bool disableOptimization;
bool exportChiselInterface;
std::string chiselInterfaceOutDirectory;
Expand Down
5 changes: 5 additions & 0 deletions lib/CAPI/Firtool/Firtool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ void circtFirtoolOptionsSetBuildMode(CirctFirtoolFirtoolOptions options,
unwrap(options)->setBuildMode(converted);
}

void circtFirtoolOptionsSetDisableLayerSink(CirctFirtoolFirtoolOptions options,
bool value) {
unwrap(options)->setDisableLayerSink(value);
}

void circtFirtoolOptionsSetDisableOptimization(
CirctFirtoolFirtoolOptions options, bool value) {
unwrap(options)->setDisableOptimization(value);
Expand Down
19 changes: 14 additions & 5 deletions lib/Firtool/Firtool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,14 @@ LogicalResult firtool::populateCHIRRTLToLowFIRRTL(mlir::PassManager &pm,
//
// TODO: Improve LowerLayers to avoid the need for canonicalization. See:
// https://github.com/llvm/circt/issues/7896
if (opt.shouldAdvancedLayerSink())
pm.nest<firrtl::CircuitOp>().addPass(firrtl::createAdvancedLayerSinkPass());
else
pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
firrtl::createLayerSinkPass());
if (!opt.shouldDisableLayerSink()) {
if (opt.shouldAdvancedLayerSink())
pm.nest<firrtl::CircuitOp>().addPass(
firrtl::createAdvancedLayerSinkPass());
else
pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
firrtl::createLayerSinkPass());
}
pm.nest<firrtl::CircuitOp>().addPass(firrtl::createLowerLayersPass());
if (!opt.shouldDisableOptimization())
pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
Expand Down Expand Up @@ -522,6 +525,11 @@ struct FirtoolCmdOptions {
"release", "Compile with optimizations")),
llvm::cl::init(firtool::FirtoolOptions::BuildModeDefault)};

llvm::cl::opt<bool> disableLayerSink{
"disable-layer-sink",
llvm::cl::desc("Disable layer sink"),
};

llvm::cl::opt<bool> disableOptimization{
"disable-opt",
llvm::cl::desc("Disable optimizations"),
Expand Down Expand Up @@ -789,6 +797,7 @@ circt::firtool::FirtoolOptions::FirtoolOptions()
preserveMode = clOptions->preserveMode;
enableDebugInfo = clOptions->enableDebugInfo;
buildMode = clOptions->buildMode;
disableLayerSink = clOptions->disableLayerSink;
disableOptimization = clOptions->disableOptimization;
exportChiselInterface = clOptions->exportChiselInterface;
chiselInterfaceOutDirectory = clOptions->chiselInterfaceOutDirectory;
Expand Down
Loading