From 3c326c09d616478a64751b24c83e9fe9845c00fc Mon Sep 17 00:00:00 2001 From: Quentin Bourgerie Date: Mon, 19 Jul 2021 11:54:54 +0200 Subject: [PATCH] clean(compiler): Remove unecessary operators for compiler v0 (#54) --- .../zamalang/Dialect/HLFHE/IR/HLFHEOps.td | 53 ------------------- compiler/lib/Dialect/HLFHE/IR/HLFHEOps.cpp | 19 +------ compiler/tests/Dialect/HLFHE/ops.mlir | 38 ------------- 3 files changed, 2 insertions(+), 108 deletions(-) diff --git a/compiler/include/zamalang/Dialect/HLFHE/IR/HLFHEOps.td b/compiler/include/zamalang/Dialect/HLFHE/IR/HLFHEOps.td index b360405f7..895d66380 100644 --- a/compiler/include/zamalang/Dialect/HLFHE/IR/HLFHEOps.td +++ b/compiler/include/zamalang/Dialect/HLFHE/IR/HLFHEOps.td @@ -18,12 +18,6 @@ include "zamalang/Dialect/HLFHE/IR/HLFHETypes.td" class HLFHE_Op traits = []> : Op; - -def ApplyUnivariateRegion : Region< - CPred<"::mlir::zamalang::predApplyUnivariateRegion($_self)">, - "apply_univariate region needs one block with one any integer argument">; - - def AddEintIntOp : HLFHE_Op<"add_eint_int"> { let arguments = (ins EncryptedIntegerType:$a, AnyInteger:$b); let results = (outs EncryptedIntegerType); @@ -46,18 +40,6 @@ def AddEintOp : HLFHE_Op<"add_eint"> { ]; } -def NegEintOp : HLFHE_Op<"neg_eint"> { - let arguments = (ins EncryptedIntegerType:$a); - let results = (outs EncryptedIntegerType); - - let builders = [ - OpBuilder<(ins "Value":$a), [{ - build($_builder, $_state, a.getType(), a); - }]> - ]; -} - - def MulEintIntOp : HLFHE_Op<"mul_eint_int"> { let arguments = (ins EncryptedIntegerType:$a, AnyInteger:$b); let results = (outs EncryptedIntegerType); @@ -69,40 +51,6 @@ def MulEintIntOp : HLFHE_Op<"mul_eint_int"> { ]; } -def MulEintOp : HLFHE_Op<"mul_eint"> { - let arguments = (ins EncryptedIntegerType:$a, EncryptedIntegerType:$b); - let results = (outs EncryptedIntegerType); - - let builders = [ - OpBuilder<(ins "Value":$a, "Value":$b), [{ - build($_builder, $_state, a.getType(), a, b); - }]> - ]; -} - -def ApplyUnivariateOp : HLFHE_Op<"apply_univariate"> { - let arguments = (ins EncryptedIntegerType:$x); - let results = (outs EncryptedIntegerType:$result); - - let builders = [ - OpBuilder<(ins "Value": $x), [{ - build($_builder, $_state, x.getType(), x); - }]> - ]; - - - let regions = (region ApplyUnivariateRegion:$body); - // let assemblyFormat = "$x `:` type($x) $body attr-dict `:` type($result)"; -} - - -def ReturnOp : HLFHE_Op<"apply_univariate_return", [NoSideEffect, ReturnLike, Terminator]> { - let summary = "terminator of apply_univariate block"; - let arguments = (ins AnyInteger); - let builders = [OpBuilder<(ins), [{ /* nothing to do */ }]>]; -} - - // Tensor operations // Dot product @@ -124,5 +72,4 @@ def Dot : HLFHE_Op<"dot_eint_int", [DeclareOpInterfaceMethods()) { - return false; - } - // TODO: need to handle when there is no terminator - auto terminator = region.getBlocks().front().getTerminator(); - return terminator->getName().getStringRef().equals( - "HLFHE.apply_univariate_return"); -} - namespace HLFHE { + void Dot::getEffects( SmallVectorImpl> &effects) { @@ -36,6 +20,7 @@ void Dot::getEffects( effects.emplace_back(MemoryEffects::Write::get(), this->out(), SideEffects::DefaultResource::get()); } + } // namespace HLFHE } // namespace zamalang } // namespace mlir diff --git a/compiler/tests/Dialect/HLFHE/ops.mlir b/compiler/tests/Dialect/HLFHE/ops.mlir index 5d2d93e10..f9fae3714 100644 --- a/compiler/tests/Dialect/HLFHE/ops.mlir +++ b/compiler/tests/Dialect/HLFHE/ops.mlir @@ -31,44 +31,6 @@ func @add_eint(%arg0: !HLFHE.eint<0>, %arg1: !HLFHE.eint<0>) -> !HLFHE.eint<0> { return %1: !HLFHE.eint<0> } -// CHECK-LABEL: func @mul_eint(%arg0: !HLFHE.eint<0>, %arg1: !HLFHE.eint<0>) -> !HLFHE.eint<0> -func @mul_eint(%arg0: !HLFHE.eint<0>, %arg1: !HLFHE.eint<0>) -> !HLFHE.eint<0> { - // CHECK-NEXT: %[[V1:.*]] = "HLFHE.mul_eint"(%arg0, %arg1) : (!HLFHE.eint<0>, !HLFHE.eint<0>) -> !HLFHE.eint<0> - // CHECK-NEXT: return %[[V1]] : !HLFHE.eint<0> - - %1 = "HLFHE.mul_eint"(%arg0, %arg1): (!HLFHE.eint<0>, !HLFHE.eint<0>) -> (!HLFHE.eint<0>) - return %1: !HLFHE.eint<0> -} - -// CHECK-LABEL: func @neg_eint(%arg0: !HLFHE.eint<0>) -> !HLFHE.eint<0> -func @neg_eint(%arg0: !HLFHE.eint<0>) -> !HLFHE.eint<0> { - // CHECK-NEXT: %[[V1:.*]] = "HLFHE.neg_eint"(%arg0) : (!HLFHE.eint<0>) -> !HLFHE.eint<0> - // CHECK-NEXT: return %[[V1]] : !HLFHE.eint<0> - - %1 = "HLFHE.neg_eint"(%arg0): (!HLFHE.eint<0>) -> (!HLFHE.eint<0>) - return %1: !HLFHE.eint<0> -} - -// CHECK-LABEL: func @apply_univariate(%arg0: !HLFHE.eint<0>) -> !HLFHE.eint<0> -func @apply_univariate(%arg0: !HLFHE.eint<0>) -> !HLFHE.eint<0> { - // CHECK-NEXT: %[[V1:.*]] = "HLFHE.apply_univariate"(%arg0) ( { - // CHECK-NEXT: ^bb0(%[[V2:.*]]: i32): - // CHECK-NEXT: %[[CST:.*]] = constant 5 : i32 - // CHECK-NEXT: %[[V3:.*]] = muli %[[V2]], %[[CST]] : i32 - // CHECK-NEXT: "HLFHE.apply_univariate_return"(%[[V3]]) : (i32) -> () - // CHECK-NEXT: }) : (!HLFHE.eint<0>) -> !HLFHE.eint<0> - // CHECK-NEXT: return %[[V1]] : !HLFHE.eint<0> - - %0 = "HLFHE.apply_univariate"(%arg0)({ - ^bb0(%a: i32): - %cst = constant 5: i32 - %res = std.muli %a, %cst : i32 - "HLFHE.apply_univariate_return"(%res): (i32) -> () - }) : (!HLFHE.eint<0>) -> !HLFHE.eint<0> - - return %0: !HLFHE.eint<0> -} - // CHECK-LABEL: func @dot_eint_int(%arg0: memref<2x!HLFHE.eint<0>>, %arg1: memref<2xi32>, %arg2: memref>) func @dot_eint_int(%arg0: memref<2x!HLFHE.eint<0>>, %arg1: memref<2xi32>,