]> granicus.if.org Git - clang/commitdiff
[WebAssembly] Update to the new names for the memory builtin functions.
authorDan Gohman <dan433584@gmail.com>
Fri, 1 Jun 2018 00:05:51 +0000 (00:05 +0000)
committerDan Gohman <dan433584@gmail.com>
Fri, 1 Jun 2018 00:05:51 +0000 (00:05 +0000)
The WebAssembly committee has decided on the names `memory.size` and
`memory.grow` for the memory intrinsics, so update the clang builtin
functions to follow those names, keeping both sets of old names in place
for compatibility.

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

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

index 95b520ac097daf9263d1b11d4cf28dd75cc06ee6..b3d877dcedf385ac2f5a99b3b7d47e419dd0f7a7 100644 (file)
 // The format of this database matches clang/Basic/Builtins.def.
 
 // Query the current memory size, and increase the current memory size.
-// Note that mem.size is not "c" (readnone) because it must be sequenced
-// with respect to grow_memory calls.
-// These are the new proposed names, which aren't yet official. Use at your own
-// risk.
+// Note that memory.size is not "c" (readnone) because it must be sequenced
+// with respect to memory.grow calls.
+BUILTIN(__builtin_wasm_memory_size, "zIi", "n")
+BUILTIN(__builtin_wasm_memory_grow, "zIiz", "n")
+
+// These are the old names.
 BUILTIN(__builtin_wasm_mem_size, "zIi", "n")
 BUILTIN(__builtin_wasm_mem_grow, "zIiz", "n")
 
-// These are the existing names, which are currently official, but expected
-// to be deprecated in the future. They also lack the immediate field.
+// These are the old old names. They also lack the immediate field.
 BUILTIN(__builtin_wasm_current_memory, "z", "n")
 BUILTIN(__builtin_wasm_grow_memory, "zz", "n")
 
index 36c811f473b215a4ba0b57c139d1b847a49054ef..2dd9c63ffabdf22d824850526e3350d990cfe0bf 100644 (file)
@@ -11221,6 +11221,21 @@ Value *CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned BuiltinID,
 Value *CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
                                                    const CallExpr *E) {
   switch (BuiltinID) {
+  case WebAssembly::BI__builtin_wasm_memory_size: {
+    llvm::Type *ResultType = ConvertType(E->getType());
+    Value *I = EmitScalarExpr(E->getArg(0));
+    Value *Callee = CGM.getIntrinsic(Intrinsic::wasm_memory_size, ResultType);
+    return Builder.CreateCall(Callee, I);
+  }
+  case WebAssembly::BI__builtin_wasm_memory_grow: {
+    llvm::Type *ResultType = ConvertType(E->getType());
+    Value *Args[] = {
+      EmitScalarExpr(E->getArg(0)),
+      EmitScalarExpr(E->getArg(1))
+    };
+    Value *Callee = CGM.getIntrinsic(Intrinsic::wasm_memory_grow, ResultType);
+    return Builder.CreateCall(Callee, Args);
+  }
   case WebAssembly::BI__builtin_wasm_mem_size: {
     llvm::Type *ResultType = ConvertType(E->getType());
     Value *I = EmitScalarExpr(E->getArg(0));
index 39252e752ac9b89c53e45490e6ae4ab6001e3074..1b647b56d1a255b65dfe208679ecba7b7b29b474 100644 (file)
@@ -4,36 +4,48 @@
 // RUN:   | FileCheck %s -check-prefix=WEBASSEMBLY64
 
 __SIZE_TYPE__ f0(void) {
+  return __builtin_wasm_memory_size(0);
+// WEBASSEMBLY32: call {{i.*}} @llvm.wasm.memory.size.i32(i32 0)
+// WEBASSEMBLY64: call {{i.*}} @llvm.wasm.memory.size.i64(i32 0)
+}
+
+__SIZE_TYPE__ f1(__SIZE_TYPE__ delta) {
+  return __builtin_wasm_memory_grow(0, delta);
+// WEBASSEMBLY32: call i32 @llvm.wasm.memory.grow.i32(i32 0, i32 %{{.*}})
+// WEBASSEMBLY64: call i64 @llvm.wasm.memory.grow.i64(i32 0, i64 %{{.*}})
+}
+
+__SIZE_TYPE__ f2(void) {
   return __builtin_wasm_mem_size(0);
 // WEBASSEMBLY32: call {{i.*}} @llvm.wasm.mem.size.i32(i32 0)
 // WEBASSEMBLY64: call {{i.*}} @llvm.wasm.mem.size.i64(i32 0)
 }
 
-__SIZE_TYPE__ f1(__SIZE_TYPE__ delta) {
+__SIZE_TYPE__ f3(__SIZE_TYPE__ delta) {
   return __builtin_wasm_mem_grow(0, delta);
 // WEBASSEMBLY32: call i32 @llvm.wasm.mem.grow.i32(i32 0, i32 %{{.*}})
 // WEBASSEMBLY64: call i64 @llvm.wasm.mem.grow.i64(i32 0, i64 %{{.*}})
 }
 
-__SIZE_TYPE__ f2(void) {
+__SIZE_TYPE__ f4(void) {
   return __builtin_wasm_current_memory();
 // WEBASSEMBLY32: call {{i.*}} @llvm.wasm.current.memory.i32()
 // WEBASSEMBLY64: call {{i.*}} @llvm.wasm.current.memory.i64()
 }
 
-__SIZE_TYPE__ f3(__SIZE_TYPE__ delta) {
+__SIZE_TYPE__ f5(__SIZE_TYPE__ delta) {
   return __builtin_wasm_grow_memory(delta);
 // WEBASSEMBLY32: call i32 @llvm.wasm.grow.memory.i32(i32 %{{.*}})
 // WEBASSEMBLY64: call i64 @llvm.wasm.grow.memory.i64(i64 %{{.*}})
 }
 
-void f4(unsigned int tag, void *obj) {
+void f6(unsigned int tag, void *obj) {
   return __builtin_wasm_throw(tag, obj);
 // WEBASSEMBLY32: call void @llvm.wasm.throw(i32 %{{.*}}, i8* %{{.*}})
 // WEBASSEMBLY64: call void @llvm.wasm.throw(i32 %{{.*}}, i8* %{{.*}})
 }
 
-void f5(void) {
+void f7(void) {
   return __builtin_wasm_rethrow();
 // WEBASSEMBLY32: call void @llvm.wasm.rethrow()
 // WEBASSEMBLY64: call void @llvm.wasm.rethrow()