-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[WebAssembly] Implement %llvm.thread.pointer intrinsic #117817
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
Conversation
@llvm/pr-subscribers-clang @llvm/pr-subscribers-backend-webassembly Author: Sam Clegg (sbc100) ChangesWe can simply use the Fixes: #117433 Full diff: https://github.com/llvm/llvm-project/pull/117817.diff 2 Files Affected:
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
index 2d00889407ff48..94b49387b58f91 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
@@ -2089,6 +2089,17 @@ SDValue WebAssemblyTargetLowering::LowerIntrinsic(SDValue Op,
}
return DAG.getNode(WebAssemblyISD::SHUFFLE, DL, Op.getValueType(), Ops);
}
+
+ case Intrinsic::thread_pointer: {
+ MVT PtrVT = getPointerTy(DAG.getDataLayout());
+ auto GlobalGet = PtrVT == MVT::i64 ? WebAssembly::GLOBAL_GET_I64
+ : WebAssembly::GLOBAL_GET_I32;
+ const char *TlsBase = MF.createExternalSymbolName("__tls_base");
+ return SDValue(
+ DAG.getMachineNode(GlobalGet, DL, PtrVT,
+ DAG.getTargetExternalSymbol(TlsBase, PtrVT)),
+ 0);
+ }
}
}
diff --git a/llvm/test/CodeGen/WebAssembly/thread_pointer.ll b/llvm/test/CodeGen/WebAssembly/thread_pointer.ll
new file mode 100644
index 00000000000000..cca739716fe887
--- /dev/null
+++ b/llvm/test/CodeGen/WebAssembly/thread_pointer.ll
@@ -0,0 +1,21 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc < %s -mtriple=wasm32-unknown-unknown | FileCheck %s --check-prefix=wasm32
+; RUN: llc < %s -mtriple=wasm64-unknown-unknown | FileCheck %s --check-prefix=wasm64
+
+declare ptr @llvm.thread.pointer()
+
+define ptr @thread_pointer() nounwind {
+; wasm32-LABEL: thread_pointer:
+; wasm32: .functype thread_pointer () -> (i32)
+; wasm32-NEXT: # %bb.0:
+; wasm32-NEXT: global.get __tls_base
+; wasm32-NEXT: # fallthrough-return
+;
+; wasm64-LABEL: thread_pointer:
+; wasm64: .functype thread_pointer () -> (i64)
+; wasm64-NEXT: # %bb.0:
+; wasm64-NEXT: global.get __tls_base
+; wasm64-NEXT: # fallthrough-return
+ %1 = tail call ptr @llvm.thread.pointer()
+ ret ptr %1
+}
|
8f29cb6
to
e2783e0
Compare
Generally LGTM; maybe we also want to add a test for |
I only see that testing in clang/test/CodeGen/builtins-arm64.c, most platforms don't seem to test this. |
e2783e0
to
9578cf1
Compare
Done! |
We can simply use the `__tls_base` global for this which is guaranteed to be non-zero and unique per thread. Fixes: llvm#117433
9578cf1
to
933be68
Compare
Hm, looking at the implementation in clang/lib/CodeGen/CGBuiltin.cpp it should work for any target where |
We can simply use the
__tls_base
global for this which is guaranteed to be non-zero and unique per thread.Fixes: #117433