@@ -121,23 +121,45 @@ static void writeToFile(std::string Filename, std::string Content) {
121
121
OS.close ();
122
122
}
123
123
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
+
124
132
// Output parameter ResKernelModuleMap is a map containing groups of kernels
125
133
// with same values of the sycl-module-id attribute.
126
134
// The function fills ResKernelModuleMap using input module M.
127
135
static void collectKernelModuleMap (
128
136
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) {
132
138
133
139
for (auto &F : M.functions ()) {
134
140
if (F.getCallingConv () == CallingConv::SPIR_KERNEL) {
135
- if (OneKernelPerModule) {
141
+ switch (EntryScope) {
142
+ case Scope_PerKernel:
136
143
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" );
138
152
Attribute Id = F.getFnAttribute (ATTR_SYCL_MODULE_ID);
139
153
StringRef Val = Id.getValueAsString ();
140
154
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" );
141
163
}
142
164
}
143
165
}
@@ -375,8 +397,12 @@ int main(int argc, char **argv) {
375
397
376
398
std::map<StringRef, std::vector<Function *>> GlobalsSet;
377
399
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
+ }
380
406
381
407
std::vector<std::unique_ptr<Module>> ResultModules;
382
408
std::vector<SpecIDMapTy> ResultSpecIDMaps;
0 commit comments