@@ -104,7 +104,7 @@ cl::opt<std::string> OutputDir{
104
104
cl::value_desc (" dirname" ), cl::cat (PostLinkCat)};
105
105
106
106
struct TargetFilenamePair {
107
- std::optional<std:: string> Target;
107
+ std::string Target;
108
108
std::string Filename;
109
109
};
110
110
@@ -305,13 +305,21 @@ std::string saveModuleIR(Module &M, int I, StringRef Suff) {
305
305
306
306
std::string saveModuleProperties (module_split::ModuleDesc &MD,
307
307
const GlobalBinImageProps &GlobProps, int I,
308
- StringRef Suff) {
309
- const auto &PropSet = computeModuleProperties (
310
- MD.getModule (), MD.entries (), GlobProps, MD.Props .SpecConstsMet ,
311
- MD.isSpecConstantDefault ());
308
+ StringRef Suff, StringRef Target = " " ) {
309
+ auto PropSet = computeModuleProperties (MD.getModule (), MD.entries (),
310
+ GlobProps, MD.Props .SpecConstsMet ,
311
+ MD.isSpecConstantDefault ());
312
+
313
+ std::string NewSuff = Suff.str ();
314
+ if (!Target.empty ()) {
315
+ PropSet.add (PropSetRegTy::SYCL_DEVICE_REQUIREMENTS, " compile_target" ,
316
+ Target);
317
+ NewSuff += " _" ;
318
+ NewSuff += Target;
319
+ }
312
320
313
321
std::error_code EC;
314
- std::string SCFile = makeResultFileName (" .prop" , I, Suff );
322
+ std::string SCFile = makeResultFileName (" .prop" , I, NewSuff );
315
323
raw_fd_ostream SCOut (SCFile, EC);
316
324
checkError (EC, " error opening file '" + SCFile + " '" );
317
325
PropSet.write (SCOut);
@@ -396,35 +404,46 @@ StringRef getModuleSuffix(const module_split::ModuleDesc &MD) {
396
404
return MD.isESIMD () ? " _esimd" : " " ;
397
405
}
398
406
407
+ bool isTargetCompatibleWithModule (const std::string &Target,
408
+ module_split::ModuleDesc &IrMD);
409
+
410
+ void addTableRow (util::SimpleTable &Table,
411
+ const IrPropSymFilenameTriple &RowData);
412
+
413
+ // @param OutTables List of tables (one for each target) to output results
399
414
// @param MD Module descriptor to save
400
415
// @param IRFilename filename of already available IR component. If not empty,
401
416
// IR component saving is skipped, and this file name is recorded as such in
402
417
// the result.
403
- // @return a triple of files where IR, Property and Symbols components of the
404
- // Module descriptor are written respectively.
405
- IrPropSymFilenameTriple saveModule (module_split::ModuleDesc &MD, int I,
406
- StringRef IRFilename = " " ) {
407
- IrPropSymFilenameTriple Res;
418
+ void saveModule (std::vector<std::unique_ptr<util::SimpleTable>> &OutTables,
419
+ module_split::ModuleDesc &MD, int I, StringRef IRFilename) {
420
+ IrPropSymFilenameTriple BaseTriple;
408
421
StringRef Suffix = getModuleSuffix (MD);
409
-
410
422
if (!IRFilename.empty ()) {
411
423
// don't save IR, just record the filename
412
- Res .Ir = IRFilename.str ();
424
+ BaseTriple .Ir = IRFilename.str ();
413
425
} else {
414
426
MD.cleanup ();
415
- Res .Ir = saveModuleIR (MD.getModule (), I, Suffix);
427
+ BaseTriple .Ir = saveModuleIR (MD.getModule (), I, Suffix);
416
428
}
417
- GlobalBinImageProps Props = {EmitKernelParamInfo, EmitProgramMetadata,
418
- EmitExportedSymbols, EmitImportedSymbols,
419
- DeviceGlobals};
420
- if (DoPropGen)
421
- Res.Prop = saveModuleProperties (MD, Props, I, Suffix);
422
-
423
429
if (DoSymGen) {
424
430
// save the names of the entry points - the symbol table
425
- Res.Sym = saveModuleSymbolTable (MD, I, Suffix);
431
+ BaseTriple.Sym = saveModuleSymbolTable (MD, I, Suffix);
432
+ }
433
+
434
+ for (const auto &[Table, OutputFile] : zip_equal (OutTables, OutputFiles)) {
435
+ if (!isTargetCompatibleWithModule (OutputFile.Target , MD))
436
+ continue ;
437
+ auto CopyTriple = BaseTriple;
438
+ if (DoPropGen) {
439
+ GlobalBinImageProps Props = {EmitKernelParamInfo, EmitProgramMetadata,
440
+ EmitExportedSymbols, EmitImportedSymbols,
441
+ DeviceGlobals};
442
+ CopyTriple.Prop =
443
+ saveModuleProperties (MD, Props, I, Suffix, OutputFile.Target );
444
+ }
445
+ addTableRow (*Table, CopyTriple);
426
446
}
427
- return Res;
428
447
}
429
448
430
449
module_split::ModuleDesc link (module_split::ModuleDesc &&MD1,
@@ -680,25 +699,25 @@ handleESIMD(module_split::ModuleDesc &&MDesc, bool &Modified,
680
699
// information comes from the device config file (DeviceConfigFile.td).
681
700
// For example, the intel_gpu_tgllp target does not support fp64 - therefore,
682
701
// a module using fp64 would *not* be compatible with intel_gpu_tgllp.
683
- bool isTargetCompatibleWithModule (const std::optional<std:: string> &Target,
702
+ bool isTargetCompatibleWithModule (const std::string &Target,
684
703
module_split::ModuleDesc &IrMD) {
685
704
// When the user does not specify a target,
686
705
// (e.g. -o out.table compared to -o intel_gpu_pvc,out-pvc.table)
687
- // Target will have no value and we will not want to perform any filtering, so
706
+ // Target will be empty and we will not want to perform any filtering, so
688
707
// we return true here.
689
- if (! Target.has_value ())
708
+ if (Target.empty ())
690
709
return true ;
691
710
692
711
// TODO: If a target not found in the device config file is passed,
693
712
// to sycl-post-link, then we should probably throw an error. However,
694
713
// since not all the information for all the targets is filled out
695
714
// right now, we return true, having the affect that unrecognized
696
715
// targets have no filtering applied to them.
697
- if (!is_contained (DeviceConfigFile::TargetTable, * Target))
716
+ if (!is_contained (DeviceConfigFile::TargetTable, Target))
698
717
return true ;
699
718
700
719
const DeviceConfigFile::TargetInfo &TargetInfo =
701
- DeviceConfigFile::TargetTable[* Target];
720
+ DeviceConfigFile::TargetTable[Target];
702
721
const SYCLDeviceRequirements &ModuleReqs =
703
722
IrMD.getOrComputeDeviceRequirements ();
704
723
@@ -856,21 +875,15 @@ processInputModule(std::unique_ptr<Module> M) {
856
875
" have been made\n " ;
857
876
}
858
877
for (module_split::ModuleDesc &IrMD : MMs) {
859
- IrPropSymFilenameTriple T = saveModule (IrMD, ID, OutIRFileName);
860
- for (const auto &[Table, OutputFile] : zip_equal (Tables, OutputFiles))
861
- if (isTargetCompatibleWithModule (OutputFile.Target , IrMD))
862
- addTableRow (*Table, T);
878
+ saveModule (Tables, IrMD, ID, OutIRFileName);
863
879
}
864
880
865
881
++ID;
866
882
867
883
if (!MMsWithDefaultSpecConsts.empty ()) {
868
884
for (size_t i = 0 ; i != MMsWithDefaultSpecConsts.size (); ++i) {
869
885
module_split::ModuleDesc &IrMD = MMsWithDefaultSpecConsts[i];
870
- IrPropSymFilenameTriple T = saveModule (IrMD, ID, OutIRFileName);
871
- for (const auto &[Table, OutputFile] : zip_equal (Tables, OutputFiles))
872
- if (isTargetCompatibleWithModule (OutputFile.Target , IrMD))
873
- addTableRow (*Table, T);
886
+ saveModule (Tables, IrMD, ID, OutIRFileName);
874
887
}
875
888
876
889
++ID;
0 commit comments