You could generate all that using our tools:
- use
show_mlir=True
in concrete-python during compilation.
- use the
concretecompiler
binary to output the IR using the representation of your choice (e.g. concretecompiler --action=dump-llvm-ir ...
)
Mul
MLIR in FHE dialect:
module {
func.func @mul(%arg0: !FHE.eint<6>, %arg1: i4) -> !FHE.eint<6> {
%0 = "FHE.mul_eint_int"(%arg0, %arg1) : (!FHE.eint<6>, i4) -> !FHE.eint<6>
return %0 : !FHE.eint<6>
}
}
MLIR in TFHE dialect:
module {
func.func @mul(%arg0: !TFHE.glwe<sk?> {TFHE.OId = 0 : i32}, %arg1: i4) -> !TFHE.glwe<sk?> {
%0 = arith.extsi %arg1 : i4 to i64
%1 = "TFHE.mul_glwe_int"(%arg0, %0) {TFHE.OId = 1 : i32} : (!TFHE.glwe<sk?>, i64) -> !TFHE.glwe<sk?>
return %1 : !TFHE.glwe<sk?>
}
}
MLIR in LLVM-IR:
; ModuleID = '-'
source_filename = "-"
declare ptr @malloc(i64)
declare void @free(ptr)
declare ptr @concrete_checked_malloc(i64)
declare void @memref_mul_cleartext_lwe_ciphertext_u64(ptr, ptr, i64, i64, i64, ptr, ptr, i64, i64, i64, i64)
declare void @_dfr_stop(i64)
declare void @_dfr_start(i64, ptr)
define { ptr, ptr, i64, [1 x i64], [1 x i64] } @mul(ptr %0, ptr %1, i64 %2, i64 %3, i64 %4, i4 %5, ptr %6) {
%8 = insertvalue { ptr, ptr, i64, [1 x i64], [1 x i64] } undef, ptr %0, 0
%9 = insertvalue { ptr, ptr, i64, [1 x i64], [1 x i64] } %8, ptr %1, 1
%10 = insertvalue { ptr, ptr, i64, [1 x i64], [1 x i64] } %9, i64 %2, 2
%11 = insertvalue { ptr, ptr, i64, [1 x i64], [1 x i64] } %10, i64 %3, 3, 0
%12 = insertvalue { ptr, ptr, i64, [1 x i64], [1 x i64] } %11, i64 %4, 4, 0
call void @_dfr_start(i64 1, ptr %6)
%13 = sext i4 %5 to i64
%14 = call ptr @concrete_checked_malloc(i64 add (i64 ptrtoint (ptr getelementptr (i64, ptr null, i32 610) to i64), i64 64))
%15 = ptrtoint ptr %14 to i64
%16 = add i64 %15, 63
%17 = urem i64 %16, 64
%18 = sub i64 %16, %17
%19 = inttoptr i64 %18 to ptr
%20 = insertvalue { ptr, ptr, i64, [1 x i64], [1 x i64] } undef, ptr %14, 0
%21 = insertvalue { ptr, ptr, i64, [1 x i64], [1 x i64] } %20, ptr %19, 1
%22 = insertvalue { ptr, ptr, i64, [1 x i64], [1 x i64] } %21, i64 0, 2
%23 = insertvalue { ptr, ptr, i64, [1 x i64], [1 x i64] } %22, i64 610, 3, 0
%24 = insertvalue { ptr, ptr, i64, [1 x i64], [1 x i64] } %23, i64 1, 4, 0
call void @memref_mul_cleartext_lwe_ciphertext_u64(ptr %14, ptr %19, i64 0, i64 610, i64 1, ptr %0, ptr %1, i64 %2, i64 %3, i64 %4, i64 %13)
call void @_dfr_stop(i64 1)
ret { ptr, ptr, i64, [1 x i64], [1 x i64] } %24
}
Add
MLIR in FHE dialect:
module {
func.func @add(%arg0: !FHE.eint<4>, %arg1: !FHE.eint<4>) -> !FHE.eint<4> {
%0 = "FHE.add_eint"(%arg0, %arg1) : (!FHE.eint<4>, !FHE.eint<4>) -> !FHE.eint<4>
return %0 : !FHE.eint<4>
}
}
MLIR in TFHE dialect:
module {
func.func @add(%arg0: !TFHE.glwe<sk?> {TFHE.OId = 0 : i32}, %arg1: !TFHE.glwe<sk?> {TFHE.OId = 1 : i32}) -> !TFHE.glwe<sk?> {
%0 = "TFHE.add_glwe"(%arg0, %arg1) {TFHE.OId = 2 : i32} : (!TFHE.glwe<sk?>, !TFHE.glwe<sk?>) -> !TFHE.glwe<sk?>
return %0 : !TFHE.glwe<sk?>
}
}
MLIR in LLVM-IR:
; ModuleID = '-'
source_filename = "-"
declare ptr @malloc(i64)
declare void @free(ptr)
declare ptr @concrete_checked_malloc(i64)
declare void @memref_add_lwe_ciphertexts_u64(ptr, ptr, i64, i64, i64, ptr, ptr, i64, i64, i64, ptr, ptr, i64, i64, i64)
declare void @_dfr_stop(i64)
declare void @_dfr_start(i64, ptr)
define { ptr, ptr, i64, [1 x i64], [1 x i64] } @add(ptr %0, ptr %1, i64 %2, i64 %3, i64 %4, ptr %5, ptr %6, i64 %7, i64 %8, i64 %9, ptr %10) {
%12 = insertvalue { ptr, ptr, i64, [1 x i64], [1 x i64] } undef, ptr %0, 0
%13 = insertvalue { ptr, ptr, i64, [1 x i64], [1 x i64] } %12, ptr %1, 1
%14 = insertvalue { ptr, ptr, i64, [1 x i64], [1 x i64] } %13, i64 %2, 2
%15 = insertvalue { ptr, ptr, i64, [1 x i64], [1 x i64] } %14, i64 %3, 3, 0
%16 = insertvalue { ptr, ptr, i64, [1 x i64], [1 x i64] } %15, i64 %4, 4, 0
%17 = insertvalue { ptr, ptr, i64, [1 x i64], [1 x i64] } undef, ptr %5, 0
%18 = insertvalue { ptr, ptr, i64, [1 x i64], [1 x i64] } %17, ptr %6, 1
%19 = insertvalue { ptr, ptr, i64, [1 x i64], [1 x i64] } %18, i64 %7, 2
%20 = insertvalue { ptr, ptr, i64, [1 x i64], [1 x i64] } %19, i64 %8, 3, 0
%21 = insertvalue { ptr, ptr, i64, [1 x i64], [1 x i64] } %20, i64 %9, 4, 0
call void @_dfr_start(i64 1, ptr %10)
%22 = call ptr @concrete_checked_malloc(i64 add (i64 ptrtoint (ptr getelementptr (i64, ptr null, i32 513) to i64), i64 64))
%23 = ptrtoint ptr %22 to i64
%24 = add i64 %23, 63
%25 = urem i64 %24, 64
%26 = sub i64 %24, %25
%27 = inttoptr i64 %26 to ptr
%28 = insertvalue { ptr, ptr, i64, [1 x i64], [1 x i64] } undef, ptr %22, 0
%29 = insertvalue { ptr, ptr, i64, [1 x i64], [1 x i64] } %28, ptr %27, 1
%30 = insertvalue { ptr, ptr, i64, [1 x i64], [1 x i64] } %29, i64 0, 2
%31 = insertvalue { ptr, ptr, i64, [1 x i64], [1 x i64] } %30, i64 513, 3, 0
%32 = insertvalue { ptr, ptr, i64, [1 x i64], [1 x i64] } %31, i64 1, 4, 0
call void @memref_add_lwe_ciphertexts_u64(ptr %22, ptr %27, i64 0, i64 513, i64 1, ptr %0, ptr %1, i64 %2, i64 %3, i64 %4, ptr %5, ptr %6, i64 %7, i64 %8, i64 %9)
call void @_dfr_stop(i64 1)
ret { ptr, ptr, i64, [1 x i64], [1 x i64] } %32
}