Skip to content

Commit c970c42

Browse files
authored
[Synth][FunctionalReduction] Fold constants (#10487)
Concerns #10484
1 parent 0e62bcb commit c970c42

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

integration_test/circt-synth/functional-reduction-cadical.mlir

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,13 @@ hw.module @functional_reduction_sat(in %a: i1, in %b: i1, in %c: i1, in %d: i1,
2020
%4 = synth.aig.and_inv %a, not %b, not %c, not %d : i1
2121
hw.output %2, %3, %4 : i1, i1, i1
2222
}
23+
24+
// CHECK-LABEL: hw.module @fold_constant_reduction
25+
hw.module @fold_constant_reduction(in %a: i1, in %b: i1, in %c: i1, out result: i1) {
26+
// CHECK: %[[FALSE:.+]] = hw.constant false
27+
// CHECK: %[[CHOICE:.+]] = synth.choice %[[FALSE]]
28+
// CHECK: hw.output %[[CHOICE]] : i1
29+
%0 = synth.aig.and_inv %a, not %a : i1
30+
%1 = synth.aig.and_inv %0 : i1
31+
hw.output %1 : i1
32+
}

lib/Dialect/Synth/Transforms/FunctionalReduction.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,14 @@ void FunctionalReductionSolver::initializeSATState() {
348348
//===----------------------------------------------------------------------===//
349349

350350
void FunctionalReductionSolver::collectValues() {
351+
352+
// Seed zero constants so nodes can be merged
353+
// if input IR does not contain constants already.
354+
OpBuilder builder(module.getContext());
355+
builder.setInsertionPointToStart(module.getBodyBlock());
356+
auto i1Type = builder.getIntegerType(1);
357+
hw::ConstantOp::create(builder, module.getLoc(), i1Type, 0);
358+
351359
// Collect block arguments (primary inputs) that are i1
352360
for (auto arg : module.getBodyBlock()->getArguments()) {
353361
if (arg.getType().isInteger(1)) {

0 commit comments

Comments
 (0)