diff options
author | Nicholas Wilson <nicholas@nicholaswilson.me.uk> | 2018-08-03 14:33:37 +0000 |
---|---|---|
committer | Nicholas Wilson <nicholas@nicholaswilson.me.uk> | 2018-08-03 14:33:37 +0000 |
commit | e408a89a3aa83acb97f22d7d51ab341c22c6e05c (patch) | |
tree | 6b829861c534d9dc48c4940345183f528fe1c081 /llvm/lib/Target | |
parent | 873de9866119754dab9146026f357a27bb1d5e26 (diff) | |
download | bcm5719-llvm-e408a89a3aa83acb97f22d7d51ab341c22c6e05c.tar.gz bcm5719-llvm-e408a89a3aa83acb97f22d7d51ab341c22c6e05c.zip |
[WebAssembly] Cleanup of the way globals and global flags are handled
Differential Revision: https://reviews.llvm.org/D44030
llvm-svn: 338894
Diffstat (limited to 'llvm/lib/Target')
8 files changed, 35 insertions, 16 deletions
diff --git a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyFixupKinds.h b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyFixupKinds.h index b0af63c924b..23d0de15ea9 100644 --- a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyFixupKinds.h +++ b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyFixupKinds.h @@ -19,8 +19,6 @@ enum Fixups { fixup_code_sleb128_i64, // 64-bit signed fixup_code_uleb128_i32, // 32-bit unsigned - fixup_code_global_index, // 32-bit unsigned - // Marker LastTargetFixupKind, NumTargetFixupKinds = LastTargetFixupKind - FirstTargetFixupKind diff --git a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCCodeEmitter.cpp b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCCodeEmitter.cpp index 94ca94e1e18..417912604e0 100644 --- a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCCodeEmitter.cpp +++ b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCCodeEmitter.cpp @@ -138,7 +138,7 @@ void WebAssemblyMCCodeEmitter::encodeInstruction( Info.OperandType == WebAssembly::OPERAND_TYPEINDEX) { FixupKind = MCFixupKind(WebAssembly::fixup_code_uleb128_i32); } else if (Info.OperandType == WebAssembly::OPERAND_GLOBAL) { - FixupKind = MCFixupKind(WebAssembly::fixup_code_global_index); + FixupKind = MCFixupKind(WebAssembly::fixup_code_uleb128_i32); } else { llvm_unreachable("unexpected symbolic operand kind"); } diff --git a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h index 62a59317165..071e4586856 100644 --- a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h +++ b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h @@ -81,6 +81,16 @@ enum { // whether the value represents a control-flow label. VariableOpImmediateIsLabel = (1 << 1) }; + +/// Target Operand Flag enum. +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_MASK = 0x3, +}; } // end namespace WebAssemblyII } // end namespace llvm diff --git a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp index 4fb12d40b01..dc876ab585b 100644 --- a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp +++ b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp @@ -81,6 +81,11 @@ static const MCSection *GetFixupSection(const MCExpr *Expr) { return nullptr; } +static bool IsGlobalType(const MCValue &Target) { + const MCSymbolRefExpr *RefA = Target.getSymA(); + return RefA && RefA->getKind() == MCSymbolRefExpr::VK_WebAssembly_GLOBAL; +} + unsigned WebAssemblyWasmObjectWriter::getRelocType(const MCValue &Target, const MCFixup &Fixup) const { @@ -89,8 +94,6 @@ WebAssemblyWasmObjectWriter::getRelocType(const MCValue &Target, bool IsFunction = IsFunctionExpr(Fixup.getValue()); switch (unsigned(Fixup.getKind())) { - case WebAssembly::fixup_code_global_index: - return wasm::R_WEBASSEMBLY_GLOBAL_INDEX_LEB; case WebAssembly::fixup_code_sleb128_i32: if (IsFunction) return wasm::R_WEBASSEMBLY_TABLE_INDEX_SLEB; @@ -98,6 +101,8 @@ WebAssemblyWasmObjectWriter::getRelocType(const MCValue &Target, case WebAssembly::fixup_code_sleb128_i64: llvm_unreachable("fixup_sleb128_i64 not implemented yet"); case WebAssembly::fixup_code_uleb128_i32: + if (IsGlobalType(Target)) + return wasm::R_WEBASSEMBLY_GLOBAL_INDEX_LEB; if (IsFunctionType(Target)) return wasm::R_WEBASSEMBLY_TYPE_INDEX_LEB; if (IsFunction) diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp index 052c94e9d6a..0835ff38a13 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp @@ -107,7 +107,7 @@ static void writeSPToMemory(unsigned SrcReg, MachineFunction &MF, const char *ES = "__stack_pointer"; auto *SPSymbol = MF.createExternalSymbolName(ES); BuildMI(MBB, InsertStore, DL, TII->get(WebAssembly::SET_GLOBAL_I32)) - .addExternalSymbol(SPSymbol) + .addExternalSymbol(SPSymbol, WebAssemblyII::MO_SYMBOL_GLOBAL) .addReg(SrcReg); } @@ -153,7 +153,7 @@ void WebAssemblyFrameLowering::emitPrologue(MachineFunction &MF, const char *ES = "__stack_pointer"; auto *SPSymbol = MF.createExternalSymbolName(ES); BuildMI(MBB, InsertPt, DL, TII->get(WebAssembly::GET_GLOBAL_I32), SPReg) - .addExternalSymbol(SPSymbol); + .addExternalSymbol(SPSymbol, WebAssemblyII::MO_SYMBOL_GLOBAL); bool HasBP = hasBP(MF); if (HasBP) { diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp index 95502762a78..aa3c0d03913 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp @@ -871,7 +871,7 @@ SDValue WebAssemblyTargetLowering::LowerExternalSymbol( // functions. return DAG.getNode(WebAssemblyISD::Wrapper, DL, VT, DAG.getTargetExternalSymbol(ES->getSymbol(), VT, - /*TargetFlags=*/0x1)); + WebAssemblyII::MO_SYMBOL_FUNCTION)); } SDValue WebAssemblyTargetLowering::LowerJumpTable(SDValue Op, diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp index d85db14fc67..5a9e3c67176 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp @@ -108,9 +108,11 @@ MCSymbol *WebAssemblyMCInstLower::GetExternalSymbolSymbol( MCOperand WebAssemblyMCInstLower::LowerSymbolOperand(MCSymbol *Sym, int64_t Offset, - bool IsFunc) const { + bool IsFunc, + bool IsGlob) const { MCSymbolRefExpr::VariantKind VK = - IsFunc ? MCSymbolRefExpr::VK_WebAssembly_FUNCTION + IsFunc ? MCSymbolRefExpr::VK_WebAssembly_FUNCTION : + IsGlob ? MCSymbolRefExpr::VK_WebAssembly_GLOBAL : MCSymbolRefExpr::VK_None; const MCExpr *Expr = MCSymbolRefExpr::create(Sym, VK, Ctx); @@ -118,6 +120,8 @@ MCOperand WebAssemblyMCInstLower::LowerSymbolOperand(MCSymbol *Sym, if (Offset != 0) { if (IsFunc) report_fatal_error("Function addresses with offsets not supported"); + if (IsGlob) + report_fatal_error("Global indexes with offsets not supported"); Expr = MCBinaryExpr::createAdd(Expr, MCConstantExpr::create(Offset, Ctx), Ctx); } @@ -212,18 +216,20 @@ void WebAssemblyMCInstLower::Lower(const MachineInstr *MI, break; } case MachineOperand::MO_GlobalAddress: - assert(MO.getTargetFlags() == 0 && + assert(MO.getTargetFlags() == WebAssemblyII::MO_NO_FLAG && "WebAssembly does not use target flags on GlobalAddresses"); MCOp = LowerSymbolOperand(GetGlobalAddressSymbol(MO), MO.getOffset(), - MO.getGlobal()->getValueType()->isFunctionTy()); + MO.getGlobal()->getValueType()->isFunctionTy(), + false); break; case MachineOperand::MO_ExternalSymbol: // The target flag indicates whether this is a symbol for a // variable or a function. - assert((MO.getTargetFlags() & -2) == 0 && - "WebAssembly uses only one target flag bit on ExternalSymbols"); + assert((MO.getTargetFlags() & ~WebAssemblyII::MO_SYMBOL_MASK) == 0 && + "WebAssembly uses only symbol flags on ExternalSymbols"); MCOp = LowerSymbolOperand(GetExternalSymbolSymbol(MO), /*Offset=*/0, - MO.getTargetFlags() & 1); + (MO.getTargetFlags() & WebAssemblyII::MO_SYMBOL_FUNCTION) != 0, + (MO.getTargetFlags() & WebAssemblyII::MO_SYMBOL_GLOBAL) != 0); break; } diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.h b/llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.h index 41b4313bb38..3a9d52b1c8c 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.h +++ b/llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.h @@ -34,7 +34,7 @@ class LLVM_LIBRARY_VISIBILITY WebAssemblyMCInstLower { MCSymbol *GetGlobalAddressSymbol(const MachineOperand &MO) const; MCSymbol *GetExternalSymbolSymbol(const MachineOperand &MO) const; MCOperand LowerSymbolOperand(MCSymbol *Sym, int64_t Offset, - bool IsFunc) const; + bool IsFunc, bool IsGlob) const; public: WebAssemblyMCInstLower(MCContext &ctx, WebAssemblyAsmPrinter &printer) |