[llvm] r365426 - [WebAssembly] Make sret parameter work with AddMissingPrototypes

Heejin Ahn via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 8 19:10:33 PDT 2019


Author: aheejin
Date: Mon Jul  8 19:10:33 2019
New Revision: 365426

URL: http://llvm.org/viewvc/llvm-project?rev=365426&view=rev
Log:
[WebAssembly] Make sret parameter work with AddMissingPrototypes

Summary:
Even with functions with `no-prototype` attribute, there can be an
argument `sret` (structure return) attribute, which is an optimization
when a function return type is a struct. Fixes PR42420.

Reviewers: sbc100

Subscribers: dschuff, jgravelle-google, llvm-commits

Tags: #llvm

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

Modified:
    llvm/trunk/lib/Target/WebAssembly/WebAssemblyAddMissingPrototypes.cpp
    llvm/trunk/test/CodeGen/WebAssembly/add-prototypes.ll

Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyAddMissingPrototypes.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyAddMissingPrototypes.cpp?rev=365426&r1=365425&r2=365426&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyAddMissingPrototypes.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyAddMissingPrototypes.cpp Mon Jul  8 19:10:33 2019
@@ -78,10 +78,13 @@ bool WebAssemblyAddMissingPrototypes::ru
       report_fatal_error(
           "Functions with 'no-prototype' attribute must take varargs: " +
           F.getName());
-    if (F.getFunctionType()->getNumParams() != 0)
-      report_fatal_error(
-          "Functions with 'no-prototype' attribute should not have params: " +
-          F.getName());
+    unsigned NumParams = F.getFunctionType()->getNumParams();
+    if (NumParams != 0) {
+      if (!(NumParams == 1 && F.arg_begin()->hasStructRetAttr()))
+        report_fatal_error("Functions with 'no-prototype' attribute should "
+                           "not have params: " +
+                           F.getName());
+    }
 
     // Create a function prototype based on the first call site (first bitcast)
     // that we find.

Modified: llvm/trunk/test/CodeGen/WebAssembly/add-prototypes.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/WebAssembly/add-prototypes.ll?rev=365426&r1=365425&r2=365426&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/WebAssembly/add-prototypes.ll (original)
+++ llvm/trunk/test/CodeGen/WebAssembly/add-prototypes.ll Mon Jul  8 19:10:33 2019
@@ -56,6 +56,17 @@ define void @as_paramater() {
   ret void
 }
 
+; Check if a sret parameter works in a no-prototype function.
+; CHECK-LABEL: @sret_param
+; CHECK: call void @make_struct_foo(%struct.foo* sret %foo)
+%struct.foo = type { i32, i32 }
+declare void @make_struct_foo(%struct.foo* sret, ...) #1
+define void @sret_param() {
+  %foo = alloca %struct.foo, align 4
+  call void bitcast (void (%struct.foo*, ...)* @make_struct_foo to void (%struct.foo*)*)(%struct.foo* sret %foo)
+  ret void
+}
+
 declare void @func_param(i64 (...)*)
 
 ; CHECK: declare void @func_not_called()




More information about the llvm-commits mailing list