diff --git a/compiler/include/concretelang-c/Dialect/FHE.h b/compiler/include/concretelang-c/Dialect/FHE.h index d7683b95a..e56e21a8c 100644 --- a/compiler/include/concretelang-c/Dialect/FHE.h +++ b/compiler/include/concretelang-c/Dialect/FHE.h @@ -36,6 +36,12 @@ fheEncryptedSignedIntegerTypeGetChecked(MlirContext context, unsigned width); /// If the type is an EncryptedSignedInteger MLIR_CAPI_EXPORTED bool fheTypeIsAnEncryptedSignedIntegerType(MlirType); +/// \brief Get bitwidth of the encrypted integer type. +/// +/// \return bitwidth of the encrypted integer or 0 if it's not an encrypted +/// integer +MLIR_CAPI_EXPORTED unsigned fheTypeIntegerWidthGet(MlirType); + #ifdef __cplusplus } #endif diff --git a/compiler/lib/CAPI/Dialect/FHE/FHE.cpp b/compiler/lib/CAPI/Dialect/FHE/FHE.cpp index 0c0f97571..d06a45b76 100644 --- a/compiler/lib/CAPI/Dialect/FHE/FHE.cpp +++ b/compiler/lib/CAPI/Dialect/FHE/FHE.cpp @@ -61,3 +61,16 @@ MlirTypeOrError fheEncryptedSignedIntegerTypeGetChecked(MlirContext ctx, unsigned width) { return IntegerTypeGetChecked(ctx, width); } + +unsigned fheTypeIntegerWidthGet(MlirType integerType) { + mlir::Type type = unwrap(integerType); + auto eint = type.dyn_cast_or_null(); + if (eint) { + return eint.getWidth(); + } + auto esint = type.dyn_cast_or_null(); + if (esint) { + return esint.getWidth(); + } + return 0; +}