From 5576d1d176b4f2825771bcd951811fd837b766d6 Mon Sep 17 00:00:00 2001 From: youben11 Date: Mon, 14 Nov 2022 14:46:14 +0100 Subject: [PATCH] feat(CAPI): expose encrypted signed int in CAPI --- compiler/include/concretelang-c/Dialect/FHE.h | 7 +++++ compiler/lib/CAPI/Dialect/FHE/FHE.cpp | 31 +++++++++++++------ 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/compiler/include/concretelang-c/Dialect/FHE.h b/compiler/include/concretelang-c/Dialect/FHE.h index 5d2d79770..d7683b95a 100644 --- a/compiler/include/concretelang-c/Dialect/FHE.h +++ b/compiler/include/concretelang-c/Dialect/FHE.h @@ -29,6 +29,13 @@ fheEncryptedIntegerTypeGetChecked(MlirContext context, unsigned width); /// If the type is an EncryptedInteger MLIR_CAPI_EXPORTED bool fheTypeIsAnEncryptedIntegerType(MlirType); +/// Creates an encrypted signed integer type of `width` bits +MLIR_CAPI_EXPORTED MlirTypeOrError +fheEncryptedSignedIntegerTypeGetChecked(MlirContext context, unsigned width); + +/// If the type is an EncryptedSignedInteger +MLIR_CAPI_EXPORTED bool fheTypeIsAnEncryptedSignedIntegerType(MlirType); + #ifdef __cplusplus } #endif diff --git a/compiler/lib/CAPI/Dialect/FHE/FHE.cpp b/compiler/lib/CAPI/Dialect/FHE/FHE.cpp index 1ffe0fbfe..0c0f97571 100644 --- a/compiler/lib/CAPI/Dialect/FHE/FHE.cpp +++ b/compiler/lib/CAPI/Dialect/FHE/FHE.cpp @@ -24,12 +24,8 @@ MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(FHE, fhe, FHEDialect) // Type API. //===----------------------------------------------------------------------===// -bool fheTypeIsAnEncryptedIntegerType(MlirType type) { - return unwrap(type).isa(); -} - -MlirTypeOrError fheEncryptedIntegerTypeGetChecked(MlirContext ctx, - unsigned width) { +template +MlirTypeOrError IntegerTypeGetChecked(MlirContext ctx, unsigned width) { MlirTypeOrError type = {{NULL}, false}; auto catchError = [&]() -> mlir::InFlightDiagnostic { type.isError = true; @@ -40,11 +36,28 @@ MlirTypeOrError fheEncryptedIntegerTypeGetChecked(MlirContext ctx, return engine.emit(mlir::UnknownLoc::get(unwrap(ctx)), mlir::DiagnosticSeverity::Warning); }; - EncryptedIntegerType eint = - EncryptedIntegerType::getChecked(catchError, unwrap(ctx), width); + T integerType = T::getChecked(catchError, unwrap(ctx), width); if (type.isError) { return type; } - type.type = wrap(eint); + type.type = wrap(integerType); return type; } + +bool fheTypeIsAnEncryptedIntegerType(MlirType type) { + return unwrap(type).isa(); +} + +MlirTypeOrError fheEncryptedIntegerTypeGetChecked(MlirContext ctx, + unsigned width) { + return IntegerTypeGetChecked(ctx, width); +} + +bool fheTypeIsAnEncryptedSignedIntegerType(MlirType type) { + return unwrap(type).isa(); +} + +MlirTypeOrError fheEncryptedSignedIntegerTypeGetChecked(MlirContext ctx, + unsigned width) { + return IntegerTypeGetChecked(ctx, width); +}