Skip to content

Verify threadlocal_address constraints #87841

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

Merged
merged 3 commits into from
Apr 9, 2024
Merged
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 llvm/docs/LangRef.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28119,7 +28119,7 @@ Syntax:
Arguments:
""""""""""

The first argument is a pointer, which refers to a thread local global.
The first argument is a thread local :ref:`global variable <globalvars>`.

Semantics:
""""""""""
Expand Down
8 changes: 8 additions & 0 deletions llvm/lib/IR/Verifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6223,6 +6223,14 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
&Call);
break;
}
case Intrinsic::threadlocal_address: {
const Value &Arg0 = *Call.getArgOperand(0);
Check(isa<GlobalVariable>(Arg0),
"llvm.threadlocal.address first argument must be a GlobalVariable");
Check(cast<GlobalVariable>(Arg0).isThreadLocal(),
"llvm.threadlocal.address operand isThreadLocal() must no be false");
break;
}
};

// Verify that there aren't any unmediated control transfers between funclets.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
; RUN: not opt -S -mtriple=amdgcn-amd-amdhsa -passes=hipstdpar-select-accelerator-code \
; RUN: %s 2>&1 | FileCheck %s
; XFAIL: *

@tls = hidden thread_local addrspace(1) global i32 0, align 4

Expand Down
6 changes: 4 additions & 2 deletions mlir/test/Target/LLVMIR/Import/intrinsic.ll
Original file line number Diff line number Diff line change
Expand Up @@ -641,10 +641,12 @@ define void @expect_with_probability(i16 %0) {
ret void
}

@tls_var = dso_local thread_local global i32 0, align 4

; CHECK-LABEL: llvm.func @threadlocal_test
define void @threadlocal_test(ptr %0) {
define void @threadlocal_test() {
; CHECK: "llvm.intr.threadlocal.address"(%{{.*}}) : (!llvm.ptr) -> !llvm.ptr
%local = call ptr @llvm.threadlocal.address.p0(ptr %0)
%local = call ptr @llvm.threadlocal.address.p0(ptr @tls_var)
ret void
}

Expand Down
9 changes: 6 additions & 3 deletions mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -576,10 +576,13 @@ llvm.func @expect_with_probability(%arg0: i16) {
llvm.return
}

llvm.mlir.global external thread_local @tls_var(0 : i32) {addr_space = 0 : i32, alignment = 4 : i64, dso_local} : i32

// CHECK-LABEL: @threadlocal_test
llvm.func @threadlocal_test(%arg0 : !llvm.ptr) {
// CHECK: call ptr @llvm.threadlocal.address.p0(ptr %{{.*}})
"llvm.intr.threadlocal.address"(%arg0) : (!llvm.ptr) -> !llvm.ptr
llvm.func @threadlocal_test() {
// CHECK: call ptr @llvm.threadlocal.address.p0(ptr @tls_var)
%0 = llvm.mlir.addressof @tls_var : !llvm.ptr
"llvm.intr.threadlocal.address"(%0) : (!llvm.ptr) -> !llvm.ptr
llvm.return
}

Expand Down