Skip to content

Commit

Permalink
working!
Browse files Browse the repository at this point in the history
  • Loading branch information
teqdruid committed Nov 26, 2024
1 parent 6bb984a commit 66eb94f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 11 deletions.
14 changes: 10 additions & 4 deletions frontends/PyCDE/test/test_handshake.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@
# CHECK: return %0 : i8
# CHECK: }

# CHECK: hw.module @Top(in %clk : i1, in %rst : i1, in %a : i8, in %a_valid : i1, in %x_ready : i1, out a_ready : i1, out x : i8, out x_valid : i1)
# CHECK: %TestFunc.in0_ready, %TestFunc.out0, %TestFunc.out0_valid = hw.instance "TestFunc" @TestFunc(in0: %a: i8, in0_valid: %a_valid: i1, clk: %clk: i1, rst: %rst: i1, out0_ready: %x_ready: i1) -> (in0_ready: i1, out0: i8, out0_valid: i1)
# CHECK: hw.output %TestFunc.in0_ready, %TestFunc.out0, %TestFunc.out0_valid : i1, i8, i1
# CHECK: hw.module @TestFunc(in %in0 : i8, in %in0_valid : i1, in %clk : i1, in %rst : i1, in %out0_ready : i1, out in0_ready : i1, out out0 : i8, out out0_valid : i1)
# CHECK: %c15_i8 = hw.constant 15 : i8
# CHECK: [[R0:%.+]] = comb.and %out0_ready, %in0_valid : i1
# CHECK: [[R1:%.+]] = comb.and bin %in0, %c15_i8 : i8
# CHECK: hw.output [[R0]], [[R1]], %in0_valid : i1, i8, i1


class TestFunc(Func):
a = Input(Bits(8))
Expand All @@ -28,10 +37,7 @@ def build(ports):
BarType = types.struct({"foo": types.i12}, "bar")


@unittestmodule(print=True,
run_passes=True,
print_after_passes=True,
debug=True)
@unittestmodule(print=True, run_passes=True, print_after_passes=True)
class Top(Module):
clk = Clock()
rst = Input(Bits(1))
Expand Down
2 changes: 1 addition & 1 deletion frontends/PyCDE/test/test_polynomial.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def construct(self):

print("Generating rest...")
poly.generate()
poly.run_passes()
poly.run_passes(debug=True)

print("=== Final IR...")
poly.print()
Expand Down
6 changes: 2 additions & 4 deletions lib/Conversion/DCToHW/DCToHW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -838,10 +838,8 @@ static bool isDCType(Type type) { return isa<TokenType, ValueType>(type); }
/// Returns true if the given `op` is considered as legal - i.e. it does not
/// contain any dc-typed values.
static bool isLegalOp(Operation *op) {
if (auto funcOp = dyn_cast<HWModuleLike>(op)) {
return llvm::none_of(funcOp.getPortTypes(), isDCType) &&
llvm::none_of(funcOp.getBodyBlock()->getArgumentTypes(), isDCType);
}
if (auto funcOp = dyn_cast<HWModuleLike>(op))
return llvm::none_of(funcOp.getPortTypes(), isDCType);

bool operandsOK = llvm::none_of(op->getOperandTypes(), isDCType);
bool resultsOK = llvm::none_of(op->getResultTypes(), isDCType);
Expand Down
5 changes: 3 additions & 2 deletions lib/Conversion/HandshakeToDC/HandshakeToDC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ class HandshakeToDCPass
void runOnOperation() override {
mlir::ModuleOp mod = getOperation();
auto targetModifier = [](mlir::ConversionTarget &target) {
target.addLegalDialect<hw::HWDialect, func::FuncDialect>();
// target.addLegalDialect<hw::HWDialect, func::FuncDialect>();
};

auto patternBuilder = [&](TypeConverter &typeConverter,
Expand Down Expand Up @@ -807,7 +807,8 @@ LogicalResult circt::handshaketodc::runHandshakeToDC(
ConversionTarget target(*ctx);
target.addIllegalDialect<handshake::HandshakeDialect>();
target.addLegalDialect<dc::DCDialect>();
target.addLegalOp<mlir::ModuleOp, handshake::ESIInstanceOp>();
target.addLegalOp<mlir::ModuleOp, handshake::ESIInstanceOp, hw::HWModuleOp,
hw::OutputOp>();

// And any user-specified target adjustments
if (configureTarget)
Expand Down
6 changes: 6 additions & 0 deletions test/Conversion/DCToHW/basic.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,9 @@ hw.module @merge(in %first : !dc.token, in %second : !dc.token, out token : !dc.
%selected = dc.merge %first, %second
hw.output %selected : !dc.value<i1>
}

// CHECK: hw.module.extern @ext(in %a : i32, out b : i32)
hw.module.extern @ext(in %a : i32, out b : i32)

// CHECK: hw.module.extern @extDC(in %a : !esi.channel<i32>, out b : i32)
hw.module.extern @extDC(in %a : !dc.value<i32>, out b : i32)

0 comments on commit 66eb94f

Please sign in to comment.