Index: llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h =================================================================== --- llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h +++ llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h @@ -90,15 +90,9 @@ enum TOF { MO_NO_FLAG = 0, - // Flags to indicate the type of the symbol being referenced - MO_SYMBOL_FUNCTION = 0x1, - MO_SYMBOL_GLOBAL = 0x2, - MO_SYMBOL_EVENT = 0x4, - MO_SYMBOL_MASK = 0x7, - // Address of data symbol via a wasm global. This adds a level of indirection // similar to the GOT on native platforms. - MO_GOT = 0x8, + MO_GOT, }; } // end namespace WebAssemblyII Index: llvm/trunk/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp =================================================================== --- llvm/trunk/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp +++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp @@ -130,7 +130,7 @@ const char *ES = "__stack_pointer"; auto *SPSymbol = MF.createExternalSymbolName(ES); BuildMI(MBB, InsertStore, DL, TII->get(WebAssembly::GLOBAL_SET_I32)) - .addExternalSymbol(SPSymbol, WebAssemblyII::MO_SYMBOL_GLOBAL) + .addExternalSymbol(SPSymbol) .addReg(SrcReg); } @@ -177,7 +177,7 @@ const char *ES = "__stack_pointer"; auto *SPSymbol = MF.createExternalSymbolName(ES); BuildMI(MBB, InsertPt, DL, TII->get(WebAssembly::GLOBAL_GET_I32), SPReg) - .addExternalSymbol(SPSymbol, WebAssemblyII::MO_SYMBOL_GLOBAL); + .addExternalSymbol(SPSymbol); bool HasBP = hasBP(MF); if (HasBP) { Index: llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp =================================================================== --- llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp +++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp @@ -996,7 +996,7 @@ if (GA->getAddressSpace() != 0) fail(DL, DAG, "WebAssembly only expects the 0 address space"); - unsigned Flags = 0; + unsigned OperandFlags = 0; if (isPositionIndependent()) { const GlobalValue *GV = GA->getGlobal(); if (getTargetMachine().shouldAssumeDSOLocal(*GV->getParent(), GV)) { @@ -1017,13 +1017,13 @@ return DAG.getNode(ISD::ADD, DL, VT, BaseAddr, SymAddr); } else { - Flags |= WebAssemblyII::MO_GOT; + OperandFlags = WebAssemblyII::MO_GOT; } } return DAG.getNode(WebAssemblyISD::Wrapper, DL, VT, DAG.getTargetGlobalAddress(GA->getGlobal(), DL, VT, - GA->getOffset(), Flags)); + GA->getOffset(), OperandFlags)); } SDValue @@ -1034,15 +1034,8 @@ EVT VT = Op.getValueType(); assert(ES->getTargetFlags() == 0 && "Unexpected target flags on generic ExternalSymbolSDNode"); - // Set the TargetFlags to MO_SYMBOL_FUNCTION which indicates that this is a - // "function" symbol rather than a data symbol. We do this unconditionally - // even though we don't know anything about the symbol other than its name, - // because all external symbols used in target-independent SelectionDAG code - // are for functions. - return DAG.getNode( - WebAssemblyISD::Wrapper, DL, VT, - DAG.getTargetExternalSymbol(ES->getSymbol(), VT, - WebAssemblyII::MO_SYMBOL_FUNCTION)); + return DAG.getNode(WebAssemblyISD::Wrapper, DL, VT, + DAG.getTargetExternalSymbol(ES->getSymbol(), VT)); } SDValue WebAssemblyTargetLowering::LowerJumpTable(SDValue Op, @@ -1136,10 +1129,8 @@ const TargetLowering &TLI = DAG.getTargetLoweringInfo(); MVT PtrVT = TLI.getPointerTy(DAG.getDataLayout()); const char *SymName = MF.createExternalSymbolName("__cpp_exception"); - SDValue SymNode = - DAG.getNode(WebAssemblyISD::Wrapper, DL, PtrVT, - DAG.getTargetExternalSymbol( - SymName, PtrVT, WebAssemblyII::MO_SYMBOL_EVENT)); + SDValue SymNode = DAG.getNode(WebAssemblyISD::Wrapper, DL, PtrVT, + DAG.getTargetExternalSymbol(SymName, PtrVT)); return DAG.getNode(WebAssemblyISD::THROW, DL, MVT::Other, // outchain type { Index: llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrInfo.cpp =================================================================== --- llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrInfo.cpp +++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrInfo.cpp @@ -199,7 +199,7 @@ const char *CPPExnSymbol = MF.createExternalSymbolName("__cpp_exception"); BuildMI(&MBB, DL, get(WebAssembly::BR_ON_EXN)) .addMBB(TBB) - .addExternalSymbol(CPPExnSymbol, WebAssemblyII::MO_SYMBOL_EVENT) + .addExternalSymbol(CPPExnSymbol) .add(Cond[1]); } else BuildMI(&MBB, DL, get(WebAssembly::BR_IF)).addMBB(TBB).add(Cond[1]); Index: llvm/trunk/lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp =================================================================== --- llvm/trunk/lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp +++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp @@ -307,7 +307,7 @@ const char *CPPExnSymbol = MF.createExternalSymbolName("__cpp_exception"); BuildMI(EHPad, DL, TII.get(WebAssembly::BR_ON_EXN)) .addMBB(ThenMBB) - .addExternalSymbol(CPPExnSymbol, WebAssemblyII::MO_SYMBOL_EVENT) + .addExternalSymbol(CPPExnSymbol) .addReg(ExnReg); BuildMI(EHPad, DL, TII.get(WebAssembly::BR)).addMBB(ElseMBB); Index: llvm/trunk/lib/Target/WebAssembly/WebAssemblyMCInstLower.h =================================================================== --- llvm/trunk/lib/Target/WebAssembly/WebAssemblyMCInstLower.h +++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyMCInstLower.h @@ -32,8 +32,7 @@ MCSymbol *GetGlobalAddressSymbol(const MachineOperand &MO) const; MCSymbol *GetExternalSymbolSymbol(const MachineOperand &MO) const; - MCOperand lowerSymbolOperand(MCSymbol *Sym, int64_t Offset, bool IsFunc, - unsigned flags) const; + MCOperand lowerSymbolOperand(const MachineOperand &MO, MCSymbol *Sym) const; public: WebAssemblyMCInstLower(MCContext &ctx, WebAssemblyAsmPrinter &printer) Index: llvm/trunk/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp =================================================================== --- llvm/trunk/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp +++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp @@ -120,26 +120,27 @@ return WasmSym; } -MCOperand WebAssemblyMCInstLower::lowerSymbolOperand( - MCSymbol *Sym, int64_t Offset, bool IsFunc, unsigned TargetFlags) const { - MCSymbolRefExpr::VariantKind Kind = MCSymbolRefExpr::VK_None; - if (TargetFlags & WebAssemblyII::MO_GOT) - Kind = MCSymbolRefExpr::VK_GOT; +MCOperand WebAssemblyMCInstLower::lowerSymbolOperand(const MachineOperand &MO, + MCSymbol *Sym) const { + bool isGOT = MO.getTargetFlags() == WebAssemblyII::MO_GOT; + MCSymbolRefExpr::VariantKind Kind = + isGOT ? MCSymbolRefExpr::VK_GOT : MCSymbolRefExpr::VK_None; const MCExpr *Expr = MCSymbolRefExpr::create(Sym, Kind, Ctx); - if (Offset != 0) { - if (TargetFlags & WebAssemblyII::MO_GOT) + if (MO.getOffset() != 0) { + const auto *WasmSym = cast(Sym); + if (isGOT) report_fatal_error("GOT symbol references do not support offsets"); - unsigned Type = TargetFlags & WebAssemblyII::MO_SYMBOL_MASK; - assert((Type == WebAssemblyII::MO_SYMBOL_FUNCTION) == IsFunc); - if (Type == WebAssemblyII::MO_SYMBOL_FUNCTION || IsFunc) + + if (WasmSym->isFunction()) report_fatal_error("Function addresses with offsets not supported"); - if (Type == WebAssemblyII::MO_SYMBOL_GLOBAL) + if (WasmSym->isGlobal()) report_fatal_error("Global indexes with offsets not supported"); - if (Type == WebAssemblyII::MO_SYMBOL_EVENT) + if (WasmSym->isEvent()) report_fatal_error("Event indexes with offsets not supported"); - Expr = - MCBinaryExpr::createAdd(Expr, MCConstantExpr::create(Offset, Ctx), Ctx); + + Expr = MCBinaryExpr::createAdd( + Expr, MCConstantExpr::create(MO.getOffset(), Ctx), Ctx); } return MCOperand::createExpr(Expr); @@ -236,24 +237,21 @@ break; } case MachineOperand::MO_GlobalAddress: - MCOp = lowerSymbolOperand(GetGlobalAddressSymbol(MO), MO.getOffset(), - MO.getGlobal()->getValueType()->isFunctionTy(), - MO.getTargetFlags()); + MCOp = lowerSymbolOperand(MO, GetGlobalAddressSymbol(MO)); break; case MachineOperand::MO_ExternalSymbol: // The target flag indicates whether this is a symbol for a // variable or a function. - assert((MO.getTargetFlags() & ~WebAssemblyII::MO_SYMBOL_MASK) == 0 && + assert(MO.getTargetFlags() == 0 && "WebAssembly uses only symbol flags on ExternalSymbols"); - MCOp = lowerSymbolOperand( - GetExternalSymbolSymbol(MO), /*Offset=*/0, false, MO.getTargetFlags()); + MCOp = lowerSymbolOperand(MO, GetExternalSymbolSymbol(MO)); break; case MachineOperand::MO_MCSymbol: // This is currently used only for LSDA symbols (GCC_except_table), // because global addresses or other external symbols are handled above. assert(MO.getTargetFlags() == 0 && "WebAssembly does not use target flags on MCSymbol"); - MCOp = lowerSymbolOperand(MO.getMCSymbol(), /*Offset=*/0, false, MO.getTargetFlags()); + MCOp = lowerSymbolOperand(MO, MO.getMCSymbol()); break; }