mirror of
https://github.com/zama-ai/concrete.git
synced 2026-02-09 12:15:09 -05:00
clean(compiler): Remove unecessary operators for compiler v0 (#54)
This commit is contained in:
@@ -18,12 +18,6 @@ include "zamalang/Dialect/HLFHE/IR/HLFHETypes.td"
|
||||
class HLFHE_Op<string mnemonic, list<OpTrait> traits = []> :
|
||||
Op<HLFHE_Dialect, mnemonic, traits>;
|
||||
|
||||
|
||||
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<MemoryEffectsOpInt
|
||||
return ::mlir::success();
|
||||
}];
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -6,24 +6,8 @@
|
||||
|
||||
namespace mlir {
|
||||
namespace zamalang {
|
||||
bool predApplyUnivariateRegion(::mlir::Region ®ion) {
|
||||
if (region.getBlocks().size() != 1) {
|
||||
return false;
|
||||
}
|
||||
auto args = region.getBlocks().front().getArguments();
|
||||
if (args.size() != 1) {
|
||||
return false;
|
||||
}
|
||||
if (!args.front().getType().isa<mlir::IntegerType>()) {
|
||||
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<SideEffects::EffectInstance<MemoryEffects::Effect>>
|
||||
&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
|
||||
|
||||
@@ -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<!HLFHE.eint<0>>)
|
||||
func @dot_eint_int(%arg0: memref<2x!HLFHE.eint<0>>,
|
||||
%arg1: memref<2xi32>,
|
||||
|
||||
Reference in New Issue
Block a user