CIRCT 23.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,
46 prefix) ^
47 llvm::hash_combine_range(writeClockIDs.begin(), writeClockIDs.end());
48 }
49
56
57 bool operator==(const FirMemConfig &other) const {
58 return getTuple() == other.getTuple();
59 }
60};
61
62/**
63 * FIR memory lowering helper.
64 */
66public:
67 /// A vector of unique `FirMemConfig`s and all the `FirMemOp`s that use it.
70
71 /// Information required to lower a single memory in a module.
73 std::tuple<FirMemConfig *, hw::HWModuleGeneratedOp, seq::FirMemOp>;
74
75 FirMemLowering(ModuleOp circuit);
76
77 /**
78 * Groups memories by their kind from the whole design.
79 */
80 UniqueConfigs collectMemories(ArrayRef<hw::HWModuleOp> modules);
81
82 /**
83 * Lowers a group of memories from the same module.
84 */
86 ArrayRef<MemoryConfig> mems);
87
88 /**
89 * Creates the generated module for a given configuration.
90 */
91 hw::HWModuleGeneratedOp createMemoryModule(FirMemConfig &mem,
92 ArrayRef<seq::FirMemOp> memOps);
93
94private:
95 FirMemConfig collectMemory(seq::FirMemOp op);
96
97 /**
98 * Find the schema or create it if it does not exist.
99 */
100 FlatSymbolRefAttr getOrCreateSchema();
101
102private:
103 MLIRContext *context;
104 ModuleOp circuit;
105
108
109 DenseMap<hw::HWModuleOp, size_t> moduleIndex;
110
111 hw::HWGeneratorSchemaOp schemaOp;
112};
113
114} // namespace circt
115
116namespace llvm {
117template <>
118struct DenseMapInfo<circt::FirMemConfig> {
119 static unsigned getHashValue(const circt::FirMemConfig &cfg) {
120 return cfg.hashValue();
121 }
122 static bool isEqual(const circt::FirMemConfig &lhs,
123 const circt::FirMemConfig &rhs) {
124 return lhs == rhs;
125 }
126};
127} // namespace llvm
128
129#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.
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 unsigned getHashValue(const circt::FirMemConfig &cfg)