Skip to content

Commit

Permalink
support Zhlt::BackOp in picus mode
Browse files Browse the repository at this point in the history
  • Loading branch information
mars-risc0 committed Dec 19, 2024
1 parent 8c837e6 commit af85011
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
13 changes: 12 additions & 1 deletion zirgen/compiler/picus/picus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ class PicusPrinter {
PackOp,
ReturnOp,
GetGlobalLayoutOp,
AliasLayoutOp>([&](auto op) { visitOp(op); })
AliasLayoutOp,
zirgen::Zhlt::BackOp>([&](auto op) { visitOp(op); })
.Case<StoreOp, arith::ConstantOp>([](auto) { /* no-op */ })
.Default([](Operation* op) { llvm::errs() << "unhandled op: " << *op << "\n"; });
}
Expand Down Expand Up @@ -288,6 +289,16 @@ class PicusPrinter {
}
}

void visitOp(zirgen::Zhlt::BackOp back) {
auto callee = back.getCallee();
size_t distance = back.getDistance().getZExtValue();
AnySignal signal = signalize(freshName(), back.getType());
if (distance > 0) {
declareSignals(signal, /*isInput=*/true);
}
valuesToSignals.insert({back.getOut(), signal});
}

// Constructs a fresh signal structure corresponding to the given type
AnySignal signalize(std::string prefix, Type type) {
if (isa<ValType>(type) || isa<RefType>(type)) {
Expand Down
13 changes: 13 additions & 0 deletions zirgen/compiler/picus/test/back.zir
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// RUN: zirgen %s --emit=picus | FileCheck %s

// CHECK: (prime-number 2013265921)
// CHECK: (begin-module Count)
// CHECK: (input x0)
// CHECK: (end-module)

#[picus]
component Count(first: Val) {
public a : Reg;
a := Reg(a@1);
}

0 comments on commit af85011

Please sign in to comment.