Skip to content

Commit 5e56496

Browse files
authored
Merge pull request #205 from lwesiers/ocl-open-100
Improving mechanism of patching dependent repositories.
2 parents 57d8be3 + b6acc8b commit 5e56496

File tree

2 files changed

+139
-9
lines changed

2 files changed

+139
-9
lines changed

cmake/modules/CMakeFunctions.cmake

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,37 @@ macro(use_eh val)
3939
endif()
4040
endmacro(use_eh)
4141

42+
# Reads hash-commit from backported patch
43+
# This function assumes that each of files starts with (for example):
44+
# From 1a400928bf8fc86fa0f062524c25d0985c94ac6f Mon Sep 17 00:00:00 2001
45+
function(get_backport_patch_hash patch_path patch_hash)
46+
file(READ ${patch_path} first_line LIMIT 40 OFFSET 5)
47+
string(STRIP ${first_line} first_line_strip)
48+
set(patch_hash ${first_line_strip} PARENT_SCOPE)
49+
endfunction()
50+
51+
# Checks if the the patch is present in current local branch
52+
function(is_backport_patch_present patch_path repo_dir base_branch patch_in_branch)
53+
get_backport_patch_hash(${patch_path} patch_hash)
54+
message(STATUS "[OPENCL-CLANG] Checking if patch ${patch_hash} is present in branch ${base_branch}")
55+
execute_process(
56+
COMMAND ${GIT_EXECUTABLE} branch --contains ${patch_hash}
57+
WORKING_DIRECTORY ${repo_dir}
58+
OUTPUT_VARIABLE patch_in_branches
59+
ERROR_QUIET
60+
)
61+
if(NOT patch_in_branches)
62+
set(patch_in_branch False PARENT_SCOPE) # The patch is not present in local branch
63+
else()
64+
string(FIND ${patch_in_branches} ${base_branch} match_branch)
65+
if(${match_branch} EQUAL -1)
66+
set(patch_in_branch False PARENT_SCOPE) # The patch is not present in local branch
67+
else()
68+
set(patch_in_branch True PARENT_SCOPE) # The patch is not present in local branch
69+
endif()
70+
endif()
71+
endfunction()
72+
4273
#
4374
# Creates `target_branch` starting at the `base_revision` in the `repo_dir`.
4475
# Then all patches from the `patches_dir` are committed to the `target_branch`.
@@ -51,31 +82,49 @@ function(apply_patches repo_dir patches_dirs base_revision target_branch ret)
5182
list(APPEND patches ${patches_in_dir})
5283
endforeach()
5384
if(NOT patches)
54-
message(STATUS "No patches in ${patches_dir}")
85+
message(STATUS "[OPENCL-CLANG] No patches in ${patches_dir}")
5586
return()
5687
endif()
5788

58-
message(STATUS "${repo_dir}:")
89+
message(STATUS "[OPENCL-CLANG] Patching repository ${repo_dir}")
5990
# Check if the target branch already exists
6091
execute_process(
6192
COMMAND ${GIT_EXECUTABLE} rev-parse --verify --no-revs -q ${target_branch}
6293
WORKING_DIRECTORY ${repo_dir}
6394
RESULT_VARIABLE patches_needed
64-
)
95+
)
6596
if(patches_needed EQUAL 128) # not a git repo
6697
set(ret_not_git_repo 1)
98+
message(STATUS "[OPENCL-CLANG] Is not a git repo")
6799
elseif(patches_needed) # The target branch doesn't exist
68100
list(SORT patches)
101+
execute_process( # Create the target branch
102+
COMMAND ${GIT_EXECUTABLE} branch
103+
WORKING_DIRECTORY ${repo_dir}
104+
OUTPUT_VARIABLE git_out_base_branch
105+
)
106+
STRING(REGEX REPLACE "\\* (.*)" "\\1" base_branch ${git_out_base_branch})
107+
message(STATUS "[OPENCL-CLANG] Base branch : ${base_branch}")
69108
execute_process( # Create the target branch
70109
COMMAND ${GIT_EXECUTABLE} checkout -b ${target_branch} ${base_revision}
71110
WORKING_DIRECTORY ${repo_dir}
72111
RESULT_VARIABLE ret_check_out
73-
)
74-
execute_process( # Apply the pathces
75-
COMMAND ${GIT_EXECUTABLE} am --3way --ignore-whitespace ${patches}
76-
WORKING_DIRECTORY ${repo_dir}
77-
RESULT_VARIABLE ret_apply_patch
78-
)
112+
ERROR_VARIABLE checkout_log
113+
)
114+
message(STATUS "[OPENCL-CLANG] ${checkout_log}")
115+
foreach(patch ${patches})
116+
is_backport_patch_present(${patch} ${repo_dir} ${base_branch} patch_in_branch)
117+
if(${patch_in_branch})
118+
message(STATUS "[OPENCL-CLANG] Patch ${patch} is already in local branch - ignore patching")
119+
else()
120+
execute_process( # Apply the patch
121+
COMMAND ${GIT_EXECUTABLE} am --3way --ignore-whitespace ${patch}
122+
WORKING_DIRECTORY ${repo_dir}
123+
OUTPUT_VARIABLE patching_log
124+
)
125+
message(STATUS "[OPENCL-CLANG] Not present - ${patching_log}")
126+
endif()
127+
endforeach(patch)
79128
else() # The target branch already exists
80129
execute_process( # Check it out
81130
COMMAND ${GIT_EXECUTABLE} checkout ${target_branch}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
From 0db501ebb43a5eec03469a226dc1822940e640b1 Mon Sep 17 00:00:00 2001
2+
From: Ben Ashbaugh <[email protected]>
3+
Date: Wed, 23 Sep 2020 15:19:36 -0700
4+
Subject: [PATCH] updates for OpenCL C 3.0
5+
6+
OpenCL C 3.0 is a derivative of OpenCL C 2.0 and not OpenCL C++.
7+
Run the OpenCL C++ passes for OpenCL 2.1 only, and run similar
8+
OpenCL C 2.0 passes for OpenCL C 3.0.
9+
---
10+
lib/SPIRV/OCL20ToSPIRV.cpp | 5 +++--
11+
lib/SPIRV/OCL21ToSPIRV.cpp | 2 +-
12+
lib/SPIRV/OCLUtil.h | 1 +
13+
lib/SPIRV/PreprocessMetadata.cpp | 4 ++--
14+
4 files changed, 7 insertions(+), 5 deletions(-)
15+
16+
diff --git a/lib/SPIRV/OCL20ToSPIRV.cpp b/lib/SPIRV/OCL20ToSPIRV.cpp
17+
index 6137692..1262c48 100644
18+
--- a/lib/SPIRV/OCL20ToSPIRV.cpp
19+
+++ b/lib/SPIRV/OCL20ToSPIRV.cpp
20+
@@ -346,7 +346,7 @@ bool OCL20ToSPIRV::runOnModule(Module &Module) {
21+
return false;
22+
23+
CLVer = std::get<1>(Src);
24+
- if (CLVer > kOCLVer::CL20)
25+
+ if (CLVer == kOCLVer::CL21)
26+
return false;
27+
28+
LLVM_DEBUG(dbgs() << "Enter OCL20ToSPIRV:\n");
29+
@@ -426,7 +426,8 @@ void OCL20ToSPIRV::visitCallInst(CallInst &CI) {
30+
DemangledName == kOCLBuiltinName::AtomicCmpXchgStrong ||
31+
DemangledName == kOCLBuiltinName::AtomicCmpXchgWeakExplicit ||
32+
DemangledName == kOCLBuiltinName::AtomicCmpXchgStrongExplicit) {
33+
- assert(CLVer == kOCLVer::CL20 && "Wrong version of OpenCL");
34+
+ assert((CLVer == kOCLVer::CL20 || CLVer == kOCLVer::CL30) &&
35+
+ "Wrong version of OpenCL");
36+
PCI = visitCallAtomicCmpXchg(PCI, DemangledName);
37+
}
38+
visitCallAtomicLegacy(PCI, MangledName, DemangledName);
39+
diff --git a/lib/SPIRV/OCL21ToSPIRV.cpp b/lib/SPIRV/OCL21ToSPIRV.cpp
40+
index 0cfc0b6..08215c1 100644
41+
--- a/lib/SPIRV/OCL21ToSPIRV.cpp
42+
+++ b/lib/SPIRV/OCL21ToSPIRV.cpp
43+
@@ -109,7 +109,7 @@ bool OCL21ToSPIRV::runOnModule(Module &Module) {
44+
return false;
45+
46+
CLVer = std::get<1>(Src);
47+
- if (CLVer < kOCLVer::CL21)
48+
+ if (CLVer != kOCLVer::CL21)
49+
return false;
50+
51+
LLVM_DEBUG(dbgs() << "Enter OCL21ToSPIRV:\n");
52+
diff --git a/lib/SPIRV/OCLUtil.h b/lib/SPIRV/OCLUtil.h
53+
index 6e9ce53..9e34d2d 100644
54+
--- a/lib/SPIRV/OCLUtil.h
55+
+++ b/lib/SPIRV/OCLUtil.h
56+
@@ -256,6 +256,7 @@ namespace kOCLVer {
57+
const unsigned CL12 = 102000;
58+
const unsigned CL20 = 200000;
59+
const unsigned CL21 = 201000;
60+
+const unsigned CL30 = 300000;
61+
} // namespace kOCLVer
62+
63+
namespace OclExt {
64+
diff --git a/lib/SPIRV/PreprocessMetadata.cpp b/lib/SPIRV/PreprocessMetadata.cpp
65+
index 0b908ac..e92ad36 100644
66+
--- a/lib/SPIRV/PreprocessMetadata.cpp
67+
+++ b/lib/SPIRV/PreprocessMetadata.cpp
68+
@@ -208,8 +208,8 @@ void PreprocessMetadata::preprocessOCLMetadata(Module *M, SPIRVMDBuilder *B,
69+
// !{x} = !{i32 3, i32 102000}
70+
B->addNamedMD(kSPIRVMD::Source)
71+
.addOp()
72+
- .add(CLVer < kOCLVer::CL21 ? spv::SourceLanguageOpenCL_C
73+
- : spv::SourceLanguageOpenCL_CPP)
74+
+ .add(CLVer == kOCLVer::CL21 ? spv::SourceLanguageOpenCL_CPP
75+
+ : spv::SourceLanguageOpenCL_C)
76+
.add(CLVer)
77+
.done();
78+
if (EraseOCLMD)
79+
--
80+
2.20.1
81+

0 commit comments

Comments
 (0)