11 #include "mlir/Pass/Pass.h"
19 #include "mlir/Transforms/GreedyPatternRewriteDriver.h"
23 #include "mlir/IR/ImplicitLocOpBuilder.h"
29 #define GEN_PASS_DEF_KANAGAWAADDOPERATORLIBRARY
30 #include "circt/Dialect/Kanagawa/KanagawaPasses.h.inc"
35 using namespace circt;
36 using namespace kanagawa;
40 struct AddOperatorLibraryPass
41 :
public circt::kanagawa::impl::KanagawaAddOperatorLibraryBase<
42 AddOperatorLibraryPass> {
43 void runOnOperation()
override;
48 template <
typename TOp>
49 void addOperator(ImplicitLocOpBuilder &b,
int latency) {
50 b.create<ssp::OperatorTypeOp>(
51 b.getStringAttr(TOp::getOperationName()),
52 b.getArrayAttr({b.getAttr<ssp::LatencyAttr>(latency)}));
57 void AddOperatorLibraryPass::runOnOperation() {
58 auto b = ImplicitLocOpBuilder::atBlockBegin(getOperation().getLoc(),
59 getOperation().getBody());
60 auto opLib = b.create<ssp::OperatorLibraryOp>();
62 b.setInsertionPointToStart(opLib.getBodyBlock());
67 addOperator<comb::AddOp>(b, 1);
68 addOperator<comb::SubOp>(b, 1);
69 addOperator<comb::MulOp>(b, 2);
70 addOperator<comb::ModSOp>(b, 2);
71 addOperator<comb::ModUOp>(b, 2);
74 addOperator<comb::AndOp>(b, 0);
75 addOperator<comb::OrOp>(b, 0);
76 addOperator<comb::XorOp>(b, 0);
79 addOperator<comb::ICmpOp>(b, 1);
82 addOperator<comb::ShlOp>(b, 0);
83 addOperator<comb::ShrUOp>(b, 0);
84 addOperator<comb::ShrSOp>(b, 1);
88 return std::make_unique<AddOperatorLibraryPass>();
static constexpr const char * kKanagawaOperatorLibName
std::unique_ptr< mlir::Pass > createAddOperatorLibraryPass()
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.