@@ -132,8 +132,12 @@ LogicalResult OpenFhePkeEmitter::printOperation(ModuleOp moduleOp) {
132
132
return success ();
133
133
}
134
134
135
+ bool OpenFhePkeEmitter::isDebugPort (StringRef debugPortName) {
136
+ return debugPortName.rfind (" __heir_debug" ) == 0 ;
137
+ }
138
+
135
139
StringRef OpenFhePkeEmitter::canonicalizeDebugPort (StringRef debugPortName) {
136
- if (debugPortName. rfind ( " __heir_debug " ) == 0 ) {
140
+ if (isDebugPort (debugPortName) ) {
137
141
return " __heir_debug" ;
138
142
}
139
143
return debugPortName;
@@ -177,6 +181,10 @@ LogicalResult OpenFhePkeEmitter::printOperation(func::FuncOp funcOp) {
177
181
os << commaSeparatedTypes (funcOp.getArgumentTypes (), [&](Type type) {
178
182
return convertType (type, funcOp->getLoc ()).value ();
179
183
});
184
+ // debug attribute map for debug call
185
+ if (isDebugPort (funcOp.getName ())) {
186
+ os << " , const std::map<std::string, std::string>&" ;
187
+ }
180
188
} else {
181
189
os << commaSeparatedValues (funcOp.getArguments (), [&](Value value) {
182
190
return convertType (value.getType (), funcOp->getLoc ()).value () + " " +
@@ -213,6 +221,29 @@ LogicalResult OpenFhePkeEmitter::printOperation(func::CallOp op) {
213
221
return emitError (op.getLoc (), " Only one return value supported" );
214
222
}
215
223
224
+ // build debug attribute map for debug call
225
+ auto debugAttrMapName = getDebugAttrMapName ();
226
+ if (isDebugPort (op.getCallee ())) {
227
+ os << " std::map<std::string, std::string> " << debugAttrMapName << " ;\n " ;
228
+ for (auto attr : op->getAttrs ()) {
229
+ // callee is also an attribute internally, skip it
230
+ if (attr.getName ().getValue () == " callee" ) {
231
+ continue ;
232
+ }
233
+ os << debugAttrMapName << " [\" " << attr.getName ().getValue ()
234
+ << " \" ] = \" " ;
235
+ // Use AsmPrinter to print Attribute
236
+ if (mlir::isa<StringAttr>(attr.getValue ())) {
237
+ os << mlir::cast<StringAttr>(attr.getValue ()).getValue () << " \"\n " ;
238
+ } else {
239
+ os << attr.getValue () << " \" ;\n " ;
240
+ }
241
+ }
242
+ // Use AsmPrinter to print Value to print the defining op
243
+ auto ciphertext = op->getOperand (op->getNumOperands () - 1 );
244
+ os << debugAttrMapName << R"( ["op"] = ")" << ciphertext << " \" ;\n " ;
245
+ }
246
+
216
247
if (op.getNumResults () != 0 ) {
217
248
emitAutoAssignPrefix (op.getResult (0 ));
218
249
}
@@ -221,6 +252,10 @@ LogicalResult OpenFhePkeEmitter::printOperation(func::CallOp op) {
221
252
os << commaSeparatedValues (op.getOperands (), [&](Value value) {
222
253
return variableNames->getNameForValue (value);
223
254
});
255
+ // pass debug attribute map
256
+ if (isDebugPort (op.getCallee ())) {
257
+ os << " , " << debugAttrMapName;
258
+ }
224
259
os << " );\n " ;
225
260
return success ();
226
261
}
0 commit comments