[llvm] r366475 - [WebAssembly] Implement __builtin_wasm_tls_base intrinsic
Guanzhong Chen via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 18 10:53:22 PDT 2019
Author: quantum
Date: Thu Jul 18 10:53:22 2019
New Revision: 366475
URL: http://llvm.org/viewvc/llvm-project?rev=366475&view=rev
Log:
[WebAssembly] Implement __builtin_wasm_tls_base intrinsic
Summary:
Add `__builtin_wasm_tls_base` so that LeakSanitizer can find the thread-local
block and scan through it for memory leaks.
Reviewers: tlively, aheejin, sbc100
Subscribers: dschuff, jgravelle-google, hiraditya, sunfish, cfe-commits, llvm-commits
Tags: #clang, #llvm
Differential Revision: https://reviews.llvm.org/D64900
Modified:
llvm/trunk/include/llvm/IR/IntrinsicsWebAssembly.td
llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp
llvm/trunk/test/CodeGen/WebAssembly/tls-general-dynamic.ll
Modified: llvm/trunk/include/llvm/IR/IntrinsicsWebAssembly.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/IntrinsicsWebAssembly.td?rev=366475&r1=366474&r2=366475&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/IntrinsicsWebAssembly.td (original)
+++ llvm/trunk/include/llvm/IR/IntrinsicsWebAssembly.td Thu Jul 18 10:53:22 2019
@@ -133,4 +133,9 @@ def int_wasm_tls_size :
[],
[IntrNoMem, IntrSpeculatable]>;
+def int_wasm_tls_base :
+ Intrinsic<[llvm_ptr_ty],
+ [],
+ [IntrReadMem]>;
+
} // TargetPrefix = "wasm"
Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp?rev=366475&r1=366474&r2=366475&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp Thu Jul 18 10:53:22 2019
@@ -227,6 +227,23 @@ void WebAssemblyDAGToDAGISel::Select(SDN
}
break;
}
+ case ISD::INTRINSIC_W_CHAIN: {
+ unsigned IntNo = cast<ConstantSDNode>(Node->getOperand(1))->getZExtValue();
+ switch (IntNo) {
+ case Intrinsic::wasm_tls_base: {
+ MVT PtrVT = TLI->getPointerTy(CurDAG->getDataLayout());
+ assert(PtrVT == MVT::i32 && "only wasm32 is supported for now");
+
+ MachineSDNode *TLSBase = CurDAG->getMachineNode(
+ WebAssembly::GLOBAL_GET_I32, DL, MVT::i32,
+ CurDAG->getTargetExternalSymbol("__tls_base", PtrVT),
+ Node->getOperand(0));
+ ReplaceNode(Node, TLSBase);
+ return;
+ }
+ }
+ break;
+ }
default:
break;
Modified: llvm/trunk/test/CodeGen/WebAssembly/tls-general-dynamic.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/WebAssembly/tls-general-dynamic.ll?rev=366475&r1=366474&r2=366475&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/WebAssembly/tls-general-dynamic.ll (original)
+++ llvm/trunk/test/CodeGen/WebAssembly/tls-general-dynamic.ll Thu Jul 18 10:53:22 2019
@@ -75,6 +75,15 @@ define i32 @tls_size() {
ret i32 %1
}
+; CHECK-LABEL: tls_base:
+; CHECK-NEXT: .functype tls_base () -> (i32)
+define i8* @tls_base() {
+; CHECK-NEXT: global.get __tls_base
+; CHECK-NEXT: return
+ %1 = call i8* @llvm.wasm.tls.base()
+ ret i8* %1
+}
+
; CHECK: .type tls, at object
; TLS-NEXT: .section .tbss.tls,"",@
; NO-TLS-NEXT: .section .bss.tls,"",@
@@ -84,3 +93,4 @@ define i32 @tls_size() {
@tls = internal thread_local global i32 0
declare i32 @llvm.wasm.tls.size.i32()
+declare i8* @llvm.wasm.tls.base()
More information about the llvm-commits
mailing list