[mlir][llvm] Add thread-local address intrinsic

Add the `llvm.threadlocal.address` intrinsic to the LLVM dialect.

Signed-off-by: Lukas Sommer <lukas.sommer@codeplay.com>

Reviewed By: gysit, zero9178

Differential Revision: https://reviews.llvm.org/D151566
This commit is contained in:
Lukas Sommer
2023-05-30 06:44:31 +00:00
committed by Tobias Gysi
parent 6c55f4ba57
commit df37e2211e
3 changed files with 21 additions and 0 deletions

View File

@@ -324,6 +324,11 @@ def LLVM_ExpectWithProbabilityOp
let assemblyFormat = "$val `,` $expected `,` $prob attr-dict `:` type($val)";
}
def LLVM_ThreadlocalAddressOp : LLVM_OneResultIntrOp<"threadlocal.address", [],
[0], [Pure]> {
let arguments = (ins LLVM_AnyPointer:$global);
}
//
// Coroutine intrinsics.
//

View File

@@ -613,6 +613,13 @@ define void @expect_with_probability(i16 %0) {
ret void
}
; CHECK-LABEL: llvm.func @threadlocal_test
define void @threadlocal_test(ptr %0) {
; CHECK: "llvm.intr.threadlocal.address"(%{{.*}}) : (!llvm.ptr) -> !llvm.ptr
%local = call ptr @llvm.threadlocal.address.p0(ptr %0)
ret void
}
; CHECK-LABEL: llvm.func @coro_id
define void @coro_id(i32 %0, ptr %1) {
; CHECK: llvm.intr.coro.id %{{.*}}, %{{.*}}, %{{.*}}, %{{.*}} : (i32, !llvm.ptr, !llvm.ptr, !llvm.ptr) -> !llvm.token
@@ -955,6 +962,7 @@ declare <8 x i32> @llvm.ushl.sat.v8i32(<8 x i32>, <8 x i32>)
declare i1 @llvm.is.constant.i32(i32)
declare i32 @llvm.expect.i32(i32, i32)
declare i16 @llvm.expect.with.probability.i16(i16, i16, double immarg)
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull)
declare token @llvm.coro.id(i32, ptr readnone, ptr nocapture readonly, ptr)
declare ptr @llvm.coro.begin(token, ptr writeonly)
declare i64 @llvm.coro.size.i64()

View File

@@ -559,6 +559,13 @@ llvm.func @expect_with_probability(%arg0: i16) {
llvm.return
}
// 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.return
}
// CHECK-LABEL: @sadd_sat_test
llvm.func @sadd_sat_test(%arg0: i32, %arg1: i32, %arg2: vector<8xi32>, %arg3: vector<8xi32>) {
// CHECK: call i32 @llvm.sadd.sat.i32
@@ -996,6 +1003,7 @@ llvm.func @lifetime(%p: !llvm.ptr) {
// CHECK-DAG: declare i1 @llvm.is.constant.i32(i32)
// CHECK-DAG: declare i32 @llvm.expect.i32(i32, i32)
// CHECK-DAG: declare i16 @llvm.expect.with.probability.i16(i16, i16, double immarg)
// CHECK-DAG: declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull)
// CHECK-DAG: declare token @llvm.coro.id(i32, ptr readnone, ptr nocapture readonly, ptr)
// CHECK-DAG: declare ptr @llvm.coro.begin(token, ptr writeonly)
// CHECK-DAG: declare i64 @llvm.coro.size.i64()