Skip to content

Commit 0fde11d

Browse files
[sycl-post-link][NFC] Refactored writing to the output table
This patch is a preparation for spliting ESIMD and SYCL kernels.
1 parent d60195b commit 0fde11d

File tree

1 file changed

+29
-12
lines changed

1 file changed

+29
-12
lines changed

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

Lines changed: 29 additions & 12 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,9 +791,24 @@ int main(int argc, char **argv) {
789791
if (OutputFilename.getNumOccurrences() == 0)
790792
OutputFilename = (Twine(sys::path::stem(InputFilename)) + ".files").str();
791793

794+
TableFiles TblFiles = processOneModule(std::move(M));
792795
util::SimpleTable Table;
793-
int Res = processOneModule(std::move(M), Table);
794-
if (Res)
796+
797+
auto addTableColumn = [&Table, &TblFiles](std::string Str) {
798+
auto &Files = TblFiles[Str];
799+
if (Files.empty())
800+
return 0;
801+
Error Err = Table.addColumn(Str, Files);
802+
CHECK_AND_EXIT(Err);
803+
return 0;
804+
};
805+
806+
int Res;
807+
if ((Res = addTableColumn(COL_CODE)) != 0)
808+
return Res;
809+
if ((Res = addTableColumn(COL_PROPS)) != 0)
810+
return Res;
811+
if ((Res = addTableColumn(COL_SYM)) != 0)
795812
return Res;
796813

797814
if (IROutputOnly)

0 commit comments

Comments
 (0)