Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map LinkOnceODR to weak_odr instead of linkonce_odr #2502

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/SPIRV/SPIRVReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4850,7 +4850,7 @@ SPIRVToLLVM::transLinkageType(const SPIRVValue *V) {
}
return GlobalValue::ExternalLinkage;
case LinkageTypeLinkOnceODR:
return GlobalValue::LinkOnceODRLinkage;
return GlobalValue::WeakODRLinkage;
default:
llvm_unreachable("Invalid linkage type");
}
Expand Down
2 changes: 1 addition & 1 deletion lib/SPIRV/SPIRVWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6570,7 +6570,7 @@ LLVMToSPIRVBase::transLinkageType(const GlobalValue *GV) {
return SPIRVLinkageTypeKind::LinkageTypeImport;
if (GV->hasInternalLinkage() || GV->hasPrivateLinkage())
return spv::internal::LinkageTypeInternal;
if (GV->hasLinkOnceODRLinkage())
if (GV->hasLinkOnceODRLinkage() || GV->hasWeakODRLinkage())
if (BM->isAllowedToUseExtension(ExtensionID::SPV_KHR_linkonce_odr))
return SPIRVLinkageTypeKind::LinkageTypeLinkOnceODR;
return SPIRVLinkageTypeKind::LinkageTypeExport;
Expand Down
18 changes: 14 additions & 4 deletions test/extensions/KHR/SPV_KHR_linkonce_odr/LinkOnceODR.ll
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,27 @@
; CHECK-SPIRV: Extension "SPV_KHR_linkonce_odr"
; CHECK-SPIRV-DAG: Decorate {{[0-9]+}} LinkageAttributes "GV" LinkOnceODR
; CHECK-SPIRV-DAG: Decorate {{[0-9]+}} LinkageAttributes "square" LinkOnceODR
; CHECK-SPIRV-DAG: Decorate {{[0-9]+}} LinkageAttributes "add1" LinkOnceODR

; CHECK-SPIRV-NOEXT-NOT: Extension "SPV_KHR_linkonce_odr"
; CHECK-SPIRV-NOEXT-NOT: Decorate {{[0-9]+}} LinkageAttributes "GV" LinkOnceODR
; CHECK-SPIRV-NOEXT-NOT: Decorate {{[0-9]+}} LinkageAttributes "square" LinkOnceODR
; CHECK-SPIRV-NOEXT-NOT: Decorate {{[0-9]+}} LinkageAttributes "add1" LinkOnceODR

target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
target triple = "spir"

; CHECK-LLVM: @GV = linkonce_odr addrspace(1) global [3 x i32] zeroinitializer, align 4
@GV = linkonce_odr addrspace(1) global [3 x i32] zeroinitializer, align 4
; CHECK-LLVM: @GV = weak_odr addrspace(1) global [3 x i32] zeroinitializer, align 4
@GV = weak_odr addrspace(1) global [3 x i32] zeroinitializer, align 4

define spir_kernel void @k() #0 !kernel_arg_addr_space !0 !kernel_arg_access_qual !0 !kernel_arg_type !0 !kernel_arg_base_type !0 !kernel_arg_type_qual !0 {
entry:
%call = call spir_func i32 @square(i32 2)
ret void
}

; CHECK-LLVM: define linkonce_odr spir_func i32 @square(i32 %in)
define linkonce_odr dso_local spir_func i32 @square(i32 %in) {
; CHECK-LLVM: define weak_odr spir_func i32 @square(i32 %in)
define weak_odr dso_local spir_func i32 @square(i32 %in) {
entry:
%in.addr = alloca i32, align 4
store i32 %in, ptr %in.addr, align 4
Expand All @@ -40,6 +42,14 @@ entry:
ret i32 %mul
}

; Verify that linkonce_odr is mapped to LinkOnceODR too.
; CHECK-LLVM: define weak_odr spir_func i32 @add1(i32 %in)
define linkonce_odr dso_local spir_func i32 @add1(i32 %in) {
entry:
%add = add nsw i32 %in, 1
ret i32 %add
}

!llvm.module.flags = !{!1}
!opencl.spir.version = !{!2}

Expand Down
Loading