@@ -155,12 +155,40 @@ class CompConversionPattern : public OpConversionPattern<arith::CmpIOp> {
155155struct MapArithToCombPass
156156 : public circt::impl::MapArithToCombPassBase<MapArithToCombPass> {
157157public:
158+ MapArithToCombPass (bool enableBestEffortLowering) {
159+ this ->enableBestEffortLowering = enableBestEffortLowering;
160+ }
161+
158162 void runOnOperation () override {
159163 auto *ctx = &getContext ();
160164
161165 ConversionTarget target (*ctx);
162166 target.addLegalDialect <comb::CombDialect, hw::HWDialect>();
163- target.addIllegalDialect <arith::ArithDialect>();
167+ if (!enableBestEffortLowering) {
168+ target.addIllegalDialect <arith::ArithDialect>();
169+ } else {
170+ // We make all arith operations with a potential lowering here (as
171+ // specified in circt::populateArithToCombPatterns) illegal
172+ target.addIllegalOp <arith::AddIOp>();
173+ target.addIllegalOp <arith::SubIOp>();
174+ target.addIllegalOp <arith::MulIOp>();
175+ target.addIllegalOp <arith::DivSIOp>();
176+ target.addIllegalOp <arith::DivUIOp>();
177+ target.addIllegalOp <arith::RemSIOp>();
178+ target.addIllegalOp <arith::RemUIOp>();
179+ target.addIllegalOp <arith::AndIOp>();
180+ target.addIllegalOp <arith::OrIOp>();
181+ target.addIllegalOp <arith::XOrIOp>();
182+ target.addIllegalOp <arith::ShLIOp>();
183+ target.addIllegalOp <arith::ShRSIOp>();
184+ target.addIllegalOp <arith::ShRUIOp>();
185+ target.addIllegalOp <arith::ConstantOp>();
186+ target.addIllegalOp <arith::SelectOp>();
187+ target.addIllegalOp <arith::ExtSIOp>();
188+ target.addIllegalOp <arith::ExtUIOp>();
189+ target.addIllegalOp <arith::TruncIOp>();
190+ target.addIllegalOp <arith::CmpIOp>();
191+ }
164192 MapArithTypeConverter typeConverter;
165193 RewritePatternSet patterns (ctx);
166194 populateArithToCombPatterns (patterns, typeConverter);
@@ -195,6 +223,7 @@ void circt::populateArithToCombPatterns(mlir::RewritePatternSet &patterns,
195223 typeConverter, patterns.getContext ());
196224}
197225
198- std::unique_ptr<mlir::Pass> circt::createMapArithToCombPass () {
199- return std::make_unique<MapArithToCombPass>();
226+ std::unique_ptr<mlir::Pass>
227+ circt::createMapArithToCombPass (bool enableBestEffortLowering) {
228+ return std::make_unique<MapArithToCombPass>(enableBestEffortLowering);
200229}
0 commit comments