Skip to content

Commit

Permalink
[Arc][ArcToLLVM] Fix seq.clock_gate lowering
Browse files Browse the repository at this point in the history
This op did not properly lower because it created comb ops for which no lowering pattern was registered. Instead, lower to LLVM directly, but also register the CombToArith patterns to support comb as intermediate operations. This is also consistent with registering HWToLLVM and CombToLLVM in this pass directly. Also, add a missing test for the clock gate lowering.
  • Loading branch information
maerhart committed Dec 31, 2024
1 parent bae447c commit afa566a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions lib/Conversion/ArcToLLVM/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ add_circt_conversion_library(CIRCTArcToLLVM
CIRCTArc
CIRCTComb
CIRCTSeq
CIRCTCombToArith
CIRCTCombToLLVM
CIRCTHWToLLVM
MLIRArithToLLVM
Expand Down
6 changes: 4 additions & 2 deletions lib/Conversion/ArcToLLVM/LowerArcToLLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//

#include "circt/Conversion/ArcToLLVM.h"
#include "circt/Conversion/CombToArith.h"
#include "circt/Conversion/CombToLLVM.h"
#include "circt/Conversion/HWToLLVM.h"
#include "circt/Dialect/Arc/ArcOps.h"
Expand Down Expand Up @@ -259,8 +260,8 @@ struct ClockGateOpLowering : public OpConversionPattern<seq::ClockGateOp> {
LogicalResult
matchAndRewrite(seq::ClockGateOp op, OpAdaptor adaptor,
ConversionPatternRewriter &rewriter) const final {
rewriter.replaceOpWithNewOp<comb::AndOp>(op, adaptor.getInput(),
adaptor.getEnable(), true);
rewriter.replaceOpWithNewOp<LLVM::AndOp>(op, adaptor.getInput(),
adaptor.getEnable());
return success();
}
};
Expand Down Expand Up @@ -648,6 +649,7 @@ void LowerArcToLLVMPass::runOnOperation() {
populateHWToLLVMConversionPatterns(converter, patterns, globals,
constAggregateGlobalsMap);
populateHWToLLVMTypeConversions(converter);
populateCombToArithConversionPatterns(converter, patterns);
populateCombToLLVMConversionPatterns(converter, patterns);

// Arc patterns.
Expand Down
6 changes: 4 additions & 2 deletions test/Conversion/ArcToLLVM/lower-arc-to-llvm.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,16 @@ func.func @seqClocks(%clk1: !seq.clock, %clk2: !seq.clock) -> !seq.clock {
%2 = arith.xori %0, %1 : i1
%3 = seq.to_clock %2
%4 = seq.clock_inv %3
return %4 : !seq.clock
%5 = seq.clock_gate %4, %0
return %5 : !seq.clock
}
// CHECK-LABEL: llvm.func @seqClocks
// CHECK-SAME: ([[CLK1:%.+]]: i1, [[CLK2:%.+]]: i1)
// CHECK: [[RES:%.+]] = llvm.xor [[CLK1]], [[CLK2]]
// CHECK: [[TRUE:%.+]] = llvm.mlir.constant(true) : i1
// CHECK: [[RES1:%.+]] = llvm.xor [[RES]], [[TRUE]] : i1
// CHECK: llvm.return [[RES1]] : i1
// CHECK: [[RES2:%.+]] = llvm.and [[RES1]], [[CLK1]] : i1
// CHECK: llvm.return [[RES2]] : i1

// CHECK-LABEL: llvm.func @ReadAggregates(
// CHECK-SAME: %arg0: !llvm.ptr
Expand Down
1 change: 0 additions & 1 deletion tools/arcilator/arcilator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,6 @@ static void populateArcToLLVMPipeline(PassManager &pm) {
// Lower the arcs and update functions to LLVM.
if (untilReached(UntilLLVMLowering))
return;
pm.addPass(createConvertCombToArithPass());
pm.addPass(createLowerArcToLLVMPass());
pm.addPass(createCSEPass());
pm.addPass(arc::createArcCanonicalizerPass());
Expand Down

0 comments on commit afa566a

Please sign in to comment.