[llvm] r366624 - [WebAssembly] Compute and export TLS block alignment
Guanzhong Chen via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 19 16:34:16 PDT 2019
Author: quantum
Date: Fri Jul 19 16:34:16 2019
New Revision: 366624
URL: http://llvm.org/viewvc/llvm-project?rev=366624&view=rev
Log:
[WebAssembly] Compute and export TLS block alignment
Summary:
Add immutable WASM global `__tls_align` which stores the alignment
requirements of the TLS segment.
Add `__builtin_wasm_tls_align()` intrinsic to get this alignment in Clang.
The expected usage has now changed to:
__wasm_init_tls(memalign(__builtin_wasm_tls_align(),
__builtin_wasm_tls_size()));
Reviewers: tlively, aheejin, sbc100, sunfish, alexcrichton
Reviewed By: tlively
Subscribers: dschuff, jgravelle-google, hiraditya, cfe-commits, llvm-commits
Tags: #clang, #llvm
Differential Revision: https://reviews.llvm.org/D65028
Modified:
llvm/trunk/include/llvm/IR/IntrinsicsWebAssembly.td
llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp
llvm/trunk/lib/Target/WebAssembly/WebAssemblyMCInstLower.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=366624&r1=366623&r2=366624&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/IntrinsicsWebAssembly.td (original)
+++ llvm/trunk/include/llvm/IR/IntrinsicsWebAssembly.td Fri Jul 19 16:34:16 2019
@@ -133,6 +133,11 @@ def int_wasm_tls_size :
[],
[IntrNoMem, IntrSpeculatable]>;
+def int_wasm_tls_align :
+ Intrinsic<[llvm_anyint_ty],
+ [],
+ [IntrNoMem, IntrSpeculatable]>;
+
def int_wasm_tls_base :
Intrinsic<[llvm_ptr_ty],
[],
Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp?rev=366624&r1=366623&r2=366624&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp Fri Jul 19 16:34:16 2019
@@ -224,6 +224,16 @@ void WebAssemblyDAGToDAGISel::Select(SDN
ReplaceNode(Node, TLSSize);
return;
}
+ case Intrinsic::wasm_tls_align: {
+ MVT PtrVT = TLI->getPointerTy(CurDAG->getDataLayout());
+ assert(PtrVT == MVT::i32 && "only wasm32 is supported for now");
+
+ MachineSDNode *TLSAlign = CurDAG->getMachineNode(
+ WebAssembly::GLOBAL_GET_I32, DL, PtrVT,
+ CurDAG->getTargetExternalSymbol("__tls_align", MVT::i32));
+ ReplaceNode(Node, TLSAlign);
+ return;
+ }
}
break;
}
Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp?rev=366624&r1=366623&r2=366624&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp Fri Jul 19 16:34:16 2019
@@ -79,7 +79,7 @@ MCSymbol *WebAssemblyMCInstLower::GetExt
// Clang-provided symbols.
if (strcmp(Name, "__stack_pointer") == 0 || strcmp(Name, "__tls_base") == 0 ||
strcmp(Name, "__memory_base") == 0 || strcmp(Name, "__table_base") == 0 ||
- strcmp(Name, "__tls_size") == 0) {
+ strcmp(Name, "__tls_size") == 0 || strcmp(Name, "__tls_align") == 0) {
bool Mutable =
strcmp(Name, "__stack_pointer") == 0 || strcmp(Name, "__tls_base") == 0;
WasmSym->setType(wasm::WASM_SYMBOL_TYPE_GLOBAL);
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=366624&r1=366623&r2=366624&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/WebAssembly/tls-general-dynamic.ll (original)
+++ llvm/trunk/test/CodeGen/WebAssembly/tls-general-dynamic.ll Fri Jul 19 16:34:16 2019
@@ -75,6 +75,15 @@ define i32 @tls_size() {
ret i32 %1
}
+; CHECK-LABEL: tls_align:
+; CHECK-NEXT: .functype tls_align () -> (i32)
+define i32 @tls_align() {
+; CHECK-NEXT: global.get __tls_align
+; CHECK-NEXT: return
+ %1 = call i32 @llvm.wasm.tls.align.i32()
+ ret i32 %1
+}
+
; CHECK-LABEL: tls_base:
; CHECK-NEXT: .functype tls_base () -> (i32)
define i8* @tls_base() {
@@ -104,4 +113,5 @@ define void @tls_base_write(i8** %output
@tls = internal thread_local global i32 0
declare i32 @llvm.wasm.tls.size.i32()
+declare i32 @llvm.wasm.tls.align.i32()
declare i8* @llvm.wasm.tls.base()
More information about the llvm-commits
mailing list