[llvm] r364445 - [WebAssembly] Implement tail calls and unify tablegen call classes

Thomas Lively via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 26 09:17:15 PDT 2019


Author: tlively
Date: Wed Jun 26 09:17:15 2019
New Revision: 364445

URL: http://llvm.org/viewvc/llvm-project?rev=364445&view=rev
Log:
[WebAssembly] Implement tail calls and unify tablegen call classes

Summary:
Implements direct and indirect tail calls enabled by the 'tail-call'
feature in both DAG ISel and FastISel. Updates existing call tests and
adds new tests including a binary encoding test.

Reviewers: aheejin

Subscribers: dschuff, sbc100, jgravelle-google, hiraditya, sunfish, llvm-commits

Tags: #llvm

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

Added:
    llvm/trunk/test/MC/WebAssembly/tail-call-encodings.s
Modified:
    llvm/trunk/docs/CodeGenerator.rst
    llvm/trunk/lib/Target/WebAssembly/WebAssemblyCallIndirectFixup.cpp
    llvm/trunk/lib/Target/WebAssembly/WebAssemblyFastISel.cpp
    llvm/trunk/lib/Target/WebAssembly/WebAssemblyISD.def
    llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
    llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrCall.td
    llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrInfo.td
    llvm/trunk/lib/Target/WebAssembly/WebAssemblyMemIntrinsicResults.cpp
    llvm/trunk/lib/Target/WebAssembly/WebAssemblyPeephole.cpp
    llvm/trunk/lib/Target/WebAssembly/WebAssemblyUtilities.cpp
    llvm/trunk/test/CodeGen/WebAssembly/call.ll
    llvm/trunk/test/CodeGen/WebAssembly/tailcall.ll
    llvm/trunk/test/DebugInfo/WebAssembly/dbg-value-move-reg-stackify.mir

Modified: llvm/trunk/docs/CodeGenerator.rst
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/CodeGenerator.rst?rev=364445&r1=364444&r2=364445&view=diff
==============================================================================
--- llvm/trunk/docs/CodeGenerator.rst (original)
+++ llvm/trunk/docs/CodeGenerator.rst Wed Jun 26 09:17:15 2019
@@ -2075,7 +2075,8 @@ Tail call optimization
 ----------------------
 
 Tail call optimization, callee reusing the stack of the caller, is currently
-supported on x86/x86-64 and PowerPC. It is performed if:
+supported on x86/x86-64, PowerPC, and WebAssembly. It is performed on x86/x86-64
+and PowerPC if:
 
 * Caller and callee have the calling convention ``fastcc``, ``cc 10`` (GHC
   calling convention) or ``cc 11`` (HiPE calling convention).
@@ -2103,6 +2104,10 @@ PowerPC constraints:
 * On ppc32/64 GOT/PIC only module-local calls (visibility = hidden or protected)
   are supported.
 
+On WebAssembly, tail calls are lowered to ``return_call`` and
+``return_call_indirect`` instructions whenever the 'tail-call' target attribute
+is enabled.
+
 Example:
 
 Call as ``llc -tailcallopt test.ll``.

Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyCallIndirectFixup.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyCallIndirectFixup.cpp?rev=364445&r1=364444&r2=364445&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyCallIndirectFixup.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyCallIndirectFixup.cpp Wed Jun 26 09:17:15 2019
@@ -65,14 +65,14 @@ static unsigned getNonPseudoCallIndirect
     using namespace WebAssembly;
   case PCALL_INDIRECT_VOID:
     return CALL_INDIRECT_VOID;
-  case PCALL_INDIRECT_I32:
-    return CALL_INDIRECT_I32;
-  case PCALL_INDIRECT_I64:
-    return CALL_INDIRECT_I64;
-  case PCALL_INDIRECT_F32:
-    return CALL_INDIRECT_F32;
-  case PCALL_INDIRECT_F64:
-    return CALL_INDIRECT_F64;
+  case PCALL_INDIRECT_i32:
+    return CALL_INDIRECT_i32;
+  case PCALL_INDIRECT_i64:
+    return CALL_INDIRECT_i64;
+  case PCALL_INDIRECT_f32:
+    return CALL_INDIRECT_f32;
+  case PCALL_INDIRECT_f64:
+    return CALL_INDIRECT_f64;
   case PCALL_INDIRECT_v16i8:
     return CALL_INDIRECT_v16i8;
   case PCALL_INDIRECT_v8i16:
@@ -85,6 +85,10 @@ static unsigned getNonPseudoCallIndirect
     return CALL_INDIRECT_v4f32;
   case PCALL_INDIRECT_v2f64:
     return CALL_INDIRECT_v2f64;
+  case PCALL_INDIRECT_ExceptRef:
+    return CALL_INDIRECT_ExceptRef;
+  case PRET_CALL_INDIRECT:
+    return RET_CALL_INDIRECT;
   default:
     return INSTRUCTION_LIST_END;
   }

Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyFastISel.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyFastISel.cpp?rev=364445&r1=364444&r2=364445&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyFastISel.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyFastISel.cpp Wed Jun 26 09:17:15 2019
@@ -741,6 +741,7 @@ bool WebAssemblyFastISel::fastLowerArgum
 bool WebAssemblyFastISel::selectCall(const Instruction *I) {
   const auto *Call = cast<CallInst>(I);
 
+  // TODO: Support tail calls in FastISel
   if (Call->isMustTailCall() || Call->isInlineAsm() ||
       Call->getFunctionType()->isVarArg())
     return false;
@@ -769,19 +770,19 @@ bool WebAssemblyFastISel::selectCall(con
     case MVT::i8:
     case MVT::i16:
     case MVT::i32:
-      Opc = IsDirect ? WebAssembly::CALL_I32 : WebAssembly::PCALL_INDIRECT_I32;
+      Opc = IsDirect ? WebAssembly::CALL_i32 : WebAssembly::PCALL_INDIRECT_i32;
       ResultReg = createResultReg(&WebAssembly::I32RegClass);
       break;
     case MVT::i64:
-      Opc = IsDirect ? WebAssembly::CALL_I64 : WebAssembly::PCALL_INDIRECT_I64;
+      Opc = IsDirect ? WebAssembly::CALL_i64 : WebAssembly::PCALL_INDIRECT_i64;
       ResultReg = createResultReg(&WebAssembly::I64RegClass);
       break;
     case MVT::f32:
-      Opc = IsDirect ? WebAssembly::CALL_F32 : WebAssembly::PCALL_INDIRECT_F32;
+      Opc = IsDirect ? WebAssembly::CALL_f32 : WebAssembly::PCALL_INDIRECT_f32;
       ResultReg = createResultReg(&WebAssembly::F32RegClass);
       break;
     case MVT::f64:
-      Opc = IsDirect ? WebAssembly::CALL_F64 : WebAssembly::PCALL_INDIRECT_F64;
+      Opc = IsDirect ? WebAssembly::CALL_f64 : WebAssembly::PCALL_INDIRECT_f64;
       ResultReg = createResultReg(&WebAssembly::F64RegClass);
       break;
     case MVT::v16i8:
@@ -815,8 +816,8 @@ bool WebAssemblyFastISel::selectCall(con
       ResultReg = createResultReg(&WebAssembly::V128RegClass);
       break;
     case MVT::ExceptRef:
-      Opc = IsDirect ? WebAssembly::CALL_EXCEPT_REF
-                     : WebAssembly::PCALL_INDIRECT_EXCEPT_REF;
+      Opc = IsDirect ? WebAssembly::CALL_ExceptRef
+                     : WebAssembly::PCALL_INDIRECT_ExceptRef;
       ResultReg = createResultReg(&WebAssembly::EXCEPT_REFRegClass);
       break;
     default:

Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyISD.def
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyISD.def?rev=364445&r1=364444&r2=364445&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyISD.def (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyISD.def Wed Jun 26 09:17:15 2019
@@ -15,6 +15,7 @@
 
 HANDLE_NODETYPE(CALL1)
 HANDLE_NODETYPE(CALL0)
+HANDLE_NODETYPE(RET_CALL)
 HANDLE_NODETYPE(RETURN)
 HANDLE_NODETYPE(ARGUMENT)
 // A wrapper node for TargetExternalSymbol, TargetGlobalAddress, and MCSymbol

Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp?rev=364445&r1=364444&r2=364445&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp Wed Jun 26 09:17:15 2019
@@ -644,13 +644,14 @@ WebAssemblyTargetLowering::LowerCall(Cal
   if (CLI.IsPatchPoint)
     fail(DL, DAG, "WebAssembly doesn't support patch point yet");
 
-  // WebAssembly doesn't currently support explicit tail calls. If they are
-  // required, fail. Otherwise, just disable them.
-  if ((CallConv == CallingConv::Fast && CLI.IsTailCall &&
-       MF.getTarget().Options.GuaranteedTailCallOpt) ||
-      (CLI.CS && CLI.CS.isMustTailCall()))
-    fail(DL, DAG, "WebAssembly doesn't support tail call yet");
-  CLI.IsTailCall = false;
+  // Fail if tail calls are required but not enabled
+  if (!Subtarget->hasTailCall()) {
+    if ((CallConv == CallingConv::Fast && CLI.IsTailCall &&
+         MF.getTarget().Options.GuaranteedTailCallOpt) ||
+        (CLI.CS && CLI.CS.isMustTailCall()))
+      fail(DL, DAG, "WebAssembly 'tail-call' feature not enabled");
+    CLI.IsTailCall = false;
+  }
 
   SmallVectorImpl<ISD::InputArg> &Ins = CLI.Ins;
   if (Ins.size() > 1)
@@ -783,6 +784,13 @@ WebAssemblyTargetLowering::LowerCall(Cal
     // registers.
     InTys.push_back(In.VT);
   }
+
+  if (CLI.IsTailCall) {
+    // ret_calls do not return values to the current frame
+    SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue);
+    return DAG.getNode(WebAssemblyISD::RET_CALL, DL, NodeTys, Ops);
+  }
+
   InTys.push_back(MVT::Other);
   SDVTList InTyList = DAG.getVTList(InTys);
   SDValue Res =

Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrCall.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrCall.td?rev=364445&r1=364444&r2=364445&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrCall.td (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrCall.td Wed Jun 26 09:17:15 2019
@@ -23,106 +23,110 @@ defm ADJCALLSTACKUP : NRI<(outs), (ins i
                           [(WebAssemblycallseq_end timm:$amt, timm:$amt2)]>;
 } // Uses = [SP32, SP64], Defs = [SP32, SP64], isCodeGenOnly = 1
 
-multiclass CALL<WebAssemblyRegClass vt, string prefix> {
-  defm CALL_#vt : I<(outs vt:$dst), (ins function32_op:$callee, variable_ops),
-                    (outs), (ins function32_op:$callee),
-                    [(set vt:$dst, (WebAssemblycall1 (i32 imm:$callee)))],
-                    !strconcat(prefix, "call\t$dst, $callee"),
-                    !strconcat(prefix, "call\t$callee"),
-                    0x10>;
+multiclass CALL<ValueType vt, WebAssemblyRegClass rt, string prefix,
+                list<Predicate> preds = []> {
+  defm CALL_#vt :
+    I<(outs rt:$dst), (ins function32_op:$callee, variable_ops),
+      (outs), (ins function32_op:$callee),
+      [(set (vt rt:$dst), (WebAssemblycall1 (i32 imm:$callee)))],
+      !strconcat(prefix, "call\t$dst, $callee"),
+      !strconcat(prefix, "call\t$callee"),
+      0x10>,
+    Requires<preds>;
 
   let isCodeGenOnly = 1 in
-  defm PCALL_INDIRECT_#vt : I<(outs vt:$dst), (ins I32:$callee, variable_ops),
-                              (outs), (ins I32:$callee),
-                              [(set vt:$dst, (WebAssemblycall1 I32:$callee))],
-                              "PSEUDO CALL INDIRECT\t$callee",
-                              "PSEUDO CALL INDIRECT\t$callee">;
-
-  defm CALL_INDIRECT_#vt : I<(outs vt:$dst),
-                             (ins TypeIndex:$type, i32imm:$flags, variable_ops),
-                             (outs), (ins TypeIndex:$type, i32imm:$flags),
-                             [],
-                             !strconcat(prefix, "call_indirect\t$dst"),
-                             !strconcat(prefix, "call_indirect\t$type"),
-                             0x11>;
-}
-
-multiclass SIMD_CALL<ValueType vt, string prefix> {
-
-  defm CALL_#vt : I<(outs V128:$dst), (ins function32_op:$callee, variable_ops),
-                    (outs), (ins function32_op:$callee),
-                    [(set (vt V128:$dst),
-                      (WebAssemblycall1 (i32 imm:$callee)))],
-                    !strconcat(prefix, "call\t$dst, $callee"),
-                    !strconcat(prefix, "call\t$callee"),
-                    0x10>,
-                  Requires<[HasSIMD128]>;
-
-  let isCodeGenOnly = 1 in
-  defm PCALL_INDIRECT_#vt : I<(outs V128:$dst),
-                              (ins I32:$callee, variable_ops),
-                              (outs), (ins I32:$callee),
-                              [(set (vt V128:$dst),
-                                    (WebAssemblycall1 I32:$callee))],
-                              "PSEUDO CALL INDIRECT\t$callee",
-                              "PSEUDO CALL INDIRECT\t$callee">,
-                              Requires<[HasSIMD128]>;
-
-  defm CALL_INDIRECT_#vt : I<(outs V128:$dst),
-                             (ins TypeIndex:$type, i32imm:$flags, variable_ops),
-                             (outs), (ins TypeIndex:$type, i32imm:$flags),
-                             [],
-                             !strconcat(prefix, "call_indirect\t$dst"),
-                             !strconcat(prefix, "call_indirect\t$type"),
-                             0x11>,
-                             Requires<[HasSIMD128]>;
+  defm PCALL_INDIRECT_#vt :
+    I<(outs rt:$dst), (ins I32:$callee, variable_ops),
+      (outs), (ins I32:$callee),
+      [(set (vt rt:$dst), (WebAssemblycall1 I32:$callee))],
+      "PSEUDO CALL INDIRECT\t$callee",
+      "PSEUDO CALL INDIRECT\t$callee">,
+    Requires<preds>;
+
+  defm CALL_INDIRECT_#vt :
+    I<(outs rt:$dst),
+      (ins TypeIndex:$type, i32imm:$flags, variable_ops),
+      (outs), (ins TypeIndex:$type, i32imm:$flags),
+      [],
+      !strconcat(prefix, "call_indirect\t$dst"),
+      !strconcat(prefix, "call_indirect\t$type"),
+      0x11>,
+    Requires<preds>;
 }
 
 let Uses = [SP32, SP64], isCall = 1 in {
-defm "" : CALL<I32, "i32.">;
-defm "" : CALL<I64, "i64.">;
-defm "" : CALL<F32, "f32.">;
-defm "" : CALL<F64, "f64.">;
-defm "" : CALL<EXCEPT_REF, "except_ref.">;
-defm "" : SIMD_CALL<v16i8, "v128.">;
-defm "" : SIMD_CALL<v8i16, "v128.">;
-defm "" : SIMD_CALL<v4i32, "v128.">;
-defm "" : SIMD_CALL<v2i64, "v128.">;
-defm "" : SIMD_CALL<v4f32, "v128.">;
-defm "" : SIMD_CALL<v2f64, "v128.">;
+defm "" : CALL<i32, I32, "i32.">;
+defm "" : CALL<i64, I64, "i64.">;
+defm "" : CALL<f32, F32, "f32.">;
+defm "" : CALL<f64, F64, "f64.">;
+defm "" : CALL<ExceptRef, EXCEPT_REF, "except_ref.", [HasExceptionHandling]>;
+defm "" : CALL<v16i8, V128, "v128.", [HasSIMD128]>;
+defm "" : CALL<v8i16, V128, "v128.", [HasSIMD128]>;
+defm "" : CALL<v4i32, V128, "v128.", [HasSIMD128]>;
+defm "" : CALL<v2i64, V128, "v128.", [HasSIMD128]>;
+defm "" : CALL<v4f32, V128, "v128.", [HasSIMD128]>;
+defm "" : CALL<v2f64, V128, "v128.", [HasSIMD128]>;
 
 let IsCanonical = 1 in {
-defm CALL_VOID : I<(outs), (ins function32_op:$callee, variable_ops),
-                   (outs), (ins function32_op:$callee),
-                   [(WebAssemblycall0 (i32 imm:$callee))],
-                   "call    \t$callee", "call\t$callee", 0x10>;
+defm CALL_VOID :
+  I<(outs), (ins function32_op:$callee, variable_ops),
+    (outs), (ins function32_op:$callee),
+    [(WebAssemblycall0 (i32 imm:$callee))],
+    "call    \t$callee", "call\t$callee", 0x10>;
+
+let isReturn = 1 in
+defm RET_CALL :
+  I<(outs), (ins function32_op:$callee, variable_ops),
+    (outs), (ins function32_op:$callee),
+    [(WebAssemblyretcall (i32 imm:$callee))],
+    "return_call    \t$callee", "return_call\t$callee", 0x12>,
+  Requires<[HasTailCall]>;
 
 let isCodeGenOnly = 1 in
-defm PCALL_INDIRECT_VOID : I<(outs), (ins I32:$callee, variable_ops),
-                             (outs), (ins I32:$callee),
-                             [(WebAssemblycall0 I32:$callee)],
-                             "PSEUDO CALL INDIRECT\t$callee",
-                             "PSEUDO CALL INDIRECT\t$callee">;
-
-defm CALL_INDIRECT_VOID : I<(outs),
-                            (ins TypeIndex:$type, i32imm:$flags,
-                              variable_ops),
-                            (outs), (ins TypeIndex:$type, i32imm:$flags),
-                            [],
-                            "call_indirect\t", "call_indirect\t$type",
-                            0x11>;
+defm PCALL_INDIRECT_VOID :
+  I<(outs), (ins I32:$callee, variable_ops),
+    (outs), (ins I32:$callee),
+    [(WebAssemblycall0 I32:$callee)],
+    "PSEUDO CALL INDIRECT\t$callee",
+    "PSEUDO CALL INDIRECT\t$callee">;
+
+defm CALL_INDIRECT_VOID :
+  I<(outs), (ins TypeIndex:$type, i32imm:$flags, variable_ops),
+    (outs), (ins TypeIndex:$type, i32imm:$flags),
+    [],
+    "call_indirect\t", "call_indirect\t$type",
+    0x11>;
+
+let isReturn = 1 in
+defm RET_CALL_INDIRECT :
+  I<(outs), (ins TypeIndex:$type, i32imm:$flags, variable_ops),
+    (outs), (ins TypeIndex:$type, i32imm:$flags),
+    [],
+    "return_call_indirect\t", "return_call_indirect\t$type",
+    0x13>,
+  Requires<[HasTailCall]>;
+
+let isCodeGenOnly = 1, isReturn = 1 in
+defm PRET_CALL_INDIRECT:
+    I<(outs), (ins I32:$callee, variable_ops),
+      (outs), (ins I32:$callee),
+      [(WebAssemblyretcall I32:$callee)],
+      "PSEUDO RET_CALL INDIRECT\t$callee",
+      "PSEUDO RET_CALL INDIRECT\t$callee">,
+    Requires<[HasTailCall]>;
+
 } // IsCanonical = 1
 } // Uses = [SP32,SP64], isCall = 1
 
 // Patterns for matching a direct call to a global address.
 def : Pat<(i32 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
-          (CALL_I32 tglobaladdr:$callee)>;
+          (CALL_i32 tglobaladdr:$callee)>;
 def : Pat<(i64 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
-          (CALL_I64 tglobaladdr:$callee)>;
+          (CALL_i64 tglobaladdr:$callee)>;
 def : Pat<(f32 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
-          (CALL_F32 tglobaladdr:$callee)>;
+          (CALL_f32 tglobaladdr:$callee)>;
 def : Pat<(f64 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
-          (CALL_F64 tglobaladdr:$callee)>;
+          (CALL_f64 tglobaladdr:$callee)>;
 def : Pat<(v16i8 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
           (CALL_v16i8 tglobaladdr:$callee)>, Requires<[HasSIMD128]>;
 def : Pat<(v8i16 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
@@ -137,19 +141,22 @@ def : Pat<(v2f64 (WebAssemblycall1 (WebA
           (CALL_v2f64 tglobaladdr:$callee)>, Requires<[HasSIMD128]>;
 def : Pat<(ExceptRef
            (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
-          (CALL_EXCEPT_REF tglobaladdr:$callee)>;
+          (CALL_ExceptRef tglobaladdr:$callee)>,
+      Requires<[HasExceptionHandling]>;
 def : Pat<(WebAssemblycall0 (WebAssemblywrapper tglobaladdr:$callee)),
           (CALL_VOID tglobaladdr:$callee)>;
+def : Pat<(WebAssemblyretcall (WebAssemblywrapper tglobaladdr:$callee)),
+          (RET_CALL tglobaladdr:$callee)>, Requires<[HasTailCall]>;
 
 // Patterns for matching a direct call to an external symbol.
 def : Pat<(i32 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
-          (CALL_I32 texternalsym:$callee)>;
+          (CALL_i32 texternalsym:$callee)>;
 def : Pat<(i64 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
-          (CALL_I64 texternalsym:$callee)>;
+          (CALL_i64 texternalsym:$callee)>;
 def : Pat<(f32 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
-          (CALL_F32 texternalsym:$callee)>;
+          (CALL_f32 texternalsym:$callee)>;
 def : Pat<(f64 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
-          (CALL_F64 texternalsym:$callee)>;
+          (CALL_f64 texternalsym:$callee)>;
 def : Pat<(v16i8 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
           (CALL_v16i8 texternalsym:$callee)>, Requires<[HasSIMD128]>;
 def : Pat<(v8i16 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
@@ -164,6 +171,9 @@ def : Pat<(v2f64 (WebAssemblycall1 (WebA
           (CALL_v2f64 texternalsym:$callee)>, Requires<[HasSIMD128]>;
 def : Pat<(ExceptRef
            (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
-          (CALL_EXCEPT_REF texternalsym:$callee)>;
+          (CALL_ExceptRef texternalsym:$callee)>,
+      Requires<[HasExceptionHandling]>;
 def : Pat<(WebAssemblycall0 (WebAssemblywrapper texternalsym:$callee)),
           (CALL_VOID texternalsym:$callee)>;
+def : Pat<(WebAssemblyretcall (WebAssemblywrapper texternalsym:$callee)),
+          (RET_CALL texternalsym:$callee)>, Requires<[HasTailCall]>;

Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrInfo.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrInfo.td?rev=364445&r1=364444&r2=364445&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrInfo.td (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrInfo.td Wed Jun 26 09:17:15 2019
@@ -97,6 +97,9 @@ def WebAssemblycall0 : SDNode<"WebAssemb
 def WebAssemblycall1 : SDNode<"WebAssemblyISD::CALL1",
                               SDT_WebAssemblyCall1,
                               [SDNPHasChain, SDNPVariadic]>;
+def WebAssemblyretcall : SDNode<"WebAssemblyISD::RET_CALL",
+                                SDT_WebAssemblyCall0,
+                                [SDNPHasChain, SDNPVariadic]>;
 def WebAssemblybr_table : SDNode<"WebAssemblyISD::BR_TABLE",
                                  SDT_WebAssemblyBrTable,
                                  [SDNPHasChain, SDNPVariadic]>;

Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyMemIntrinsicResults.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyMemIntrinsicResults.cpp?rev=364445&r1=364444&r2=364445&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyMemIntrinsicResults.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyMemIntrinsicResults.cpp Wed Jun 26 09:17:15 2019
@@ -200,8 +200,8 @@ bool WebAssemblyMemIntrinsicResults::run
       switch (MI.getOpcode()) {
       default:
         break;
-      case WebAssembly::CALL_I32:
-      case WebAssembly::CALL_I64:
+      case WebAssembly::CALL_i32:
+      case WebAssembly::CALL_i64:
         Changed |= optimizeCall(MBB, MI, MRI, MDT, LIS, TLI, LibInfo);
         break;
       }

Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyPeephole.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyPeephole.cpp?rev=364445&r1=364444&r2=364445&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyPeephole.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyPeephole.cpp Wed Jun 26 09:17:15 2019
@@ -128,8 +128,8 @@ bool WebAssemblyPeephole::runOnMachineFu
       switch (MI.getOpcode()) {
       default:
         break;
-      case WebAssembly::CALL_I32:
-      case WebAssembly::CALL_I64: {
+      case WebAssembly::CALL_i32:
+      case WebAssembly::CALL_i64: {
         MachineOperand &Op1 = MI.getOperand(1);
         if (Op1.isSymbol()) {
           StringRef Name(Op1.getSymbolName());

Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyUtilities.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyUtilities.cpp?rev=364445&r1=364444&r2=364445&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyUtilities.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyUtilities.cpp Wed Jun 26 09:17:15 2019
@@ -107,14 +107,14 @@ bool WebAssembly::isCallDirect(const Mac
   switch (MI.getOpcode()) {
   case WebAssembly::CALL_VOID:
   case WebAssembly::CALL_VOID_S:
-  case WebAssembly::CALL_I32:
-  case WebAssembly::CALL_I32_S:
-  case WebAssembly::CALL_I64:
-  case WebAssembly::CALL_I64_S:
-  case WebAssembly::CALL_F32:
-  case WebAssembly::CALL_F32_S:
-  case WebAssembly::CALL_F64:
-  case WebAssembly::CALL_F64_S:
+  case WebAssembly::CALL_i32:
+  case WebAssembly::CALL_i32_S:
+  case WebAssembly::CALL_i64:
+  case WebAssembly::CALL_i64_S:
+  case WebAssembly::CALL_f32:
+  case WebAssembly::CALL_f32_S:
+  case WebAssembly::CALL_f64:
+  case WebAssembly::CALL_f64_S:
   case WebAssembly::CALL_v16i8:
   case WebAssembly::CALL_v16i8_S:
   case WebAssembly::CALL_v8i16:
@@ -127,8 +127,10 @@ bool WebAssembly::isCallDirect(const Mac
   case WebAssembly::CALL_v4f32_S:
   case WebAssembly::CALL_v2f64:
   case WebAssembly::CALL_v2f64_S:
-  case WebAssembly::CALL_EXCEPT_REF:
-  case WebAssembly::CALL_EXCEPT_REF_S:
+  case WebAssembly::CALL_ExceptRef:
+  case WebAssembly::CALL_ExceptRef_S:
+  case WebAssembly::RET_CALL:
+  case WebAssembly::RET_CALL_S:
     return true;
   default:
     return false;
@@ -139,14 +141,14 @@ bool WebAssembly::isCallIndirect(const M
   switch (MI.getOpcode()) {
   case WebAssembly::CALL_INDIRECT_VOID:
   case WebAssembly::CALL_INDIRECT_VOID_S:
-  case WebAssembly::CALL_INDIRECT_I32:
-  case WebAssembly::CALL_INDIRECT_I32_S:
-  case WebAssembly::CALL_INDIRECT_I64:
-  case WebAssembly::CALL_INDIRECT_I64_S:
-  case WebAssembly::CALL_INDIRECT_F32:
-  case WebAssembly::CALL_INDIRECT_F32_S:
-  case WebAssembly::CALL_INDIRECT_F64:
-  case WebAssembly::CALL_INDIRECT_F64_S:
+  case WebAssembly::CALL_INDIRECT_i32:
+  case WebAssembly::CALL_INDIRECT_i32_S:
+  case WebAssembly::CALL_INDIRECT_i64:
+  case WebAssembly::CALL_INDIRECT_i64_S:
+  case WebAssembly::CALL_INDIRECT_f32:
+  case WebAssembly::CALL_INDIRECT_f32_S:
+  case WebAssembly::CALL_INDIRECT_f64:
+  case WebAssembly::CALL_INDIRECT_f64_S:
   case WebAssembly::CALL_INDIRECT_v16i8:
   case WebAssembly::CALL_INDIRECT_v16i8_S:
   case WebAssembly::CALL_INDIRECT_v8i16:
@@ -159,8 +161,10 @@ bool WebAssembly::isCallIndirect(const M
   case WebAssembly::CALL_INDIRECT_v4f32_S:
   case WebAssembly::CALL_INDIRECT_v2f64:
   case WebAssembly::CALL_INDIRECT_v2f64_S:
-  case WebAssembly::CALL_INDIRECT_EXCEPT_REF:
-  case WebAssembly::CALL_INDIRECT_EXCEPT_REF_S:
+  case WebAssembly::CALL_INDIRECT_ExceptRef:
+  case WebAssembly::CALL_INDIRECT_ExceptRef_S:
+  case WebAssembly::RET_CALL_INDIRECT:
+  case WebAssembly::RET_CALL_INDIRECT_S:
     return true;
   default:
     return false;
@@ -173,15 +177,19 @@ unsigned WebAssembly::getCalleeOpNo(cons
   case WebAssembly::CALL_VOID_S:
   case WebAssembly::CALL_INDIRECT_VOID:
   case WebAssembly::CALL_INDIRECT_VOID_S:
+  case WebAssembly::RET_CALL:
+  case WebAssembly::RET_CALL_S:
+  case WebAssembly::RET_CALL_INDIRECT:
+  case WebAssembly::RET_CALL_INDIRECT_S:
     return 0;
-  case WebAssembly::CALL_I32:
-  case WebAssembly::CALL_I32_S:
-  case WebAssembly::CALL_I64:
-  case WebAssembly::CALL_I64_S:
-  case WebAssembly::CALL_F32:
-  case WebAssembly::CALL_F32_S:
-  case WebAssembly::CALL_F64:
-  case WebAssembly::CALL_F64_S:
+  case WebAssembly::CALL_i32:
+  case WebAssembly::CALL_i32_S:
+  case WebAssembly::CALL_i64:
+  case WebAssembly::CALL_i64_S:
+  case WebAssembly::CALL_f32:
+  case WebAssembly::CALL_f32_S:
+  case WebAssembly::CALL_f64:
+  case WebAssembly::CALL_f64_S:
   case WebAssembly::CALL_v16i8:
   case WebAssembly::CALL_v16i8_S:
   case WebAssembly::CALL_v8i16:
@@ -194,16 +202,16 @@ unsigned WebAssembly::getCalleeOpNo(cons
   case WebAssembly::CALL_v4f32_S:
   case WebAssembly::CALL_v2f64:
   case WebAssembly::CALL_v2f64_S:
-  case WebAssembly::CALL_EXCEPT_REF:
-  case WebAssembly::CALL_EXCEPT_REF_S:
-  case WebAssembly::CALL_INDIRECT_I32:
-  case WebAssembly::CALL_INDIRECT_I32_S:
-  case WebAssembly::CALL_INDIRECT_I64:
-  case WebAssembly::CALL_INDIRECT_I64_S:
-  case WebAssembly::CALL_INDIRECT_F32:
-  case WebAssembly::CALL_INDIRECT_F32_S:
-  case WebAssembly::CALL_INDIRECT_F64:
-  case WebAssembly::CALL_INDIRECT_F64_S:
+  case WebAssembly::CALL_ExceptRef:
+  case WebAssembly::CALL_ExceptRef_S:
+  case WebAssembly::CALL_INDIRECT_i32:
+  case WebAssembly::CALL_INDIRECT_i32_S:
+  case WebAssembly::CALL_INDIRECT_i64:
+  case WebAssembly::CALL_INDIRECT_i64_S:
+  case WebAssembly::CALL_INDIRECT_f32:
+  case WebAssembly::CALL_INDIRECT_f32_S:
+  case WebAssembly::CALL_INDIRECT_f64:
+  case WebAssembly::CALL_INDIRECT_f64_S:
   case WebAssembly::CALL_INDIRECT_v16i8:
   case WebAssembly::CALL_INDIRECT_v16i8_S:
   case WebAssembly::CALL_INDIRECT_v8i16:
@@ -216,8 +224,8 @@ unsigned WebAssembly::getCalleeOpNo(cons
   case WebAssembly::CALL_INDIRECT_v4f32_S:
   case WebAssembly::CALL_INDIRECT_v2f64:
   case WebAssembly::CALL_INDIRECT_v2f64_S:
-  case WebAssembly::CALL_INDIRECT_EXCEPT_REF:
-  case WebAssembly::CALL_INDIRECT_EXCEPT_REF_S:
+  case WebAssembly::CALL_INDIRECT_ExceptRef:
+  case WebAssembly::CALL_INDIRECT_ExceptRef_S:
     return 1;
   default:
     llvm_unreachable("Not a call instruction");

Modified: llvm/trunk/test/CodeGen/WebAssembly/call.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/WebAssembly/call.ll?rev=364445&r1=364444&r2=364445&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/WebAssembly/call.ll (original)
+++ llvm/trunk/test/CodeGen/WebAssembly/call.ll Wed Jun 26 09:17:15 2019
@@ -1,5 +1,7 @@
-; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-keep-registers -mattr=+sign-ext,+simd128 | FileCheck %s
-; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-keep-registers -fast-isel -fast-isel-abort=1 -mattr=+sign-ext,+simd128 | FileCheck %s
+; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-keep-registers -mattr=+sign-ext,+simd128 | FileCheck --check-prefixes=CHECK,NO-TAIL,SLOW-NO-TAIL %s
+; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-keep-registers -fast-isel -fast-isel-abort=1 -mattr=+sign-ext,+simd128 | FileCheck --check-prefixes=CHECK,NO-TAIL,FAST,FAST-NO-TAIL %s
+; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-keep-registers -mattr=+sign-ext,+simd128,+tail-call | FileCheck --check-prefixes=CHECK,TAIL,SLOW-TAIL %s
+; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-keep-registers -fast-isel -fast-isel-abort=1 -mattr=+sign-ext,+simd128,+tail-call | FileCheck --check-prefixes=CHECK,TAIL,FAST-TAIL %s
 
 ; Test that basic call operations assemble as expected.
 
@@ -176,8 +178,11 @@ define void @call_indirect_arg_2(i32 (i3
 
 ; CHECK-LABEL: tail_call_void_nullary:
 ; CHECK-NEXT: .functype tail_call_void_nullary () -> (){{$}}
-; CHECK-NEXT: {{^}} call void_nullary{{$}}
-; CHECK-NEXT: return{{$}}
+; NO-TAIL-NEXT: {{^}} call void_nullary{{$}}
+; NO-TAIL-NEXT: return{{$}}
+; SLOW-TAIL-NEXT: {{^}} return_call void_nullary{{$}}
+; FAST-TAIL-NEXT: {{^}} call void_nullary{{$}}
+; FAST-TAIL-NEXT: return{{$}}
 define void @tail_call_void_nullary() {
   tail call void @void_nullary()
   ret void
@@ -185,8 +190,11 @@ define void @tail_call_void_nullary() {
 
 ; CHECK-LABEL: fastcc_tail_call_void_nullary:
 ; CHECK-NEXT: .functype fastcc_tail_call_void_nullary () -> (){{$}}
-; CHECK-NEXT: {{^}} call void_nullary{{$}}
-; CHECK-NEXT: return{{$}}
+; NO-TAIL-NEXT: {{^}} call void_nullary{{$}}
+; NO-TAIL-NEXT: return{{$}}
+; SLOW-TAIL-NEXT: {{^}} return_call void_nullary{{$}}
+; FAST-TAIL-NEXT: {{^}} call void_nullary{{$}}
+; FAST-TAIL-NEXT: return{{$}}
 define void @fastcc_tail_call_void_nullary() {
   tail call fastcc void @void_nullary()
   ret void
@@ -194,8 +202,11 @@ define void @fastcc_tail_call_void_nulla
 
 ; CHECK-LABEL: coldcc_tail_call_void_nullary:
 ; CHECK-NEXT: .functype coldcc_tail_call_void_nullary () -> (){{$}}
-; CHECK-NEXT: {{^}} call void_nullary{{$}}
-; CHECK-NEXT: return{{$}}
+; NO-TAIL-NEXT: {{^}} call void_nullary{{$}}
+; NO-TAIL-NEXT: return{{$}}
+; SLOW-TAIL-NEXT: {{^}} return_call void_nullary{{$}}
+; FAST-TAIL-NEXT: {{^}} call void_nullary{{$}}
+; FAST-TAIL-NEXT: return{{$}}
 define void @coldcc_tail_call_void_nullary() {
   tail call coldcc void @void_nullary()
   ret void

Modified: llvm/trunk/test/CodeGen/WebAssembly/tailcall.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/WebAssembly/tailcall.ll?rev=364445&r1=364444&r2=364445&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/WebAssembly/tailcall.ll (original)
+++ llvm/trunk/test/CodeGen/WebAssembly/tailcall.ll Wed Jun 26 09:17:15 2019
@@ -1,16 +1,144 @@
-; RUN: llc < %s -asm-verbose=false -verify-machineinstrs -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -mattr=+tail-call | FileCheck %s
+; RUN: llc < %s -asm-verbose=false -verify-machineinstrs -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -mattr=+tail-call | FileCheck --check-prefixes=CHECK,SLOW %s
+; RUN: llc < %s -asm-verbose=false -verify-machineinstrs -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -fast-isel -mattr=+tail-call | FileCheck --check-prefixes=CHECK,FAST %s
 
 ; Test that the tail-call attribute is accepted
-; TODO(tlively): implement tail call
 
 target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
 target triple = "wasm32-unknown-unknown"
 
+%fn = type <{i32 (%fn, i32, i32)*}>
+declare i1 @foo(i1)
+declare i1 @bar(i1)
+
+; CHECK-LABEL: recursive_notail_nullary:
+; CHECK: {{^}} call recursive_notail_nullary{{$}}
+; CHECK-NEXT: return
+define void @recursive_notail_nullary() {
+  notail call void @recursive_notail_nullary()
+  ret void
+}
+
+; CHECK-LABEL: recursive_musttail_nullary:
+; CHECK: return_call recursive_musttail_nullary{{$}}
+define void @recursive_musttail_nullary() {
+  musttail call void @recursive_musttail_nullary()
+  ret void
+}
+
+; CHECK-LABEL: recursive_tail_nullary:
+; SLOW: return_call recursive_tail_nullary{{$}}
+; FAST: {{^}} call recursive_tail_nullary{{$}}
+; FAST-NEXT: return{{$}}
+define void @recursive_tail_nullary() {
+  tail call void @recursive_tail_nullary()
+  ret void
+}
+
+; CHECK-LABEL: recursive_notail:
+; CHECK: i32.call $push[[L:[0-9]+]]=, recursive_notail, $0, $1{{$}}
+; CHECK-NEXT: return $pop[[L]]{{$}}
+define i32 @recursive_notail(i32 %x, i32 %y) {
+  %v = notail call i32 @recursive_notail(i32 %x, i32 %y)
+  ret i32 %v
+}
+
+; CHECK-LABEL: recursive_musttail:
+; CHECK: return_call recursive_musttail, $0, $1{{$}}
+define i32 @recursive_musttail(i32 %x, i32 %y) {
+  %v = musttail call i32 @recursive_musttail(i32 %x, i32 %y)
+  ret i32 %v
+}
+
 ; CHECK-LABEL: recursive_tail:
-; CHECK:      i32.call $push[[L0:[0-9]+]]=, recursive_tail{{$}}
-; CHECK-NEXT: return $pop[[L0]]{{$}}
-define i32 @recursive_tail() {
-  %v = tail call i32 @recursive_tail()
+; SLOW: return_call recursive_tail, $0, $1{{$}}
+; FAST: i32.call $push[[L:[0-9]+]]=, recursive_tail, $0, $1{{$}}
+; FAST-NEXT: return $pop[[L]]{{$}}
+define i32 @recursive_tail(i32 %x, i32 %y) {
+  %v = tail call i32 @recursive_tail(i32 %x, i32 %y)
+  ret i32 %v
+}
+
+; CHECK-LABEL: indirect_notail:
+; CHECK: i32.call_indirect $push[[L:[0-9]+]]=, $0, $1, $2, $0{{$}}
+; CHECK-NEXT: return $pop[[L]]{{$}}
+define i32 @indirect_notail(%fn %f, i32 %x, i32 %y) {
+  %p = extractvalue %fn %f, 0
+  %v = notail call i32 %p(%fn %f, i32 %x, i32 %y)
+  ret i32 %v
+}
+
+; CHECK-LABEL: indirect_musttail:
+; CHECK: return_call_indirect , $0, $1, $2, $0{{$}}
+define i32 @indirect_musttail(%fn %f, i32 %x, i32 %y) {
+  %p = extractvalue %fn %f, 0
+  %v = musttail call i32 %p(%fn %f, i32 %x, i32 %y)
+  ret i32 %v
+}
+
+; CHECK-LABEL: indirect_tail:
+; CHECK: return_call_indirect , $0, $1, $2, $0{{$}}
+define i32 @indirect_tail(%fn %f, i32 %x, i32 %y) {
+  %p = extractvalue %fn %f, 0
+  %v = tail call i32 %p(%fn %f, i32 %x, i32 %y)
+  ret i32 %v
+}
+
+; CHECK-LABEL: choice_notail:
+; CHECK: i32.call_indirect $push[[L:[0-9]+]]=, $0, $pop{{[0-9]+}}{{$}}
+; CHECK-NEXT: return $pop[[L]]{{$}}
+define i1 @choice_notail(i1 %x) {
+  %p = select i1 %x, i1 (i1)* @foo, i1 (i1)* @bar
+  %v = notail call i1 %p(i1 %x)
+  ret i1 %v
+}
+
+; CHECK-LABEL: choice_musttail:
+; CHECK: return_call_indirect , $0, $pop{{[0-9]+}}{{$}}
+define i1 @choice_musttail(i1 %x) {
+  %p = select i1 %x, i1 (i1)* @foo, i1 (i1)* @bar
+  %v = musttail call i1 %p(i1 %x)
+  ret i1 %v
+}
+
+; CHECK-LABEL: choice_tail:
+; SLOW: return_call_indirect , $0, $pop{{[0-9]+}}{{$}}
+; FAST: i32.call_indirect $push[[L:[0-9]+]]=, $0, $pop{{[0-9]+}}{{$}}
+; FAST: return $pop[[L]]{{$}}
+define i1 @choice_tail(i1 %x) {
+  %p = select i1 %x, i1 (i1)* @foo, i1 (i1)* @bar
+  %v = tail call i1 %p(i1 %x)
+  ret i1 %v
+}
+
+; It is an LLVM validation error for a 'musttail' callee to have a different
+; prototype than its caller, so the following tests can only be done with
+; 'tail'.
+
+; CHECK-LABEL: mismatched_prototypes:
+; SLOW: return_call baz, $pop{{[0-9]+}}, $pop{{[0-9]+}}, $pop{{[0-9]+}}{{$}}
+; FAST: i32.call $push[[L:[0-9]+]]=, baz, $pop{{[0-9]+}}, $pop{{[0-9]+}}, $pop{{[0-9]+}}{{$}}
+; FAST: return $pop[[L]]{{$}}
+declare i32 @baz(i32, i32, i32)
+define i32 @mismatched_prototypes() {
+  %v = tail call i32 @baz(i32 0, i32 42, i32 6)
+  ret i32 %v
+}
+
+; CHECK-LABEL: mismatched_byval:
+; CHECK: i32.store
+; CHECK: return_call quux, $pop{{[0-9]+}}{{$}}
+declare i32 @quux(i32* byval)
+define i32 @mismatched_byval(i32* %x) {
+  %v = tail call i32 @quux(i32* byval %x)
+  ret i32 %v
+}
+
+; CHECK-LABEL: varargs:
+; CHECK: i32.store
+; CHECK: return_call var, $1{{$}}
+declare i32 @var(...)
+define i32 @varargs(i32 %x) {
+  %v = tail call i32 (...) @var(i32 %x)
   ret i32 %v
 }
 

Modified: llvm/trunk/test/DebugInfo/WebAssembly/dbg-value-move-reg-stackify.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/WebAssembly/dbg-value-move-reg-stackify.mir?rev=364445&r1=364444&r2=364445&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/WebAssembly/dbg-value-move-reg-stackify.mir (original)
+++ llvm/trunk/test/DebugInfo/WebAssembly/dbg-value-move-reg-stackify.mir Wed Jun 26 09:17:15 2019
@@ -3,9 +3,9 @@
 # CHECK: body:
 # CHECK: %1:i32 = I32_WRAP_I64 %0,
 # CHECK-NEXT: DBG_VALUE %1,
-# CHECK-NEXT: %1:i32 = CALL_I32 @bar,
+# CHECK-NEXT: %1:i32 = CALL_i32 @bar,
 # CHECK-NEXT: DBG_VALUE %1,
-# CHECK-NEXT: %[[NEWREG:.*]]:i32 = CALL_I32 @bar,
+# CHECK-NEXT: %[[NEWREG:.*]]:i32 = CALL_i32 @bar,
 # CHECK-NEXT: DBG_VALUE %[[NEWREG]],
 # CHECK-NEXT: CALL_VOID @foo, %[[NEWREG]],
 
@@ -50,9 +50,9 @@ body: |
     %0:i64 = ARGUMENT_i64 0, implicit $arguments
     %1:i32 = I32_WRAP_I64 %0:i64, implicit-def dead $arguments
     DBG_VALUE %1:i32, $noreg, !10, !DIExpression(), debug-location !13; <unknown>:357:12 line no:357
-    %1:i32 = CALL_I32 @bar, implicit-def dead $arguments, implicit $sp32, implicit $sp64
+    %1:i32 = CALL_i32 @bar, implicit-def dead $arguments, implicit $sp32, implicit $sp64
     DBG_VALUE %1:i32, $noreg, !11, !DIExpression(), debug-location !14; <unknown>:357:12 line no:357
-    %1:i32 = CALL_I32 @bar, implicit-def dead $arguments, implicit $sp32, implicit $sp64
+    %1:i32 = CALL_i32 @bar, implicit-def dead $arguments, implicit $sp32, implicit $sp64
     DBG_VALUE %1:i32, $noreg, !12, !DIExpression(), debug-location !15; <unknown>:357:12 line no:357
     CALL_VOID @foo, %1:i32, implicit-def dead $arguments, implicit $sp32, implicit $sp64
     RETURN_VOID implicit-def dead $arguments

Added: llvm/trunk/test/MC/WebAssembly/tail-call-encodings.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/WebAssembly/tail-call-encodings.s?rev=364445&view=auto
==============================================================================
--- llvm/trunk/test/MC/WebAssembly/tail-call-encodings.s (added)
+++ llvm/trunk/test/MC/WebAssembly/tail-call-encodings.s Wed Jun 26 09:17:15 2019
@@ -0,0 +1,22 @@
+# RUN: llvm-mc -show-encoding -triple=wasm32-unkown-unknown -mattr=+tail-call < %s | FileCheck %s
+
+bar1:
+    .functype bar1 () -> ()
+    end_function
+
+foo1:
+    .functype foo1 () -> ()
+
+    # CHECK: return_call bar1  # encoding: [0x12,
+    # CHECK-NEXT: fixup A - offset: 1, value: bar1, kind: fixup_uleb128_i32
+    return_call bar1
+
+    end_function
+
+foo2:
+    .functype foo2 () -> ()
+
+    # CHECK: return_call_indirect 0 # encoding: [0x13,0x00,0x00]
+    return_call_indirect 0
+
+    end_function




More information about the llvm-commits mailing list