Skip to content
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: 2 additions & 1 deletion include/circt/Transforms/Passes.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ enum class OpCountEmissionFormat {
void populateArithToCombPatterns(mlir::RewritePatternSet &patterns,
TypeConverter &typeConverter);

std::unique_ptr<mlir::Pass> createMapArithToCombPass();
std::unique_ptr<mlir::Pass>
createMapArithToCombPass(bool enableBestEffortLowering = false);
std::unique_ptr<mlir::Pass> createConvertIndexToUIntPass();
std::unique_ptr<mlir::Pass> createFlattenMemRefPass();
std::unique_ptr<mlir::Pass> createFlattenMemRefCallsPass();
Expand Down
9 changes: 8 additions & 1 deletion include/circt/Transforms/Passes.td
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,14 @@ def MapArithToCombPass : Pass<"map-arith-to-comb"> {
Rather, it provides a simple way (mostly for testing purposes) to map
`arith` operations.
}];
let constructor = "circt::createMapArithToCombPass()";
let options = [
Option<"enableBestEffortLowering", "enable-best-effort-lowering",
"bool", /*default=*/"false",
"Enable best effort lowering of operations"
"(eg, existing arith operations that have no lowering stay as is)">
];

let constructor = "circt::createMapArithToCombPass(/*enableBestEffortLowering=*/false)";
let dependentDialects = ["circt::hw::HWDialect, mlir::arith::ArithDialect, circt::comb::CombDialect"];
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Conversion/ImportVerilog/ImportVerilog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ void circt::populateLlhdToCorePipeline(

// Convert `arith.select` generated by some of the control flow canonicalizers
// to `comb.mux`.
modulePM.addPass(createMapArithToCombPass());
modulePM.addPass(createMapArithToCombPass(true));

// Simplify module-level signals.
modulePM.addPass(llhd::createCombineDrivesPass());
Expand Down
35 changes: 32 additions & 3 deletions lib/Transforms/MapArithToComb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,40 @@ class CompConversionPattern : public OpConversionPattern<arith::CmpIOp> {
struct MapArithToCombPass
: public circt::impl::MapArithToCombPassBase<MapArithToCombPass> {
public:
MapArithToCombPass(bool enableBestEffortLowering) {
this->enableBestEffortLowering = enableBestEffortLowering;
}

void runOnOperation() override {
auto *ctx = &getContext();

ConversionTarget target(*ctx);
target.addLegalDialect<comb::CombDialect, hw::HWDialect>();
target.addIllegalDialect<arith::ArithDialect>();
if (!enableBestEffortLowering) {
target.addIllegalDialect<arith::ArithDialect>();
} else {
// We make all arith operations with a potential lowering here (as
// specified in circt::populateArithToCombPatterns) illegal
target.addIllegalOp<arith::AddIOp>();
target.addIllegalOp<arith::SubIOp>();
target.addIllegalOp<arith::MulIOp>();
target.addIllegalOp<arith::DivSIOp>();
target.addIllegalOp<arith::DivUIOp>();
target.addIllegalOp<arith::RemSIOp>();
target.addIllegalOp<arith::RemUIOp>();
target.addIllegalOp<arith::AndIOp>();
target.addIllegalOp<arith::OrIOp>();
target.addIllegalOp<arith::XOrIOp>();
target.addIllegalOp<arith::ShLIOp>();
target.addIllegalOp<arith::ShRSIOp>();
target.addIllegalOp<arith::ShRUIOp>();
target.addIllegalOp<arith::ConstantOp>();
target.addIllegalOp<arith::SelectOp>();
target.addIllegalOp<arith::ExtSIOp>();
target.addIllegalOp<arith::ExtUIOp>();
target.addIllegalOp<arith::TruncIOp>();
target.addIllegalOp<arith::CmpIOp>();
}
MapArithTypeConverter typeConverter;
RewritePatternSet patterns(ctx);
populateArithToCombPatterns(patterns, typeConverter);
Expand Down Expand Up @@ -195,6 +223,7 @@ void circt::populateArithToCombPatterns(mlir::RewritePatternSet &patterns,
typeConverter, patterns.getContext());
}

std::unique_ptr<mlir::Pass> circt::createMapArithToCombPass() {
return std::make_unique<MapArithToCombPass>();
std::unique_ptr<mlir::Pass>
circt::createMapArithToCombPass(bool enableBestEffortLowering) {
return std::make_unique<MapArithToCombPass>(enableBestEffortLowering);
}