CIRCT 23.0.0git
Loading...
Searching...
No Matches
ResourceUsageAnalysis.h
Go to the documentation of this file.
1//===- ResourceUsageAnalysis.h - Resource Usage Analysis --------*- 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 resource usage analysis for the Synth dialect.
10// The analysis computes resource utilization including and-inverter gates,
11// DFF bits, and LUTs across module hierarchies.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef CIRCT_DIALECT_SYNTH_ANALYSIS_RESOURCEUSAGEANALYSIS_H
16#define CIRCT_DIALECT_SYNTH_ANALYSIS_RESOURCEUSAGEANALYSIS_H
17
19#include "circt/Support/LLVM.h"
20#include "llvm/ADT/DenseMap.h"
21#include "llvm/ADT/StringMap.h"
22#include <memory>
23
24namespace mlir {
25class AnalysisManager;
26} // namespace mlir
27
28namespace circt {
29namespace synth {
30
31/// Analysis that computes resource usage for Synth dialect operations.
32/// This analysis walks module hierarchies and counts resources such as:
33/// - And-inverter graph (AIG)
34/// - Majority-inverter graph (MIG)
35/// - Truth tables (LUTs)
36/// - Sequential elements (DFFs)
38public:
39 ResourceUsageAnalysis(mlir::Operation *moduleOp, mlir::AnalysisManager &am);
40
41 /// Resource usage counts for a set of operations.
43 ResourceUsage(llvm::StringMap<uint64_t> counts)
44 : counts(std::move(counts)) {}
45 ResourceUsage() = default;
46
47 /// Accumulate resource counts from another ResourceUsage.
49 for (const auto &count : other.counts)
50 counts[count.getKey()] += count.second;
51 return *this;
52 }
53
54 const auto &getCounts() const { return counts; }
55
56 private:
57 llvm::StringMap<uint64_t> counts;
58 };
59
60 /// Resource usage for a single module, including local and total counts.
66
67 StringAttr moduleName;
68 ResourceUsage local; ///< Resources used directly in this module.
69 ResourceUsage total; ///< Resources including all child instances.
70
71 /// Information about a child module instance.
79
80 SmallVector<InstanceResource> instances;
81 const ResourceUsage &getTotal() const { return total; }
82 const ResourceUsage &getLocal() const { return local; }
83 void emitJSON(raw_ostream &os) const;
84 };
85
86 /// Get resource usage for a module.
87 ModuleResourceUsage *getResourceUsage(igraph::ModuleOpInterface module);
88 ModuleResourceUsage *getResourceUsage(StringAttr moduleName);
89
90 /// Get the instance graph used by this analysis.
92
93private:
94 /// Cache of computed resource usage per module.
95 DenseMap<StringAttr, std::unique_ptr<ModuleResourceUsage>> designUsageCache;
96
97 /// Instance graph for module hierarchy traversal.
99};
100
101} // namespace synth
102} // namespace circt
103
104#endif // CIRCT_DIALECT_SYNTH_ANALYSIS_RESOURCEUSAGEANALYSIS_H
This graph tracks modules and where they are instantiated.
Analysis that computes resource usage for Synth dialect operations.
igraph::InstanceGraph * getInstanceGraph() const
Get the instance graph used by this analysis.
DenseMap< StringAttr, std::unique_ptr< ModuleResourceUsage > > designUsageCache
Cache of computed resource usage per module.
ModuleResourceUsage * getResourceUsage(igraph::ModuleOpInterface module)
Get resource usage for a module.
igraph::InstanceGraph * instanceGraph
Instance graph for module hierarchy traversal.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition synth.py:1
InstanceResource(StringAttr moduleName, StringAttr instanceName, ModuleResourceUsage *usage)
Resource usage for a single module, including local and total counts.
ModuleResourceUsage(StringAttr moduleName, ResourceUsage local, ResourceUsage total)
ResourceUsage total
Resources including all child instances.
ResourceUsage local
Resources used directly in this module.
Resource usage counts for a set of operations.
ResourceUsage & operator+=(const ResourceUsage &other)
Accumulate resource counts from another ResourceUsage.