Skip to content

Commit ed4d6ec

Browse files
committed
[SYCL] Ignore kernel uses from @llvm.used and @llvm.compiler.used globals
Signed-off-by: Sergey Dmitriev <[email protected]>
1 parent 6b6501f commit ed4d6ec

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

llvm/lib/Target/NVPTX/SYCL/GlobalOffset.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,15 @@ class GlobalOffset : public ModulePass {
320320
auto NvvmMetadata = M.getNamedMetadata("nvvm.annotations");
321321
assert(NvvmMetadata && "IR compiled to PTX must have nvvm.annotations");
322322

323+
SmallPtrSet<GlobalValue *, 8u> Used;
324+
collectUsedGlobalVariables(M, Used, /*CompilerUsed=*/false);
325+
collectUsedGlobalVariables(M, Used, /*CompilerUsed=*/true);
326+
auto HasUseOtherThanLLVMUsed = [&Used](GlobalValue *GV) {
327+
if (GV->use_empty())
328+
return false;
329+
return !GV->hasOneUse() || !Used.count(GV);
330+
};
331+
323332
llvm::DenseMap<Function *, MDNode *> NvvmEntryPointMetadata;
324333
for (auto MetadataNode : NvvmMetadata->operands()) {
325334
if (MetadataNode->getNumOperands() != 3)
@@ -341,7 +350,7 @@ class GlobalOffset : public ModulePass {
341350
if (!Func)
342351
continue;
343352

344-
assert(Func->use_empty() && "Kernel entry point with uses");
353+
assert(!HasUseOtherThanLLVMUsed(Func) && "Kernel entry point with uses");
345354
NvvmEntryPointMetadata[Func] = MetadataNode;
346355
}
347356
return NvvmEntryPointMetadata;

0 commit comments

Comments
 (0)