Skip to content

Commit 6a13fa9

Browse files
Artem Gindinsonigcbot
authored andcommitted
Rework kernel metadata handling in SPIR-V Reader
After the introduction of kernel entry point wrappers within KhronosGroup/SPIRV-LLVM-Translator@85815e7, initial approach to avoiding kernel metadata duplication within our internal SPIR-V consumer has been to skip metadata generation whenever we encounter the entry point kernel (we would assume that all necessary metadata had already been assigned to the LLVM function upon encountering the "actual" SPIR-V kernel). For more details on the initial approach, see 12332c1. The change, however, did not take into account that all SPIR-V information regarding the kernel execution mode was being stored exclusively for the entry point wrapper kernel. Therefore, by skipping the SPIR-V entry point wrappers we end up losing certain metadata entries, e.g. "required WG size". Assume that the entry point wrappers contain fuller information and generate LLVM metadata based on these SPIR-V functions instead. This fixes kernel attributes' lowering with LLVM 14. An alternative SPIR-V Reader solution would imply copying over all SPIR-V information from entry point wrappers to the actual kernel body, and then dropping entry point wrappers from the `SPIRVModule`'s/`SPIRVToLLVM`'s function collections.
1 parent 3bbca97 commit 6a13fa9

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

IGC/AdaptorOCL/SPIRV/SPIRVReader.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ THE SOFTWARE.
5858
#include <llvm/Support/ScaledNumber.h>
5959
#include <llvm/IR/IntrinsicInst.h>
6060
#include <llvm/Analysis/CFG.h>
61-
#include <llvm/ADT/SmallSet.h>
6261
#include "libSPIRV/SPIRVDebugInfoExt.h"
6362
#include "llvmWrapper/Transforms/Utils/Cloning.h"
6463
#include "common/LLVMWarningsPop.hpp"
@@ -4707,15 +4706,11 @@ SPIRVToLLVM::transKernelMetadata()
47074706
transCapsIntoMetadata(MD);
47084707

47094708
NamedMDNode *KernelMDs = M->getOrInsertNamedMetadata(SPIR_MD_KERNELS);
4710-
SmallSet<Function*, 16> HandledLLVMKernels;
47114709
for (unsigned I = 0, E = BM->getNumFunctions(); I != E; ++I)
47124710
{
47134711
SPIRVFunction *BF = BM->getFunction(I);
47144712
Function *F = static_cast<Function *>(getTranslatedValue(BF));
47154713
IGC_ASSERT_MESSAGE(F, "Invalid translated function");
4716-
if (HandledLLVMKernels.count(F))
4717-
continue;
4718-
HandledLLVMKernels.insert(F);
47194714

47204715
// __attribute__((annotate("some_user_annotation"))) are passed via
47214716
// UserSemantic decoration on functions.
@@ -4727,6 +4722,17 @@ SPIRVToLLVM::transKernelMetadata()
47274722

47284723
if (F->getCallingConv() != CallingConv::SPIR_KERNEL || F->isDeclaration())
47294724
continue;
4725+
// Kernel entry point wrappers and SPIR-V functions with actual kernel
4726+
// body resolve to the same LLVM functions. Only generate metadata upon
4727+
// encountering entry point wrappers, as SPIR-V stores all execution
4728+
// mode information at the entry point wrapper site.
4729+
// TODO: Instead, consider copying all SPIR-V function information from
4730+
// entry point wrappers to the actual SPIR-V funtions, and then
4731+
// erasing entry point wrappers as such from the SPIRVModule/
4732+
// SPIRVToLLVM classes. Preferably, such a rework should be done in the
4733+
// Khronos SPIR-V Translator and then downstreamed.
4734+
if (!isOpenCLKernel(BF))
4735+
continue;
47304736
std::vector<llvm::Metadata*> KernelMD;
47314737
KernelMD.push_back(ValueAsMetadata::get(F));
47324738

0 commit comments

Comments
 (0)