Skip to content

Commit e16efea

Browse files
[sycl-post-link][NFC] Refactored writing to the output table (#3043)
This patch is a preparation for spliting ESIMD and SYCL kernels.
1 parent a05f5de commit e16efea

File tree

1 file changed

+31
-14
lines changed

1 file changed

+31
-14
lines changed

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

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -614,8 +614,10 @@ static string_vector saveResultSymbolsLists(string_vector &ResSymbolsLists) {
614614
} \
615615
}
616616

617-
static int processOneModule(std::unique_ptr<Module> M,
618-
util::SimpleTable &Table) {
617+
using TableFiles = std::map<StringRef, string_vector>;
618+
619+
static TableFiles processOneModule(std::unique_ptr<Module> M) {
620+
TableFiles TblFiles;
619621
std::map<StringRef, std::vector<Function *>> GlobalsSet;
620622

621623
bool DoSplit = SplitMode.getNumOccurrences() > 0;
@@ -657,7 +659,7 @@ static int processOneModule(std::unique_ptr<Module> M,
657659
if (IROutputOnly) {
658660
// the result is the transformed input LLVMIR file rather than a file table
659661
saveModule(*M, OutputFilename);
660-
return 0;
662+
return TblFiles;
661663
}
662664
if (DoSplit) {
663665
splitModule(*M, GlobalsSet, ResultModules);
@@ -673,16 +675,16 @@ static int processOneModule(std::unique_ptr<Module> M,
673675
? saveResultModules(ResultModules)
674676
: string_vector{InputFilename};
675677
// "Code" column is always output
676-
Error Err = Table.addColumn(COL_CODE, Files);
677-
CHECK_AND_EXIT(Err);
678+
std::copy(Files.begin(), Files.end(),
679+
std::back_inserter(TblFiles[COL_CODE]));
678680
}
679681

680682
{
681683
ImagePropSaveInfo ImgPSInfo = {true, DoSpecConst, SetSpecConstAtRT,
682684
SpecConstsMet, EmitKernelParamInfo};
683685
string_vector Files = saveDeviceImageProperty(ResultModules, ImgPSInfo);
684-
Error Err = Table.addColumn(COL_PROPS, Files);
685-
CHECK_AND_EXIT(Err);
686+
std::copy(Files.begin(), Files.end(),
687+
std::back_inserter(TblFiles[COL_PROPS]));
686688
}
687689
if (DoSymGen) {
688690
// extract symbols per each module
@@ -693,10 +695,10 @@ static int processOneModule(std::unique_ptr<Module> M,
693695
ResultSymbolsLists.push_back("");
694696
}
695697
string_vector Files = saveResultSymbolsLists(ResultSymbolsLists);
696-
Error Err = Table.addColumn(COL_SYM, Files);
697-
CHECK_AND_EXIT(Err);
698+
std::copy(Files.begin(), Files.end(),
699+
std::back_inserter(TblFiles[COL_SYM]));
698700
}
699-
return 0;
701+
return TblFiles;
700702
}
701703

702704
int main(int argc, char **argv) {
@@ -789,14 +791,29 @@ int main(int argc, char **argv) {
789791
if (OutputFilename.getNumOccurrences() == 0)
790792
OutputFilename = (Twine(sys::path::stem(InputFilename)) + ".files").str();
791793

792-
util::SimpleTable Table;
793-
int Res = processOneModule(std::move(M), Table);
794-
if (Res)
795-
return Res;
794+
TableFiles TblFiles = processOneModule(std::move(M));
796795

797796
if (IROutputOnly)
798797
return 0;
799798

799+
util::SimpleTable Table;
800+
auto addTableColumn = [&Table, &TblFiles](std::string Str) {
801+
auto &Files = TblFiles[Str];
802+
if (Files.empty())
803+
return 0;
804+
Error Err = Table.addColumn(Str, Files);
805+
CHECK_AND_EXIT(Err);
806+
return 0;
807+
};
808+
809+
int Res;
810+
if ((Res = addTableColumn(COL_CODE)) != 0)
811+
return Res;
812+
if ((Res = addTableColumn(COL_PROPS)) != 0)
813+
return Res;
814+
if ((Res = addTableColumn(COL_SYM)) != 0)
815+
return Res;
816+
800817
{
801818
std::error_code EC;
802819
raw_fd_ostream Out{OutputFilename, EC, sys::fs::OF_None};

0 commit comments

Comments
 (0)