[PATCH] D100995: [WebAssembly] Put utility functions in Utils directory (NFC)

Andy Wingo via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 22 00:20:06 PDT 2021


wingo added a comment.

In D100995#2706433 <https://reviews.llvm.org/D100995#2706433>, @aheejin wrote:

> @wingo, I wanted to merge WebAssembly::getOrCreateFunctionTableSymbol <https://github.com/llvm/llvm-project/blob/5d1c43f333c2327be61604dc90ea675f0d1e6913/llvm/lib/Target/WebAssembly/WebAssemblyUtilities.cpp#L100-L117> in WebAssemblyUtilities.cpp and GetOrCreateFunctionTableSymbol <https://github.com/llvm/llvm-project/blob/5d1c43f333c2327be61604dc90ea675f0d1e6913/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp#L177-L190> in WebAssemblyAsmParser.cpp and put it in Utils/WebAssemblyUtilities.cpp, but it looks they became diverged in D90948 <https://reviews.llvm.org/D90948> and are not the same anymore. Can they still be merged?

Excellent initiative, you are more valiant than I was!  Yes these can be merged, with a little tweak.  Perhaps like this:

  enum class SymbolCompat { None, OmitFromLinkingSection };
  
  MCSymbolWasm *WebAssembly::getOrCreateFunctionTableSymbol(
      MCContext &Ctx, const StringRef &Name,
      SymbolCompat Compat = SymbolCompat::None) {
    MCSymbolWasm *Sym = cast_or_null<MCSymbolWasm>(Ctx.lookupSymbol(Name));
    if (Sym) {
      if (!Sym->isFunctionTable())
        Ctx.reportError(SMLoc(), "symbol is not a wasm funcref table");
    } else {
      Sym = cast<MCSymbolWasm>(Ctx.getOrCreateSymbol(Name));
      Sym->setFunctionTable();
      // The default function table is synthesized by the linker.
      Sym->setUndefined();
    }
    if (Compat == SymbolCompat::OmitFromLinkingSection)
      Sym->setOmitFromLinkingSection();
    return Sym;
  }
  
  MCSymbolWasm *WebAssembly::getOrCreateFunctionTableSymbol(
      MCContext &Ctx, const WebAssemblySubtarget *Subtarget) {
    StringRef Name = "__indirect_function_table";
    SymbolCompat Compat = SymbolCompat::None;
    // MVP object files can't have symtab entries for tables.
    if !(Subtarget && Subtarget->hasReferenceTypes()))
      Compat = SymbolCompat::OmitFromLinkingSection;
    return getOrCreateFunctionTableSymbol(Ctx, Name, Compat);
  }

Then change the caller in AsmParser to `s/GetOrCreateFunctionTableSymbol/WebAssembly::getOrCreateFunctionTableSymbol/`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100995/new/

https://reviews.llvm.org/D100995



More information about the llvm-commits mailing list