CIRCT  19.0.0git
IbisAddOperatorLibrary.cpp
Go to the documentation of this file.
1 //===- IbisAddOperatorLibraryPass.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 
17 #include "mlir/Transforms/GreedyPatternRewriteDriver.h"
18 
20 
21 #include <iterator>
22 
23 using namespace mlir;
24 using namespace circt;
25 using namespace ibis;
26 
27 namespace {
28 
29 struct AddOperatorLibraryPass
30  : public IbisAddOperatorLibraryBase<AddOperatorLibraryPass> {
31  void runOnOperation() override;
32 };
33 
34 // TODO @mortbopet: once we have c++20, change this to a templated lambda to
35 // avoid passing the builder around.
36 template <typename TOp>
37 void addOperator(ImplicitLocOpBuilder &b, int latency) {
38  b.create<ssp::OperatorTypeOp>(
39  b.getStringAttr(TOp::getOperationName()),
40  b.getArrayAttr({b.getAttr<ssp::LatencyAttr>(latency)}));
41 }
42 
43 } // anonymous namespace
44 
45 void AddOperatorLibraryPass::runOnOperation() {
46  auto b = ImplicitLocOpBuilder::atBlockBegin(getOperation().getLoc(),
47  getOperation().getBody());
48  auto opLib = b.create<ssp::OperatorLibraryOp>();
49  opLib.setSymNameAttr(b.getStringAttr(kIbisOperatorLibName));
50  b.setInsertionPointToStart(opLib.getBodyBlock());
51 
52  // Provide definitions for some comb ops - just latency properties for now.
53 
54  // Arithmetic operators
55  addOperator<comb::AddOp>(b, 1);
56  addOperator<comb::SubOp>(b, 1);
57  addOperator<comb::MulOp>(b, 2);
58  addOperator<comb::ModSOp>(b, 2);
59  addOperator<comb::ModUOp>(b, 2);
60 
61  // Boolean operators
62  addOperator<comb::AndOp>(b, 0);
63  addOperator<comb::OrOp>(b, 0);
64  addOperator<comb::XorOp>(b, 0);
65 
66  // Comparison
67  addOperator<comb::ICmpOp>(b, 1);
68 
69  // Shift
70  addOperator<comb::ShlOp>(b, 0);
71  addOperator<comb::ShrUOp>(b, 0);
72  addOperator<comb::ShrSOp>(b, 1);
73 }
74 
76  return std::make_unique<AddOperatorLibraryPass>();
77 }
static constexpr const char * kIbisOperatorLibName
Definition: IbisOps.h:36
std::unique_ptr< mlir::Pass > createAddOperatorLibraryPass()
This file defines an intermediate representation for circuits acting as an abstraction for constraint...
Definition: DebugAnalysis.h:21