diff options
Diffstat (limited to 'lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp')
| -rw-r--r-- | lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp | 87 | 
1 files changed, 42 insertions, 45 deletions
diff --git a/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp b/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp index 4a93d4810c7d..d85db14fc679 100644 --- a/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp +++ b/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp @@ -8,7 +8,7 @@  //===----------------------------------------------------------------------===//  ///  /// \file -/// \brief This file contains code to lower WebAssembly MachineInstrs to their +/// This file contains code to lower WebAssembly MachineInstrs to their  /// corresponding MCInst records.  ///  //===----------------------------------------------------------------------===// @@ -25,7 +25,6 @@  #include "llvm/MC/MCContext.h"  #include "llvm/MC/MCExpr.h"  #include "llvm/MC/MCInst.h" -#include "llvm/MC/MCSymbolELF.h"  #include "llvm/MC/MCSymbolWasm.h"  #include "llvm/Support/ErrorHandling.h"  #include "llvm/Support/raw_ostream.h" @@ -34,11 +33,7 @@ using namespace llvm;  MCSymbol *  WebAssemblyMCInstLower::GetGlobalAddressSymbol(const MachineOperand &MO) const {    const GlobalValue *Global = MO.getGlobal(); -  MCSymbol *Sym = Printer.getSymbol(Global); -  if (isa<MCSymbolELF>(Sym)) -    return Sym; - -  MCSymbolWasm *WasmSym = cast<MCSymbolWasm>(Sym); +  MCSymbolWasm *WasmSym = cast<MCSymbolWasm>(Printer.getSymbol(Global));    if (const auto *FuncTy = dyn_cast<FunctionType>(Global->getValueType())) {      const MachineFunction &MF = *MO.getParent()->getParent()->getParent(); @@ -74,7 +69,7 @@ WebAssemblyMCInstLower::GetGlobalAddressSymbol(const MachineOperand &MO) const {      WasmSym->setReturns(std::move(Returns));      WasmSym->setParams(std::move(Params)); -    WasmSym->setIsFunction(true); +    WasmSym->setType(wasm::WASM_SYMBOL_TYPE_FUNCTION);    }    return WasmSym; @@ -83,17 +78,22 @@ WebAssemblyMCInstLower::GetGlobalAddressSymbol(const MachineOperand &MO) const {  MCSymbol *WebAssemblyMCInstLower::GetExternalSymbolSymbol(      const MachineOperand &MO) const {    const char *Name = MO.getSymbolName(); -  MCSymbol *Sym = Printer.GetExternalSymbolSymbol(Name); -  if (isa<MCSymbolELF>(Sym)) -    return Sym; - -  MCSymbolWasm *WasmSym = cast<MCSymbolWasm>(Sym); +  MCSymbolWasm *WasmSym = +      cast<MCSymbolWasm>(Printer.GetExternalSymbolSymbol(Name));    const WebAssemblySubtarget &Subtarget = Printer.getSubtarget();    // __stack_pointer is a global variable; all other external symbols used by -  // CodeGen are functions. -  if (strcmp(Name, "__stack_pointer") == 0) +  // CodeGen are functions.  It's OK to hardcode knowledge of specific symbols +  // here; this method is precisely there for fetching the signatures of known +  // Clang-provided symbols. +  if (strcmp(Name, "__stack_pointer") == 0) { +    WasmSym->setType(wasm::WASM_SYMBOL_TYPE_GLOBAL); +    WasmSym->setGlobalType(wasm::WasmGlobalType{ +        uint8_t(Subtarget.hasAddr64() ? wasm::WASM_TYPE_I64 +                                      : wasm::WASM_TYPE_I32), +        true});      return WasmSym; +  }    SmallVector<wasm::ValType, 4> Returns;    SmallVector<wasm::ValType, 4> Params; @@ -101,7 +101,7 @@ MCSymbol *WebAssemblyMCInstLower::GetExternalSymbolSymbol(    WasmSym->setReturns(std::move(Returns));    WasmSym->setParams(std::move(Params)); -  WasmSym->setIsFunction(true); +  WasmSym->setType(wasm::WASM_SYMBOL_TYPE_FUNCTION);    return WasmSym;  } @@ -169,35 +169,32 @@ void WebAssemblyMCInstLower::Lower(const MachineInstr *MI,          const MCOperandInfo &Info = Desc.OpInfo[i];          if (Info.OperandType == WebAssembly::OPERAND_TYPEINDEX) {            MCSymbol *Sym = Printer.createTempSymbol("typeindex"); -          if (!isa<MCSymbolELF>(Sym)) { -            SmallVector<wasm::ValType, 4> Returns; -            SmallVector<wasm::ValType, 4> Params; - -            const MachineRegisterInfo &MRI = -                MI->getParent()->getParent()->getRegInfo(); -            for (const MachineOperand &MO : MI->defs()) -              Returns.push_back(getType(MRI.getRegClass(MO.getReg()))); -            for (const MachineOperand &MO : MI->explicit_uses()) -              if (MO.isReg()) -                Params.push_back(getType(MRI.getRegClass(MO.getReg()))); - -            // call_indirect instructions have a callee operand at the end which -            // doesn't count as a param. -            if (WebAssembly::isCallIndirect(*MI)) -              Params.pop_back(); - -            MCSymbolWasm *WasmSym = cast<MCSymbolWasm>(Sym); -            WasmSym->setReturns(std::move(Returns)); -            WasmSym->setParams(std::move(Params)); -            WasmSym->setIsFunction(true); - -            const MCExpr *Expr = -                MCSymbolRefExpr::create(WasmSym, -                                        MCSymbolRefExpr::VK_WebAssembly_TYPEINDEX, -                                        Ctx); -            MCOp = MCOperand::createExpr(Expr); -            break; -          } + +          SmallVector<wasm::ValType, 4> Returns; +          SmallVector<wasm::ValType, 4> Params; + +          const MachineRegisterInfo &MRI = +              MI->getParent()->getParent()->getRegInfo(); +          for (const MachineOperand &MO : MI->defs()) +            Returns.push_back(getType(MRI.getRegClass(MO.getReg()))); +          for (const MachineOperand &MO : MI->explicit_uses()) +            if (MO.isReg()) +              Params.push_back(getType(MRI.getRegClass(MO.getReg()))); + +          // call_indirect instructions have a callee operand at the end which +          // doesn't count as a param. +          if (WebAssembly::isCallIndirect(*MI)) +            Params.pop_back(); + +          MCSymbolWasm *WasmSym = cast<MCSymbolWasm>(Sym); +          WasmSym->setReturns(std::move(Returns)); +          WasmSym->setParams(std::move(Params)); +          WasmSym->setType(wasm::WASM_SYMBOL_TYPE_FUNCTION); + +          const MCExpr *Expr = MCSymbolRefExpr::create( +              WasmSym, MCSymbolRefExpr::VK_WebAssembly_TYPEINDEX, Ctx); +          MCOp = MCOperand::createExpr(Expr); +          break;          }        }        MCOp = MCOperand::createImm(MO.getImm());  | 
