Skip to content
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
5 changes: 5 additions & 0 deletions clang/test/CodeGen/builtins-wasm.c
Original file line number Diff line number Diff line change
Expand Up @@ -740,3 +740,8 @@ __externref_t externref_null() {
// WEBASSEMBLY: tail call ptr addrspace(10) @llvm.wasm.ref.null.extern()
// WEBASSEMBLY-NEXT: ret
}

void *tp (void) {
return __builtin_thread_pointer ();
// WEBASSEMBLY: call {{.*}} @llvm.thread.pointer()
}
11 changes: 11 additions & 0 deletions llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down
21 changes: 21 additions & 0 deletions llvm/test/CodeGen/WebAssembly/thread_pointer.ll
Original file line number Diff line number Diff line change
@@ -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
}