CIRCT 24.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/// - Truth tables (LUTs)
35/// - Sequential elements (DFFs)
37public:
38 ResourceUsageAnalysis(mlir::Operation *moduleOp, mlir::AnalysisManager &am);
39
40 /// Resource usage counts for a set of operations.
42 ResourceUsage(llvm::StringMap<uint64_t> counts)
43 : counts(std::move(counts)) {}
44 ResourceUsage() = default;
45
46 /// Accumulate resource counts from another ResourceUsage.
48 for (const auto &count : other.counts)
49 counts[count.getKey()] += count.second;
50 return *this;
51 }
52
53 const auto &getCounts() const { return counts; }
54
55 private:
56 llvm::StringMap<uint64_t> counts;
57 };
58
59 /// Resource usage for a single module, including local and total counts.
65
66 StringAttr moduleName;
67 ResourceUsage local; ///< Resources used directly in this module.
68 ResourceUsage total; ///< Resources including all child instances.
69
70 /// Information about a child module instance.
78
79 SmallVector<InstanceResource> instances;
80 const ResourceUsage &getTotal() const { return total; }
81 const ResourceUsage &getLocal() const { return local; }
82 void emitJSON(raw_ostream &os) const;
83 };
84
85 /// Get resource usage for a module.
86 ModuleResourceUsage *getResourceUsage(igraph::ModuleOpInterface module);
87 ModuleResourceUsage *getResourceUsage(StringAttr moduleName);
88
89 /// Get the instance graph used by this analysis.
91
92private:
93 /// Cache of computed resource usage per module.
94 DenseMap<StringAttr, std::unique_ptr<ModuleResourceUsage>> designUsageCache;
95
96 /// Instance graph for module hierarchy traversal.
98};
99
100} // namespace synth
101} // namespace circt
102
103#endif // CIRCT_DIALECT_SYNTH_ANALYSIS_RESOURCEUSAGEANALYSIS_H
This graph tracks modules and where they are instantiated.
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.
ResourceUsageAnalysis(mlir::Operation *moduleOp, mlir::AnalysisManager &am)
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.
InstanceResource(StringAttr moduleName, StringAttr instanceName, ModuleResourceUsage *usage)
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.