]> granicus.if.org Git - clang/commitdiff
[WebAssembly] Compute and export TLS block alignment
authorGuanzhong Chen <gzchen@google.com>
Fri, 19 Jul 2019 23:34:16 +0000 (23:34 +0000)
committerGuanzhong Chen <gzchen@google.com>
Fri, 19 Jul 2019 23:34:16 +0000 (23:34 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@366624 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/BuiltinsWebAssembly.def
lib/CodeGen/CGBuiltin.cpp
test/CodeGen/builtins-wasm.c

index 0c0ca9e9308b44b73b5734067262d1ccc611c3f2..acd713d465b7b39ef77251d3674113f089f71c7c 100644 (file)
@@ -31,6 +31,7 @@ TARGET_BUILTIN(__builtin_wasm_data_drop, "vIUi", "", "bulk-memory")
 
 // Thread-local storage
 TARGET_BUILTIN(__builtin_wasm_tls_size, "z", "nc", "bulk-memory")
+TARGET_BUILTIN(__builtin_wasm_tls_align, "z", "nc", "bulk-memory")
 TARGET_BUILTIN(__builtin_wasm_tls_base, "v*", "nU", "bulk-memory")
 
 // Floating point min/max
index 8c7411fc30567150be19c27c52f81164093eed36..dee1e207ef30fa2ce9ae02ac994134ed98227996 100644 (file)
@@ -13924,6 +13924,11 @@ Value *CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
     Function *Callee = CGM.getIntrinsic(Intrinsic::wasm_tls_size, ResultType);
     return Builder.CreateCall(Callee);
   }
+  case WebAssembly::BI__builtin_wasm_tls_align: {
+    llvm::Type *ResultType = ConvertType(E->getType());
+    Function *Callee = CGM.getIntrinsic(Intrinsic::wasm_tls_align, ResultType);
+    return Builder.CreateCall(Callee);
+  }
   case WebAssembly::BI__builtin_wasm_tls_base: {
     Function *Callee = CGM.getIntrinsic(Intrinsic::wasm_tls_base);
     return Builder.CreateCall(Callee);
index 8f8e7a9e4d0aa69f791fc06de3e87174a3e8f67d..f3129b787acf493e46e9bdfa90af8a145b41002c 100644 (file)
@@ -44,6 +44,12 @@ __SIZE_TYPE__ tls_size() {
   // WEBASSEMBLY64: call i64 @llvm.wasm.tls.size.i64()
 }
 
+__SIZE_TYPE__ tls_align() {
+  return __builtin_wasm_tls_align();
+  // WEBASSEMBLY32: call i32 @llvm.wasm.tls.align.i32()
+  // WEBASSEMBLY64: call i64 @llvm.wasm.tls.align.i64()
+}
+
 void *tls_base() {
   return __builtin_wasm_tls_base();
   // WEBASSEMBLY: call i8* @llvm.wasm.tls.base()