CIRCT 21.0.0git
Loading...
Searching...
No Matches
FirMemLowering.h
Go to the documentation of this file.
1//===- FirMemLowering.h - FirMem lowering utilities ===========--*- 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// NOLINTNEXTLINE(llvm-header-guard)
10#ifndef CONVERSION_SEQTOSV_FIRMEMLOWERING_H
11#define CONVERSION_SEQTOSV_FIRMEMLOWERING_H
12
15#include "circt/Support/LLVM.h"
18#include "llvm/ADT/MapVector.h"
19
20namespace circt {
21
22/// The configuration of a FIR memory.
24 size_t numReadPorts = 0;
25 size_t numWritePorts = 0;
27 size_t dataWidth = 0;
28 size_t depth = 0;
29 size_t readLatency = 0;
30 size_t writeLatency = 0;
31 size_t maskBits = 0;
32 seq::RUW readUnderWrite = seq::RUW::Undefined;
33 seq::WUW writeUnderWrite = seq::WUW::Undefined;
34 SmallVector<int32_t, 1> writeClockIDs;
35 StringRef initFilename;
36 bool initIsBinary = false;
37 bool initIsInline = false;
38 Attribute outputFile;
39 StringRef prefix;
40
41 llvm::hash_code hashValue() const {
42 return llvm::hash_combine(numReadPorts, numWritePorts, numReadWritePorts,
47 llvm::hash_combine_range(writeClockIDs.begin(), writeClockIDs.end());
48 }
49
57
58 bool operator==(const FirMemConfig &other) const {
59 return getTuple() == other.getTuple();
60 }
61};
62
63/**
64 * FIR memory lowering helper.
65 */
67public:
68 /// A vector of unique `FirMemConfig`s and all the `FirMemOp`s that use it.
70 llvm::MapVector<FirMemConfig, SmallVector<seq::FirMemOp, 1>>;
71
72 /// Information required to lower a single memory in a module.
74 std::tuple<FirMemConfig *, hw::HWModuleGeneratedOp, seq::FirMemOp>;
75
76 FirMemLowering(ModuleOp circuit);
77
78 /**
79 * Groups memories by their kind from the whole design.
80 */
81 UniqueConfigs collectMemories(ArrayRef<hw::HWModuleOp> modules);
82
83 /**
84 * Lowers a group of memories from the same module.
85 */
87 ArrayRef<MemoryConfig> mems);
88
89 /**
90 * Creates the generated module for a given configuration.
91 */
92 hw::HWModuleGeneratedOp createMemoryModule(FirMemConfig &mem,
93 ArrayRef<seq::FirMemOp> memOps);
94
95private:
96 FirMemConfig collectMemory(seq::FirMemOp op);
97
98 /**
99 * Find the schema or create it if it does not exist.
100 */
101 FlatSymbolRefAttr getOrCreateSchema();
102
103private:
104 MLIRContext *context;
105 ModuleOp circuit;
106
109
110 DenseMap<hw::HWModuleOp, size_t> moduleIndex;
111
112 hw::HWGeneratorSchemaOp schemaOp;
113};
114
115} // namespace circt
116
117namespace llvm {
118template <>
119struct DenseMapInfo<circt::FirMemConfig> {
123 return cfg;
124 }
128 return cfg;
129 }
130 static unsigned getHashValue(const circt::FirMemConfig &cfg) {
131 return cfg.hashValue();
132 }
133 static bool isEqual(const circt::FirMemConfig &lhs,
134 const circt::FirMemConfig &rhs) {
135 return lhs == rhs;
136 }
137};
138} // namespace llvm
139
140#endif // CONVERSION_SEQTOSV_FIRMEMLOWERING_H
FIR memory lowering helper.
UniqueConfigs collectMemories(ArrayRef< hw::HWModuleOp > modules)
Groups memories by their kind from the whole design.
void lowerMemoriesInModule(hw::HWModuleOp module, ArrayRef< MemoryConfig > mems)
Lowers a group of memories from the same module.
hw::HWGeneratorSchemaOp schemaOp
hw::HWModuleGeneratedOp createMemoryModule(FirMemConfig &mem, ArrayRef< seq::FirMemOp > memOps)
Creates the generated module for a given configuration.
FlatSymbolRefAttr getOrCreateSchema()
Find the schema or create it if it does not exist.
DenseMap< hw::HWModuleOp, size_t > moduleIndex
std::tuple< FirMemConfig *, hw::HWModuleGeneratedOp, seq::FirMemOp > MemoryConfig
Information required to lower a single memory in a module.
llvm::MapVector< FirMemConfig, SmallVector< seq::FirMemOp, 1 > > UniqueConfigs
A vector of unique FirMemConfigs and all the FirMemOps that use it.
FirMemConfig collectMemory(seq::FirMemOp op)
Determine the exact parametrization of the memory that should be generated for a given FirMemOp.
A namespace that is used to store existing names and generate new names in some scope within the IR.
Definition Namespace.h:30
Default symbol cache implementation; stores associations between names (StringAttr's) to mlir::Operat...
Definition SymCache.h:85
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
The configuration of a FIR memory.
llvm::hash_code hashValue() const
bool operator==(const FirMemConfig &other) const
SmallVector< int32_t, 1 > writeClockIDs
auto getTuple() const
static bool isEqual(const circt::FirMemConfig &lhs, const circt::FirMemConfig &rhs)
static circt::FirMemConfig getTombstoneKey()
static circt::FirMemConfig getEmptyKey()
static unsigned getHashValue(const circt::FirMemConfig &cfg)