CIRCT  19.0.0git
IbisConvertCFToHandshake.cpp
Go to the documentation of this file.
1 //===- IbisConvertCFToHandshakePass.cpp -----------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "PassDetails.h"
10 
15 
17 #include "mlir/Transforms/DialectConversion.h"
18 
20 
21 using namespace mlir;
22 using namespace circt;
23 using namespace ibis;
24 
25 namespace {
26 
27 struct ConvertCFToHandshakePass
28  : public IbisConvertCFToHandshakeBase<ConvertCFToHandshakePass> {
29  void runOnOperation() override;
30 
31  LogicalResult convertMethod(MethodOp method);
32 };
33 } // anonymous namespace
34 
35 LogicalResult ConvertCFToHandshakePass::convertMethod(MethodOp method) {
36  // Add a control input/output to the method.
37  OpBuilder b(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(),
51  method.getLoc());
52  Value entryCtrl = dataflowMethodOp.getBodyBlock()->getArguments().back();
53  method.erase();
54 
55  handshake::HandshakeLowering fol(dataflowMethodOp.getBody());
56  if (failed(handshake::lowerRegion<ibis::ReturnOp, ibis::ReturnOp>(
57  fol,
58  /*sourceConstants*/ false, /*disableTaskPipelining*/ false,
59  entryCtrl)))
60  return failure();
61 
62  return success();
63 }
64 
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();
70  }
71 }
72 
74  return std::make_unique<ConvertCFToHandshakePass>();
75 }
Direction get(bool isOutput)
Returns an output direction if isOutput is true, otherwise returns an input direction.
Definition: CalyxOps.cpp:54
std::unique_ptr< mlir::Pass > createConvertCFToHandshakePass()
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition: DebugAnalysis.h:21