11 #include "mlir/Pass/Pass.h"
19 #include "mlir/Transforms/DialectConversion.h"
25 #define GEN_PASS_DEF_KANAGAWACONVERTCFTOHANDSHAKE
26 #include "circt/Dialect/Kanagawa/KanagawaPasses.h.inc"
31 using namespace circt;
32 using namespace kanagawa;
36 struct ConvertCFToHandshakePass
37 :
public circt::kanagawa::impl::KanagawaConvertCFToHandshakeBase<
38 ConvertCFToHandshakePass> {
39 void runOnOperation()
override;
41 LogicalResult convertMethod(MethodOp method);
45 LogicalResult ConvertCFToHandshakePass::convertMethod(MethodOp method) {
48 llvm::SmallVector<Type> newArgTypes, newResTypes;
49 auto methodLikeOp = cast<MethodLikeOpInterface>(method.getOperation());
50 llvm::copy(methodLikeOp.getArgumentTypes(), std::back_inserter(newArgTypes));
51 llvm::copy(methodLikeOp.getResultTypes(), std::back_inserter(newResTypes));
52 newArgTypes.push_back(b.getNoneType());
53 newResTypes.push_back(b.getNoneType());
54 auto newFuncType = b.getFunctionType(newArgTypes, newResTypes);
55 auto dataflowMethodOp = b.create<DataflowMethodOp>(
56 method.getLoc(), method.getInnerSymAttr(),
TypeAttr::get(newFuncType),
57 method.getArgNamesAttr(), method.getArgAttrsAttr(),
58 method.getResAttrsAttr());
59 dataflowMethodOp.getFunctionBody().takeBody(method.getBody());
60 dataflowMethodOp.getBodyBlock()->addArgument(b.getNoneType(),
62 Value entryCtrl = dataflowMethodOp.getBodyBlock()->getArguments().back();
65 handshake::HandshakeLowering fol(dataflowMethodOp.getBody());
66 if (failed(handshake::lowerRegion<kanagawa::ReturnOp, kanagawa::ReturnOp>(
75 void ConvertCFToHandshakePass::runOnOperation() {
76 ClassOp classOp = getOperation();
77 for (
auto method : llvm::make_early_inc_range(classOp.getOps<MethodOp>())) {
78 if (failed(convertMethod(method)))
79 return signalPassFailure();
84 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.