From f50d964bdb0674db3e7f18d06a2d1964e0dbd731 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Tue, 25 Oct 2016 16:55:52 +0000 Subject: [PATCH] [WebAssembly] Add immediate fields to call_indirect and memory operators. call_indirect, grow_memory, and current_memory now have immediate operands in the 0xd binary encoding. llvm-svn: 285085 --- .../InstPrinter/WebAssemblyInstPrinter.cpp | 7 +++++- .../WebAssembly/WebAssemblyCallIndirectFixup.cpp | 7 ++++-- .../lib/Target/WebAssembly/WebAssemblyInstrCall.td | 9 +++++--- .../Target/WebAssembly/WebAssemblyInstrMemory.td | 21 ++++++++--------- llvm/test/CodeGen/WebAssembly/memory-addr64.ll | 27 ---------------------- 5 files changed, 26 insertions(+), 45 deletions(-) delete mode 100644 llvm/test/CodeGen/WebAssembly/memory-addr64.ll diff --git a/llvm/lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp b/llvm/lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp index a1710dd5..00afb88 100644 --- a/llvm/lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp +++ b/llvm/lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp @@ -54,7 +54,12 @@ void WebAssemblyInstPrinter::printInst(const MCInst *MI, raw_ostream &OS, const MCInstrDesc &Desc = MII.get(MI->getOpcode()); if (Desc.isVariadic()) for (auto i = Desc.getNumOperands(), e = MI->getNumOperands(); i < e; ++i) { - if (i != 0) + // FIXME: For CALL_INDIRECT_VOID, don't print a leading comma, because + // we have an extra flags operand which is not currently printed, for + // compatiblity reasons. + if (i != 0 && + (MI->getOpcode() != WebAssembly::CALL_INDIRECT_VOID || + i != Desc.getNumOperands())) OS << ", "; printOperand(MI, i, OS); } diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyCallIndirectFixup.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyCallIndirectFixup.cpp index 31cef3c..fc0a01c 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyCallIndirectFixup.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyCallIndirectFixup.cpp @@ -100,8 +100,11 @@ bool WebAssemblyCallIndirectFixup::runOnMachineFunction(MachineFunction &MF) { auto Uses = MI.explicit_uses(); MachineInstr::mop_iterator it = Uses.begin(); const MachineOperand MO = *it; - unsigned num = MI.getOperandNo(it); - MI.RemoveOperand(num); + + // Set up the flags immediate, which currently has no defined flags + // so it's always zero. + it->ChangeToImmediate(0); + MI.addOperand(MF, MO); DEBUG(dbgs() << " After transform: " << MI); diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyInstrCall.td b/llvm/lib/Target/WebAssembly/WebAssemblyInstrCall.td index f4906e9..41bfcbc 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyInstrCall.td +++ b/llvm/lib/Target/WebAssembly/WebAssemblyInstrCall.td @@ -35,7 +35,8 @@ multiclass CALL { [(set vt:$dst, (WebAssemblycall1 I32:$callee))], "PSEUDO CALL INDIRECT\t$callee">; } // isCodeGenOnly = 1 - def CALL_INDIRECT_#vt : I<(outs vt:$dst), (ins variable_ops), + + def CALL_INDIRECT_#vt : I<(outs vt:$dst), (ins i32imm:$flags, variable_ops), [], !strconcat(prefix, "call_indirect\t$dst"), 0x11>; @@ -54,8 +55,9 @@ multiclass SIMD_CALL { (WebAssemblycall1 I32:$callee))], "PSEUDO CALL INDIRECT\t$callee">; } // isCodeGenOnly = 1 + def CALL_INDIRECT_#vt : SIMD_I<(outs V128:$dst), - (ins variable_ops), + (ins i32imm:$flags, variable_ops), [], !strconcat(prefix, "call_indirect\t$dst"), 0x11>; @@ -79,7 +81,8 @@ let Uses = [SP32, SP64], isCall = 1 in { [(WebAssemblycall0 I32:$callee)], "PSEUDO CALL INDIRECT\t$callee">; } // isCodeGenOnly = 1 - def CALL_INDIRECT_VOID : I<(outs), (ins variable_ops), + + def CALL_INDIRECT_VOID : I<(outs), (ins i32imm:$flags, variable_ops), [], "call_indirect\t", 0x11>; } // Uses = [SP32,SP64], isCall = 1 diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyInstrMemory.td b/llvm/lib/Target/WebAssembly/WebAssemblyInstrMemory.td index 4c9e30e..057dde1 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyInstrMemory.td +++ b/llvm/lib/Target/WebAssembly/WebAssemblyInstrMemory.td @@ -667,23 +667,20 @@ def : Pat<(truncstorei32 I64:$val, (WebAssemblywrapper texternalsym:$off)), let Defs = [ARGUMENTS] in { // Current memory size. -def CURRENT_MEMORY_I32 : I<(outs I32:$dst), (ins), - [(set I32:$dst, (int_wasm_current_memory))], +def CURRENT_MEMORY_I32 : I<(outs I32:$dst), (ins i32imm:$flags), + [], "current_memory\t$dst", 0x3f>, Requires<[HasAddr32]>; -def CURRENT_MEMORY_I64 : I<(outs I64:$dst), (ins), - [(set I64:$dst, (int_wasm_current_memory))], - "current_memory\t$dst">, - Requires<[HasAddr64]>; // Grow memory. -def GROW_MEMORY_I32 : I<(outs), (ins I32:$delta), - [(int_wasm_grow_memory I32:$delta)], +def GROW_MEMORY_I32 : I<(outs), (ins i32imm:$flags, I32:$delta), + [], "grow_memory\t$delta", 0x40>, Requires<[HasAddr32]>; -def GROW_MEMORY_I64 : I<(outs), (ins I64:$delta), - [(int_wasm_grow_memory I64:$delta)], - "grow_memory\t$delta">, - Requires<[HasAddr64]>; } // Defs = [ARGUMENTS] + +def : Pat<(int_wasm_current_memory), + (CURRENT_MEMORY_I32 0)>; +def : Pat<(int_wasm_grow_memory I32:$delta), + (GROW_MEMORY_I32 0, $delta)>; diff --git a/llvm/test/CodeGen/WebAssembly/memory-addr64.ll b/llvm/test/CodeGen/WebAssembly/memory-addr64.ll deleted file mode 100644 index dc6da61..0000000 --- a/llvm/test/CodeGen/WebAssembly/memory-addr64.ll +++ /dev/null @@ -1,27 +0,0 @@ -; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt | FileCheck %s - -; Test that basic memory operations assemble as expected with 64-bit addresses. - -target datalayout = "e-m:e-p:64:64-i64:64-n32:64-S128" -target triple = "wasm64-unknown-unknown" - -declare i64 @llvm.wasm.current.memory.i64() nounwind readonly -declare void @llvm.wasm.grow.memory.i64(i64) nounwind - -; CHECK-LABEL: current_memory: -; CHECK-NEXT: .result i64{{$}} -; CHECK-NEXT: current_memory $push0={{$}} -; CHECK-NEXT: return $pop0{{$}} -define i64 @current_memory() { - %a = call i64 @llvm.wasm.current.memory.i64() - ret i64 %a -} - -; CHECK-LABEL: grow_memory: -; CHECK-NEXT: .param i64{{$}} -; CHECK: grow_memory $0{{$}} -; CHECK-NEXT: return{{$}} -define void @grow_memory(i64 %n) { - call void @llvm.wasm.grow.memory.i64(i64 %n) - ret void -} -- 2.7.4