@@ -135,35 +135,28 @@ bool isESIMDFunction(const Function &F) {
135
135
136
136
// This function makes one or two groups depending on kernel types (SYCL, ESIMD)
137
137
EntryPointGroupVec
138
- groupEntryPointsByKernelType (const Module &M, bool EmitOnlyKernelsAsEntryPoints,
139
- EntryPointVec *AllowedEntriesVec,
140
- EntryPointGroup::Properties BlueprintProps) {
141
- SmallPtrSet<const Function *, 32 > AllowedEntries;
142
-
143
- if (AllowedEntriesVec) {
144
- std::copy (AllowedEntriesVec->begin (), AllowedEntriesVec->end (),
145
- std::inserter (AllowedEntries, AllowedEntries.end ()));
146
- }
138
+ groupEntryPointsByKernelType (const ModuleDesc &MD,
139
+ bool EmitOnlyKernelsAsEntryPoints) {
140
+ const Module &M = MD.getModule ();
147
141
EntryPointGroupVec EntryPointGroups{};
148
- std::map<StringRef, EntryPointVec > EntryPointMap;
142
+ std::map<StringRef, EntryPointSet > EntryPointMap;
149
143
150
144
// Only process module entry points:
151
145
for (const auto &F : M.functions ()) {
152
- if (!isEntryPoint (F, EmitOnlyKernelsAsEntryPoints))
153
- continue ;
154
- if (AllowedEntriesVec && (AllowedEntries.find (&F) == AllowedEntries.end ()))
146
+ if (!isEntryPoint (F, EmitOnlyKernelsAsEntryPoints) ||
147
+ !MD.isEntryPointCandidate (F))
155
148
continue ;
156
149
157
150
if (isESIMDFunction (F))
158
- EntryPointMap[ESIMD_SCOPE_NAME].push_back (&F);
151
+ EntryPointMap[ESIMD_SCOPE_NAME].insert (&F);
159
152
else
160
- EntryPointMap[SYCL_SCOPE_NAME].push_back (&F);
153
+ EntryPointMap[SYCL_SCOPE_NAME].insert (&F);
161
154
}
162
155
163
156
if (!EntryPointMap.empty ()) {
164
157
for (auto &EPG : EntryPointMap) {
165
- EntryPointGroups.emplace_back (
166
- EntryPointGroup{ EPG.first , std::move (EPG.second ), BlueprintProps });
158
+ EntryPointGroups.emplace_back (EntryPointGroup{
159
+ EPG.first , std::move (EPG.second ), MD. getEntryPointGroup (). Props });
167
160
EntryPointGroup &G = EntryPointGroups.back ();
168
161
169
162
if (G.GroupId == ESIMD_SCOPE_NAME) {
@@ -175,7 +168,8 @@ groupEntryPointsByKernelType(const Module &M, bool EmitOnlyKernelsAsEntryPoints,
175
168
}
176
169
} else {
177
170
// No entry points met, record this.
178
- EntryPointGroups.emplace_back (EntryPointGroup{SYCL_SCOPE_NAME, {}});
171
+ EntryPointGroups.emplace_back (
172
+ EntryPointGroup{SYCL_SCOPE_NAME, EntryPointSet{}});
179
173
EntryPointGroup &G = EntryPointGroups.back ();
180
174
G.Props .HasESIMD = SyclEsimdSplitStatus::SYCL_ONLY;
181
175
}
@@ -189,22 +183,23 @@ groupEntryPointsByKernelType(const Module &M, bool EmitOnlyKernelsAsEntryPoints,
189
183
// which contains pairs of group id and entry points for that group. Each such
190
184
// group along with IR it depends on (globals, functions from its call graph,
191
185
// ...) will constitute a separate module.
192
- EntryPointGroupVec
193
- groupEntryPointsByScope (const Module &M, EntryPointsGroupScope EntryScope,
194
- bool EmitOnlyKernelsAsEntryPoints,
195
- EntryPointGroup::Properties BlueprintProps) {
186
+ EntryPointGroupVec groupEntryPointsByScope (const ModuleDesc &MD,
187
+ EntryPointsGroupScope EntryScope,
188
+ bool EmitOnlyKernelsAsEntryPoints) {
196
189
EntryPointGroupVec EntryPointGroups{};
197
190
// Use MapVector for deterministic order of traversal (helps tests).
198
- MapVector<StringRef, EntryPointVec> EntryPointMap;
191
+ MapVector<StringRef, EntryPointSet> EntryPointMap;
192
+ const Module &M = MD.getModule ();
199
193
200
194
// Only process module entry points:
201
195
for (const auto &F : M.functions ()) {
202
- if (!isEntryPoint (F, EmitOnlyKernelsAsEntryPoints))
196
+ if (!isEntryPoint (F, EmitOnlyKernelsAsEntryPoints) ||
197
+ !MD.isEntryPointCandidate (F))
203
198
continue ;
204
199
205
200
switch (EntryScope) {
206
201
case Scope_PerKernel:
207
- EntryPointMap[F.getName ()].push_back (&F);
202
+ EntryPointMap[F.getName ()].insert (&F);
208
203
break ;
209
204
210
205
case Scope_PerModule: {
@@ -218,55 +213,59 @@ groupEntryPointsByScope(const Module &M, EntryPointsGroupScope EntryScope,
218
213
219
214
Attribute Id = F.getFnAttribute (ATTR_SYCL_MODULE_ID);
220
215
StringRef Val = Id.getValueAsString ();
221
- EntryPointMap[Val].push_back (&F);
216
+ EntryPointMap[Val].insert (&F);
222
217
break ;
223
218
}
224
219
225
220
case Scope_Global:
226
221
// the map key is not significant here
227
- EntryPointMap[GLOBAL_SCOPE_NAME].push_back (&F);
222
+ EntryPointMap[GLOBAL_SCOPE_NAME].insert (&F);
228
223
break ;
229
224
}
230
225
}
231
226
232
227
if (!EntryPointMap.empty ()) {
233
228
EntryPointGroups.reserve (EntryPointMap.size ());
234
229
for (auto &EPG : EntryPointMap) {
235
- EntryPointGroups.emplace_back (
236
- EntryPointGroup{ EPG.first , std::move (EPG.second ), BlueprintProps });
230
+ EntryPointGroups.emplace_back (EntryPointGroup{
231
+ EPG.first , std::move (EPG.second ), MD. getEntryPointGroup (). Props });
237
232
EntryPointGroup &G = EntryPointGroups.back ();
238
233
G.Props .Scope = EntryScope;
239
234
}
240
235
} else {
241
236
// No entry points met, record this.
242
- EntryPointGroups.push_back ({GLOBAL_SCOPE_NAME, {}});
237
+ EntryPointGroups.emplace_back (
238
+ EntryPointGroup{GLOBAL_SCOPE_NAME, EntryPointSet{}});
243
239
}
244
240
return EntryPointGroups;
245
241
}
246
242
247
243
template <class EntryPoinGroupFunc >
248
- EntryPointGroupVec groupEntryPointsByAttribute (
249
- const Module &M, StringRef AttrName, bool EmitOnlyKernelsAsEntryPoints,
250
- EntryPoinGroupFunc F, EntryPointGroup::Properties BlueprintProps) {
244
+ EntryPointGroupVec
245
+ groupEntryPointsByAttribute (const ModuleDesc &MD, StringRef AttrName,
246
+ bool EmitOnlyKernelsAsEntryPoints,
247
+ EntryPoinGroupFunc F) {
251
248
EntryPointGroupVec EntryPointGroups{};
252
- std::map<StringRef, EntryPointVec> EntryPointMap;
249
+ std::map<StringRef, EntryPointSet> EntryPointMap;
250
+ const Module &M = MD.getModule ();
253
251
254
252
// Only process module entry points:
255
253
for (const auto &F : M.functions ()) {
256
- if (!isEntryPoint (F, EmitOnlyKernelsAsEntryPoints)) {
254
+ if (!isEntryPoint (F, EmitOnlyKernelsAsEntryPoints) ||
255
+ !MD.isEntryPointCandidate (F)) {
257
256
continue ;
258
257
}
259
258
if (F.hasFnAttribute (AttrName)) {
260
- EntryPointMap[AttrName].push_back (&F);
259
+ EntryPointMap[AttrName].insert (&F);
261
260
} else {
262
- EntryPointMap[" " ].push_back (&F);
261
+ EntryPointMap[" " ].insert (&F);
263
262
}
264
263
}
265
264
if (!EntryPointMap.empty ()) {
266
265
EntryPointGroups.reserve (EntryPointMap.size ());
267
266
for (auto &EPG : EntryPointMap) {
268
- EntryPointGroups.emplace_back (
269
- EntryPointGroup{ EPG.first , std::move (EPG.second ), BlueprintProps });
267
+ EntryPointGroups.emplace_back (EntryPointGroup{
268
+ EPG.first , std::move (EPG.second ), MD. getEntryPointGroup (). Props });
270
269
F (EntryPointGroups.back ());
271
270
}
272
271
} else {
@@ -354,12 +353,11 @@ ModuleDesc extractSubModule(const ModuleDesc &MD,
354
353
std::unique_ptr<Module> SubM = CloneModule (
355
354
M, VMap, [&](const GlobalValue *GV) { return GVs.count (GV); });
356
355
// Replace entry points with cloned ones.
357
- EntryPointVec NewEPs;
358
- const EntryPointVec &EPs = ModuleEntryPoints.Functions ;
359
- NewEPs.reserve (EPs.size ());
360
- std::transform (
361
- EPs.cbegin (), EPs.cend (), std::inserter (NewEPs, NewEPs.end ()),
362
- [&VMap](const Function *F) { return cast<Function>(VMap[F]); });
356
+ EntryPointSet NewEPs;
357
+ const EntryPointSet &EPs = ModuleEntryPoints.Functions ;
358
+ std::for_each (EPs.begin (), EPs.end (), [&](const Function *F) {
359
+ NewEPs.insert (cast<Function>(VMap[F]));
360
+ });
363
361
ModuleEntryPoints.Functions = std::move (NewEPs);
364
362
return ModuleDesc{std::move (SubM), std::move (ModuleEntryPoints), MD.Props };
365
363
}
@@ -416,11 +414,9 @@ namespace llvm {
416
414
namespace module_split {
417
415
418
416
std::unique_ptr<ModuleSplitterBase>
419
- getSplitterByKernelType (ModuleDesc &&MD, bool EmitOnlyKernelsAsEntryPoints,
420
- EntryPointVec *AllowedEntries) {
421
- EntryPointGroupVec Groups = groupEntryPointsByKernelType (
422
- MD.getModule (), EmitOnlyKernelsAsEntryPoints, AllowedEntries,
423
- MD.getEntryPointGroup ().Props );
417
+ getSplitterByKernelType (ModuleDesc &&MD, bool EmitOnlyKernelsAsEntryPoints) {
418
+ EntryPointGroupVec Groups =
419
+ groupEntryPointsByKernelType (MD, EmitOnlyKernelsAsEntryPoints);
424
420
bool DoSplit = (Groups.size () > 1 );
425
421
426
422
if (DoSplit)
@@ -435,9 +431,8 @@ getSplitterByMode(ModuleDesc &&MD, IRSplitMode Mode,
435
431
bool EmitOnlyKernelsAsEntryPoints) {
436
432
EntryPointsGroupScope Scope =
437
433
selectDeviceCodeGroupScope (MD.getModule (), Mode, AutoSplitIsGlobalScope);
438
- EntryPointGroupVec Groups = groupEntryPointsByScope (
439
- MD.getModule (), Scope, EmitOnlyKernelsAsEntryPoints,
440
- MD.getEntryPointGroup ().Props );
434
+ EntryPointGroupVec Groups =
435
+ groupEntryPointsByScope (MD, Scope, EmitOnlyKernelsAsEntryPoints);
441
436
assert (!Groups.empty () && " At least one group is expected" );
442
437
bool DoSplit = (Mode != SPLIT_NONE &&
443
438
(Groups.size () > 1 || !Groups.cbegin ()->Functions .empty ()));
@@ -526,7 +521,7 @@ void tab(int N) {
526
521
}
527
522
}
528
523
529
- void dumpEntryPoints (const EntryPointVec &C, const char *msg, int Tab) {
524
+ void dumpEntryPoints (const EntryPointSet &C, const char *msg, int Tab) {
530
525
tab (Tab);
531
526
llvm::errs () << " ENTRY POINTS"
532
527
<< " " << msg << " {\n " ;
@@ -565,8 +560,8 @@ void ModuleDesc::renameDuplicatesOf(const Module &MA, StringRef Suff) {
565
560
Module &MB = getModule ();
566
561
#ifndef NDEBUG
567
562
DenseSet<StringRef> EntryNamesB;
568
- auto It0 = entries ().cbegin ();
569
- auto It1 = entries ().cend ();
563
+ const auto It0 = entries ().begin ();
564
+ const auto It1 = entries ().end ();
570
565
std::for_each (It0, It1,
571
566
[&](const Function *F) { EntryNamesB.insert (F->getName ()); });
572
567
#endif // NDEBUG
@@ -640,52 +635,47 @@ void ModuleDesc::dump() const {
640
635
641
636
void EntryPointGroup::saveNames (std::vector<std::string> &Dest) const {
642
637
Dest.reserve (Dest.size () + Functions.size ());
643
- std::transform (Functions.cbegin (), Functions.cend (),
638
+ std::transform (Functions.begin (), Functions.end (),
644
639
std::inserter (Dest, Dest.end ()),
645
640
[](const Function *F) { return F->getName ().str (); });
646
641
}
647
642
648
643
void EntryPointGroup::rebuildFromNames (const std::vector<std::string> &Names,
649
644
const Module &M) {
650
645
Functions.clear ();
651
- Functions.reserve (Names.size ());
652
646
auto It0 = Names.cbegin ();
653
647
auto It1 = Names.cend ();
654
- std::transform (It0, It1, std::inserter (Functions, Functions.begin ()),
655
- [&M](const std::string &Name) {
656
- const Function *F = M.getFunction (Name);
657
- assert (F && " entry point lost" );
658
- return F;
659
- });
648
+ std::for_each (It0, It1, [&](const std::string &Name) {
649
+ const Function *F = M.getFunction (Name);
650
+ assert (F && " entry point lost" );
651
+ Functions.insert (F);
652
+ });
660
653
}
661
654
662
655
void EntryPointGroup::rebuild (const Module &M) {
663
656
if (Functions.size () == 0 ) {
664
657
return ;
665
658
}
666
- EntryPointVec NewFunctions;
667
- NewFunctions.reserve (Functions.size ());
668
- auto It0 = Functions.cbegin ();
669
- auto It1 = Functions.cend ();
670
- std::transform (It0, It1, std::inserter (NewFunctions, NewFunctions.begin ()),
671
- [&M](const Function *F) {
672
- Function *NewF = M.getFunction (F->getName ());
673
- assert (NewF && " entry point lost" );
674
- return NewF;
675
- });
659
+ EntryPointSet NewFunctions;
660
+ const auto It0 = Functions.begin ();
661
+ const auto It1 = Functions.end ();
662
+ std::for_each (It0, It1, [&](const Function *F) {
663
+ Function *NewF = M.getFunction (F->getName ());
664
+ assert (NewF && " entry point lost" );
665
+ NewFunctions.insert (NewF);
666
+ });
676
667
Functions = std::move (NewFunctions);
677
668
}
678
669
679
670
std::unique_ptr<ModuleSplitterBase>
680
671
getESIMDDoubleGRFSplitter (ModuleDesc &&MD, bool EmitOnlyKernelsAsEntryPoints) {
681
672
EntryPointGroupVec Groups = groupEntryPointsByAttribute (
682
- MD. getModule () , ATTR_DOUBLE_GRF, EmitOnlyKernelsAsEntryPoints,
673
+ MD, ATTR_DOUBLE_GRF, EmitOnlyKernelsAsEntryPoints,
683
674
[](EntryPointGroup &G) {
684
675
if (G.GroupId == ATTR_DOUBLE_GRF) {
685
676
G.Props .UsesDoubleGRF = true ;
686
677
}
687
- },
688
- MD.getEntryPointGroup ().Props );
678
+ });
689
679
assert (!Groups.empty () && " At least one group is expected" );
690
680
assert (Groups.size () <= 2 && " At most 2 groups are expected" );
691
681
0 commit comments