CIRCT  20.0.0git
PrintCostModel.cpp
Go to the documentation of this file.
1 //===- DummyAnalysisTester.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 // This is a dummy pass to test the cost model results it doesn't do any thing.
10 // just walks over the ops to compute some statistics.
11 //
12 //===----------------------------------------------------------------------===//
13 
16 #include "circt/Dialect/HW/HWOps.h"
17 #include "mlir/IR/MLIRContext.h"
18 #include "mlir/Pass/Pass.h"
19 
20 #define DEBUG_TYPE "arc-print-cost-model"
21 
22 namespace circt {
23 namespace arc {
24 #define GEN_PASS_DEF_PRINTCOSTMODEL
25 #include "circt/Dialect/Arc/ArcPasses.h.inc"
26 } // namespace arc
27 } // namespace circt
28 
29 using namespace circt;
30 using namespace arc;
31 
32 namespace {
33 struct PrintCostModelPass
34  : public arc::impl::PrintCostModelBase<PrintCostModelPass> {
35  void runOnOperation() override;
36 };
37 } // namespace
38 
39 void PrintCostModelPass::runOnOperation() {
40  OperationCosts statVars;
41  ArcCostModel arcCostModel;
42  for (auto moduleOp : getOperation().getOps<hw::HWModuleOp>()) {
43  moduleOp.walk([&](Operation *op) { statVars += arcCostModel.getCost(op); });
44  }
45 
46  moduleCost = statVars.totalCost();
47  packingCost = statVars.packingCost;
48  shufflingCost = statVars.shufflingCost;
49  vectoroizeOpsBodyCost = statVars.vectorizeOpsBodyCost;
50  allVectorizeOpsCost = statVars.packingCost + statVars.shufflingCost +
51  statVars.vectorizeOpsBodyCost;
52 }
53 
54 std::unique_ptr<Pass> arc::createPrintCostModelPass() {
55  return std::make_unique<PrintCostModelPass>();
56 }
OperationCosts getCost(Operation *op)
std::unique_ptr< mlir::Pass > createPrintCostModelPass()
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition: DebugAnalysis.h:21
size_t totalCost() const
Definition: ArcCostModel.h:26