1
1
#include " lib/Pipelines/BooleanPipelineRegistration.h"
2
2
3
- #include < functional>
4
3
#include < memory>
5
4
#include < string>
6
5
#include < vector>
@@ -40,11 +39,17 @@ namespace mlir::heir {
40
39
static std::vector<std::string> opsToDistribute = {" secret.separator" };
41
40
static std::vector<unsigned > bitWidths = {1 , 2 , 4 , 8 , 16 };
42
41
43
- void tosaToCGGIPipelineBuilder (OpPassManager &pm,
44
- const TosaToBooleanTfheOptions &options,
45
- const std::string &yosysFilesPath,
46
- const std::string &abcPath,
47
- bool abcBooleanGates) {
42
+ CGGIPipelineBuilder mlirToCGGIPipelineBuilder (const std::string &yosysFilesPath,
43
+ const std::string &abcPath) {
44
+ return [=](OpPassManager &pm, const MLIRToCGGIPipelineOptions &options) {
45
+ mlirToCGGIPipeline (pm, options, yosysFilesPath, abcPath);
46
+ };
47
+ }
48
+
49
+ void mlirToCGGIPipeline (OpPassManager &pm,
50
+ const MLIRToCGGIPipelineOptions &options,
51
+ const std::string &yosysFilesPath,
52
+ const std::string &abcPath) {
48
53
// TOSA to linalg
49
54
::mlir::heir::tosaToLinalg (pm);
50
55
@@ -89,9 +94,9 @@ void tosaToCGGIPipelineBuilder(OpPassManager &pm,
89
94
pm.addPass (createCanonicalizerPass ());
90
95
91
96
// Booleanize and Yosys Optimize
92
- pm.addPass (createYosysOptimizer (
93
- yosysFilesPath, abcPath, options.abcFast , options.unrollFactor ,
94
- /* useSubmodules= */ true , abcBooleanGates ? Mode:: Boolean : Mode::LUT ));
97
+ pm.addPass (createYosysOptimizer (yosysFilesPath, abcPath, options. abcFast ,
98
+ options.unrollFactor , options.useSubmodules ,
99
+ options. mode ));
95
100
96
101
// Cleanup
97
102
pm.addPass (mlir::createCSEPass ());
@@ -115,99 +120,77 @@ void tosaToCGGIPipelineBuilder(OpPassManager &pm,
115
120
pm.addPass (createSCCPPass ());
116
121
}
117
122
118
- void registerTosaToBooleanTfhePipeline (const std::string &yosysFilesPath,
119
- const std::string &abcPath) {
120
- PassPipelineRegistration<TosaToBooleanTfheOptions>(
121
- " tosa-to-boolean-tfhe" , " Arithmetic modules to boolean tfhe-rs pipeline." ,
122
- [yosysFilesPath, abcPath](OpPassManager &pm,
123
- const TosaToBooleanTfheOptions &options) {
124
- tosaToCGGIPipelineBuilder (pm, options, yosysFilesPath, abcPath,
125
- /* abcBooleanGates=*/ false );
126
-
127
- // CGGI to Tfhe-Rust exit dialect
128
- pm.addPass (createCGGIToTfheRust ());
129
- // CSE must be run before canonicalizer, so that redundant ops are
130
- // cleared before the canonicalizer hoists TfheRust ops.
131
- pm.addPass (createCSEPass ());
132
- pm.addPass (createCanonicalizerPass ());
133
-
134
- // Cleanup loads and stores
135
- pm.addPass (createExpandCopyPass (
136
- ExpandCopyPassOptions{.disableAffineLoop = true }));
137
- pm.addPass (memref::createFoldMemRefAliasOpsPass ());
138
- pm.addPass (createForwardStoreToLoad ());
139
- pm.addPass (createCanonicalizerPass ());
140
- pm.addPass (createCSEPass ());
141
- pm.addPass (createSCCPPass ());
142
- });
123
+ CGGIBackendPipelineBuilder toTfheRsPipelineBuilder () {
124
+ return [=](OpPassManager &pm) {
125
+ // CGGI to Tfhe-Rust exit dialect
126
+ pm.addPass (createCGGIToTfheRust ());
127
+ // CSE must be run before canonicalizer, so that redundant ops are
128
+ // cleared before the canonicalizer hoists TfheRust ops.
129
+ pm.addPass (createCSEPass ());
130
+ pm.addPass (createCanonicalizerPass ());
131
+
132
+ // Cleanup loads and stores
133
+ pm.addPass (
134
+ createExpandCopyPass (ExpandCopyPassOptions{.disableAffineLoop = true }));
135
+ pm.addPass (memref::createFoldMemRefAliasOpsPass ());
136
+ pm.addPass (createForwardStoreToLoad ());
137
+ pm.addPass (createCanonicalizerPass ());
138
+ pm.addPass (createCSEPass ());
139
+ pm.addPass (createSCCPPass ());
140
+ };
143
141
}
144
142
145
- void registerTosaToBooleanFpgaTfhePipeline (const std::string &yosysFilesPath,
146
- const std::string &abcPath) {
147
- PassPipelineRegistration<TosaToBooleanTfheOptions>(
148
- " tosa-to-boolean-fpga-tfhe" ,
149
- " Arithmetic modules to boolean tfhe-rs for FPGA backend pipeline." ,
150
- [yosysFilesPath, abcPath](OpPassManager &pm,
151
- const TosaToBooleanTfheOptions &options) {
152
- tosaToCGGIPipelineBuilder (pm, options, yosysFilesPath, abcPath,
153
- /* abcBooleanGates=*/ true );
154
-
155
- // Vectorize CGGI operations
156
- pm.addPass (cggi::createBooleanVectorizer ());
157
- pm.addPass (createCanonicalizerPass ());
158
- pm.addPass (createCSEPass ());
159
- pm.addPass (createSCCPPass ());
160
-
161
- // CGGI to Tfhe-Rust exit dialect
162
- pm.addPass (createCGGIToTfheRustBool ());
163
- // CSE must be run before canonicalizer, so that redundant ops are
164
- // cleared before the canonicalizer hoists TfheRust ops.
165
- pm.addPass (createCSEPass ());
166
- pm.addPass (createCanonicalizerPass ());
167
-
168
- // Cleanup loads and stores
169
- pm.addPass (createExpandCopyPass (
170
- ExpandCopyPassOptions{.disableAffineLoop = true }));
171
- pm.addPass (memref::createFoldMemRefAliasOpsPass ());
172
- pm.addPass (createForwardStoreToLoad ());
173
- pm.addPass (createCanonicalizerPass ());
174
- pm.addPass (createCSEPass ());
175
- pm.addPass (createSCCPPass ());
176
- });
143
+ CGGIBackendPipelineBuilder toFptPipelineBuilder () {
144
+ return [=](OpPassManager &pm) {
145
+ // Vectorize CGGI operations
146
+ pm.addPass (cggi::createBooleanVectorizer ());
147
+ pm.addPass (createCanonicalizerPass ());
148
+ pm.addPass (createCSEPass ());
149
+ pm.addPass (createSCCPPass ());
150
+
151
+ // CGGI to Tfhe-Rust exit dialect
152
+ pm.addPass (createCGGIToTfheRustBool ());
153
+ // CSE must be run before canonicalizer, so that redundant ops are
154
+ // cleared before the canonicalizer hoists TfheRust ops.
155
+ pm.addPass (createCSEPass ());
156
+ pm.addPass (createCanonicalizerPass ());
157
+
158
+ // Cleanup loads and stores
159
+ pm.addPass (
160
+ createExpandCopyPass (ExpandCopyPassOptions{.disableAffineLoop = true }));
161
+ pm.addPass (memref::createFoldMemRefAliasOpsPass ());
162
+ pm.addPass (createForwardStoreToLoad ());
163
+ pm.addPass (createCanonicalizerPass ());
164
+ pm.addPass (createCSEPass ());
165
+ pm.addPass (createSCCPPass ());
166
+ };
177
167
}
178
168
179
- void registerTosaToJaxitePipeline (const std::string &yosysFilesPath,
180
- const std::string &abcPath) {
181
- PassPipelineRegistration<TosaToBooleanJaxiteOptions>(
182
- " tosa-to-boolean-jaxite" , " Arithmetic modules to jaxite pipeline." ,
183
- [yosysFilesPath, abcPath](OpPassManager &pm,
184
- const TosaToBooleanJaxiteOptions &options) {
185
- tosaToCGGIPipelineBuilder (pm, options, yosysFilesPath, abcPath,
186
- /* abcBooleanGates=*/ false );
187
- if (options.parallelism > 0 ) {
188
- pm.addPass (
189
- cggi::createBooleanVectorizer (cggi::BooleanVectorizerOptions{
190
- .parallelism = options.parallelism }));
191
- pm.addPass (createCSEPass ());
192
- pm.addPass (createRemoveDeadValuesPass ());
193
- }
194
-
195
- // CGGI to Jaxite exit dialect
196
- pm.addPass (createCGGIToJaxite ());
197
- // CSE must be run before canonicalizer, so that redundant ops are
198
- // cleared before the canonicalizer hoists TfheRust ops.
199
- pm.addPass (createCSEPass ());
200
- pm.addPass (createCanonicalizerPass ());
201
-
202
- // Cleanup loads and stores
203
- pm.addPass (createExpandCopyPass (
204
- ExpandCopyPassOptions{.disableAffineLoop = true }));
205
- pm.addPass (memref::createFoldMemRefAliasOpsPass ());
206
- pm.addPass (createForwardStoreToLoad ());
207
- pm.addPass (createCanonicalizerPass ());
208
- pm.addPass (createCSEPass ());
209
- pm.addPass (createSCCPPass ());
210
- });
169
+ JaxiteBackendPipelineBuilder toJaxitePipelineBuilder () {
170
+ return [=](OpPassManager &pm, const CGGIBackendOptions &options) {
171
+ if (options.parallelism > 0 ) {
172
+ pm.addPass (cggi::createBooleanVectorizer (
173
+ cggi::BooleanVectorizerOptions{.parallelism = options.parallelism }));
174
+ pm.addPass (createCSEPass ());
175
+ pm.addPass (createRemoveDeadValuesPass ());
176
+ }
177
+
178
+ // CGGI to Jaxite exit dialect
179
+ pm.addPass (createCGGIToJaxite ());
180
+ // CSE must be run before canonicalizer, so that redundant ops are
181
+ // cleared before the canonicalizer hoists TfheRust ops.
182
+ pm.addPass (createCSEPass ());
183
+ pm.addPass (createCanonicalizerPass ());
184
+
185
+ // Cleanup loads and stores
186
+ pm.addPass (
187
+ createExpandCopyPass (ExpandCopyPassOptions{.disableAffineLoop = true }));
188
+ pm.addPass (memref::createFoldMemRefAliasOpsPass ());
189
+ pm.addPass (createForwardStoreToLoad ());
190
+ pm.addPass (createCanonicalizerPass ());
191
+ pm.addPass (createCSEPass ());
192
+ pm.addPass (createSCCPPass ());
193
+ };
211
194
}
212
195
213
196
} // namespace mlir::heir
0 commit comments