Skip to content

Commit 12332c1

Browse files
Artem Gindinsonigcbot
authored andcommitted
Avoid duplicate entries into !opencl.kernels metadata with LLVM 14
The LLVM 14 version of the SPIR-V Translator (and, consequently, OpenCL Clang) introduces the kernel entry point wrappers functionality (see commit KhronosGroup/SPIRV-LLVM-Translator@85815e7). As IGC's SPIR-V Reader collects root nodes for kernel argument metadata into the `!opencl.kernels` module metadata, it treats SPIR-V entry point wrappers as separate kernels despite that they are mapped onto the same LLVM function. Consequently, each LLVM IR kernel function recieves a "duplicate" set of kernel argument metadata, which breaks our kernel argument analysis passes upon a switch to LLVM 14. Do not update the module metadata upon encountering previously seen LLVM functions. This fixes #245.
1 parent 2102e7e commit 12332c1

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

IGC/AdaptorOCL/SPIRV/SPIRVReader.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ 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>
6162
#include "libSPIRV/SPIRVDebugInfoExt.h"
6263
#include "llvmWrapper/Transforms/Utils/Cloning.h"
6364
#include "common/LLVMWarningsPop.hpp"
@@ -4706,11 +4707,15 @@ SPIRVToLLVM::transKernelMetadata()
47064707
transCapsIntoMetadata(MD);
47074708

47084709
NamedMDNode *KernelMDs = M->getOrInsertNamedMetadata(SPIR_MD_KERNELS);
4710+
SmallSet<Function*, 16> HandledLLVMKernels;
47094711
for (unsigned I = 0, E = BM->getNumFunctions(); I != E; ++I)
47104712
{
47114713
SPIRVFunction *BF = BM->getFunction(I);
47124714
Function *F = static_cast<Function *>(getTranslatedValue(BF));
47134715
IGC_ASSERT_MESSAGE(F, "Invalid translated function");
4716+
if (HandledLLVMKernels.count(F))
4717+
continue;
4718+
HandledLLVMKernels.insert(F);
47144719

47154720
// __attribute__((annotate("some_user_annotation"))) are passed via
47164721
// UserSemantic decoration on functions.

0 commit comments

Comments
 (0)