Skip to content

Commit 67a5e37

Browse files
committed
[SYCL] Fix sycl-post-link when no split and symbols are requested.
Signed-off-by: Konstantin S Bobrovsky <konstantin.s.bobrovsky@intel.com>
1 parent 18a2354 commit 67a5e37

File tree

2 files changed

+58
-7
lines changed

2 files changed

+58
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
; This test checks that the post-link tool produces a correct resulting file
2+
; table and a symbol file for an input module with two kernels when no code
3+
; splitting is requested.
4+
;
5+
; RUN: sycl-post-link -symbols -spec-const=rt -S %s -o %T/files.table
6+
; RUN: FileCheck %s -input-file=%T/files.table --check-prefixes CHECK-TABLE
7+
; RUN: FileCheck %s -input-file=%T/files_0.sym --match-full-lines --check-prefixes CHECK-SYM
8+
9+
define dso_local spir_kernel void @KERNEL_AAA() {
10+
; CHECK-SYM-NOT: {{[a-zA-Z0-9._@]+}}
11+
; CHECK-SYM: KERNEL_AAA
12+
entry:
13+
ret void
14+
}
15+
16+
define dso_local spir_kernel void @KERNEL_BBB() {
17+
; CHECK-SYM-NEXT: KERNEL_BBB
18+
; CHECK-SYM-EMPTY:
19+
entry:
20+
ret void
21+
}
22+
23+
; CHECK-TABLE: [Code|Properties|Symbols]
24+
; CHECK-TABLE-NEXT: {{.*}}files_0.sym
25+
; CHECK-TABLE-EMPTY:

llvm/tools/sycl-post-link/sycl-post-link.cpp

+33-7
Original file line numberDiff line numberDiff line change
@@ -121,23 +121,45 @@ static void writeToFile(std::string Filename, std::string Content) {
121121
OS.close();
122122
}
123123

124+
// Describes scope covered by each entry in the module-kernel map populated by
125+
// the function below.
126+
enum KernelMapEntryScope {
127+
Scope_PerKernel, // one entry per kernel
128+
Scope_PerModule, // one entry per module
129+
Scope_Global // single entry in the map for all kernels
130+
};
131+
124132
// Output parameter ResKernelModuleMap is a map containing groups of kernels
125133
// with same values of the sycl-module-id attribute.
126134
// The function fills ResKernelModuleMap using input module M.
127135
static void collectKernelModuleMap(
128136
Module &M, std::map<StringRef, std::vector<Function *>> &ResKernelModuleMap,
129-
bool OneKernelPerModule) {
130-
131-
constexpr char ATTR_SYCL_MODULE_ID[] = "sycl-module-id";
137+
KernelMapEntryScope EntryScope) {
132138

133139
for (auto &F : M.functions()) {
134140
if (F.getCallingConv() == CallingConv::SPIR_KERNEL) {
135-
if (OneKernelPerModule) {
141+
switch (EntryScope) {
142+
case Scope_PerKernel:
136143
ResKernelModuleMap[F.getName()].push_back(&F);
137-
} else if (F.hasFnAttribute(ATTR_SYCL_MODULE_ID)) {
144+
break;
145+
case Scope_PerModule: {
146+
constexpr char ATTR_SYCL_MODULE_ID[] = "sycl-module-id";
147+
148+
if (!F.hasFnAttribute(ATTR_SYCL_MODULE_ID))
149+
error("no '" + Twine(ATTR_SYCL_MODULE_ID) +
150+
"' attribute in kernel '" + F.getName() +
151+
"', per-module split not possible");
138152
Attribute Id = F.getFnAttribute(ATTR_SYCL_MODULE_ID);
139153
StringRef Val = Id.getValueAsString();
140154
ResKernelModuleMap[Val].push_back(&F);
155+
break;
156+
}
157+
case Scope_Global:
158+
// the map key is not significant here
159+
ResKernelModuleMap["<GLOBAL>"].push_back(&F);
160+
break;
161+
default:
162+
llvm_unreachable("unknown scope");
141163
}
142164
}
143165
}
@@ -375,8 +397,12 @@ int main(int argc, char **argv) {
375397

376398
std::map<StringRef, std::vector<Function *>> GlobalsSet;
377399

378-
if (DoSplit || DoSymGen)
379-
collectKernelModuleMap(*MPtr, GlobalsSet, SplitMode == SPLIT_PER_KERNEL);
400+
if (DoSplit || DoSymGen) {
401+
KernelMapEntryScope Scope = Scope_Global;
402+
if (DoSplit)
403+
Scope = SplitMode == SPLIT_PER_KERNEL ? Scope_PerKernel : Scope_PerModule;
404+
collectKernelModuleMap(*MPtr, GlobalsSet, Scope);
405+
}
380406

381407
std::vector<std::unique_ptr<Module>> ResultModules;
382408
std::vector<SpecIDMapTy> ResultSpecIDMaps;

0 commit comments

Comments
 (0)