diff options
author | Sam Clegg <sbc@chromium.org> | 2019-02-22 22:29:34 +0000 |
---|---|---|
committer | Sam Clegg <sbc@chromium.org> | 2019-02-22 22:29:34 +0000 |
commit | 8fffa1dfa3bddf44b73a6f622eafa752347202f5 (patch) | |
tree | e7f2e6050d2c9510bbc54a770b87e6b882985006 /llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp | |
parent | 1e4f0735824abc9d618ae19b40b57dad2a5c5149 (diff) | |
download | bcm5719-llvm-8fffa1dfa3bddf44b73a6f622eafa752347202f5.tar.gz bcm5719-llvm-8fffa1dfa3bddf44b73a6f622eafa752347202f5.zip |
[WebAssembly] Remove unneeded MCSymbolRefExpr variants
We record the type of the symbol (event/function/data/global) in the
MCWasmSymbol and so it should always be clear how to handle a relocation
based on the symbol itself.
The exception is a function which still needs the special @TYPEINDEX
then the relocation contains the signature rather than the address
of the functions.
Differential Revision: https://reviews.llvm.org/D58472
llvm-svn: 354697
Diffstat (limited to 'llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp')
-rw-r--r-- | llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp | 53 |
1 files changed, 15 insertions, 38 deletions
diff --git a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp index 2c97aadd7f9..3b800858063 100644 --- a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp +++ b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp @@ -42,23 +42,8 @@ private: WebAssemblyWasmObjectWriter::WebAssemblyWasmObjectWriter(bool Is64Bit) : MCWasmObjectTargetWriter(Is64Bit) {} -// Test whether the given expression computes a function address. -static bool isFunctionExpr(const MCExpr *Expr) { - if (auto SyExp = dyn_cast<MCSymbolRefExpr>(Expr)) - return cast<MCSymbolWasm>(SyExp->getSymbol()).isFunction(); - - if (auto BinOp = dyn_cast<MCBinaryExpr>(Expr)) - return isFunctionExpr(BinOp->getLHS()) != isFunctionExpr(BinOp->getRHS()); - - if (auto UnOp = dyn_cast<MCUnaryExpr>(Expr)) - return isFunctionExpr(UnOp->getSubExpr()); - - return false; -} - -static bool isFunctionType(const MCValue &Target) { - const MCSymbolRefExpr *RefA = Target.getSymA(); - return RefA && RefA->getKind() == MCSymbolRefExpr::VK_WebAssembly_TYPEINDEX; +static bool isFunctionSignatureRef(const MCSymbolRefExpr *Ref) { + return Ref->getKind() == MCSymbolRefExpr::VK_WebAssembly_TYPEINDEX; } static const MCSection *getFixupSection(const MCExpr *Expr) { @@ -80,41 +65,33 @@ 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; -} - -static bool isEventType(const MCValue &Target) { - const MCSymbolRefExpr *RefA = Target.getSymA(); - return RefA && RefA->getKind() == MCSymbolRefExpr::VK_WebAssembly_EVENT; -} - unsigned WebAssemblyWasmObjectWriter::getRelocType(const MCValue &Target, const MCFixup &Fixup) const { - // WebAssembly functions are not allocated in the data address space. To - // resolve a pointer to a function, we must use a special relocation type. - bool IsFunction = isFunctionExpr(Fixup.getValue()); + const MCSymbolRefExpr *RefA = Target.getSymA(); + assert(RefA); + auto& SymA = cast<MCSymbolWasm>(RefA->getSymbol()); switch (unsigned(Fixup.getKind())) { case WebAssembly::fixup_code_sleb128_i32: - if (IsFunction) + if (SymA.isFunction()) return wasm::R_WASM_TABLE_INDEX_SLEB; return wasm::R_WASM_MEMORY_ADDR_SLEB; case WebAssembly::fixup_code_sleb128_i64: llvm_unreachable("fixup_sleb128_i64 not implemented yet"); case WebAssembly::fixup_code_uleb128_i32: - if (isGlobalType(Target)) + if (SymA.isFunction()) { + if (isFunctionSignatureRef(RefA)) + return wasm::R_WASM_TYPE_INDEX_LEB; + else + return wasm::R_WASM_FUNCTION_INDEX_LEB; + } + if (SymA.isGlobal()) return wasm::R_WASM_GLOBAL_INDEX_LEB; - if (isFunctionType(Target)) - return wasm::R_WASM_TYPE_INDEX_LEB; - if (IsFunction) - return wasm::R_WASM_FUNCTION_INDEX_LEB; - if (isEventType(Target)) + if (SymA.isEvent()) return wasm::R_WASM_EVENT_INDEX_LEB; return wasm::R_WASM_MEMORY_ADDR_LEB; case FK_Data_4: - if (IsFunction) + if (SymA.isFunction()) return wasm::R_WASM_TABLE_INDEX_I32; if (auto Section = static_cast<const MCSectionWasm *>( getFixupSection(Fixup.getValue()))) { |