CIRCT  20.0.0git
OpCountAnalysis.cpp
Go to the documentation of this file.
1 //===- OpCountAnalysis.cpp - operation count analyses -----------*- C++ -*-===//
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 file defines the op count analysis. This is an analysis that
10 // provides information about the frequency of different kinds of operations
11 // found in a builtin.module.
12 //
13 //===----------------------------------------------------------------------===//
14 
16 #include "mlir/IR/Operation.h"
17 
18 using namespace circt;
19 using namespace analysis;
20 
22  mlir::AnalysisManager &am) {
23  moduleOp->walk([&](Operation *op) {
24  auto opName = op->getName();
25  // Update opCounts
26  opCounts[opName]++;
27 
28  // Update operandCounts
29  operandCounts[opName][op->getNumOperands()]++;
30  });
31 }
32 
33 SmallVector<OperationName> OpCountAnalysis::getFoundOpNames() {
34  SmallVector<OperationName> opNames;
35  for (auto pair : opCounts)
36  opNames.push_back(pair.first);
37  return opNames;
38 }
39 
40 size_t OpCountAnalysis::getOpCount(OperationName opName) {
41  return opCounts[opName];
42 }
43 
44 DenseMap<size_t, size_t>
45 OpCountAnalysis::getOperandCountMap(OperationName opName) {
46  return operandCounts[opName];
47 }
size_t getOpCount(OperationName opName)
Get the frequency of operations of a specific name.
DenseMap< size_t, size_t > getOperandCountMap(OperationName opName)
Get a map from number of operands to corresponding frequency for the given operation.
DenseMap< OperationName, DenseMap< size_t, size_t > > operandCounts
DenseMap< OperationName, size_t > opCounts
SmallVector< OperationName > getFoundOpNames()
Get the names of all distinct operations found by the analysis.
OpCountAnalysis(Operation *moduleOp, mlir::AnalysisManager &am)
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition: DebugAnalysis.h:21