17 #include "mlir/Transforms/DialectConversion.h"
22 using namespace circt;
27 struct ConvertCFToHandshakePass
28 :
public IbisConvertCFToHandshakeBase<ConvertCFToHandshakePass> {
29 void runOnOperation()
override;
31 LogicalResult convertMethod(MethodOp method);
35 LogicalResult ConvertCFToHandshakePass::convertMethod(MethodOp method) {
38 llvm::SmallVector<Type> newArgTypes, newResTypes;
39 auto methodLikeOp = cast<MethodLikeOpInterface>(method.getOperation());
40 llvm::copy(methodLikeOp.getArgumentTypes(), std::back_inserter(newArgTypes));
41 llvm::copy(methodLikeOp.getResultTypes(), std::back_inserter(newResTypes));
42 newArgTypes.push_back(b.getNoneType());
43 newResTypes.push_back(b.getNoneType());
44 auto newFuncType = b.getFunctionType(newArgTypes, newResTypes);
45 auto dataflowMethodOp = b.create<DataflowMethodOp>(
46 method.getLoc(), method.getInnerSymAttr(),
TypeAttr::get(newFuncType),
47 method.getArgNamesAttr(), method.getArgAttrsAttr(),
48 method.getResAttrsAttr());
49 dataflowMethodOp.getFunctionBody().takeBody(method.getBody());
50 dataflowMethodOp.getBodyBlock()->addArgument(b.getNoneType(),
52 Value entryCtrl = dataflowMethodOp.getBodyBlock()->getArguments().back();
56 if (failed(handshake::lowerRegion<ibis::ReturnOp, ibis::ReturnOp>(
65 void ConvertCFToHandshakePass::runOnOperation() {
66 ClassOp classOp = getOperation();
67 for (
auto method : llvm::make_early_inc_range(classOp.getOps<MethodOp>())) {
68 if (failed(convertMethod(method)))
69 return signalPassFailure();
74 return std::make_unique<ConvertCFToHandshakePass>();
Direction get(bool isOutput)
Returns an output direction if isOutput is true, otherwise returns an input direction.
std::unique_ptr< mlir::Pass > createConvertCFToHandshakePass()
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.