Dan Gohman | e9361d5 | 2015-11-05 19:28:16 +0000 | [diff] [blame] | 1 | // WebAssemblyMCInstLower.cpp - Convert WebAssembly MachineInstr to an MCInst // |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | /// |
| 10 | /// \file |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 11 | /// This file contains code to lower WebAssembly MachineInstrs to their |
Dan Gohman | e9361d5 | 2015-11-05 19:28:16 +0000 | [diff] [blame] | 12 | /// corresponding MCInst records. |
| 13 | /// |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
| 16 | #include "WebAssemblyMCInstLower.h" |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 17 | #include "WebAssemblyAsmPrinter.h" |
Dan Gohman | cf4748f | 2015-11-12 17:04:33 +0000 | [diff] [blame] | 18 | #include "WebAssemblyMachineFunctionInfo.h" |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 19 | #include "WebAssemblyRuntimeLibcallSignatures.h" |
| 20 | #include "WebAssemblyUtilities.h" |
Dan Gohman | e9361d5 | 2015-11-05 19:28:16 +0000 | [diff] [blame] | 21 | #include "llvm/CodeGen/AsmPrinter.h" |
Dan Gohman | cf4748f | 2015-11-12 17:04:33 +0000 | [diff] [blame] | 22 | #include "llvm/CodeGen/MachineFunction.h" |
Dan Gohman | cf4748f | 2015-11-12 17:04:33 +0000 | [diff] [blame] | 23 | #include "llvm/IR/Constants.h" |
Dan Gohman | e9361d5 | 2015-11-05 19:28:16 +0000 | [diff] [blame] | 24 | #include "llvm/MC/MCAsmInfo.h" |
| 25 | #include "llvm/MC/MCContext.h" |
| 26 | #include "llvm/MC/MCExpr.h" |
| 27 | #include "llvm/MC/MCInst.h" |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 28 | #include "llvm/MC/MCSymbolWasm.h" |
Dan Gohman | e9361d5 | 2015-11-05 19:28:16 +0000 | [diff] [blame] | 29 | #include "llvm/Support/ErrorHandling.h" |
| 30 | #include "llvm/Support/raw_ostream.h" |
| 31 | using namespace llvm; |
| 32 | |
Wouter van Oortmerssen | 8a9cb24 | 2018-08-27 15:45:51 +0000 | [diff] [blame^] | 33 | // This disables the removal of registers when lowering into MC, as required |
| 34 | // by some current tests. |
| 35 | static cl::opt<bool> WasmKeepRegisters( |
| 36 | "wasm-keep-registers", cl::Hidden, |
| 37 | cl::desc("WebAssembly: output stack registers in" |
| 38 | " instruction output for test purposes only."), |
| 39 | cl::init(false)); |
| 40 | |
| 41 | static unsigned regInstructionToStackInstruction(unsigned OpCode); |
| 42 | static void removeRegisterOperands(const MachineInstr *MI, MCInst &OutMI); |
| 43 | |
Dan Gohman | e9361d5 | 2015-11-05 19:28:16 +0000 | [diff] [blame] | 44 | MCSymbol * |
| 45 | WebAssemblyMCInstLower::GetGlobalAddressSymbol(const MachineOperand &MO) const { |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 46 | const GlobalValue *Global = MO.getGlobal(); |
Sam Clegg | cf2a9e2 | 2018-07-16 23:09:29 +0000 | [diff] [blame] | 47 | MCSymbolWasm *WasmSym = cast<MCSymbolWasm>(Printer.getSymbol(Global)); |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 48 | |
| 49 | if (const auto *FuncTy = dyn_cast<FunctionType>(Global->getValueType())) { |
| 50 | const MachineFunction &MF = *MO.getParent()->getParent()->getParent(); |
| 51 | const TargetMachine &TM = MF.getTarget(); |
David Blaikie | 2110924 | 2017-12-15 23:52:06 +0000 | [diff] [blame] | 52 | const Function &CurrentFunc = MF.getFunction(); |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 53 | |
Derek Schuff | e2688c4 | 2017-03-14 20:23:22 +0000 | [diff] [blame] | 54 | SmallVector<wasm::ValType, 4> Returns; |
| 55 | SmallVector<wasm::ValType, 4> Params; |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 56 | |
Derek Schuff | e2688c4 | 2017-03-14 20:23:22 +0000 | [diff] [blame] | 57 | wasm::ValType iPTR = |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 58 | MF.getSubtarget<WebAssemblySubtarget>().hasAddr64() ? |
Derek Schuff | e2688c4 | 2017-03-14 20:23:22 +0000 | [diff] [blame] | 59 | wasm::ValType::I64 : |
| 60 | wasm::ValType::I32; |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 61 | |
| 62 | SmallVector<MVT, 4> ResultMVTs; |
| 63 | ComputeLegalValueVTs(CurrentFunc, TM, FuncTy->getReturnType(), ResultMVTs); |
| 64 | // WebAssembly can't currently handle returning tuples. |
| 65 | if (ResultMVTs.size() <= 1) |
| 66 | for (MVT ResultMVT : ResultMVTs) |
Derek Schuff | e2688c4 | 2017-03-14 20:23:22 +0000 | [diff] [blame] | 67 | Returns.push_back(WebAssembly::toValType(ResultMVT)); |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 68 | else |
Derek Schuff | e2688c4 | 2017-03-14 20:23:22 +0000 | [diff] [blame] | 69 | Params.push_back(iPTR); |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 70 | |
| 71 | for (Type *Ty : FuncTy->params()) { |
| 72 | SmallVector<MVT, 4> ParamMVTs; |
| 73 | ComputeLegalValueVTs(CurrentFunc, TM, Ty, ParamMVTs); |
| 74 | for (MVT ParamMVT : ParamMVTs) |
Derek Schuff | e2688c4 | 2017-03-14 20:23:22 +0000 | [diff] [blame] | 75 | Params.push_back(WebAssembly::toValType(ParamMVT)); |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | if (FuncTy->isVarArg()) |
Derek Schuff | e2688c4 | 2017-03-14 20:23:22 +0000 | [diff] [blame] | 79 | Params.push_back(iPTR); |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 80 | |
| 81 | WasmSym->setReturns(std::move(Returns)); |
| 82 | WasmSym->setParams(std::move(Params)); |
Sam Clegg | 6c899ba | 2018-02-23 05:08:34 +0000 | [diff] [blame] | 83 | WasmSym->setType(wasm::WASM_SYMBOL_TYPE_FUNCTION); |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | return WasmSym; |
Dan Gohman | e9361d5 | 2015-11-05 19:28:16 +0000 | [diff] [blame] | 87 | } |
| 88 | |
Dan Gohman | 7a6b982 | 2015-11-29 22:32:02 +0000 | [diff] [blame] | 89 | MCSymbol *WebAssemblyMCInstLower::GetExternalSymbolSymbol( |
| 90 | const MachineOperand &MO) const { |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 91 | const char *Name = MO.getSymbolName(); |
Sam Clegg | cf2a9e2 | 2018-07-16 23:09:29 +0000 | [diff] [blame] | 92 | MCSymbolWasm *WasmSym = |
| 93 | cast<MCSymbolWasm>(Printer.GetExternalSymbolSymbol(Name)); |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 94 | const WebAssemblySubtarget &Subtarget = Printer.getSubtarget(); |
| 95 | |
| 96 | // __stack_pointer is a global variable; all other external symbols used by |
Sam Clegg | 6c899ba | 2018-02-23 05:08:34 +0000 | [diff] [blame] | 97 | // CodeGen are functions. It's OK to hardcode knowledge of specific symbols |
| 98 | // here; this method is precisely there for fetching the signatures of known |
| 99 | // Clang-provided symbols. |
| 100 | if (strcmp(Name, "__stack_pointer") == 0) { |
Sam Clegg | 6c899ba | 2018-02-23 05:08:34 +0000 | [diff] [blame] | 101 | WasmSym->setType(wasm::WASM_SYMBOL_TYPE_GLOBAL); |
Sam Clegg | 03e101f | 2018-03-01 18:06:21 +0000 | [diff] [blame] | 102 | WasmSym->setGlobalType(wasm::WasmGlobalType{ |
Sam Clegg | 503fdea | 2018-03-01 18:48:08 +0000 | [diff] [blame] | 103 | uint8_t(Subtarget.hasAddr64() ? wasm::WASM_TYPE_I64 |
| 104 | : wasm::WASM_TYPE_I32), |
Sam Clegg | 03e101f | 2018-03-01 18:06:21 +0000 | [diff] [blame] | 105 | true}); |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 106 | return WasmSym; |
Sam Clegg | 6c899ba | 2018-02-23 05:08:34 +0000 | [diff] [blame] | 107 | } |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 108 | |
Derek Schuff | e2688c4 | 2017-03-14 20:23:22 +0000 | [diff] [blame] | 109 | SmallVector<wasm::ValType, 4> Returns; |
| 110 | SmallVector<wasm::ValType, 4> Params; |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 111 | GetSignature(Subtarget, Name, Returns, Params); |
| 112 | |
| 113 | WasmSym->setReturns(std::move(Returns)); |
| 114 | WasmSym->setParams(std::move(Params)); |
Sam Clegg | 6c899ba | 2018-02-23 05:08:34 +0000 | [diff] [blame] | 115 | WasmSym->setType(wasm::WASM_SYMBOL_TYPE_FUNCTION); |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 116 | |
| 117 | return WasmSym; |
Dan Gohman | 2c8fe6a | 2015-11-25 16:44:29 +0000 | [diff] [blame] | 118 | } |
| 119 | |
Dan Gohman | 26c6765 | 2016-01-11 23:38:05 +0000 | [diff] [blame] | 120 | MCOperand WebAssemblyMCInstLower::LowerSymbolOperand(MCSymbol *Sym, |
| 121 | int64_t Offset, |
Nicholas Wilson | e408a89 | 2018-08-03 14:33:37 +0000 | [diff] [blame] | 122 | bool IsFunc, |
| 123 | bool IsGlob) const { |
Dan Gohman | 26c6765 | 2016-01-11 23:38:05 +0000 | [diff] [blame] | 124 | MCSymbolRefExpr::VariantKind VK = |
Nicholas Wilson | e408a89 | 2018-08-03 14:33:37 +0000 | [diff] [blame] | 125 | IsFunc ? MCSymbolRefExpr::VK_WebAssembly_FUNCTION : |
| 126 | IsGlob ? MCSymbolRefExpr::VK_WebAssembly_GLOBAL |
Dan Gohman | 26c6765 | 2016-01-11 23:38:05 +0000 | [diff] [blame] | 127 | : MCSymbolRefExpr::VK_None; |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 128 | |
Dan Gohman | 26c6765 | 2016-01-11 23:38:05 +0000 | [diff] [blame] | 129 | const MCExpr *Expr = MCSymbolRefExpr::create(Sym, VK, Ctx); |
Dan Gohman | e9361d5 | 2015-11-05 19:28:16 +0000 | [diff] [blame] | 130 | |
Dan Gohman | a4b710a | 2015-12-06 19:33:32 +0000 | [diff] [blame] | 131 | if (Offset != 0) { |
Dan Gohman | 26c6765 | 2016-01-11 23:38:05 +0000 | [diff] [blame] | 132 | if (IsFunc) |
| 133 | report_fatal_error("Function addresses with offsets not supported"); |
Nicholas Wilson | e408a89 | 2018-08-03 14:33:37 +0000 | [diff] [blame] | 134 | if (IsGlob) |
| 135 | report_fatal_error("Global indexes with offsets not supported"); |
Dan Gohman | a4b710a | 2015-12-06 19:33:32 +0000 | [diff] [blame] | 136 | Expr = |
| 137 | MCBinaryExpr::createAdd(Expr, MCConstantExpr::create(Offset, Ctx), Ctx); |
| 138 | } |
Dan Gohman | e9361d5 | 2015-11-05 19:28:16 +0000 | [diff] [blame] | 139 | |
| 140 | return MCOperand::createExpr(Expr); |
| 141 | } |
| 142 | |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 143 | // Return the WebAssembly type associated with the given register class. |
Derek Schuff | e2688c4 | 2017-03-14 20:23:22 +0000 | [diff] [blame] | 144 | static wasm::ValType getType(const TargetRegisterClass *RC) { |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 145 | if (RC == &WebAssembly::I32RegClass) |
Derek Schuff | e2688c4 | 2017-03-14 20:23:22 +0000 | [diff] [blame] | 146 | return wasm::ValType::I32; |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 147 | if (RC == &WebAssembly::I64RegClass) |
Derek Schuff | e2688c4 | 2017-03-14 20:23:22 +0000 | [diff] [blame] | 148 | return wasm::ValType::I64; |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 149 | if (RC == &WebAssembly::F32RegClass) |
Derek Schuff | e2688c4 | 2017-03-14 20:23:22 +0000 | [diff] [blame] | 150 | return wasm::ValType::F32; |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 151 | if (RC == &WebAssembly::F64RegClass) |
Derek Schuff | e2688c4 | 2017-03-14 20:23:22 +0000 | [diff] [blame] | 152 | return wasm::ValType::F64; |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 153 | llvm_unreachable("Unexpected register class"); |
| 154 | } |
| 155 | |
Dan Gohman | e9361d5 | 2015-11-05 19:28:16 +0000 | [diff] [blame] | 156 | void WebAssemblyMCInstLower::Lower(const MachineInstr *MI, |
| 157 | MCInst &OutMI) const { |
| 158 | OutMI.setOpcode(MI->getOpcode()); |
| 159 | |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 160 | const MCInstrDesc &Desc = MI->getDesc(); |
Dan Gohman | e9361d5 | 2015-11-05 19:28:16 +0000 | [diff] [blame] | 161 | for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { |
| 162 | const MachineOperand &MO = MI->getOperand(i); |
| 163 | |
| 164 | MCOperand MCOp; |
| 165 | switch (MO.getType()) { |
| 166 | default: |
Richard Trieu | 3de487b | 2017-01-28 03:23:49 +0000 | [diff] [blame] | 167 | MI->print(errs()); |
Dan Gohman | e9361d5 | 2015-11-05 19:28:16 +0000 | [diff] [blame] | 168 | llvm_unreachable("unknown operand type"); |
Dan Gohman | 1d68e80f | 2016-01-12 19:14:46 +0000 | [diff] [blame] | 169 | case MachineOperand::MO_MachineBasicBlock: |
Richard Trieu | 3de487b | 2017-01-28 03:23:49 +0000 | [diff] [blame] | 170 | MI->print(errs()); |
Dan Gohman | 1d68e80f | 2016-01-12 19:14:46 +0000 | [diff] [blame] | 171 | llvm_unreachable("MachineBasicBlock operand should have been rewritten"); |
Dan Gohman | cf4748f | 2015-11-12 17:04:33 +0000 | [diff] [blame] | 172 | case MachineOperand::MO_Register: { |
Dan Gohman | e9361d5 | 2015-11-05 19:28:16 +0000 | [diff] [blame] | 173 | // Ignore all implicit register operands. |
| 174 | if (MO.isImplicit()) |
| 175 | continue; |
Dan Gohman | cf4748f | 2015-11-12 17:04:33 +0000 | [diff] [blame] | 176 | const WebAssemblyFunctionInfo &MFI = |
| 177 | *MI->getParent()->getParent()->getInfo<WebAssemblyFunctionInfo>(); |
| 178 | unsigned WAReg = MFI.getWAReg(MO.getReg()); |
| 179 | MCOp = MCOperand::createReg(WAReg); |
Dan Gohman | e9361d5 | 2015-11-05 19:28:16 +0000 | [diff] [blame] | 180 | break; |
Dan Gohman | cf4748f | 2015-11-12 17:04:33 +0000 | [diff] [blame] | 181 | } |
Dan Gohman | e9361d5 | 2015-11-05 19:28:16 +0000 | [diff] [blame] | 182 | case MachineOperand::MO_Immediate: |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 183 | if (i < Desc.NumOperands) { |
| 184 | const MCOperandInfo &Info = Desc.OpInfo[i]; |
| 185 | if (Info.OperandType == WebAssembly::OPERAND_TYPEINDEX) { |
| 186 | MCSymbol *Sym = Printer.createTempSymbol("typeindex"); |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 187 | |
Sam Clegg | cf2a9e2 | 2018-07-16 23:09:29 +0000 | [diff] [blame] | 188 | SmallVector<wasm::ValType, 4> Returns; |
| 189 | SmallVector<wasm::ValType, 4> Params; |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 190 | |
Sam Clegg | cf2a9e2 | 2018-07-16 23:09:29 +0000 | [diff] [blame] | 191 | const MachineRegisterInfo &MRI = |
| 192 | MI->getParent()->getParent()->getRegInfo(); |
| 193 | for (const MachineOperand &MO : MI->defs()) |
| 194 | Returns.push_back(getType(MRI.getRegClass(MO.getReg()))); |
| 195 | for (const MachineOperand &MO : MI->explicit_uses()) |
| 196 | if (MO.isReg()) |
| 197 | Params.push_back(getType(MRI.getRegClass(MO.getReg()))); |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 198 | |
Sam Clegg | cf2a9e2 | 2018-07-16 23:09:29 +0000 | [diff] [blame] | 199 | // call_indirect instructions have a callee operand at the end which |
| 200 | // doesn't count as a param. |
| 201 | if (WebAssembly::isCallIndirect(*MI)) |
| 202 | Params.pop_back(); |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 203 | |
Sam Clegg | cf2a9e2 | 2018-07-16 23:09:29 +0000 | [diff] [blame] | 204 | MCSymbolWasm *WasmSym = cast<MCSymbolWasm>(Sym); |
| 205 | WasmSym->setReturns(std::move(Returns)); |
| 206 | WasmSym->setParams(std::move(Params)); |
| 207 | WasmSym->setType(wasm::WASM_SYMBOL_TYPE_FUNCTION); |
| 208 | |
| 209 | const MCExpr *Expr = MCSymbolRefExpr::create( |
| 210 | WasmSym, MCSymbolRefExpr::VK_WebAssembly_TYPEINDEX, Ctx); |
| 211 | MCOp = MCOperand::createExpr(Expr); |
| 212 | break; |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 213 | } |
| 214 | } |
Dan Gohman | e9361d5 | 2015-11-05 19:28:16 +0000 | [diff] [blame] | 215 | MCOp = MCOperand::createImm(MO.getImm()); |
| 216 | break; |
Dan Gohman | cf4748f | 2015-11-12 17:04:33 +0000 | [diff] [blame] | 217 | case MachineOperand::MO_FPImmediate: { |
| 218 | // TODO: MC converts all floating point immediate operands to double. |
| 219 | // This is fine for numeric values, but may cause NaNs to change bits. |
| 220 | const ConstantFP *Imm = MO.getFPImm(); |
| 221 | if (Imm->getType()->isFloatTy()) |
| 222 | MCOp = MCOperand::createFPImm(Imm->getValueAPF().convertToFloat()); |
| 223 | else if (Imm->getType()->isDoubleTy()) |
| 224 | MCOp = MCOperand::createFPImm(Imm->getValueAPF().convertToDouble()); |
| 225 | else |
| 226 | llvm_unreachable("unknown floating point immediate type"); |
Dan Gohman | e9361d5 | 2015-11-05 19:28:16 +0000 | [diff] [blame] | 227 | break; |
Dan Gohman | cf4748f | 2015-11-12 17:04:33 +0000 | [diff] [blame] | 228 | } |
Dan Gohman | e9361d5 | 2015-11-05 19:28:16 +0000 | [diff] [blame] | 229 | case MachineOperand::MO_GlobalAddress: |
Nicholas Wilson | e408a89 | 2018-08-03 14:33:37 +0000 | [diff] [blame] | 230 | assert(MO.getTargetFlags() == WebAssemblyII::MO_NO_FLAG && |
Dan Gohman | 26c6765 | 2016-01-11 23:38:05 +0000 | [diff] [blame] | 231 | "WebAssembly does not use target flags on GlobalAddresses"); |
| 232 | MCOp = LowerSymbolOperand(GetGlobalAddressSymbol(MO), MO.getOffset(), |
Nicholas Wilson | e408a89 | 2018-08-03 14:33:37 +0000 | [diff] [blame] | 233 | MO.getGlobal()->getValueType()->isFunctionTy(), |
| 234 | false); |
Dan Gohman | e9361d5 | 2015-11-05 19:28:16 +0000 | [diff] [blame] | 235 | break; |
Dan Gohman | 2c8fe6a | 2015-11-25 16:44:29 +0000 | [diff] [blame] | 236 | case MachineOperand::MO_ExternalSymbol: |
Dan Gohman | 26c6765 | 2016-01-11 23:38:05 +0000 | [diff] [blame] | 237 | // The target flag indicates whether this is a symbol for a |
| 238 | // variable or a function. |
Nicholas Wilson | e408a89 | 2018-08-03 14:33:37 +0000 | [diff] [blame] | 239 | assert((MO.getTargetFlags() & ~WebAssemblyII::MO_SYMBOL_MASK) == 0 && |
| 240 | "WebAssembly uses only symbol flags on ExternalSymbols"); |
Dan Gohman | 26c6765 | 2016-01-11 23:38:05 +0000 | [diff] [blame] | 241 | MCOp = LowerSymbolOperand(GetExternalSymbolSymbol(MO), /*Offset=*/0, |
Nicholas Wilson | e408a89 | 2018-08-03 14:33:37 +0000 | [diff] [blame] | 242 | (MO.getTargetFlags() & WebAssemblyII::MO_SYMBOL_FUNCTION) != 0, |
| 243 | (MO.getTargetFlags() & WebAssemblyII::MO_SYMBOL_GLOBAL) != 0); |
Dan Gohman | 2c8fe6a | 2015-11-25 16:44:29 +0000 | [diff] [blame] | 244 | break; |
Dan Gohman | e9361d5 | 2015-11-05 19:28:16 +0000 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | OutMI.addOperand(MCOp); |
| 248 | } |
Wouter van Oortmerssen | 8a9cb24 | 2018-08-27 15:45:51 +0000 | [diff] [blame^] | 249 | |
| 250 | if (!WasmKeepRegisters) |
| 251 | removeRegisterOperands(MI, OutMI); |
| 252 | } |
| 253 | |
| 254 | static void removeRegisterOperands(const MachineInstr *MI, MCInst &OutMI) { |
| 255 | // Remove all uses of stackified registers to bring the instruction format |
| 256 | // into its final stack form used thruout MC, and transition opcodes to |
| 257 | // their _S variant. |
| 258 | // We do this seperate from the above code that still may need these |
| 259 | // registers for e.g. call_indirect signatures. |
| 260 | // See comments in lib/Target/WebAssembly/WebAssemblyInstrFormats.td for |
| 261 | // details. |
| 262 | // TODO: the code above creates new registers which are then removed here. |
| 263 | // That code could be slightly simplified by not doing that, though maybe |
| 264 | // it is simpler conceptually to keep the code above in "register mode" |
| 265 | // until this transition point. |
| 266 | // FIXME: we are not processing inline assembly, which contains register |
| 267 | // operands, because it is used by later target generic code. |
| 268 | if (MI->isDebugInstr() || MI->isLabel() || MI->isInlineAsm()) |
| 269 | return; |
| 270 | |
| 271 | // Transform to _S instruction. |
| 272 | auto RegOpcode = OutMI.getOpcode(); |
| 273 | auto StackOpcode = regInstructionToStackInstruction(RegOpcode); |
| 274 | OutMI.setOpcode(StackOpcode); |
| 275 | |
| 276 | // Remove register operands. |
| 277 | for (auto I = OutMI.getNumOperands(); I; --I) { |
| 278 | auto &MO = OutMI.getOperand(I - 1); |
| 279 | if (MO.isReg()) { |
| 280 | OutMI.erase(&MO); |
| 281 | } |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | static unsigned regInstructionToStackInstruction(unsigned OpCode) { |
| 286 | switch (OpCode) { |
| 287 | default: |
| 288 | // You may hit this if you add new instructions, please add them below. |
| 289 | // For most of these opcodes, this function could have been implemented |
| 290 | // as "return OpCode + 1", but since table-gen alphabetically sorts them, |
| 291 | // this cannot be guaranteed (see e.g. BR and BR_IF). |
| 292 | // The approach below is the same as what the x87 backend does. |
| 293 | // TODO(wvo): to make this code cleaner, create a custom tablegen |
| 294 | // code generator that emits the table below automatically. |
| 295 | llvm_unreachable( |
| 296 | "unknown WebAssembly instruction in Explicit Locals pass"); |
| 297 | case WebAssembly::ABS_F32: return WebAssembly::ABS_F32_S; |
| 298 | case WebAssembly::ABS_F64: return WebAssembly::ABS_F64_S; |
| 299 | case WebAssembly::ADD_F32: return WebAssembly::ADD_F32_S; |
| 300 | case WebAssembly::ADD_F64: return WebAssembly::ADD_F64_S; |
| 301 | case WebAssembly::ADD_I32: return WebAssembly::ADD_I32_S; |
| 302 | case WebAssembly::ADD_I64: return WebAssembly::ADD_I64_S; |
| 303 | case WebAssembly::ADD_v16i8: return WebAssembly::ADD_v16i8_S; |
| 304 | case WebAssembly::ADD_v2f64: return WebAssembly::ADD_v2f64_S; |
| 305 | case WebAssembly::ADD_v2i64: return WebAssembly::ADD_v2i64_S; |
| 306 | case WebAssembly::ADD_v4f32: return WebAssembly::ADD_v4f32_S; |
| 307 | case WebAssembly::ADD_v4i32: return WebAssembly::ADD_v4i32_S; |
| 308 | case WebAssembly::ADD_v8i16: return WebAssembly::ADD_v8i16_S; |
| 309 | case WebAssembly::ADJCALLSTACKDOWN: return WebAssembly::ADJCALLSTACKDOWN_S; |
| 310 | case WebAssembly::ADJCALLSTACKUP: return WebAssembly::ADJCALLSTACKUP_S; |
| 311 | case WebAssembly::AND_I32: return WebAssembly::AND_I32_S; |
| 312 | case WebAssembly::AND_I64: return WebAssembly::AND_I64_S; |
| 313 | case WebAssembly::ARGUMENT_EXCEPT_REF: return WebAssembly::ARGUMENT_EXCEPT_REF_S; |
| 314 | case WebAssembly::ARGUMENT_F32: return WebAssembly::ARGUMENT_F32_S; |
| 315 | case WebAssembly::ARGUMENT_F64: return WebAssembly::ARGUMENT_F64_S; |
| 316 | case WebAssembly::ARGUMENT_I32: return WebAssembly::ARGUMENT_I32_S; |
| 317 | case WebAssembly::ARGUMENT_I64: return WebAssembly::ARGUMENT_I64_S; |
| 318 | case WebAssembly::ARGUMENT_v16i8: return WebAssembly::ARGUMENT_v16i8_S; |
| 319 | case WebAssembly::ARGUMENT_v4f32: return WebAssembly::ARGUMENT_v4f32_S; |
| 320 | case WebAssembly::ARGUMENT_v4i32: return WebAssembly::ARGUMENT_v4i32_S; |
| 321 | case WebAssembly::ARGUMENT_v8i16: return WebAssembly::ARGUMENT_v8i16_S; |
| 322 | case WebAssembly::ARGUMENT_v2f64: return WebAssembly::ARGUMENT_v2f64_S; |
| 323 | case WebAssembly::ARGUMENT_v2i64: return WebAssembly::ARGUMENT_v2i64_S; |
| 324 | case WebAssembly::ATOMIC_LOAD16_U_I32: return WebAssembly::ATOMIC_LOAD16_U_I32_S; |
| 325 | case WebAssembly::ATOMIC_LOAD16_U_I64: return WebAssembly::ATOMIC_LOAD16_U_I64_S; |
| 326 | case WebAssembly::ATOMIC_LOAD32_U_I64: return WebAssembly::ATOMIC_LOAD32_U_I64_S; |
| 327 | case WebAssembly::ATOMIC_LOAD8_U_I32: return WebAssembly::ATOMIC_LOAD8_U_I32_S; |
| 328 | case WebAssembly::ATOMIC_LOAD8_U_I64: return WebAssembly::ATOMIC_LOAD8_U_I64_S; |
| 329 | case WebAssembly::ATOMIC_LOAD_I32: return WebAssembly::ATOMIC_LOAD_I32_S; |
| 330 | case WebAssembly::ATOMIC_LOAD_I64: return WebAssembly::ATOMIC_LOAD_I64_S; |
| 331 | case WebAssembly::ATOMIC_STORE16_I32: return WebAssembly::ATOMIC_STORE16_I32_S; |
| 332 | case WebAssembly::ATOMIC_STORE16_I64: return WebAssembly::ATOMIC_STORE16_I64_S; |
| 333 | case WebAssembly::ATOMIC_STORE32_I64: return WebAssembly::ATOMIC_STORE32_I64_S; |
| 334 | case WebAssembly::ATOMIC_STORE8_I32: return WebAssembly::ATOMIC_STORE8_I32_S; |
| 335 | case WebAssembly::ATOMIC_STORE8_I64: return WebAssembly::ATOMIC_STORE8_I64_S; |
| 336 | case WebAssembly::ATOMIC_STORE_I32: return WebAssembly::ATOMIC_STORE_I32_S; |
| 337 | case WebAssembly::ATOMIC_STORE_I64: return WebAssembly::ATOMIC_STORE_I64_S; |
| 338 | case WebAssembly::BLOCK: return WebAssembly::BLOCK_S; |
| 339 | case WebAssembly::BR: return WebAssembly::BR_S; |
| 340 | case WebAssembly::BR_IF: return WebAssembly::BR_IF_S; |
| 341 | case WebAssembly::BR_TABLE_I32: return WebAssembly::BR_TABLE_I32_S; |
| 342 | case WebAssembly::BR_TABLE_I64: return WebAssembly::BR_TABLE_I64_S; |
| 343 | case WebAssembly::BR_UNLESS: return WebAssembly::BR_UNLESS_S; |
| 344 | case WebAssembly::CALL_EXCEPT_REF: return WebAssembly::CALL_EXCEPT_REF_S; |
| 345 | case WebAssembly::CALL_F32: return WebAssembly::CALL_F32_S; |
| 346 | case WebAssembly::CALL_F64: return WebAssembly::CALL_F64_S; |
| 347 | case WebAssembly::CALL_I32: return WebAssembly::CALL_I32_S; |
| 348 | case WebAssembly::CALL_I64: return WebAssembly::CALL_I64_S; |
| 349 | case WebAssembly::CALL_INDIRECT_EXCEPT_REF: return WebAssembly::CALL_INDIRECT_EXCEPT_REF_S; |
| 350 | case WebAssembly::CALL_INDIRECT_F32: return WebAssembly::CALL_INDIRECT_F32_S; |
| 351 | case WebAssembly::CALL_INDIRECT_F64: return WebAssembly::CALL_INDIRECT_F64_S; |
| 352 | case WebAssembly::CALL_INDIRECT_I32: return WebAssembly::CALL_INDIRECT_I32_S; |
| 353 | case WebAssembly::CALL_INDIRECT_I64: return WebAssembly::CALL_INDIRECT_I64_S; |
| 354 | case WebAssembly::CALL_INDIRECT_VOID: return WebAssembly::CALL_INDIRECT_VOID_S; |
| 355 | case WebAssembly::CALL_INDIRECT_v16i8: return WebAssembly::CALL_INDIRECT_v16i8_S; |
| 356 | case WebAssembly::CALL_INDIRECT_v4f32: return WebAssembly::CALL_INDIRECT_v4f32_S; |
| 357 | case WebAssembly::CALL_INDIRECT_v4i32: return WebAssembly::CALL_INDIRECT_v4i32_S; |
| 358 | case WebAssembly::CALL_INDIRECT_v8i16: return WebAssembly::CALL_INDIRECT_v8i16_S; |
| 359 | case WebAssembly::CALL_VOID: return WebAssembly::CALL_VOID_S; |
| 360 | case WebAssembly::CALL_v16i8: return WebAssembly::CALL_v16i8_S; |
| 361 | case WebAssembly::CALL_v4f32: return WebAssembly::CALL_v4f32_S; |
| 362 | case WebAssembly::CALL_v4i32: return WebAssembly::CALL_v4i32_S; |
| 363 | case WebAssembly::CALL_v8i16: return WebAssembly::CALL_v8i16_S; |
| 364 | case WebAssembly::CATCHRET: return WebAssembly::CATCHRET_S; |
| 365 | case WebAssembly::CATCH_ALL: return WebAssembly::CATCH_ALL_S; |
| 366 | case WebAssembly::CATCH_I32: return WebAssembly::CATCH_I32_S; |
| 367 | case WebAssembly::CATCH_I64: return WebAssembly::CATCH_I64_S; |
| 368 | case WebAssembly::CEIL_F32: return WebAssembly::CEIL_F32_S; |
| 369 | case WebAssembly::CEIL_F64: return WebAssembly::CEIL_F64_S; |
| 370 | case WebAssembly::CLEANUPRET: return WebAssembly::CLEANUPRET_S; |
| 371 | case WebAssembly::CLZ_I32: return WebAssembly::CLZ_I32_S; |
| 372 | case WebAssembly::CLZ_I64: return WebAssembly::CLZ_I64_S; |
| 373 | case WebAssembly::CONST_F32: return WebAssembly::CONST_F32_S; |
| 374 | case WebAssembly::CONST_F64: return WebAssembly::CONST_F64_S; |
| 375 | case WebAssembly::CONST_I32: return WebAssembly::CONST_I32_S; |
| 376 | case WebAssembly::CONST_I64: return WebAssembly::CONST_I64_S; |
| 377 | case WebAssembly::COPYSIGN_F32: return WebAssembly::COPYSIGN_F32_S; |
| 378 | case WebAssembly::COPYSIGN_F64: return WebAssembly::COPYSIGN_F64_S; |
| 379 | case WebAssembly::COPY_EXCEPT_REF: return WebAssembly::COPY_EXCEPT_REF_S; |
| 380 | case WebAssembly::COPY_F32: return WebAssembly::COPY_F32_S; |
| 381 | case WebAssembly::COPY_F64: return WebAssembly::COPY_F64_S; |
| 382 | case WebAssembly::COPY_I32: return WebAssembly::COPY_I32_S; |
| 383 | case WebAssembly::COPY_I64: return WebAssembly::COPY_I64_S; |
| 384 | case WebAssembly::COPY_V128: return WebAssembly::COPY_V128_S; |
| 385 | case WebAssembly::CTZ_I32: return WebAssembly::CTZ_I32_S; |
| 386 | case WebAssembly::CTZ_I64: return WebAssembly::CTZ_I64_S; |
| 387 | case WebAssembly::CURRENT_MEMORY_I32: return WebAssembly::CURRENT_MEMORY_I32_S; |
| 388 | case WebAssembly::DIV_F32: return WebAssembly::DIV_F32_S; |
| 389 | case WebAssembly::DIV_F64: return WebAssembly::DIV_F64_S; |
| 390 | case WebAssembly::DIV_S_I32: return WebAssembly::DIV_S_I32_S; |
| 391 | case WebAssembly::DIV_S_I64: return WebAssembly::DIV_S_I64_S; |
| 392 | case WebAssembly::DIV_U_I32: return WebAssembly::DIV_U_I32_S; |
| 393 | case WebAssembly::DIV_U_I64: return WebAssembly::DIV_U_I64_S; |
| 394 | case WebAssembly::DROP_EXCEPT_REF: return WebAssembly::DROP_EXCEPT_REF_S; |
| 395 | case WebAssembly::DROP_F32: return WebAssembly::DROP_F32_S; |
| 396 | case WebAssembly::DROP_F64: return WebAssembly::DROP_F64_S; |
| 397 | case WebAssembly::DROP_I32: return WebAssembly::DROP_I32_S; |
| 398 | case WebAssembly::DROP_I64: return WebAssembly::DROP_I64_S; |
| 399 | case WebAssembly::DROP_V128: return WebAssembly::DROP_V128_S; |
| 400 | case WebAssembly::END_BLOCK: return WebAssembly::END_BLOCK_S; |
| 401 | case WebAssembly::END_FUNCTION: return WebAssembly::END_FUNCTION_S; |
| 402 | case WebAssembly::END_LOOP: return WebAssembly::END_LOOP_S; |
| 403 | case WebAssembly::END_TRY: return WebAssembly::END_TRY_S; |
| 404 | case WebAssembly::EQZ_I32: return WebAssembly::EQZ_I32_S; |
| 405 | case WebAssembly::EQZ_I64: return WebAssembly::EQZ_I64_S; |
| 406 | case WebAssembly::EQ_F32: return WebAssembly::EQ_F32_S; |
| 407 | case WebAssembly::EQ_F64: return WebAssembly::EQ_F64_S; |
| 408 | case WebAssembly::EQ_I32: return WebAssembly::EQ_I32_S; |
| 409 | case WebAssembly::EQ_I64: return WebAssembly::EQ_I64_S; |
| 410 | case WebAssembly::F32_CONVERT_S_I32: return WebAssembly::F32_CONVERT_S_I32_S; |
| 411 | case WebAssembly::F32_CONVERT_S_I64: return WebAssembly::F32_CONVERT_S_I64_S; |
| 412 | case WebAssembly::F32_CONVERT_U_I32: return WebAssembly::F32_CONVERT_U_I32_S; |
| 413 | case WebAssembly::F32_CONVERT_U_I64: return WebAssembly::F32_CONVERT_U_I64_S; |
| 414 | case WebAssembly::F32_DEMOTE_F64: return WebAssembly::F32_DEMOTE_F64_S; |
| 415 | case WebAssembly::F32_REINTERPRET_I32: return WebAssembly::F32_REINTERPRET_I32_S; |
| 416 | case WebAssembly::F64_CONVERT_S_I32: return WebAssembly::F64_CONVERT_S_I32_S; |
| 417 | case WebAssembly::F64_CONVERT_S_I64: return WebAssembly::F64_CONVERT_S_I64_S; |
| 418 | case WebAssembly::F64_CONVERT_U_I32: return WebAssembly::F64_CONVERT_U_I32_S; |
| 419 | case WebAssembly::F64_CONVERT_U_I64: return WebAssembly::F64_CONVERT_U_I64_S; |
| 420 | case WebAssembly::F64_PROMOTE_F32: return WebAssembly::F64_PROMOTE_F32_S; |
| 421 | case WebAssembly::F64_REINTERPRET_I64: return WebAssembly::F64_REINTERPRET_I64_S; |
| 422 | case WebAssembly::FALLTHROUGH_RETURN_EXCEPT_REF: return WebAssembly::FALLTHROUGH_RETURN_EXCEPT_REF_S; |
| 423 | case WebAssembly::FALLTHROUGH_RETURN_F32: return WebAssembly::FALLTHROUGH_RETURN_F32_S; |
| 424 | case WebAssembly::FALLTHROUGH_RETURN_F64: return WebAssembly::FALLTHROUGH_RETURN_F64_S; |
| 425 | case WebAssembly::FALLTHROUGH_RETURN_I32: return WebAssembly::FALLTHROUGH_RETURN_I32_S; |
| 426 | case WebAssembly::FALLTHROUGH_RETURN_I64: return WebAssembly::FALLTHROUGH_RETURN_I64_S; |
| 427 | case WebAssembly::FALLTHROUGH_RETURN_VOID: return WebAssembly::FALLTHROUGH_RETURN_VOID_S; |
| 428 | case WebAssembly::FALLTHROUGH_RETURN_v16i8: return WebAssembly::FALLTHROUGH_RETURN_v16i8_S; |
| 429 | case WebAssembly::FALLTHROUGH_RETURN_v4f32: return WebAssembly::FALLTHROUGH_RETURN_v4f32_S; |
| 430 | case WebAssembly::FALLTHROUGH_RETURN_v4i32: return WebAssembly::FALLTHROUGH_RETURN_v4i32_S; |
| 431 | case WebAssembly::FALLTHROUGH_RETURN_v8i16: return WebAssembly::FALLTHROUGH_RETURN_v8i16_S; |
| 432 | case WebAssembly::FALLTHROUGH_RETURN_v2f64: return WebAssembly::FALLTHROUGH_RETURN_v2f64_S; |
| 433 | case WebAssembly::FALLTHROUGH_RETURN_v2i64: return WebAssembly::FALLTHROUGH_RETURN_v2i64_S; |
| 434 | case WebAssembly::FLOOR_F32: return WebAssembly::FLOOR_F32_S; |
| 435 | case WebAssembly::FLOOR_F64: return WebAssembly::FLOOR_F64_S; |
| 436 | case WebAssembly::FP_TO_SINT_I32_F32: return WebAssembly::FP_TO_SINT_I32_F32_S; |
| 437 | case WebAssembly::FP_TO_SINT_I32_F64: return WebAssembly::FP_TO_SINT_I32_F64_S; |
| 438 | case WebAssembly::FP_TO_SINT_I64_F32: return WebAssembly::FP_TO_SINT_I64_F32_S; |
| 439 | case WebAssembly::FP_TO_SINT_I64_F64: return WebAssembly::FP_TO_SINT_I64_F64_S; |
| 440 | case WebAssembly::FP_TO_UINT_I32_F32: return WebAssembly::FP_TO_UINT_I32_F32_S; |
| 441 | case WebAssembly::FP_TO_UINT_I32_F64: return WebAssembly::FP_TO_UINT_I32_F64_S; |
| 442 | case WebAssembly::FP_TO_UINT_I64_F32: return WebAssembly::FP_TO_UINT_I64_F32_S; |
| 443 | case WebAssembly::FP_TO_UINT_I64_F64: return WebAssembly::FP_TO_UINT_I64_F64_S; |
| 444 | case WebAssembly::GET_GLOBAL_EXCEPT_REF: return WebAssembly::GET_GLOBAL_EXCEPT_REF_S; |
| 445 | case WebAssembly::GET_GLOBAL_F32: return WebAssembly::GET_GLOBAL_F32_S; |
| 446 | case WebAssembly::GET_GLOBAL_F64: return WebAssembly::GET_GLOBAL_F64_S; |
| 447 | case WebAssembly::GET_GLOBAL_I32: return WebAssembly::GET_GLOBAL_I32_S; |
| 448 | case WebAssembly::GET_GLOBAL_I64: return WebAssembly::GET_GLOBAL_I64_S; |
| 449 | case WebAssembly::GET_GLOBAL_V128: return WebAssembly::GET_GLOBAL_V128_S; |
| 450 | case WebAssembly::GET_LOCAL_EXCEPT_REF: return WebAssembly::GET_LOCAL_EXCEPT_REF_S; |
| 451 | case WebAssembly::GET_LOCAL_F32: return WebAssembly::GET_LOCAL_F32_S; |
| 452 | case WebAssembly::GET_LOCAL_F64: return WebAssembly::GET_LOCAL_F64_S; |
| 453 | case WebAssembly::GET_LOCAL_I32: return WebAssembly::GET_LOCAL_I32_S; |
| 454 | case WebAssembly::GET_LOCAL_I64: return WebAssembly::GET_LOCAL_I64_S; |
| 455 | case WebAssembly::GET_LOCAL_V128: return WebAssembly::GET_LOCAL_V128_S; |
| 456 | case WebAssembly::GE_F32: return WebAssembly::GE_F32_S; |
| 457 | case WebAssembly::GE_F64: return WebAssembly::GE_F64_S; |
| 458 | case WebAssembly::GE_S_I32: return WebAssembly::GE_S_I32_S; |
| 459 | case WebAssembly::GE_S_I64: return WebAssembly::GE_S_I64_S; |
| 460 | case WebAssembly::GE_U_I32: return WebAssembly::GE_U_I32_S; |
| 461 | case WebAssembly::GE_U_I64: return WebAssembly::GE_U_I64_S; |
| 462 | case WebAssembly::GROW_MEMORY_I32: return WebAssembly::GROW_MEMORY_I32_S; |
| 463 | case WebAssembly::GT_F32: return WebAssembly::GT_F32_S; |
| 464 | case WebAssembly::GT_F64: return WebAssembly::GT_F64_S; |
| 465 | case WebAssembly::GT_S_I32: return WebAssembly::GT_S_I32_S; |
| 466 | case WebAssembly::GT_S_I64: return WebAssembly::GT_S_I64_S; |
| 467 | case WebAssembly::GT_U_I32: return WebAssembly::GT_U_I32_S; |
| 468 | case WebAssembly::GT_U_I64: return WebAssembly::GT_U_I64_S; |
| 469 | case WebAssembly::I32_EXTEND16_S_I32: return WebAssembly::I32_EXTEND16_S_I32_S; |
| 470 | case WebAssembly::I32_EXTEND8_S_I32: return WebAssembly::I32_EXTEND8_S_I32_S; |
| 471 | case WebAssembly::I32_REINTERPRET_F32: return WebAssembly::I32_REINTERPRET_F32_S; |
| 472 | case WebAssembly::I32_TRUNC_S_F32: return WebAssembly::I32_TRUNC_S_F32_S; |
| 473 | case WebAssembly::I32_TRUNC_S_F64: return WebAssembly::I32_TRUNC_S_F64_S; |
| 474 | case WebAssembly::I32_TRUNC_S_SAT_F32: return WebAssembly::I32_TRUNC_S_SAT_F32_S; |
| 475 | case WebAssembly::I32_TRUNC_S_SAT_F64: return WebAssembly::I32_TRUNC_S_SAT_F64_S; |
| 476 | case WebAssembly::I32_TRUNC_U_F32: return WebAssembly::I32_TRUNC_U_F32_S; |
| 477 | case WebAssembly::I32_TRUNC_U_F64: return WebAssembly::I32_TRUNC_U_F64_S; |
| 478 | case WebAssembly::I32_TRUNC_U_SAT_F32: return WebAssembly::I32_TRUNC_U_SAT_F32_S; |
| 479 | case WebAssembly::I32_TRUNC_U_SAT_F64: return WebAssembly::I32_TRUNC_U_SAT_F64_S; |
| 480 | case WebAssembly::I32_WRAP_I64: return WebAssembly::I32_WRAP_I64_S; |
| 481 | case WebAssembly::I64_EXTEND16_S_I64: return WebAssembly::I64_EXTEND16_S_I64_S; |
| 482 | case WebAssembly::I64_EXTEND32_S_I64: return WebAssembly::I64_EXTEND32_S_I64_S; |
| 483 | case WebAssembly::I64_EXTEND8_S_I64: return WebAssembly::I64_EXTEND8_S_I64_S; |
| 484 | case WebAssembly::I64_EXTEND_S_I32: return WebAssembly::I64_EXTEND_S_I32_S; |
| 485 | case WebAssembly::I64_EXTEND_U_I32: return WebAssembly::I64_EXTEND_U_I32_S; |
| 486 | case WebAssembly::I64_REINTERPRET_F64: return WebAssembly::I64_REINTERPRET_F64_S; |
| 487 | case WebAssembly::I64_TRUNC_S_F32: return WebAssembly::I64_TRUNC_S_F32_S; |
| 488 | case WebAssembly::I64_TRUNC_S_F64: return WebAssembly::I64_TRUNC_S_F64_S; |
| 489 | case WebAssembly::I64_TRUNC_S_SAT_F32: return WebAssembly::I64_TRUNC_S_SAT_F32_S; |
| 490 | case WebAssembly::I64_TRUNC_S_SAT_F64: return WebAssembly::I64_TRUNC_S_SAT_F64_S; |
| 491 | case WebAssembly::I64_TRUNC_U_F32: return WebAssembly::I64_TRUNC_U_F32_S; |
| 492 | case WebAssembly::I64_TRUNC_U_F64: return WebAssembly::I64_TRUNC_U_F64_S; |
| 493 | case WebAssembly::I64_TRUNC_U_SAT_F32: return WebAssembly::I64_TRUNC_U_SAT_F32_S; |
| 494 | case WebAssembly::I64_TRUNC_U_SAT_F64: return WebAssembly::I64_TRUNC_U_SAT_F64_S; |
| 495 | case WebAssembly::LE_F32: return WebAssembly::LE_F32_S; |
| 496 | case WebAssembly::LE_F64: return WebAssembly::LE_F64_S; |
| 497 | case WebAssembly::LE_S_I32: return WebAssembly::LE_S_I32_S; |
| 498 | case WebAssembly::LE_S_I64: return WebAssembly::LE_S_I64_S; |
| 499 | case WebAssembly::LE_U_I32: return WebAssembly::LE_U_I32_S; |
| 500 | case WebAssembly::LE_U_I64: return WebAssembly::LE_U_I64_S; |
| 501 | case WebAssembly::LOAD16_S_I32: return WebAssembly::LOAD16_S_I32_S; |
| 502 | case WebAssembly::LOAD16_S_I64: return WebAssembly::LOAD16_S_I64_S; |
| 503 | case WebAssembly::LOAD16_U_I32: return WebAssembly::LOAD16_U_I32_S; |
| 504 | case WebAssembly::LOAD16_U_I64: return WebAssembly::LOAD16_U_I64_S; |
| 505 | case WebAssembly::LOAD32_S_I64: return WebAssembly::LOAD32_S_I64_S; |
| 506 | case WebAssembly::LOAD32_U_I64: return WebAssembly::LOAD32_U_I64_S; |
| 507 | case WebAssembly::LOAD8_S_I32: return WebAssembly::LOAD8_S_I32_S; |
| 508 | case WebAssembly::LOAD8_S_I64: return WebAssembly::LOAD8_S_I64_S; |
| 509 | case WebAssembly::LOAD8_U_I32: return WebAssembly::LOAD8_U_I32_S; |
| 510 | case WebAssembly::LOAD8_U_I64: return WebAssembly::LOAD8_U_I64_S; |
| 511 | case WebAssembly::LOAD_F32: return WebAssembly::LOAD_F32_S; |
| 512 | case WebAssembly::LOAD_F64: return WebAssembly::LOAD_F64_S; |
| 513 | case WebAssembly::LOAD_I32: return WebAssembly::LOAD_I32_S; |
| 514 | case WebAssembly::LOAD_I64: return WebAssembly::LOAD_I64_S; |
| 515 | case WebAssembly::LOOP: return WebAssembly::LOOP_S; |
| 516 | case WebAssembly::LT_F32: return WebAssembly::LT_F32_S; |
| 517 | case WebAssembly::LT_F64: return WebAssembly::LT_F64_S; |
| 518 | case WebAssembly::LT_S_I32: return WebAssembly::LT_S_I32_S; |
| 519 | case WebAssembly::LT_S_I64: return WebAssembly::LT_S_I64_S; |
| 520 | case WebAssembly::LT_U_I32: return WebAssembly::LT_U_I32_S; |
| 521 | case WebAssembly::LT_U_I64: return WebAssembly::LT_U_I64_S; |
| 522 | case WebAssembly::MAX_F32: return WebAssembly::MAX_F32_S; |
| 523 | case WebAssembly::MAX_F64: return WebAssembly::MAX_F64_S; |
| 524 | case WebAssembly::MEMORY_GROW_I32: return WebAssembly::MEMORY_GROW_I32_S; |
| 525 | case WebAssembly::MEMORY_SIZE_I32: return WebAssembly::MEMORY_SIZE_I32_S; |
| 526 | case WebAssembly::MEM_GROW_I32: return WebAssembly::MEM_GROW_I32_S; |
| 527 | case WebAssembly::MEM_SIZE_I32: return WebAssembly::MEM_SIZE_I32_S; |
| 528 | case WebAssembly::MIN_F32: return WebAssembly::MIN_F32_S; |
| 529 | case WebAssembly::MIN_F64: return WebAssembly::MIN_F64_S; |
| 530 | case WebAssembly::MUL_F32: return WebAssembly::MUL_F32_S; |
| 531 | case WebAssembly::MUL_F64: return WebAssembly::MUL_F64_S; |
| 532 | case WebAssembly::MUL_I32: return WebAssembly::MUL_I32_S; |
| 533 | case WebAssembly::MUL_I64: return WebAssembly::MUL_I64_S; |
| 534 | case WebAssembly::MUL_v16i8: return WebAssembly::MUL_v16i8_S; |
| 535 | case WebAssembly::MUL_v2f64: return WebAssembly::MUL_v2f64_S; |
| 536 | case WebAssembly::MUL_v4f32: return WebAssembly::MUL_v4f32_S; |
| 537 | case WebAssembly::MUL_v4i32: return WebAssembly::MUL_v4i32_S; |
| 538 | case WebAssembly::MUL_v8i16: return WebAssembly::MUL_v8i16_S; |
| 539 | case WebAssembly::NEAREST_F32: return WebAssembly::NEAREST_F32_S; |
| 540 | case WebAssembly::NEAREST_F64: return WebAssembly::NEAREST_F64_S; |
| 541 | case WebAssembly::NEG_F32: return WebAssembly::NEG_F32_S; |
| 542 | case WebAssembly::NEG_F64: return WebAssembly::NEG_F64_S; |
| 543 | case WebAssembly::NE_F32: return WebAssembly::NE_F32_S; |
| 544 | case WebAssembly::NE_F64: return WebAssembly::NE_F64_S; |
| 545 | case WebAssembly::NE_I32: return WebAssembly::NE_I32_S; |
| 546 | case WebAssembly::NE_I64: return WebAssembly::NE_I64_S; |
| 547 | case WebAssembly::NOP: return WebAssembly::NOP_S; |
| 548 | case WebAssembly::OR_I32: return WebAssembly::OR_I32_S; |
| 549 | case WebAssembly::OR_I64: return WebAssembly::OR_I64_S; |
| 550 | case WebAssembly::PCALL_INDIRECT_EXCEPT_REF: return WebAssembly::PCALL_INDIRECT_EXCEPT_REF_S; |
| 551 | case WebAssembly::PCALL_INDIRECT_F32: return WebAssembly::PCALL_INDIRECT_F32_S; |
| 552 | case WebAssembly::PCALL_INDIRECT_F64: return WebAssembly::PCALL_INDIRECT_F64_S; |
| 553 | case WebAssembly::PCALL_INDIRECT_I32: return WebAssembly::PCALL_INDIRECT_I32_S; |
| 554 | case WebAssembly::PCALL_INDIRECT_I64: return WebAssembly::PCALL_INDIRECT_I64_S; |
| 555 | case WebAssembly::PCALL_INDIRECT_VOID: return WebAssembly::PCALL_INDIRECT_VOID_S; |
| 556 | case WebAssembly::PCALL_INDIRECT_v16i8: return WebAssembly::PCALL_INDIRECT_v16i8_S; |
| 557 | case WebAssembly::PCALL_INDIRECT_v4f32: return WebAssembly::PCALL_INDIRECT_v4f32_S; |
| 558 | case WebAssembly::PCALL_INDIRECT_v4i32: return WebAssembly::PCALL_INDIRECT_v4i32_S; |
| 559 | case WebAssembly::PCALL_INDIRECT_v8i16: return WebAssembly::PCALL_INDIRECT_v8i16_S; |
| 560 | case WebAssembly::POPCNT_I32: return WebAssembly::POPCNT_I32_S; |
| 561 | case WebAssembly::POPCNT_I64: return WebAssembly::POPCNT_I64_S; |
| 562 | case WebAssembly::REM_S_I32: return WebAssembly::REM_S_I32_S; |
| 563 | case WebAssembly::REM_S_I64: return WebAssembly::REM_S_I64_S; |
| 564 | case WebAssembly::REM_U_I32: return WebAssembly::REM_U_I32_S; |
| 565 | case WebAssembly::REM_U_I64: return WebAssembly::REM_U_I64_S; |
| 566 | case WebAssembly::RETHROW: return WebAssembly::RETHROW_S; |
| 567 | case WebAssembly::RETHROW_TO_CALLER: return WebAssembly::RETHROW_TO_CALLER_S; |
| 568 | case WebAssembly::RETURN_EXCEPT_REF: return WebAssembly::RETURN_EXCEPT_REF_S; |
| 569 | case WebAssembly::RETURN_F32: return WebAssembly::RETURN_F32_S; |
| 570 | case WebAssembly::RETURN_F64: return WebAssembly::RETURN_F64_S; |
| 571 | case WebAssembly::RETURN_I32: return WebAssembly::RETURN_I32_S; |
| 572 | case WebAssembly::RETURN_I64: return WebAssembly::RETURN_I64_S; |
| 573 | case WebAssembly::RETURN_VOID: return WebAssembly::RETURN_VOID_S; |
| 574 | case WebAssembly::RETURN_v16i8: return WebAssembly::RETURN_v16i8_S; |
| 575 | case WebAssembly::RETURN_v4f32: return WebAssembly::RETURN_v4f32_S; |
| 576 | case WebAssembly::RETURN_v4i32: return WebAssembly::RETURN_v4i32_S; |
| 577 | case WebAssembly::RETURN_v8i16: return WebAssembly::RETURN_v8i16_S; |
| 578 | case WebAssembly::ROTL_I32: return WebAssembly::ROTL_I32_S; |
| 579 | case WebAssembly::ROTL_I64: return WebAssembly::ROTL_I64_S; |
| 580 | case WebAssembly::ROTR_I32: return WebAssembly::ROTR_I32_S; |
| 581 | case WebAssembly::ROTR_I64: return WebAssembly::ROTR_I64_S; |
| 582 | case WebAssembly::SELECT_EXCEPT_REF: return WebAssembly::SELECT_EXCEPT_REF_S; |
| 583 | case WebAssembly::SELECT_F32: return WebAssembly::SELECT_F32_S; |
| 584 | case WebAssembly::SELECT_F64: return WebAssembly::SELECT_F64_S; |
| 585 | case WebAssembly::SELECT_I32: return WebAssembly::SELECT_I32_S; |
| 586 | case WebAssembly::SELECT_I64: return WebAssembly::SELECT_I64_S; |
| 587 | case WebAssembly::SET_GLOBAL_EXCEPT_REF: return WebAssembly::SET_GLOBAL_EXCEPT_REF_S; |
| 588 | case WebAssembly::SET_GLOBAL_F32: return WebAssembly::SET_GLOBAL_F32_S; |
| 589 | case WebAssembly::SET_GLOBAL_F64: return WebAssembly::SET_GLOBAL_F64_S; |
| 590 | case WebAssembly::SET_GLOBAL_I32: return WebAssembly::SET_GLOBAL_I32_S; |
| 591 | case WebAssembly::SET_GLOBAL_I64: return WebAssembly::SET_GLOBAL_I64_S; |
| 592 | case WebAssembly::SET_GLOBAL_V128: return WebAssembly::SET_GLOBAL_V128_S; |
| 593 | case WebAssembly::SET_LOCAL_EXCEPT_REF: return WebAssembly::SET_LOCAL_EXCEPT_REF_S; |
| 594 | case WebAssembly::SET_LOCAL_F32: return WebAssembly::SET_LOCAL_F32_S; |
| 595 | case WebAssembly::SET_LOCAL_F64: return WebAssembly::SET_LOCAL_F64_S; |
| 596 | case WebAssembly::SET_LOCAL_I32: return WebAssembly::SET_LOCAL_I32_S; |
| 597 | case WebAssembly::SET_LOCAL_I64: return WebAssembly::SET_LOCAL_I64_S; |
| 598 | case WebAssembly::SET_LOCAL_V128: return WebAssembly::SET_LOCAL_V128_S; |
| 599 | case WebAssembly::SHL_I32: return WebAssembly::SHL_I32_S; |
| 600 | case WebAssembly::SHL_I64: return WebAssembly::SHL_I64_S; |
| 601 | case WebAssembly::SHR_S_I32: return WebAssembly::SHR_S_I32_S; |
| 602 | case WebAssembly::SHR_S_I64: return WebAssembly::SHR_S_I64_S; |
| 603 | case WebAssembly::SHR_U_I32: return WebAssembly::SHR_U_I32_S; |
| 604 | case WebAssembly::SHR_U_I64: return WebAssembly::SHR_U_I64_S; |
| 605 | case WebAssembly::SQRT_F32: return WebAssembly::SQRT_F32_S; |
| 606 | case WebAssembly::SQRT_F64: return WebAssembly::SQRT_F64_S; |
| 607 | case WebAssembly::STORE16_I32: return WebAssembly::STORE16_I32_S; |
| 608 | case WebAssembly::STORE16_I64: return WebAssembly::STORE16_I64_S; |
| 609 | case WebAssembly::STORE32_I64: return WebAssembly::STORE32_I64_S; |
| 610 | case WebAssembly::STORE8_I32: return WebAssembly::STORE8_I32_S; |
| 611 | case WebAssembly::STORE8_I64: return WebAssembly::STORE8_I64_S; |
| 612 | case WebAssembly::STORE_F32: return WebAssembly::STORE_F32_S; |
| 613 | case WebAssembly::STORE_F64: return WebAssembly::STORE_F64_S; |
| 614 | case WebAssembly::STORE_I32: return WebAssembly::STORE_I32_S; |
| 615 | case WebAssembly::STORE_I64: return WebAssembly::STORE_I64_S; |
| 616 | case WebAssembly::SUB_F32: return WebAssembly::SUB_F32_S; |
| 617 | case WebAssembly::SUB_F64: return WebAssembly::SUB_F64_S; |
| 618 | case WebAssembly::SUB_I32: return WebAssembly::SUB_I32_S; |
| 619 | case WebAssembly::SUB_I64: return WebAssembly::SUB_I64_S; |
| 620 | case WebAssembly::SUB_v16i8: return WebAssembly::SUB_v16i8_S; |
| 621 | case WebAssembly::SUB_v2f64: return WebAssembly::SUB_v2f64_S; |
| 622 | case WebAssembly::SUB_v2i64: return WebAssembly::SUB_v2i64_S; |
| 623 | case WebAssembly::SUB_v4f32: return WebAssembly::SUB_v4f32_S; |
| 624 | case WebAssembly::SUB_v4i32: return WebAssembly::SUB_v4i32_S; |
| 625 | case WebAssembly::SUB_v8i16: return WebAssembly::SUB_v8i16_S; |
| 626 | case WebAssembly::TEE_EXCEPT_REF: return WebAssembly::TEE_EXCEPT_REF_S; |
| 627 | case WebAssembly::TEE_F32: return WebAssembly::TEE_F32_S; |
| 628 | case WebAssembly::TEE_F64: return WebAssembly::TEE_F64_S; |
| 629 | case WebAssembly::TEE_I32: return WebAssembly::TEE_I32_S; |
| 630 | case WebAssembly::TEE_I64: return WebAssembly::TEE_I64_S; |
| 631 | case WebAssembly::TEE_LOCAL_EXCEPT_REF: return WebAssembly::TEE_LOCAL_EXCEPT_REF_S; |
| 632 | case WebAssembly::TEE_LOCAL_F32: return WebAssembly::TEE_LOCAL_F32_S; |
| 633 | case WebAssembly::TEE_LOCAL_F64: return WebAssembly::TEE_LOCAL_F64_S; |
| 634 | case WebAssembly::TEE_LOCAL_I32: return WebAssembly::TEE_LOCAL_I32_S; |
| 635 | case WebAssembly::TEE_LOCAL_I64: return WebAssembly::TEE_LOCAL_I64_S; |
| 636 | case WebAssembly::TEE_LOCAL_V128: return WebAssembly::TEE_LOCAL_V128_S; |
| 637 | case WebAssembly::TEE_V128: return WebAssembly::TEE_V128_S; |
| 638 | case WebAssembly::THROW_I32: return WebAssembly::THROW_I32_S; |
| 639 | case WebAssembly::THROW_I64: return WebAssembly::THROW_I64_S; |
| 640 | case WebAssembly::TRUNC_F32: return WebAssembly::TRUNC_F32_S; |
| 641 | case WebAssembly::TRUNC_F64: return WebAssembly::TRUNC_F64_S; |
| 642 | case WebAssembly::TRY: return WebAssembly::TRY_S; |
| 643 | case WebAssembly::UNREACHABLE: return WebAssembly::UNREACHABLE_S; |
| 644 | case WebAssembly::XOR_I32: return WebAssembly::XOR_I32_S; |
| 645 | case WebAssembly::XOR_I64: return WebAssembly::XOR_I64_S; |
| 646 | } |
Dan Gohman | e9361d5 | 2015-11-05 19:28:16 +0000 | [diff] [blame] | 647 | } |