Skip to content

Commit c6c55fb

Browse files
authored
Add clang patch to enable BFloat16 for SPIR/SPIR-V (#590)
1 parent 6537d42 commit c6c55fb

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

cmake/modules/CMakeFunctions.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ function(apply_patches repo_dir patches_dir base_revision target_branch)
141141
message(STATUS "[OPENCL-CLANG] Not present - ${patching_log}")
142142
endif()
143143
endforeach(patch)
144-
elsef(patches_needed EQUAL 0) # The target branch already exists
144+
elseif(patches_needed EQUAL 0) # The target branch already exists
145145
execute_process( # Check it out
146146
COMMAND ${GIT_EXECUTABLE} checkout ${target_branch}
147147
WORKING_DIRECTORY ${repo_dir}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
From 6e240c1b150b4623d126539320b00375f6ee4ed6 Mon Sep 17 00:00:00 2001
2+
From: Wenju He <[email protected]>
3+
Date: Fri, 21 Nov 2025 05:37:58 +0100
4+
Subject: [PATCH] [Clang] Enable BFloat16 for SPIR/SPIR-V
5+
6+
---
7+
clang/lib/Basic/Targets/SPIR.h | 6 +++---
8+
1 file changed, 3 insertions(+), 3 deletions(-)
9+
10+
diff --git a/clang/lib/Basic/Targets/SPIR.h b/clang/lib/Basic/Targets/SPIR.h
11+
index 37cf9d7921ba..f593971bb3a0 100644
12+
--- a/clang/lib/Basic/Targets/SPIR.h
13+
+++ b/clang/lib/Basic/Targets/SPIR.h
14+
@@ -101,6 +101,9 @@ protected:
15+
UseAddrSpaceMapMangling = true;
16+
HasLegalHalfType = true;
17+
HasFloat16 = true;
18+
+ HasBFloat16 = true;
19+
+ BFloat16Width = BFloat16Align = 16;
20+
+ BFloat16Format = &llvm::APFloat::BFloat();
21+
// Define available target features
22+
// These must be defined in sorted order!
23+
NoAsmVariants = true;
24+
@@ -384,9 +387,6 @@ public:
25+
resetDataLayout("e-i64:64-v16:16-v24:32-v32:32-v48:64-"
26+
"v96:128-v192:256-v256:256-v512:512-v1024:1024-G1-P4-A0");
27+
28+
- BFloat16Width = BFloat16Align = 16;
29+
- BFloat16Format = &llvm::APFloat::BFloat();
30+
-
31+
HasLegalHalfType = true;
32+
HasFloat16 = true;
33+
HalfArgsAndReturns = true;
34+
--
35+
2.39.1
36+

0 commit comments

Comments
 (0)