From cb580f16d2d5b189869fff9a1df4747eda67cda7 Mon Sep 17 00:00:00 2001 From: Andi Drebes Date: Fri, 30 Jul 2021 14:47:50 +0200 Subject: [PATCH] feat(compiler): Add operation HLFHE.zero generating an encrypted zero --- compiler/include/zamalang/Dialect/HLFHE/IR/HLFHEOps.td | 6 ++++++ compiler/tests/Dialect/HLFHE/ops.mlir | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/compiler/include/zamalang/Dialect/HLFHE/IR/HLFHEOps.td b/compiler/include/zamalang/Dialect/HLFHE/IR/HLFHEOps.td index ccd8de077..4d6882772 100644 --- a/compiler/include/zamalang/Dialect/HLFHE/IR/HLFHEOps.td +++ b/compiler/include/zamalang/Dialect/HLFHE/IR/HLFHEOps.td @@ -18,6 +18,12 @@ include "zamalang/Dialect/HLFHE/IR/HLFHETypes.td" class HLFHE_Op traits = []> : Op; +// Generates an encrypted zero constant +def ZeroOp : HLFHE_Op<"zero"> { + let arguments = (ins); + let results = (outs EncryptedIntegerType:$out); +} + def AddEintIntOp : HLFHE_Op<"add_eint_int"> { let arguments = (ins EncryptedIntegerType:$a, AnyInteger:$b); let results = (outs EncryptedIntegerType); diff --git a/compiler/tests/Dialect/HLFHE/ops.mlir b/compiler/tests/Dialect/HLFHE/ops.mlir index c40ba3c8b..2afd85ba9 100644 --- a/compiler/tests/Dialect/HLFHE/ops.mlir +++ b/compiler/tests/Dialect/HLFHE/ops.mlir @@ -1,5 +1,14 @@ // RUN: zamacompiler --round-trip %s 2>&1| FileCheck %s +// CHECK-LABEL: func @zero() -> !HLFHE.eint<2> +func @zero() -> !HLFHE.eint<2> { + // CHECK-NEXT: %[[RET:.*]] = "HLFHE.zero"() : () -> !HLFHE.eint<2> + // CHECK-NEXT: return %[[RET]] : !HLFHE.eint<2> + + %1 = "HLFHE.zero"() : () -> !HLFHE.eint<2> + return %1: !HLFHE.eint<2> +} + // CHECK-LABEL: func @add_eint_int(%arg0: !HLFHE.eint<2>) -> !HLFHE.eint<2> func @add_eint_int(%arg0: !HLFHE.eint<2>) -> !HLFHE.eint<2> { // CHECK-NEXT: %[[V1:.*]] = constant 1 : i3