@@ -735,32 +735,52 @@ SYCLDeviceLibFuncMap SDLMap = {
735735
736736} // namespace
737737
738- // Each fallback device library corresponds to one SPV file whose name is kept
739- // in DeviceLibSPVExtMap.
740- static std::unordered_map<DeviceLibExt, const char *> DeviceLibSPVExtMap = {
741- {DeviceLibExt::cl_intel_devicelib_assert, " libsycl-fallback-cassert.spv" },
742- {DeviceLibExt::cl_intel_devicelib_math, " libsycl-fallback-cmath.spv" },
738+ // One devicelib extension may correspond to multiple spv files, following
739+ // map stores corresponding index values in SPVMetaList for an extension.
740+ static std::unordered_map<DeviceLibExt, std::vector<size_t >>
741+ DeviceLibSPVExtMap = {{DeviceLibExt::cl_intel_devicelib_assert, {0 }},
742+ {DeviceLibExt::cl_intel_devicelib_math, {1 }},
743+ {DeviceLibExt::cl_intel_devicelib_math_fp64, {2 }},
744+ {DeviceLibExt::cl_intel_devicelib_complex, {3 }},
745+ {DeviceLibExt::cl_intel_devicelib_complex_fp64, {4 }},
746+ {DeviceLibExt::cl_intel_devicelib_cstring, {5 }},
747+ {DeviceLibExt::cl_intel_devicelib_imf, {6 }},
748+ {DeviceLibExt::cl_intel_devicelib_imf_fp64, {7 }},
749+ {DeviceLibExt::cl_intel_devicelib_imf_bf16, {8 }},
750+ {DeviceLibExt::cl_intel_devicelib_bfloat16, {9 , 10 }}};
751+
752+ static SYCLDeviceLibSPVMeta SPVMetaList[] = {
753+ {DeviceLibExt::cl_intel_devicelib_assert, " libsycl-fallback-cassert.spv" ,
754+ DeviceLibIsNative::Ignore},
755+ {DeviceLibExt::cl_intel_devicelib_math, " libsycl-fallback-cmath.spv" ,
756+ DeviceLibIsNative::Ignore},
743757 {DeviceLibExt::cl_intel_devicelib_math_fp64,
744- " libsycl-fallback-cmath-fp64.spv" },
745- {DeviceLibExt::cl_intel_devicelib_complex, " libsycl-fallback-complex.spv" },
758+ " libsycl-fallback-cmath-fp64.spv" , DeviceLibIsNative::Ignore},
759+ {DeviceLibExt::cl_intel_devicelib_complex, " libsycl-fallback-complex.spv" ,
760+ DeviceLibIsNative::Ignore},
746761 {DeviceLibExt::cl_intel_devicelib_complex_fp64,
747- " libsycl-fallback-complex-fp64.spv" },
748- {DeviceLibExt::cl_intel_devicelib_cstring, " libsycl-fallback-cstring.spv" },
749- {DeviceLibExt::cl_intel_devicelib_imf, " libsycl-fallback-imf.spv" },
750- {DeviceLibExt::cl_intel_devicelib_imf_fp64,
751- " libsycl-fallback-imf-fp64.spv" },
752- {DeviceLibExt::cl_intel_devicelib_imf_bf16,
753- " libsycl-fallback-imf-bf16.spv" },
754- {DeviceLibExt::cl_intel_devicelib_bfloat16,
755- " libsycl-fallback-bfloat16.spv" }};
762+ " libsycl-fallback-complex-fp64.spv" , DeviceLibIsNative::Ignore},
763+ {DeviceLibExt::cl_intel_devicelib_cstring, " libsycl-fallback-cstring.spv" ,
764+ DeviceLibIsNative::Ignore},
765+ {DeviceLibExt::cl_intel_devicelib_imf, " libsycl-fallback-imf.spv" ,
766+ DeviceLibIsNative::Ignore},
767+ {DeviceLibExt::cl_intel_devicelib_imf_fp64, " libsycl-fallback-imf-fp64.spv" ,
768+ DeviceLibIsNative::Ignore},
769+ {DeviceLibExt::cl_intel_devicelib_imf_bf16, " libsycl-fallback-imf-bf16.spv" ,
770+ DeviceLibIsNative::Ignore},
771+ {DeviceLibExt::cl_intel_devicelib_bfloat16, " libsycl-fallback-bfloat16.spv" ,
772+ DeviceLibIsNative::No},
773+ {DeviceLibExt::cl_intel_devicelib_bfloat16, " libsycl-native-bfloat16.spv" ,
774+ DeviceLibIsNative::Yes}};
756775
757776namespace llvm {
758777// For each device image module, we go through all functions which meets
759778// 1. The function name has prefix "__devicelib_"
760779// 2. The function is declaration which means it doesn't have function body
761780// And we don't expect non-spirv functions with "__devicelib_" prefix.
762781void getRequiredSYCLDeviceLibs (
763- const Module &M, llvm::SmallVector<DeviceLibExt, 16 > &ReqDeviceLibs) {
782+ const Module &M,
783+ llvm::SmallVector<SYCLDeviceLibSPVMeta, 16 > &ReqDeviceLibs) {
764784 // Device libraries will be enabled only for spir-v module.
765785 if (!Triple (M.getTargetTriple ()).isSPIROrSPIRV ())
766786 return ;
@@ -776,12 +796,10 @@ void getRequiredSYCLDeviceLibs(
776796 continue ;
777797
778798 DeviceLibUsed.insert (DeviceLibFuncIter->second );
779- ReqDeviceLibs.push_back (DeviceLibFuncIter->second );
799+ for (size_t idx : DeviceLibSPVExtMap[DeviceLibFuncIter->second ]) {
800+ ReqDeviceLibs.push_back (SPVMetaList[idx]);
801+ }
780802 }
781803 }
782804}
783-
784- const char *getDeviceLibFileName (DeviceLibExt RequiredDeviceLibExt) {
785- return DeviceLibSPVExtMap[RequiredDeviceLibExt];
786- }
787805} // namespace llvm
0 commit comments