Skip to content

Commit cec3ecd

Browse files
asudarsasys-ce-bb
authored andcommitted
Emit error for LLVM bfloat type (#3047)
Signed-off-by: Arvind Sudarsanam <[email protected]> Original commit: KhronosGroup/SPIRV-LLVM-Translator@5bda7566d980a71
1 parent e669ee1 commit cec3ecd

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

llvm-spirv/lib/SPIRV/SPIRVWriter.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,9 @@ SPIRVType *LLVMToSPIRVBase::transType(Type *T) {
401401
}
402402
}
403403

404+
// Emit error if type is bfloat. LLVM native bfloat type is not supported.
405+
BM->getErrorLog().checkError(!T->isBFloatTy(),
406+
SPIRVEC_UnsupportedLLVMBFloatType);
404407
if (T->isFloatingPointTy())
405408
return mapType(T, BM->addFloatType(T->getPrimitiveSizeInBits()));
406409

llvm-spirv/lib/SPIRV/libSPIRV/SPIRVErrorEnum.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ _SPIRV_OP(UnspecifiedMemoryModel, "Unspecified Memory Model.")
2828
_SPIRV_OP(RepeatedMemoryModel, "Expects a single OpMemoryModel instruction.")
2929
_SPIRV_OP(UnsupportedVarArgFunction,
3030
"Variadic functions other than 'printf' are not supported in SPIR-V.")
31+
_SPIRV_OP(UnsupportedLLVMBFloatType,
32+
"LLVM bfloat type is not supported in SPIR-V.")
3133

3234
/* This is the last error code to have a maximum valid value to compare to */
3335
_SPIRV_OP(InternalMaxErrorCode, "Unknown error code")

llvm-spirv/test/bfloat.ll

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
; Check that translator emits error for LLVM bfloat type
2+
; RUN: llvm-as %s -o %t.bc
3+
; RUN: not llvm-spirv --spirv-ext=+all %t.bc -o %t.spv 2>&1 | FileCheck %s --check-prefix=CHECK-ERROR
4+
5+
; CHECK-ERROR: UnsupportedLLVMBFloatType: LLVM bfloat type is not supported in SPIR-V
6+
7+
target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
8+
target triple = "spir-unknown-unknown"
9+
10+
; Function Attrs: nounwind
11+
define spir_kernel void @testBFloat(bfloat %a, bfloat %b) {
12+
entry:
13+
%r1 = fmul bfloat %a, %b
14+
ret void
15+
}
16+
17+
!llvm.module.flags = !{!0}
18+
!opencl.ocl.version = !{!1}
19+
!opencl.spir.version = !{!1}
20+
21+
!0 = !{i32 1, !"wchar_size", i32 4}
22+
!1 = !{i32 2, i32 0}

0 commit comments

Comments
 (0)