Skip to content

Commit c1458bc

Browse files
committedJan 28, 2025
Merge pull request #1324 from ZenithalHourlyRate:follow-1306
PiperOrigin-RevId: 720545594
2 parents 49b537a + da3b6f1 commit c1458bc

File tree

2 files changed

+10
-19
lines changed

2 files changed

+10
-19
lines changed
 

‎lib/Dialect/LWE/Conversions/LWEToOpenfhe/LWEToOpenfhe.cpp

+7-16
Original file line numberDiff line numberDiff line change
@@ -92,23 +92,14 @@ struct AddCryptoContextArg : public OpConversionPattern<func::FuncOp> {
9292
}
9393

9494
auto cryptoContextType = openfhe::CryptoContextType::get(getContext());
95-
FunctionType originalType = op.getFunctionType();
96-
llvm::SmallVector<Type, 4> newTypes;
97-
newTypes.reserve(originalType.getNumInputs() + 1);
98-
newTypes.push_back(cryptoContextType);
99-
for (auto t : originalType.getInputs()) {
100-
newTypes.push_back(t);
101-
}
102-
auto newFuncType =
103-
FunctionType::get(getContext(), newTypes, originalType.getResults());
10495
rewriter.modifyOpInPlace(op, [&] {
105-
op.setType(newFuncType);
106-
107-
// guard against private FuncOp (i.e. declaration)
108-
if (op.getVisibility() != SymbolTable::Visibility::Private) {
109-
Block &block = op.getBody().getBlocks().front();
110-
block.insertArgument(&block.getArguments().front(), cryptoContextType,
111-
op.getLoc());
96+
if (op.isDeclaration()) {
97+
auto newFuncType = op.getTypeWithArgsAndResults(
98+
ArrayRef<unsigned int>{0}, ArrayRef<Type>{cryptoContextType}, {},
99+
{});
100+
op.setType(newFuncType);
101+
} else {
102+
op.insertArgument(0, cryptoContextType, nullptr, op.getLoc());
112103
}
113104
});
114105

‎lib/Target/OpenFhePke/OpenFhePkeEmitter.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ LogicalResult OpenFhePkeEmitter::printOperation(func::FuncOp funcOp) {
171171
}
172172
}
173173

174-
if (funcOp.getVisibility() == SymbolTable::Visibility::Private) {
174+
if (funcOp.isDeclaration()) {
175175
// function declaration
176176
os << commaSeparatedTypes(funcOp.getArgumentTypes(), [&](Type type) {
177177
return convertType(type, funcOp->getLoc()).value();
@@ -186,7 +186,7 @@ LogicalResult OpenFhePkeEmitter::printOperation(func::FuncOp funcOp) {
186186
os << ")";
187187

188188
// function declaration
189-
if (funcOp.getVisibility() == SymbolTable::Visibility::Private) {
189+
if (funcOp.isDeclaration()) {
190190
os << ";\n";
191191
return success();
192192
}
@@ -213,7 +213,7 @@ LogicalResult OpenFhePkeEmitter::printOperation(func::CallOp op) {
213213
}
214214

215215
if (op.getNumResults() != 0) {
216-
os << variableNames->getNameForValue(op.getResult(0)) << " = ";
216+
emitAutoAssignPrefix(op.getResult(0));
217217
}
218218

219219
os << canonicalizeDebugPort(op.getCallee()) << "(";

0 commit comments

Comments
 (0)