Skip to content

Commit fbd2413

Browse files
committed
Apply remarks
1 parent 8ccf00b commit fbd2413

File tree

1 file changed

+31
-32
lines changed

1 file changed

+31
-32
lines changed

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

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,7 @@
5252
using namespace llvm;
5353

5454
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 *>>;
6056

6157
namespace {
6258

@@ -319,7 +315,7 @@ bool isEntryPoint(const Function &F) {
319315
// group along with IR it depends on (globals, functions from its call graph,
320316
// ...) will constitute a separate module.
321317
void collectEntryPointToModuleMap(const Module &M,
322-
EntryPointsSet &ResKernelModuleMap,
318+
EntryPointsMap &ResKernelModuleMap,
323319
KernelMapEntryScope EntryScope) {
324320

325321
// Only process module entry points:
@@ -361,11 +357,11 @@ HasAssertStatus hasAssertInFunctionCallGraph(const Function *Func) {
361357
// true - if there is an assertion in underlying functions,
362358
// false - if there are definetely no assertions in underlying functions.
363359
static std::map<const Function *, bool> hasAssertionInCallGraphMap;
364-
FuncPtrVector FuncCallStack;
360+
std::vector<const Function *> FuncCallStack;
365361

366-
static FuncPtrVector isIndirectlyCalledInGraph;
362+
static std::vector<const Function *> isIndirectlyCalledInGraph;
367363

368-
FuncPtrVector Workstack;
364+
std::vector<const Function *> Workstack;
369365
Workstack.push_back(Func);
370366

371367
while (!Workstack.empty()) {
@@ -440,11 +436,11 @@ HasAssertStatus hasAssertInFunctionCallGraph(const Function *Func) {
440436
return No_Assert;
441437
}
442438

443-
StringRefVector getKernelNamesUsingAssert(const Module &M) {
444-
StringRefVector Result;
439+
std::vector<StringRef> getKernelNamesUsingAssert(const Module &M) {
440+
std::vector<StringRef> Result;
445441

446442
bool HasIndirectlyCalledAssert = false;
447-
FuncPtrVector Kernels;
443+
std::vector<const Function *> Kernels;
448444
for (const auto &F : M.functions()) {
449445
// TODO: handle SYCL_EXTERNAL functions for dynamic linkage.
450446
// TODO: handle function pointers.
@@ -497,7 +493,7 @@ std::vector<uint32_t> getKernelReqdWorkGroupSizeMetadata(const Function &Func) {
497493
// names from the same module separated by \n.
498494
// The function saves names of entry points from one group to a single
499495
// std::string and stores this string to the ResSymbolsLists vector.
500-
string_vector collectSymbolsLists(const EntryPointsSet &KernelModuleMap) {
496+
string_vector collectSymbolsLists(const EntryPointsMap &KernelModuleMap) {
501497
string_vector ResSymbolsLists{};
502498
for (const auto &It : KernelModuleMap) {
503499
std::string SymbolsList;
@@ -512,7 +508,7 @@ string_vector collectSymbolsLists(const EntryPointsSet &KernelModuleMap) {
512508

513509
struct ResultModule {
514510
StringRef KernelModuleName;
515-
ModuleUPtr ModulePtr;
511+
std::unique_ptr<Module> ModulePtr;
516512
};
517513

518514
// Input parameter KernelModuleMap is a map containing groups of entry points
@@ -522,13 +518,13 @@ struct ResultModule {
522518
// The function splits input LLVM IR module M into smaller ones and stores them
523519
// to the ResModules vector.
524520
std::vector<ResultModule> splitModule(const Module &M,
525-
const EntryPointsSet &KernelModuleMap) {
521+
const EntryPointsMap &KernelModuleMap) {
526522
std::vector<ResultModule> ResModules{};
527523

528524
for (const auto &It : KernelModuleMap) {
529525
// For each group of entry points collect all dependencies.
530526
SetVector<const GlobalValue *> GVs;
531-
FuncPtrVector Workqueue;
527+
std::vector<const Function *> Workqueue;
532528

533529
for (const auto &F : It.second) {
534530
GVs.insert(F);
@@ -559,7 +555,7 @@ std::vector<ResultModule> splitModule(const Module &M,
559555
ValueToValueMapTy VMap;
560556
// Clone definitions only for needed globals. Others will be added as
561557
// declarations and removed later.
562-
ModuleUPtr MClone = CloneModule(
558+
std::unique_ptr<Module> MClone = CloneModule(
563559
M, VMap, [&](const GlobalValue *GV) { return GVs.count(GV); });
564560

565561
// TODO: Use the new PassManager instead?
@@ -621,8 +617,10 @@ string_vector saveResultModules(const std::vector<ResultModule> &ResModules,
621617

622618
string_vector
623619
saveDeviceImageProperty(const std::vector<ResultModule> &ResultModules,
624-
const EntryPointsSet &KernelModuleMap,
620+
const EntryPointsMap &KernelModuleMap,
625621
const ImagePropSaveInfo &ImgPSInfo) {
622+
using PropSetRegTy = llvm::util::PropertySetRegistry;
623+
626624
string_vector Res;
627625
legacy::PassManager GetSYCLDeviceLibReqMask;
628626
auto *SDLReqMaskLegacyPass = new SYCLDeviceLibReqMaskPass();
@@ -716,7 +714,7 @@ saveDeviceImageProperty(const std::vector<ResultModule> &ResultModules,
716714
PropSet[PropSetRegTy::SYCL_MISC_PROP].insert({"isEsimdImage", true});
717715

718716
{
719-
StringRefVector FuncNames = getKernelNamesUsingAssert(M);
717+
std::vector<StringRef> FuncNames = getKernelNamesUsingAssert(M);
720718
for (const StringRef &FName : FuncNames)
721719
PropSet[PropSetRegTy::SYCL_ASSERT_USED].insert({FName, true});
722720
}
@@ -786,7 +784,8 @@ void LowerEsimdConstructs(Module &M) {
786784

787785
using TableFiles = std::map<StringRef, string_vector>;
788786

789-
TableFiles processOneModule(ModuleUPtr M, bool IsEsimd, bool SyclAndEsimdCode) {
787+
TableFiles processOneModule(std::unique_ptr<Module> M, bool IsEsimd,
788+
bool SyclAndEsimdCode) {
790789
TableFiles TblFiles;
791790
if (!M)
792791
return TblFiles;
@@ -808,7 +807,7 @@ TableFiles processOneModule(ModuleUPtr M, bool IsEsimd, bool SyclAndEsimdCode) {
808807
if (IsEsimd && LowerEsimd)
809808
LowerEsimdConstructs(*M);
810809

811-
EntryPointsSet GlobalsSet;
810+
EntryPointsMap GlobalsSet;
812811

813812
bool DoSplit = SplitMode.getNumOccurrences() > 0;
814813

@@ -896,13 +895,13 @@ TableFiles processOneModule(ModuleUPtr M, bool IsEsimd, bool SyclAndEsimdCode) {
896895
return TblFiles;
897896
}
898897

899-
using ModulePair = std::pair<ModuleUPtr, ModuleUPtr>;
898+
using ModulePair = std::pair<std::unique_ptr<Module>, std::unique_ptr<Module>>;
900899

901900
// This function splits a module with a mix of SYCL and ESIMD kernels
902901
// 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;
906905
// Collect information about the SYCL and ESIMD functions in the module.
907906
// Only process module entry points.
908907
for (const auto &F : M->functions()) {
@@ -916,29 +915,29 @@ ModulePair splitSyclEsimd(ModuleUPtr M) {
916915

917916
// If only SYCL kernels or only ESIMD kernels, no splitting needed.
918917
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));
920919

921920
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));
923922

924923
// Key values in KernelModuleMap are not significant, but they define the
925924
// order, in which entry points are processed in the splitModule function. The
926925
// caller of the splitSyclEsimd function expects a pair of 1-Sycl and 2-Esimd
927926
// modules, hence the strings names below.
928-
EntryPointsSet KernelModuleMap(
927+
EntryPointsMap KernelModuleMap(
929928
{{"1-SYCL", SyclFunctions}, {"2-ESIMD", EsimdFunctions}});
930929
std::vector<ResultModule> ResultModules = splitModule(*M, KernelModuleMap);
931930
assert(ResultModules.size() == 2);
932931
return std::make_pair(std::move(ResultModules[0].ModulePtr),
933932
std::move(ResultModules[1].ModulePtr));
934933
}
935934

936-
TableFiles processInputModule(ModuleUPtr M) {
935+
TableFiles processInputModule(std::unique_ptr<Module> M) {
937936
if (!SplitEsimd)
938937
return processOneModule(std::move(M), false, false);
939938

940-
ModuleUPtr SyclModule;
941-
ModuleUPtr EsimdModule;
939+
std::unique_ptr<Module> SyclModule;
940+
std::unique_ptr<Module> EsimdModule;
942941
std::tie(SyclModule, EsimdModule) = splitSyclEsimd(std::move(M));
943942

944943
// Do we have both Sycl and Esimd code?
@@ -1061,7 +1060,7 @@ int main(int argc, char **argv) {
10611060
return 1;
10621061
}
10631062
SMDiagnostic Err;
1064-
ModuleUPtr M = parseIRFile(InputFilename, Err, Context);
1063+
std::unique_ptr<Module> M = parseIRFile(InputFilename, Err, Context);
10651064
// It is OK to use raw pointer here as we control that it does not outlive M
10661065
// or objects it is moved to
10671066
Module *MPtr = M.get();

0 commit comments

Comments
 (0)