From 96267409660aa15d6d432c3fb5819dbfa5ed8274 Mon Sep 17 00:00:00 2001 From: Steffen Larsen Date: Thu, 23 Sep 2021 13:45:49 +0300 Subject: [PATCH 1/5] [sycl-post-link] Adds property listing exported functions These changes make sycl-post-link generate a list of exported functions as properties for each generated module. This is enabled through the -emit-exported-symbols option. The properties follow the naming proposed in the "Dynamic linking of device code" documentation. Signed-off-by: Steffen Larsen --- clang/lib/Driver/ToolChains/Clang.cpp | 1 + llvm/include/llvm/Support/PropertySetIO.h | 1 + llvm/lib/Support/PropertySetIO.cpp | 1 + .../sycl-post-link/emit_exported_symbols.ll | 129 ++++++++++++++++++ llvm/tools/sycl-post-link/sycl-post-link.cpp | 88 ++++++++---- sycl/include/CL/sycl/detail/pi.h | 3 + 6 files changed, 196 insertions(+), 27 deletions(-) create mode 100644 llvm/test/tools/sycl-post-link/emit_exported_symbols.ll diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 28a6e96fba2ab..f942dd16049de 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -8941,6 +8941,7 @@ void SYCLPostLink::ConstructJob(Compilation &C, const JobAction &JA, // Symbol file and specialization constant info generation is mandatory - // add options unconditionally addArgs(CmdArgs, TCArgs, {"-symbols"}); + addArgs(CmdArgs, TCArgs, {"-emit-exported-symbols"}); addArgs(CmdArgs, TCArgs, {"-split-esimd"}); addArgs(CmdArgs, TCArgs, {"-lower-esimd"}); } diff --git a/llvm/include/llvm/Support/PropertySetIO.h b/llvm/include/llvm/Support/PropertySetIO.h index ee5c8443deb06..d2875c441aa7c 100644 --- a/llvm/include/llvm/Support/PropertySetIO.h +++ b/llvm/include/llvm/Support/PropertySetIO.h @@ -191,6 +191,7 @@ class PropertySetRegistry { static constexpr char SYCL_PROGRAM_METADATA[] = "SYCL/program metadata"; static constexpr char SYCL_MISC_PROP[] = "SYCL/misc properties"; static constexpr char SYCL_ASSERT_USED[] = "SYCL/assert used"; + static constexpr char SYCL_EXPORTED_SYMBOLS[] = "SYCL/exported symbols"; // Function for bulk addition of an entire property set under given category // (property set name). diff --git a/llvm/lib/Support/PropertySetIO.cpp b/llvm/lib/Support/PropertySetIO.cpp index 1e92f1f8b9e3f..1d805b9610b06 100644 --- a/llvm/lib/Support/PropertySetIO.cpp +++ b/llvm/lib/Support/PropertySetIO.cpp @@ -200,6 +200,7 @@ constexpr char PropertySetRegistry::SYCL_KERNEL_PARAM_OPT_INFO[]; constexpr char PropertySetRegistry::SYCL_PROGRAM_METADATA[]; constexpr char PropertySetRegistry::SYCL_MISC_PROP[]; constexpr char PropertySetRegistry::SYCL_ASSERT_USED[]; +constexpr char PropertySetRegistry::SYCL_EXPORTED_SYMBOLS[]; } // namespace util } // namespace llvm diff --git a/llvm/test/tools/sycl-post-link/emit_exported_symbols.ll b/llvm/test/tools/sycl-post-link/emit_exported_symbols.ll new file mode 100644 index 0000000000000..f96e26c5de507 --- /dev/null +++ b/llvm/test/tools/sycl-post-link/emit_exported_symbols.ll @@ -0,0 +1,129 @@ +; This test checks that the post-link tool generates list of exported symbols. +; +; Global scope +; RUN: sycl-post-link -symbols -emit-exported-symbols -S %s -o %t.global.files.table +; RUN: FileCheck %s -input-file=%t.global.files.table --check-prefixes CHECK-GLOBAL-TABLE +; RUN: FileCheck %s -input-file=%t.global.files_0.prop --check-prefixes CHECK-GLOBAL-PROP +; +; Per-module split +; RUN: sycl-post-link -symbols -split=source -emit-exported-symbols -S %s -o %t.per_module.files.table +; RUN: FileCheck %s -input-file=%t.per_module.files.table --check-prefixes CHECK-PERMODULE-TABLE +; RUN: FileCheck %s -input-file=%t.per_module.files_0.prop --check-prefixes CHECK-PERMODULE-0-PROP +; RUN: FileCheck %s -input-file=%t.per_module.files_1.prop --check-prefixes CHECK-PERMODULE-1-PROP +; RUN: FileCheck %s -input-file=%t.per_module.files_2.prop --check-prefixes CHECK-KERNELONLY-PROP +; +; Per-kernel split +; RUN: sycl-post-link -symbols -split=kernel -emit-exported-symbols -S %s -o %t.per_kernel.files.table +; RUN: FileCheck %s -input-file=%t.per_kernel.files.table --check-prefixes CHECK-PERKERNEL-TABLE +; RUN: FileCheck %s -input-file=%t.per_kernel.files_0.prop --check-prefixes CHECK-PERKERNEL-0-PROP +; RUN: FileCheck %s -input-file=%t.per_kernel.files_1.prop --check-prefixes CHECK-PERKERNEL-1-PROP +; RUN: FileCheck %s -input-file=%t.per_kernel.files_2.prop --check-prefixes CHECK-PERKERNEL-2-PROP +; RUN: FileCheck %s -input-file=%t.per_kernel.files_3.prop --check-prefixes CHECK-KERNELONLY-PROP +; RUN: FileCheck %s -input-file=%t.per_kernel.files_4.prop --check-prefixes CHECK-KERNELONLY-PROP + +target triple = "spir64-unknown-unknown" + +define dso_local spir_kernel void @SpirKernel1(float %arg1) #0 { +entry: + ret void +} + +define dso_local spir_kernel void @SpirKernel2(float %arg1) #2 { +entry: + ret void +} + +define dso_local spir_func void @ExportedSpirFunc1(float %arg1) #0 { +entry: + ret void +} + +define dso_local spir_func void @ExportedSpirFunc2(i32 %arg1, i32 %arg2) #1 { +entry: + ret void +} + +define dso_local spir_func void @ExportedSpirFunc3(float %arg1) #0 { +entry: + ret void +} + +define dso_local spir_func void @NotExportedSpirFunc1(float %arg1) { +entry: + ret void +} + +attributes #0 = { "sycl-module-id"="a.cpp" } +attributes #1 = { "sycl-module-id"="b.cpp" } +attributes #2 = { "sycl-module-id"="c.cpp" } + +; Global scope +; CHECK-GLOBAL-PROP: [SYCL/exported symbols] +; CHECK-GLOBAL-PROP-NEXT: ExportedSpirFunc1 +; CHECK-GLOBAL-PROP-NEXT: ExportedSpirFunc2 +; CHECK-GLOBAL-PROP-NEXT: ExportedSpirFunc3 +; CHECK-GLOBAL-PROP-NOT: SpirKernel1 +; CHECK-GLOBAL-PROP-NOT: NotExportedSpirFunc1 + +; CHECK-GLOBAL-TABLE: [Code|Properties|Symbols] +; CHECK-GLOBAL-TABLE-NEXT: {{.*}}global.files_0.prop +; CHECK-GLOBAL-TABLE-EMPTY: + +; Per-module split +; CHECK-PERMODULE-0-PROP: [SYCL/exported symbols] +; CHECK-PERMODULE-0-PROP-NEXT: ExportedSpirFunc1 +; CHECK-PERMODULE-0-PROP-NEXT: ExportedSpirFunc3 +; CHECK-PERMODULE-0-PROP-NOT: ExportedSpirFunc2 +; CHECK-PERMODULE-0-PROP-NOT: SpirKernel1 +; CHECK-PERMODULE-0-PROP-NOT: NotExportedSpirFunc1 + +; CHECK-PERMODULE-1-PROP: [SYCL/exported symbols] +; CHECK-PERMODULE-1-PROP-NEXT: ExportedSpirFunc2 +; CHECK-PERMODULE-1-PROP-NOT: ExportedSpirFunc1 +; CHECK-PERMODULE-1-PROP-NOT: ExportedSpirFunc3 +; CHECK-PERMODULE-1-PROP-NOT: SpirKernel1 +; CHECK-PERMODULE-1-PROP-NOT: NotExportedSpirFunc1 + +; CHECK-PERMODULE-TABLE: [Code|Properties|Symbols] +; CHECK-PERMODULE-TABLE-NEXT: {{.*}}per_module.files_0.prop +; CHECK-PERMODULE-TABLE-NEXT: {{.*}}per_module.files_1.prop +; CHECK-PERMODULE-TABLE-NEXT: {{.*}}per_module.files_2.prop +; CHECK-PERMODULE-TABLE-EMPTY: + +; Per-kernel split +; CHECK-PERKERNEL-0-PROP: [SYCL/exported symbols] +; CHECK-PERKERNEL-0-PROP-NEXT: ExportedSpirFunc1 +; CHECK-PERKERNEL-0-PROP-NOT: ExportedSpirFunc2 +; CHECK-PERKERNEL-0-PROP-NOT: ExportedSpirFunc3 +; CHECK-PERKERNEL-0-PROP-NOT: SpirKernel1 +; CHECK-PERKERNEL-0-PROP-NOT: NotExportedSpirFunc1 + +; CHECK-PERKERNEL-1-PROP: [SYCL/exported symbols] +; CHECK-PERKERNEL-1-PROP-NEXT: ExportedSpirFunc2 +; CHECK-PERKERNEL-1-PROP-NOT: ExportedSpirFunc1 +; CHECK-PERKERNEL-1-PROP-NOT: ExportedSpirFunc3 +; CHECK-PERKERNEL-1-PROP-NOT: SpirKernel1 +; CHECK-PERKERNEL-1-PROP-NOT: NotExportedSpirFunc1 + +; CHECK-PERKERNEL-2-PROP: [SYCL/exported symbols] +; CHECK-PERKERNEL-2-PROP-NEXT: ExportedSpirFunc3 +; CHECK-PERKERNEL-2-PROP-NOT: ExportedSpirFunc1 +; CHECK-PERKERNEL-2-PROP-NOT: ExportedSpirFunc2 +; CHECK-PERKERNEL-2-PROP-NOT: SpirKernel1 +; CHECK-PERKERNEL-2-PROP-NOT: NotExportedSpirFunc1 + +; CHECK-PERKERNEL-TABLE: [Code|Properties|Symbols] +; CHECK-PERKERNEL-TABLE-NEXT: {{.*}}per_kernel.files_0.prop +; CHECK-PERKERNEL-TABLE-NEXT: {{.*}}per_kernel.files_1.prop +; CHECK-PERKERNEL-TABLE-NEXT: {{.*}}per_kernel.files_2.prop +; CHECK-PERKERNEL-TABLE-NEXT: {{.*}}per_kernel.files_3.prop +; CHECK-PERKERNEL-TABLE-NEXT: {{.*}}per_kernel.files_4.prop +; CHECK-PERKERNEL-TABLE-EMPTY: + +; Kernel-only generated modules should have no exported Symbols +; CHECK-KERNELONLY-PROP-NOT: [SYCL/exported symbols] +; CHECK-KERNELONLY-PROP-NOT: ExportedSpirFunc3 +; CHECK-KERNELONLY-PROP-NOT: ExportedSpirFunc1 +; CHECK-KERNELONLY-PROP-NOT: ExportedSpirFunc2 +; CHECK-KERNELONLY-PROP-NOT: SpirKernel1 +; CHECK-KERNELONLY-PROP-NOT: NotExportedSpirFunc1 diff --git a/llvm/tools/sycl-post-link/sycl-post-link.cpp b/llvm/tools/sycl-post-link/sycl-post-link.cpp index 2e5c7af154ac4..3f87045f0b7f7 100644 --- a/llvm/tools/sycl-post-link/sycl-post-link.cpp +++ b/llvm/tools/sycl-post-link/sycl-post-link.cpp @@ -60,6 +60,9 @@ static constexpr char COL_SYM[] = "Symbols"; static constexpr char COL_PROPS[] = "Properties"; static constexpr char ATTR_SYCL_MODULE_ID[] = "sycl-module-id"; +// Identifying name for global scope +static constexpr char GLOBAL_SCOPE_NAME[] = ""; + // InputFilename - The filename to read from. static cl::opt InputFilename{ cl::Positional, cl::desc(""), cl::init("-"), @@ -168,6 +171,10 @@ static cl::opt EmitProgramMetadata{"emit-program-metadata", cl::desc("emit SYCL program metadata"), cl::cat(PostLinkCat)}; +static cl::opt EmitExportedSymbols{"emit-exported-symbols", + cl::desc("emit exported symbols"), + cl::cat(PostLinkCat)}; + struct ImagePropSaveInfo { bool NeedDeviceLibReqMask; bool DoSpecConst; @@ -175,6 +182,7 @@ struct ImagePropSaveInfo { bool SpecConstsMet; bool EmitKernelParamInfo; bool EmitProgramMetadata; + bool EmitExportedSymbols; bool IsEsimdKernel; }; @@ -278,7 +286,7 @@ static void collectKernelModuleMap( } case Scope_Global: // the map key is not significant here - ResKernelModuleMap[""].push_back(&F); + ResKernelModuleMap[GLOBAL_SCOPE_NAME].push_back(&F); break; } } else if (EntryScope == Scope_PerModule && @@ -417,16 +425,21 @@ static void collectSymbolsLists( } } +struct ResultModule { + StringRef KernelModuleName; + std::unique_ptr ModulePtr; +}; + // Input parameter KernelModuleMap is a map containing groups of kernels with // same values of the sycl-module-id attribute. For each group of kernels a // separate IR module will be produced. -// ResModules is a vector of produced modules. +// ResModules is a vector of pairs of kernel module names and produced modules. // The function splits input LLVM IR module M into smaller ones and stores them // to the ResModules vector. static void splitModule(Module &M, std::map> &KernelModuleMap, - std::vector> &ResModules) { + std::vector &ResModules) { for (auto &It : KernelModuleMap) { // For each group of kernels collect all dependencies. SetVector GVs; @@ -473,7 +486,7 @@ splitModule(Module &M, Passes.run(*MClone.get()); // Save results. - ResModules.push_back(std::move(MClone)); + ResModules.push_back({It.first, std::move(MClone)}); } } @@ -506,23 +519,23 @@ static void saveModule(Module &M, StringRef OutFilename) { // Saves specified collection of llvm IR modules to files. // Saves file list if user specified corresponding filename. -static string_vector -saveResultModules(std::vector> &ResModules, - StringRef Suffix) { +static string_vector saveResultModules(std::vector &ResModules, + StringRef Suffix) { string_vector Res; for (size_t I = 0; I < ResModules.size(); ++I) { std::error_code EC; StringRef FileExt = (OutputAssembly) ? ".ll" : ".bc"; std::string CurOutFileName = makeResultFileName(FileExt, I, Suffix); - saveModule(*ResModules[I].get(), CurOutFileName); + saveModule(*ResModules[I].ModulePtr, CurOutFileName); Res.emplace_back(std::move(CurOutFileName)); } return Res; } static string_vector saveDeviceImageProperty( - const std::vector> &ResultModules, + const std::vector &ResultModules, + const std::map> &KernelModuleMap, const ImagePropSaveInfo &ImgPSInfo) { string_vector Res; legacy::PassManager GetSYCLDeviceLibReqMask; @@ -532,7 +545,7 @@ static string_vector saveDeviceImageProperty( for (size_t I = 0; I < ResultModules.size(); ++I) { llvm::util::PropertySetRegistry PropSet; if (ImgPSInfo.NeedDeviceLibReqMask) { - GetSYCLDeviceLibReqMask.run(*ResultModules[I]); + GetSYCLDeviceLibReqMask.run(*ResultModules[I].ModulePtr); uint32_t MRMask = SDLReqMaskLegacyPass->getSYCLDeviceLibReqMask(); std::map RMEntry = {{"DeviceLibReqMask", MRMask}}; PropSet.add(llvm::util::PropertySetRegistry::SYCL_DEVICELIB_REQ_MASK, @@ -542,8 +555,8 @@ static string_vector saveDeviceImageProperty( if (ImgPSInfo.SpecConstsMet) { // extract spec constant maps per each module SpecIDMapTy TmpSpecIDMap; - SpecConstantsPass::collectSpecConstantMetadata(*ResultModules[I].get(), - TmpSpecIDMap); + SpecConstantsPass::collectSpecConstantMetadata( + *ResultModules[I].ModulePtr, TmpSpecIDMap); PropSet.add( llvm::util::PropertySetRegistry::SYCL_SPECIALIZATION_CONSTANTS, TmpSpecIDMap); @@ -553,7 +566,7 @@ static string_vector saveDeviceImageProperty( if (!ImgPSInfo.SetSpecConstAtRT) { std::vector DefaultValues; SpecConstantsPass::collectSpecConstantDefaultValuesMetadata( - *ResultModules[I].get(), DefaultValues); + *ResultModules[I].ModulePtr, DefaultValues); PropSet.add(llvm::util::PropertySetRegistry:: SYCL_SPEC_CONSTANTS_DEFAULT_VALUES, "all", DefaultValues); @@ -568,7 +581,8 @@ static string_vector saveDeviceImageProperty( // Register the payload analysis MAM.registerPass([&] { return SPIRKernelParamOptInfoAnalysis(); }); SPIRKernelParamOptInfo PInfo = - MAM.getResult(*ResultModules[I]); + MAM.getResult( + *ResultModules[I].ModulePtr); // convert analysis results into properties and record them llvm::util::PropertySet &Props = @@ -584,6 +598,19 @@ static string_vector saveDeviceImageProperty( NameInfoPair.first, llvm::util::PropertyValue(Data, DataBitSize))); } } + if (ImgPSInfo.EmitExportedSymbols) { + // For each result module, extract the exported functions + auto ModuleFunctionsIt = + KernelModuleMap.find(ResultModules[I].KernelModuleName); + if (ModuleFunctionsIt != KernelModuleMap.end()) { + for (auto &F : ModuleFunctionsIt->second) { + if (F->getCallingConv() == CallingConv::SPIR_FUNC) { + PropSet[llvm::util::PropertySetRegistry::SYCL_EXPORTED_SYMBOLS] + .insert({F->getName(), true}); + } + } + } + } // Metadata names may be composite so we keep them alive until the // properties have been written. @@ -593,7 +620,7 @@ static string_vector saveDeviceImageProperty( PropSet[llvm::util::PropertySetRegistry::SYCL_PROGRAM_METADATA]; // Add reqd_work_group_size information to program metadata - for (const Function &Func : ResultModules[I]->functions()) { + for (const Function &Func : ResultModules[I].ModulePtr->functions()) { std::vector KernelReqdWorkGroupSize = getKernelReqdWorkGroupSizeMetadata(Func); if (KernelReqdWorkGroupSize.empty()) @@ -609,7 +636,7 @@ static string_vector saveDeviceImageProperty( } { - Module *M = ResultModules[I].get(); + Module *M = ResultModules[I].ModulePtr.get(); bool HasIndirectlyCalledAssert = false; std::vector Kernels; for (auto &F : M->functions()) { @@ -748,7 +775,7 @@ static TableFiles processOneModule(std::unique_ptr M, bool IsEsimd, collectKernelModuleMap(*M, GlobalsSet, Scope); } - std::vector> ResultModules; + std::vector ResultModules; string_vector ResultSymbolsLists; bool SpecConstsMet = false; @@ -758,7 +785,7 @@ static TableFiles processOneModule(std::unique_ptr M, bool IsEsimd, splitModule(*M, GlobalsSet, ResultModules); // post-link always produces a code result, even if it is unmodified input if (ResultModules.empty()) - ResultModules.push_back(std::move(M)); + ResultModules.push_back({GLOBAL_SCOPE_NAME, std::move(M)}); if (DoSpecConst) { ModulePassManager RunSpecConst; @@ -768,17 +795,17 @@ static TableFiles processOneModule(std::unique_ptr M, bool IsEsimd, MAM.registerPass([&] { return PassInstrumentationAnalysis(); }); RunSpecConst.addPass(std::move(SCP)); - for (auto &MPtr : ResultModules) { + for (auto &ResultModule : ResultModules) { // perform the spec constant intrinsics transformation on each resulting // module - PreservedAnalyses Res = RunSpecConst.run(*MPtr, MAM); + PreservedAnalyses Res = RunSpecConst.run(*ResultModule.ModulePtr, MAM); SpecConstsMet |= !Res.areAllPreserved(); } } if (IROutputOnly) { // the result is the transformed input LLVMIR file rather than a file table - saveModule(*ResultModules.front(), OutputFilename); + saveModule(*ResultModules.front().ModulePtr, OutputFilename); return TblFiles; } @@ -803,8 +830,9 @@ static TableFiles processOneModule(std::unique_ptr M, bool IsEsimd, ImagePropSaveInfo ImgPSInfo = { true, DoSpecConst, SetSpecConstAtRT, SpecConstsMet, EmitKernelParamInfo, EmitProgramMetadata, - IsEsimd}; - string_vector Files = saveDeviceImageProperty(ResultModules, ImgPSInfo); + EmitExportedSymbols, IsEsimd}; + string_vector Files = + saveDeviceImageProperty(ResultModules, GlobalsSet, ImgPSInfo); std::copy(Files.begin(), Files.end(), std::back_inserter(TblFiles[COL_PROPS])); } @@ -859,11 +887,11 @@ static ModulePair splitSyclEsimd(std::unique_ptr M) { // modules, hence the strings names below. std::map> KernelModuleMap( {{"1-SYCL", SyclFunctions}, {"2-ESIMD", EsimdFunctions}}); - std::vector> ResultModules; + std::vector ResultModules; splitModule(*M, KernelModuleMap, ResultModules); assert(ResultModules.size() == 2); - return std::make_pair(std::move(ResultModules[0]), - std::move(ResultModules[1])); + return std::make_pair(std::move(ResultModules[0].ModulePtr), + std::move(ResultModules[1].ModulePtr)); } static TableFiles processInputModule(std::unique_ptr M) { @@ -954,9 +982,10 @@ int main(int argc, char **argv) { bool DoSpecConst = SpecConstLower.getNumOccurrences() > 0; bool DoParamInfo = EmitKernelParamInfo.getNumOccurrences() > 0; bool DoProgMetadata = EmitProgramMetadata.getNumOccurrences() > 0; + bool DoExportedSyms = EmitExportedSymbols.getNumOccurrences() > 0; if (!DoSplit && !DoSpecConst && !DoSymGen && !DoParamInfo && - !DoProgMetadata && !DoSplitEsimd) { + !DoProgMetadata && !DoSplitEsimd && !DoExportedSyms) { errs() << "no actions specified; try --help for usage info\n"; return 1; } @@ -985,6 +1014,11 @@ int main(int argc, char **argv) { << " -" << IROutputOnly.ArgStr << "\n"; return 1; } + if (IROutputOnly && DoExportedSyms) { + errs() << "error: -" << EmitExportedSymbols.ArgStr << " can't be used with" + << " -" << IROutputOnly.ArgStr << "\n"; + return 1; + } SMDiagnostic Err; std::unique_ptr M = parseIRFile(InputFilename, Err, Context); // It is OK to use raw pointer here as we control that it does not outlive M diff --git a/sycl/include/CL/sycl/detail/pi.h b/sycl/include/CL/sycl/detail/pi.h index a38f1ab0b054f..c2ab0bcaccf80 100644 --- a/sycl/include/CL/sycl/detail/pi.h +++ b/sycl/include/CL/sycl/detail/pi.h @@ -714,7 +714,10 @@ static const uint8_t PI_DEVICE_BINARY_OFFLOAD_KIND_SYCL = 4; #define __SYCL_PI_PROPERTY_SET_PROGRAM_METADATA "SYCL/program metadata" /// PropertySetRegistry::SYCL_MISC_PROP defined in PropertySetIO.h #define __SYCL_PI_PROPERTY_SET_SYCL_MISC_PROP "SYCL/misc properties" +/// PropertySetRegistry::SYCL_ASSERT_USED defined in PropertySetIO.h #define __SYCL_PI_PROPERTY_SET_SYCL_ASSERT_USED "SYCL/assert used" +/// PropertySetRegistry::SYCL_EXPORTED_SYMBOLS defined in PropertySetIO.h +#define __SYCL_PI_PROPERTY_SET_SYCL_EXPORTED_SYMBOLS "SYCL/exported symbols" /// Program metadata tags recognized by the PI backends. For kernels the tag /// must appear after the kernel name. From 3cb7fd22bbb04378c6d0dfeed0a980d08a2a205b Mon Sep 17 00:00:00 2001 From: Steffen Larsen Date: Thu, 23 Sep 2021 14:18:40 +0300 Subject: [PATCH 2/5] Fix formatting Signed-off-by: Steffen Larsen --- llvm/tools/sycl-post-link/sycl-post-link.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/llvm/tools/sycl-post-link/sycl-post-link.cpp b/llvm/tools/sycl-post-link/sycl-post-link.cpp index 3f87045f0b7f7..efaeb01844c05 100644 --- a/llvm/tools/sycl-post-link/sycl-post-link.cpp +++ b/llvm/tools/sycl-post-link/sycl-post-link.cpp @@ -827,10 +827,14 @@ static TableFiles processOneModule(std::unique_ptr M, bool IsEsimd, } { - ImagePropSaveInfo ImgPSInfo = { - true, DoSpecConst, SetSpecConstAtRT, - SpecConstsMet, EmitKernelParamInfo, EmitProgramMetadata, - EmitExportedSymbols, IsEsimd}; + ImagePropSaveInfo ImgPSInfo = {true, + DoSpecConst, + SetSpecConstAtRT, + SpecConstsMet, + EmitKernelParamInfo, + EmitProgramMetadata, + EmitExportedSymbols, + IsEsimd}; string_vector Files = saveDeviceImageProperty(ResultModules, GlobalsSet, ImgPSInfo); std::copy(Files.begin(), Files.end(), From 368a5bcfe772bbeca9307559bb5784dd20710545 Mon Sep 17 00:00:00 2001 From: Steffen Larsen Date: Thu, 23 Sep 2021 18:05:04 +0300 Subject: [PATCH 3/5] Add new option to driver test Signed-off-by: Steffen Larsen --- clang/test/Driver/sycl-device-lib.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/Driver/sycl-device-lib.cpp b/clang/test/Driver/sycl-device-lib.cpp index 734b6ab39ae04..1e64227681382 100644 --- a/clang/test/Driver/sycl-device-lib.cpp +++ b/clang/test/Driver/sycl-device-lib.cpp @@ -125,7 +125,7 @@ // RUN: | FileCheck %s -check-prefix=SYCL_LLVM_LINK_NO_DEVICE_LIB // SYCL_LLVM_LINK_NO_DEVICE_LIB: clang{{.*}} "-cc1" {{.*}} "-fsycl-is-device" // SYCL_LLVM_LINK_NO_DEVICE_LIB-NOT: llvm-link{{.*}} "-only-needed" -// SYCL_LLVM_LINK_NO_DEVICE_LIB: sycl-post-link{{.*}} "-symbols" "-split-esimd" "-lower-esimd" "-O2" "-spec-const=rt" "-o" "{{.*}}.table" "{{.*}}.bc" +// SYCL_LLVM_LINK_NO_DEVICE_LIB: sycl-post-link{{.*}} "-symbols" "-emit-exported-symbols" "-split-esimd" "-lower-esimd" "-O2" "-spec-const=rt" "-o" "{{.*}}.table" "{{.*}}.bc" /// ########################################################################### /// test llvm-link behavior for special user input whose filename resembles SYCL device library From 545d22f3e91b796b3ca44df63cee2f584bd7c677 Mon Sep 17 00:00:00 2001 From: Steffen Larsen Date: Tue, 28 Sep 2021 11:07:13 +0300 Subject: [PATCH 4/5] Remove table file checks Signed-off-by: Steffen Larsen --- .../sycl-post-link/emit_exported_symbols.ll | 21 ------------------- 1 file changed, 21 deletions(-) diff --git a/llvm/test/tools/sycl-post-link/emit_exported_symbols.ll b/llvm/test/tools/sycl-post-link/emit_exported_symbols.ll index f96e26c5de507..c1db9d0f8ad8e 100644 --- a/llvm/test/tools/sycl-post-link/emit_exported_symbols.ll +++ b/llvm/test/tools/sycl-post-link/emit_exported_symbols.ll @@ -2,19 +2,16 @@ ; ; Global scope ; RUN: sycl-post-link -symbols -emit-exported-symbols -S %s -o %t.global.files.table -; RUN: FileCheck %s -input-file=%t.global.files.table --check-prefixes CHECK-GLOBAL-TABLE ; RUN: FileCheck %s -input-file=%t.global.files_0.prop --check-prefixes CHECK-GLOBAL-PROP ; ; Per-module split ; RUN: sycl-post-link -symbols -split=source -emit-exported-symbols -S %s -o %t.per_module.files.table -; RUN: FileCheck %s -input-file=%t.per_module.files.table --check-prefixes CHECK-PERMODULE-TABLE ; RUN: FileCheck %s -input-file=%t.per_module.files_0.prop --check-prefixes CHECK-PERMODULE-0-PROP ; RUN: FileCheck %s -input-file=%t.per_module.files_1.prop --check-prefixes CHECK-PERMODULE-1-PROP ; RUN: FileCheck %s -input-file=%t.per_module.files_2.prop --check-prefixes CHECK-KERNELONLY-PROP ; ; Per-kernel split ; RUN: sycl-post-link -symbols -split=kernel -emit-exported-symbols -S %s -o %t.per_kernel.files.table -; RUN: FileCheck %s -input-file=%t.per_kernel.files.table --check-prefixes CHECK-PERKERNEL-TABLE ; RUN: FileCheck %s -input-file=%t.per_kernel.files_0.prop --check-prefixes CHECK-PERKERNEL-0-PROP ; RUN: FileCheck %s -input-file=%t.per_kernel.files_1.prop --check-prefixes CHECK-PERKERNEL-1-PROP ; RUN: FileCheck %s -input-file=%t.per_kernel.files_2.prop --check-prefixes CHECK-PERKERNEL-2-PROP @@ -65,10 +62,6 @@ attributes #2 = { "sycl-module-id"="c.cpp" } ; CHECK-GLOBAL-PROP-NOT: SpirKernel1 ; CHECK-GLOBAL-PROP-NOT: NotExportedSpirFunc1 -; CHECK-GLOBAL-TABLE: [Code|Properties|Symbols] -; CHECK-GLOBAL-TABLE-NEXT: {{.*}}global.files_0.prop -; CHECK-GLOBAL-TABLE-EMPTY: - ; Per-module split ; CHECK-PERMODULE-0-PROP: [SYCL/exported symbols] ; CHECK-PERMODULE-0-PROP-NEXT: ExportedSpirFunc1 @@ -84,12 +77,6 @@ attributes #2 = { "sycl-module-id"="c.cpp" } ; CHECK-PERMODULE-1-PROP-NOT: SpirKernel1 ; CHECK-PERMODULE-1-PROP-NOT: NotExportedSpirFunc1 -; CHECK-PERMODULE-TABLE: [Code|Properties|Symbols] -; CHECK-PERMODULE-TABLE-NEXT: {{.*}}per_module.files_0.prop -; CHECK-PERMODULE-TABLE-NEXT: {{.*}}per_module.files_1.prop -; CHECK-PERMODULE-TABLE-NEXT: {{.*}}per_module.files_2.prop -; CHECK-PERMODULE-TABLE-EMPTY: - ; Per-kernel split ; CHECK-PERKERNEL-0-PROP: [SYCL/exported symbols] ; CHECK-PERKERNEL-0-PROP-NEXT: ExportedSpirFunc1 @@ -112,14 +99,6 @@ attributes #2 = { "sycl-module-id"="c.cpp" } ; CHECK-PERKERNEL-2-PROP-NOT: SpirKernel1 ; CHECK-PERKERNEL-2-PROP-NOT: NotExportedSpirFunc1 -; CHECK-PERKERNEL-TABLE: [Code|Properties|Symbols] -; CHECK-PERKERNEL-TABLE-NEXT: {{.*}}per_kernel.files_0.prop -; CHECK-PERKERNEL-TABLE-NEXT: {{.*}}per_kernel.files_1.prop -; CHECK-PERKERNEL-TABLE-NEXT: {{.*}}per_kernel.files_2.prop -; CHECK-PERKERNEL-TABLE-NEXT: {{.*}}per_kernel.files_3.prop -; CHECK-PERKERNEL-TABLE-NEXT: {{.*}}per_kernel.files_4.prop -; CHECK-PERKERNEL-TABLE-EMPTY: - ; Kernel-only generated modules should have no exported Symbols ; CHECK-KERNELONLY-PROP-NOT: [SYCL/exported symbols] ; CHECK-KERNELONLY-PROP-NOT: ExportedSpirFunc3 From 79da4710518ae01e0ef54af61cb73d1381907324 Mon Sep 17 00:00:00 2001 From: Steffen Larsen Date: Tue, 28 Sep 2021 13:28:56 +0300 Subject: [PATCH 5/5] Add implicit-check-not for NotExported Signed-off-by: Steffen Larsen --- .../sycl-post-link/emit_exported_symbols.ll | 36 ++++++------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/llvm/test/tools/sycl-post-link/emit_exported_symbols.ll b/llvm/test/tools/sycl-post-link/emit_exported_symbols.ll index c1db9d0f8ad8e..960a79d4d6a4e 100644 --- a/llvm/test/tools/sycl-post-link/emit_exported_symbols.ll +++ b/llvm/test/tools/sycl-post-link/emit_exported_symbols.ll @@ -2,30 +2,30 @@ ; ; Global scope ; RUN: sycl-post-link -symbols -emit-exported-symbols -S %s -o %t.global.files.table -; RUN: FileCheck %s -input-file=%t.global.files_0.prop --check-prefixes CHECK-GLOBAL-PROP +; RUN: FileCheck %s -input-file=%t.global.files_0.prop --implicit-check-not="NotExported" --check-prefix=CHECK-GLOBAL-PROP ; ; Per-module split ; RUN: sycl-post-link -symbols -split=source -emit-exported-symbols -S %s -o %t.per_module.files.table -; RUN: FileCheck %s -input-file=%t.per_module.files_0.prop --check-prefixes CHECK-PERMODULE-0-PROP -; RUN: FileCheck %s -input-file=%t.per_module.files_1.prop --check-prefixes CHECK-PERMODULE-1-PROP -; RUN: FileCheck %s -input-file=%t.per_module.files_2.prop --check-prefixes CHECK-KERNELONLY-PROP +; RUN: FileCheck %s -input-file=%t.per_module.files_0.prop -implicit-check-not="NotExported" --check-prefix=CHECK-PERMODULE-0-PROP +; RUN: FileCheck %s -input-file=%t.per_module.files_1.prop -implicit-check-not="NotExported" --check-prefix=CHECK-PERMODULE-1-PROP +; RUN: FileCheck %s -input-file=%t.per_module.files_2.prop -implicit-check-not="NotExported" --check-prefix=CHECK-KERNELONLY-PROP ; ; Per-kernel split ; RUN: sycl-post-link -symbols -split=kernel -emit-exported-symbols -S %s -o %t.per_kernel.files.table -; RUN: FileCheck %s -input-file=%t.per_kernel.files_0.prop --check-prefixes CHECK-PERKERNEL-0-PROP -; RUN: FileCheck %s -input-file=%t.per_kernel.files_1.prop --check-prefixes CHECK-PERKERNEL-1-PROP -; RUN: FileCheck %s -input-file=%t.per_kernel.files_2.prop --check-prefixes CHECK-PERKERNEL-2-PROP -; RUN: FileCheck %s -input-file=%t.per_kernel.files_3.prop --check-prefixes CHECK-KERNELONLY-PROP -; RUN: FileCheck %s -input-file=%t.per_kernel.files_4.prop --check-prefixes CHECK-KERNELONLY-PROP +; RUN: FileCheck %s -input-file=%t.per_kernel.files_0.prop --implicit-check-not="NotExported" --check-prefix=CHECK-PERKERNEL-0-PROP +; RUN: FileCheck %s -input-file=%t.per_kernel.files_1.prop --implicit-check-not="NotExported" --check-prefix=CHECK-PERKERNEL-1-PROP +; RUN: FileCheck %s -input-file=%t.per_kernel.files_2.prop --implicit-check-not="NotExported" --check-prefix=CHECK-PERKERNEL-2-PROP +; RUN: FileCheck %s -input-file=%t.per_kernel.files_3.prop --implicit-check-not="NotExported" --check-prefix=CHECK-KERNELONLY-PROP +; RUN: FileCheck %s -input-file=%t.per_kernel.files_4.prop --implicit-check-not="NotExported" --check-prefix=CHECK-KERNELONLY-PROP target triple = "spir64-unknown-unknown" -define dso_local spir_kernel void @SpirKernel1(float %arg1) #0 { +define dso_local spir_kernel void @NotExportedSpirKernel1(float %arg1) #0 { entry: ret void } -define dso_local spir_kernel void @SpirKernel2(float %arg1) #2 { +define dso_local spir_kernel void @NotExportedSpirKernel2(float %arg1) #2 { entry: ret void } @@ -59,50 +59,36 @@ attributes #2 = { "sycl-module-id"="c.cpp" } ; CHECK-GLOBAL-PROP-NEXT: ExportedSpirFunc1 ; CHECK-GLOBAL-PROP-NEXT: ExportedSpirFunc2 ; CHECK-GLOBAL-PROP-NEXT: ExportedSpirFunc3 -; CHECK-GLOBAL-PROP-NOT: SpirKernel1 -; CHECK-GLOBAL-PROP-NOT: NotExportedSpirFunc1 ; Per-module split ; CHECK-PERMODULE-0-PROP: [SYCL/exported symbols] ; CHECK-PERMODULE-0-PROP-NEXT: ExportedSpirFunc1 ; CHECK-PERMODULE-0-PROP-NEXT: ExportedSpirFunc3 ; CHECK-PERMODULE-0-PROP-NOT: ExportedSpirFunc2 -; CHECK-PERMODULE-0-PROP-NOT: SpirKernel1 -; CHECK-PERMODULE-0-PROP-NOT: NotExportedSpirFunc1 ; CHECK-PERMODULE-1-PROP: [SYCL/exported symbols] ; CHECK-PERMODULE-1-PROP-NEXT: ExportedSpirFunc2 ; CHECK-PERMODULE-1-PROP-NOT: ExportedSpirFunc1 ; CHECK-PERMODULE-1-PROP-NOT: ExportedSpirFunc3 -; CHECK-PERMODULE-1-PROP-NOT: SpirKernel1 -; CHECK-PERMODULE-1-PROP-NOT: NotExportedSpirFunc1 ; Per-kernel split ; CHECK-PERKERNEL-0-PROP: [SYCL/exported symbols] ; CHECK-PERKERNEL-0-PROP-NEXT: ExportedSpirFunc1 ; CHECK-PERKERNEL-0-PROP-NOT: ExportedSpirFunc2 ; CHECK-PERKERNEL-0-PROP-NOT: ExportedSpirFunc3 -; CHECK-PERKERNEL-0-PROP-NOT: SpirKernel1 -; CHECK-PERKERNEL-0-PROP-NOT: NotExportedSpirFunc1 ; CHECK-PERKERNEL-1-PROP: [SYCL/exported symbols] ; CHECK-PERKERNEL-1-PROP-NEXT: ExportedSpirFunc2 ; CHECK-PERKERNEL-1-PROP-NOT: ExportedSpirFunc1 ; CHECK-PERKERNEL-1-PROP-NOT: ExportedSpirFunc3 -; CHECK-PERKERNEL-1-PROP-NOT: SpirKernel1 -; CHECK-PERKERNEL-1-PROP-NOT: NotExportedSpirFunc1 ; CHECK-PERKERNEL-2-PROP: [SYCL/exported symbols] ; CHECK-PERKERNEL-2-PROP-NEXT: ExportedSpirFunc3 ; CHECK-PERKERNEL-2-PROP-NOT: ExportedSpirFunc1 ; CHECK-PERKERNEL-2-PROP-NOT: ExportedSpirFunc2 -; CHECK-PERKERNEL-2-PROP-NOT: SpirKernel1 -; CHECK-PERKERNEL-2-PROP-NOT: NotExportedSpirFunc1 ; Kernel-only generated modules should have no exported Symbols ; CHECK-KERNELONLY-PROP-NOT: [SYCL/exported symbols] ; CHECK-KERNELONLY-PROP-NOT: ExportedSpirFunc3 ; CHECK-KERNELONLY-PROP-NOT: ExportedSpirFunc1 ; CHECK-KERNELONLY-PROP-NOT: ExportedSpirFunc2 -; CHECK-KERNELONLY-PROP-NOT: SpirKernel1 -; CHECK-KERNELONLY-PROP-NOT: NotExportedSpirFunc1