52
52
using namespace llvm ;
53
53
54
54
using string_vector = std::vector<std::string>;
55
- using FuncPtrVector = std::vector<const Function *>;
56
- using EntryPointsSet = std::map<StringRef, FuncPtrVector>;
57
- using ModuleUPtr = std::unique_ptr<Module>;
58
- using PropSetRegTy = llvm::util::PropertySetRegistry;
59
- using StringRefVector = std::vector<StringRef>;
55
+ using EntryPointsMap = std::map<StringRef, std::vector<const Function *>>;
60
56
61
57
namespace {
62
58
@@ -319,7 +315,7 @@ bool isEntryPoint(const Function &F) {
319
315
// group along with IR it depends on (globals, functions from its call graph,
320
316
// ...) will constitute a separate module.
321
317
void collectEntryPointToModuleMap (const Module &M,
322
- EntryPointsSet &ResKernelModuleMap,
318
+ EntryPointsMap &ResKernelModuleMap,
323
319
KernelMapEntryScope EntryScope) {
324
320
325
321
// Only process module entry points:
@@ -361,11 +357,11 @@ HasAssertStatus hasAssertInFunctionCallGraph(const Function *Func) {
361
357
// true - if there is an assertion in underlying functions,
362
358
// false - if there are definetely no assertions in underlying functions.
363
359
static std::map<const Function *, bool > hasAssertionInCallGraphMap;
364
- FuncPtrVector FuncCallStack;
360
+ std::vector< const Function *> FuncCallStack;
365
361
366
- static FuncPtrVector isIndirectlyCalledInGraph;
362
+ static std::vector< const Function *> isIndirectlyCalledInGraph;
367
363
368
- FuncPtrVector Workstack;
364
+ std::vector< const Function *> Workstack;
369
365
Workstack.push_back (Func);
370
366
371
367
while (!Workstack.empty ()) {
@@ -440,11 +436,11 @@ HasAssertStatus hasAssertInFunctionCallGraph(const Function *Func) {
440
436
return No_Assert;
441
437
}
442
438
443
- StringRefVector getKernelNamesUsingAssert (const Module &M) {
444
- StringRefVector Result;
439
+ std::vector<StringRef> getKernelNamesUsingAssert (const Module &M) {
440
+ std::vector<StringRef> Result;
445
441
446
442
bool HasIndirectlyCalledAssert = false ;
447
- FuncPtrVector Kernels;
443
+ std::vector< const Function *> Kernels;
448
444
for (const auto &F : M.functions ()) {
449
445
// TODO: handle SYCL_EXTERNAL functions for dynamic linkage.
450
446
// TODO: handle function pointers.
@@ -497,7 +493,7 @@ std::vector<uint32_t> getKernelReqdWorkGroupSizeMetadata(const Function &Func) {
497
493
// names from the same module separated by \n.
498
494
// The function saves names of entry points from one group to a single
499
495
// std::string and stores this string to the ResSymbolsLists vector.
500
- string_vector collectSymbolsLists (const EntryPointsSet &KernelModuleMap) {
496
+ string_vector collectSymbolsLists (const EntryPointsMap &KernelModuleMap) {
501
497
string_vector ResSymbolsLists{};
502
498
for (const auto &It : KernelModuleMap) {
503
499
std::string SymbolsList;
@@ -512,7 +508,7 @@ string_vector collectSymbolsLists(const EntryPointsSet &KernelModuleMap) {
512
508
513
509
struct ResultModule {
514
510
StringRef KernelModuleName;
515
- ModuleUPtr ModulePtr;
511
+ std::unique_ptr<Module> ModulePtr;
516
512
};
517
513
518
514
// Input parameter KernelModuleMap is a map containing groups of entry points
@@ -522,13 +518,13 @@ struct ResultModule {
522
518
// The function splits input LLVM IR module M into smaller ones and stores them
523
519
// to the ResModules vector.
524
520
std::vector<ResultModule> splitModule (const Module &M,
525
- const EntryPointsSet &KernelModuleMap) {
521
+ const EntryPointsMap &KernelModuleMap) {
526
522
std::vector<ResultModule> ResModules{};
527
523
528
524
for (const auto &It : KernelModuleMap) {
529
525
// For each group of entry points collect all dependencies.
530
526
SetVector<const GlobalValue *> GVs;
531
- FuncPtrVector Workqueue;
527
+ std::vector< const Function *> Workqueue;
532
528
533
529
for (const auto &F : It.second ) {
534
530
GVs.insert (F);
@@ -559,7 +555,7 @@ std::vector<ResultModule> splitModule(const Module &M,
559
555
ValueToValueMapTy VMap;
560
556
// Clone definitions only for needed globals. Others will be added as
561
557
// declarations and removed later.
562
- ModuleUPtr MClone = CloneModule (
558
+ std::unique_ptr<Module> MClone = CloneModule (
563
559
M, VMap, [&](const GlobalValue *GV) { return GVs.count (GV); });
564
560
565
561
// TODO: Use the new PassManager instead?
@@ -621,8 +617,10 @@ string_vector saveResultModules(const std::vector<ResultModule> &ResModules,
621
617
622
618
string_vector
623
619
saveDeviceImageProperty (const std::vector<ResultModule> &ResultModules,
624
- const EntryPointsSet &KernelModuleMap,
620
+ const EntryPointsMap &KernelModuleMap,
625
621
const ImagePropSaveInfo &ImgPSInfo) {
622
+ using PropSetRegTy = llvm::util::PropertySetRegistry;
623
+
626
624
string_vector Res;
627
625
legacy::PassManager GetSYCLDeviceLibReqMask;
628
626
auto *SDLReqMaskLegacyPass = new SYCLDeviceLibReqMaskPass ();
@@ -716,7 +714,7 @@ saveDeviceImageProperty(const std::vector<ResultModule> &ResultModules,
716
714
PropSet[PropSetRegTy::SYCL_MISC_PROP].insert ({" isEsimdImage" , true });
717
715
718
716
{
719
- StringRefVector FuncNames = getKernelNamesUsingAssert (M);
717
+ std::vector<StringRef> FuncNames = getKernelNamesUsingAssert (M);
720
718
for (const StringRef &FName : FuncNames)
721
719
PropSet[PropSetRegTy::SYCL_ASSERT_USED].insert ({FName, true });
722
720
}
@@ -786,7 +784,8 @@ void LowerEsimdConstructs(Module &M) {
786
784
787
785
using TableFiles = std::map<StringRef, string_vector>;
788
786
789
- TableFiles processOneModule (ModuleUPtr M, bool IsEsimd, bool SyclAndEsimdCode) {
787
+ TableFiles processOneModule (std::unique_ptr<Module> M, bool IsEsimd,
788
+ bool SyclAndEsimdCode) {
790
789
TableFiles TblFiles;
791
790
if (!M)
792
791
return TblFiles;
@@ -808,7 +807,7 @@ TableFiles processOneModule(ModuleUPtr M, bool IsEsimd, bool SyclAndEsimdCode) {
808
807
if (IsEsimd && LowerEsimd)
809
808
LowerEsimdConstructs (*M);
810
809
811
- EntryPointsSet GlobalsSet;
810
+ EntryPointsMap GlobalsSet;
812
811
813
812
bool DoSplit = SplitMode.getNumOccurrences () > 0 ;
814
813
@@ -896,13 +895,13 @@ TableFiles processOneModule(ModuleUPtr M, bool IsEsimd, bool SyclAndEsimdCode) {
896
895
return TblFiles;
897
896
}
898
897
899
- using ModulePair = std::pair<ModuleUPtr, ModuleUPtr >;
898
+ using ModulePair = std::pair<std::unique_ptr<Module>, std::unique_ptr<Module> >;
900
899
901
900
// This function splits a module with a mix of SYCL and ESIMD kernels
902
901
// into two separate modules.
903
- ModulePair splitSyclEsimd (ModuleUPtr M) {
904
- FuncPtrVector SyclFunctions;
905
- FuncPtrVector EsimdFunctions;
902
+ ModulePair splitSyclEsimd (std::unique_ptr<Module> M) {
903
+ std::vector< const Function *> SyclFunctions;
904
+ std::vector< const Function *> EsimdFunctions;
906
905
// Collect information about the SYCL and ESIMD functions in the module.
907
906
// Only process module entry points.
908
907
for (const auto &F : M->functions ()) {
@@ -916,29 +915,29 @@ ModulePair splitSyclEsimd(ModuleUPtr M) {
916
915
917
916
// If only SYCL kernels or only ESIMD kernels, no splitting needed.
918
917
if (EsimdFunctions.empty ())
919
- return std::make_pair (std::move (M), ModuleUPtr (nullptr ));
918
+ return std::make_pair (std::move (M), std::unique_ptr<Module> (nullptr ));
920
919
921
920
if (SyclFunctions.empty ())
922
- return std::make_pair (ModuleUPtr (nullptr ), std::move (M));
921
+ return std::make_pair (std::unique_ptr<Module> (nullptr ), std::move (M));
923
922
924
923
// Key values in KernelModuleMap are not significant, but they define the
925
924
// order, in which entry points are processed in the splitModule function. The
926
925
// caller of the splitSyclEsimd function expects a pair of 1-Sycl and 2-Esimd
927
926
// modules, hence the strings names below.
928
- EntryPointsSet KernelModuleMap (
927
+ EntryPointsMap KernelModuleMap (
929
928
{{" 1-SYCL" , SyclFunctions}, {" 2-ESIMD" , EsimdFunctions}});
930
929
std::vector<ResultModule> ResultModules = splitModule (*M, KernelModuleMap);
931
930
assert (ResultModules.size () == 2 );
932
931
return std::make_pair (std::move (ResultModules[0 ].ModulePtr ),
933
932
std::move (ResultModules[1 ].ModulePtr ));
934
933
}
935
934
936
- TableFiles processInputModule (ModuleUPtr M) {
935
+ TableFiles processInputModule (std::unique_ptr<Module> M) {
937
936
if (!SplitEsimd)
938
937
return processOneModule (std::move (M), false , false );
939
938
940
- ModuleUPtr SyclModule;
941
- ModuleUPtr EsimdModule;
939
+ std::unique_ptr<Module> SyclModule;
940
+ std::unique_ptr<Module> EsimdModule;
942
941
std::tie (SyclModule, EsimdModule) = splitSyclEsimd (std::move (M));
943
942
944
943
// Do we have both Sycl and Esimd code?
@@ -1061,7 +1060,7 @@ int main(int argc, char **argv) {
1061
1060
return 1 ;
1062
1061
}
1063
1062
SMDiagnostic Err;
1064
- ModuleUPtr M = parseIRFile (InputFilename, Err, Context);
1063
+ std::unique_ptr<Module> M = parseIRFile (InputFilename, Err, Context);
1065
1064
// It is OK to use raw pointer here as we control that it does not outlive M
1066
1065
// or objects it is moved to
1067
1066
Module *MPtr = M.get ();
0 commit comments