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

[circt-synth] Partially lower Comb operations and run canonicalizations #8218

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion include/circt/Conversion/Passes.td
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ def ConvertCombToAIG: Pass<"convert-comb-to-aig", "hw::HWModuleOp"> {

let options = [
ListOption<"additionalLegalOps", "additional-legal-ops", "std::string",
"Specify additional legal ops for testing">,
"Specify additional legal ops to partially legalize Comb to AIG">,
Option<"maxEmulationUnknownBits", "max-emulation-unknown-bits", "uint32_t", "10",
"Maximum number of unknown bits to emulate in a table lookup">
];
Expand Down
2 changes: 1 addition & 1 deletion lib/Conversion/CombToAIG/CombToAIG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ void ConvertCombToAIGPass::runOnOperation() {
// AIG is target dialect.
target.addLegalDialect<aig::AIGDialect>();

// This is a test only option to add logical ops.
// If additional legal ops are specified, add them to the target.
if (!additionalLegalOps.empty())
for (const auto &opName : additionalLegalOps)
target.addLegalOp(OperationName(opName, &getContext()));
Expand Down
21 changes: 21 additions & 0 deletions tools/circt-synth/circt-synth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "circt/Dialect/AIG/AIGDialect.h"
#include "circt/Dialect/AIG/AIGPasses.h"
#include "circt/Dialect/Comb/CombDialect.h"
#include "circt/Dialect/Comb/CombOps.h"
#include "circt/Dialect/HW/HWDialect.h"
#include "circt/Dialect/HW/HWOps.h"
#include "circt/Dialect/HW/HWPasses.h"
Expand Down Expand Up @@ -97,6 +98,11 @@ static bool untilReached(Until until) {
// Tool implementation
//===----------------------------------------------------------------------===//

template <typename... AllowedOpTy>
static void partiallyLegalizeCombToAIG(SmallVectorImpl<std::string> &ops) {
(ops.push_back(AllowedOpTy::getOperationName().str()), ...);
}

static void populateSynthesisPipeline(PassManager &pm) {
// Add the AIG to Comb at the scope exit if requested.
auto addAIGToComb = llvm::make_scope_exit([&]() {
Expand All @@ -108,6 +114,21 @@ static void populateSynthesisPipeline(PassManager &pm) {
});

auto &mpm = pm.nest<hw::HWModuleOp>();

{
// Partially legalize Comb to AIG, run CSE and canonicalization.
circt::ConvertCombToAIGOptions options;
partiallyLegalizeCombToAIG<comb::AndOp, comb::OrOp, comb::XorOp,
comb::MuxOp, comb::ICmpOp, hw::ArrayGetOp,
hw::ArraySliceOp, hw::ArrayCreateOp,
hw::ArrayConcatOp, hw::AggregateConstantOp>(
options.additionalLegalOps);
mpm.addPass(circt::createConvertCombToAIG(options));
}
mpm.addPass(createCSEPass());
mpm.addPass(createSimpleCanonicalizerPass());

// Fully legalize AIG to Comb.
mpm.addPass(circt::hw::createHWAggregateToCombPass());
mpm.addPass(circt::createConvertCombToAIG());
mpm.addPass(createCSEPass());
Expand Down