Skip to content

Commit e301d7d

Browse files
authored
Add clang patch to enable BFloat16 for SPIR/SPIR-V (#591)
1 parent 4708338 commit e301d7d

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 e3aa87e0aaad941c35709c8dc7a479b2a5251cfe Mon Sep 17 00:00:00 2001
2+
From: Wenju He <[email protected]>
3+
Date: Fri, 21 Nov 2025 05:43:57 +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 c0849b69dcdb..78a1c0e78107 100644
12+
--- a/clang/lib/Basic/Targets/SPIR.h
13+
+++ b/clang/lib/Basic/Targets/SPIR.h
14+
@@ -103,6 +103,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+
@@ -389,9 +392,6 @@ public:
25+
resetDataLayout("e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-"
26+
"v256:256-v512:512-v1024:1024-n32:64-S32-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)