[WebAssembly] Avoid cast ExprType to wasm::ValType
authorSam Clegg <sbc@chromium.org>
Fri, 2 Mar 2018 21:33:14 +0000 (21:33 +0000)
committerSam Clegg <sbc@chromium.org>
Fri, 2 Mar 2018 21:33:14 +0000 (21:33 +0000)
This cast was causing invalid signatures to be written
for libcall functions.

Add an MC test which includes a call to builtin memcpy.

Differential Revision: https://reviews.llvm.org/D44037

llvm-svn: 326618

llvm/lib/Target/WebAssembly/WebAssemblyRuntimeLibcallSignatures.cpp
llvm/test/MC/WebAssembly/libcall.ll [new file with mode: 0644]

index 97d33c4..e2a0d9d 100644 (file)
@@ -491,9 +491,8 @@ void llvm::GetSignature(const WebAssemblySubtarget &Subtarget,
   assert(Rets.empty());
   assert(Params.empty());
 
-  WebAssembly::ExprType iPTR = Subtarget.hasAddr64() ?
-                               WebAssembly::ExprType::I64 :
-                               WebAssembly::ExprType::I32;
+  wasm::ValType iPTR =
+      Subtarget.hasAddr64() ? wasm::ValType::I64 : wasm::ValType::I32;
 
   auto& Table = RuntimeLibcallSignatures->Table;
   switch (Table[LC]) {
@@ -600,13 +599,13 @@ void llvm::GetSignature(const WebAssemblySubtarget &Subtarget,
     break;
   case func_f32_iPTR_iPTR:
     Params.push_back(wasm::ValType::F32);
-    Params.push_back(wasm::ValType(iPTR));
-    Params.push_back(wasm::ValType(iPTR));
+    Params.push_back(iPTR);
+    Params.push_back(iPTR);
     break;
   case func_f64_iPTR_iPTR:
     Params.push_back(wasm::ValType::F64);
-    Params.push_back(wasm::ValType(iPTR));
-    Params.push_back(wasm::ValType(iPTR));
+    Params.push_back(iPTR);
+    Params.push_back(iPTR);
     break;
   case i16_func_i16_i16:
     Rets.push_back(wasm::ValType::I32);
@@ -638,7 +637,7 @@ void llvm::GetSignature(const WebAssemblySubtarget &Subtarget,
     Rets.push_back(wasm::ValType::I64);
     Rets.push_back(wasm::ValType::I64);
 #else
-    Params.push_back(wasm::ValType(iPTR));
+    Params.push_back(iPTR);
 #endif
     Params.push_back(wasm::ValType::F32);
     break;
@@ -647,7 +646,7 @@ void llvm::GetSignature(const WebAssemblySubtarget &Subtarget,
     Rets.push_back(wasm::ValType::I64);
     Rets.push_back(wasm::ValType::I64);
 #else
-    Params.push_back(wasm::ValType(iPTR));
+    Params.push_back(iPTR);
 #endif
     Params.push_back(wasm::ValType::F64);
     break;
@@ -656,7 +655,7 @@ void llvm::GetSignature(const WebAssemblySubtarget &Subtarget,
     Rets.push_back(wasm::ValType::I32);
     Rets.push_back(wasm::ValType::I32);
 #else
-    Params.push_back(wasm::ValType(iPTR));
+    Params.push_back(iPTR);
 #endif
     Params.push_back(wasm::ValType::I32);
     Params.push_back(wasm::ValType::I32);
@@ -666,7 +665,7 @@ void llvm::GetSignature(const WebAssemblySubtarget &Subtarget,
     Rets.push_back(wasm::ValType::I32);
     Rets.push_back(wasm::ValType::I32);
 #else
-    Params.push_back(wasm::ValType(iPTR));
+    Params.push_back(iPTR);
 #endif
     Params.push_back(wasm::ValType::I32);
     Params.push_back(wasm::ValType::I32);
@@ -676,7 +675,7 @@ void llvm::GetSignature(const WebAssemblySubtarget &Subtarget,
     Rets.push_back(wasm::ValType::I64);
     Rets.push_back(wasm::ValType::I64);
 #else
-    Params.push_back(wasm::ValType(iPTR));
+    Params.push_back(iPTR);
 #endif
     Params.push_back(wasm::ValType::I64);
     Params.push_back(wasm::ValType::I64);
@@ -686,7 +685,7 @@ void llvm::GetSignature(const WebAssemblySubtarget &Subtarget,
     Rets.push_back(wasm::ValType::I64);
     Rets.push_back(wasm::ValType::I64);
 #else
-    Params.push_back(wasm::ValType(iPTR));
+    Params.push_back(iPTR);
 #endif
     Params.push_back(wasm::ValType::I64);
     Params.push_back(wasm::ValType::I64);
@@ -700,7 +699,7 @@ void llvm::GetSignature(const WebAssemblySubtarget &Subtarget,
     Rets.push_back(wasm::ValType::I64);
     Rets.push_back(wasm::ValType::I64);
 #else
-    Params.push_back(wasm::ValType(iPTR));
+    Params.push_back(iPTR);
 #endif
     Params.push_back(wasm::ValType::I64);
     Params.push_back(wasm::ValType::I64);
@@ -714,23 +713,23 @@ void llvm::GetSignature(const WebAssemblySubtarget &Subtarget,
     Rets.push_back(wasm::ValType::I64);
     Rets.push_back(wasm::ValType::I64);
 #else
-    Params.push_back(wasm::ValType(iPTR));
+    Params.push_back(iPTR);
 #endif
     Params.push_back(wasm::ValType::I64);
     Params.push_back(wasm::ValType::I64);
     Params.push_back(wasm::ValType::I32);
     break;
   case iPTR_func_iPTR_i32_iPTR:
-    Rets.push_back(wasm::ValType(iPTR));
-    Params.push_back(wasm::ValType(iPTR));
+    Rets.push_back(iPTR);
+    Params.push_back(iPTR);
     Params.push_back(wasm::ValType::I32);
-    Params.push_back(wasm::ValType(iPTR));
+    Params.push_back(iPTR);
     break;
   case iPTR_func_iPTR_iPTR_iPTR:
-    Rets.push_back(wasm::ValType(iPTR));
-    Params.push_back(wasm::ValType(iPTR));
-    Params.push_back(wasm::ValType(iPTR));
-    Params.push_back(wasm::ValType(iPTR));
+    Rets.push_back(iPTR);
+    Params.push_back(iPTR);
+    Params.push_back(iPTR);
+    Params.push_back(iPTR);
     break;
   case f32_func_f32_f32_f32:
     Rets.push_back(wasm::ValType::F32);
@@ -747,39 +746,39 @@ void llvm::GetSignature(const WebAssemblySubtarget &Subtarget,
   case func_i64_i64_iPTR_iPTR:
     Params.push_back(wasm::ValType::I64);
     Params.push_back(wasm::ValType::I64);
-    Params.push_back(wasm::ValType(iPTR));
-    Params.push_back(wasm::ValType(iPTR));
+    Params.push_back(iPTR);
+    Params.push_back(iPTR);
     break;
   case func_iPTR_f32:
-    Params.push_back(wasm::ValType(iPTR));
+    Params.push_back(iPTR);
     Params.push_back(wasm::ValType::F32);
     break;
   case func_iPTR_f64:
-    Params.push_back(wasm::ValType(iPTR));
+    Params.push_back(iPTR);
     Params.push_back(wasm::ValType::F64);
     break;
   case func_iPTR_i32:
-    Params.push_back(wasm::ValType(iPTR));
+    Params.push_back(iPTR);
     Params.push_back(wasm::ValType::I32);
     break;
   case func_iPTR_i64:
-    Params.push_back(wasm::ValType(iPTR));
+    Params.push_back(iPTR);
     Params.push_back(wasm::ValType::I64);
     break;
   case func_iPTR_i64_i64:
-    Params.push_back(wasm::ValType(iPTR));
+    Params.push_back(iPTR);
     Params.push_back(wasm::ValType::I64);
     Params.push_back(wasm::ValType::I64);
     break;
   case func_iPTR_i64_i64_i64_i64:
-    Params.push_back(wasm::ValType(iPTR));
+    Params.push_back(iPTR);
     Params.push_back(wasm::ValType::I64);
     Params.push_back(wasm::ValType::I64);
     Params.push_back(wasm::ValType::I64);
     Params.push_back(wasm::ValType::I64);
     break;
   case func_iPTR_i64_i64_i64_i64_i64_i64:
-    Params.push_back(wasm::ValType(iPTR));
+    Params.push_back(iPTR);
     Params.push_back(wasm::ValType::I64);
     Params.push_back(wasm::ValType::I64);
     Params.push_back(wasm::ValType::I64);
diff --git a/llvm/test/MC/WebAssembly/libcall.ll b/llvm/test/MC/WebAssembly/libcall.ll
new file mode 100644 (file)
index 0000000..d337cbb
--- /dev/null
@@ -0,0 +1,30 @@
+; RUN: llc -filetype=obj %s -o - | obj2yaml | FileCheck %s
+
+target triple = "wasm32-unknown-unknown-wasm"
+
+define hidden void @call_memcpy(i8* align 4 %a, i8* align 4 %b) {
+entry:
+  tail call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %a, i8* align 4 %b, i32 512, i1 false)
+  ret void
+}
+
+declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture writeonly, i8* nocapture readonly, i32, i1)
+
+; CHECK:      --- !WASM
+; CHECK-NEXT: FileHeader:
+; CHECK-NEXT:   Version:         0x00000001
+; CHECK-NEXT: Sections:
+; CHECK-NEXT:   - Type:            TYPE
+; CHECK-NEXT:     Signatures:
+; CHECK-NEXT:       - Index:           0
+; CHECK-NEXT:         ReturnType:      NORESULT
+; CHECK-NEXT:         ParamTypes:
+; CHECK-NEXT:           - I32
+; CHECK-NEXT:           - I32
+; CHECK-NEXT:       - Index:           1
+; CHECK-NEXT:         ReturnType:      I32
+; CHECK-NEXT:         ParamTypes:
+; CHECK-NEXT:           - I32
+; CHECK-NEXT:           - I32
+; CHECK-NEXT:           - I32
+; CHECK-NEXT:   - Type:            IMPORT