diff --git a/lib/Target/OpenFhePke/OpenFhePkeEmitter.cpp b/lib/Target/OpenFhePke/OpenFhePkeEmitter.cpp index f9e105962d..284e566202 100644 --- a/lib/Target/OpenFhePke/OpenFhePkeEmitter.cpp +++ b/lib/Target/OpenFhePke/OpenFhePkeEmitter.cpp @@ -1692,8 +1692,12 @@ LogicalResult OpenFhePkeEmitter::printOperation(tensor::SplatOp op) { LogicalResult OpenFhePkeEmitter::printOperation(tensor::FromElementsOp op) { // std::vector result = {input[0], ..., input[n]}; auto result = op.getResult(); - if (result.getType().getRank() != 1) { - return failure(); + // Only rank-0 and rank-1 tensor construction is currently supported. + // TODO(#1703): Support higher-rank tensors. + if (result.getType().getRank() > 1) { + return op.emitOpError() + << "expected a rank-0 or rank-1 tensor, but got rank " + << result.getType().getRank(); } os << "const "; if (failed(emitTypedAssignPrefix(result, op->getLoc()))) { diff --git a/tests/Emitter/Openfhe/emit_0d_tensor.mlir b/tests/Emitter/Openfhe/emit_0d_tensor.mlir index 9b1196d2bc..bfb533eda3 100644 --- a/tests/Emitter/Openfhe/emit_0d_tensor.mlir +++ b/tests/Emitter/Openfhe/emit_0d_tensor.mlir @@ -21,4 +21,12 @@ module attributes {scheme.bgv} { %0 = tensor.insert %v into %arg0[] : tensor return %0 : tensor } + + func.func @test_0d_tensor_from_elements(%arg0: f32) -> tensor { + // CHECK: std::vector test_0d_tensor_from_elements(float [[arg0:[^ ]*]]) + // CHECK: const std::vector [[result:[^ ]*]] = {[[arg0]]}; + // CHECK: return [[result]]; + %0 = tensor.from_elements %arg0 : tensor + return %0 : tensor + } } diff --git a/tests/Emitter/Openfhe/emit_2d_tensor_error.mlir b/tests/Emitter/Openfhe/emit_2d_tensor_error.mlir new file mode 100644 index 0000000000..541684f941 --- /dev/null +++ b/tests/Emitter/Openfhe/emit_2d_tensor_error.mlir @@ -0,0 +1,9 @@ +// RUN: not heir-translate %s --emit-openfhe-pke 2>&1 | FileCheck %s + +module attributes {scheme.bgv} { + func.func @test_2d_tensor_from_elements(%arg0: f32) -> tensor<1x1xf32> { + // CHECK: 'tensor.from_elements' op expected a rank-0 or rank-1 tensor, but got rank 2 + %0 = tensor.from_elements %arg0 : tensor<1x1xf32> + return %0 : tensor<1x1xf32> + } +}