[lld] r325415 - [WebAssembly] Simplify FunctionSymbol::get/set/hasFunctionType. NFC.

Sam Clegg via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 16 15:50:23 PST 2018


Author: sbc
Date: Fri Feb 16 15:50:23 2018
New Revision: 325415

URL: http://llvm.org/viewvc/llvm-project?rev=325415&view=rev
Log:
[WebAssembly] Simplify FunctionSymbol::get/set/hasFunctionType. NFC.

Differential Revision: https://reviews.llvm.org/D43416

Modified:
    lld/trunk/wasm/InputFiles.cpp
    lld/trunk/wasm/InputFiles.h
    lld/trunk/wasm/SymbolTable.cpp
    lld/trunk/wasm/Symbols.cpp
    lld/trunk/wasm/Symbols.h
    lld/trunk/wasm/Writer.cpp

Modified: lld/trunk/wasm/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/InputFiles.cpp?rev=325415&r1=325414&r2=325415&view=diff
==============================================================================
--- lld/trunk/wasm/InputFiles.cpp (original)
+++ lld/trunk/wasm/InputFiles.cpp Fri Feb 16 15:50:23 2018
@@ -303,17 +303,17 @@ Symbol *ObjFile::createUndefined(const W
 }
 
 Symbol *ObjFile::createDefinedFunction(const WasmSymbol &Sym,
-                                       InputChunk *Chunk) {
+                                       InputFunction *Function) {
   if (Sym.isBindingLocal())
-    return make<DefinedFunction>(Sym.Name, Sym.Flags, this, Chunk);
-  return Symtab->addDefined(true, Sym.Name, Sym.Flags, this, Chunk);
+    return make<DefinedFunction>(Sym.Name, Sym.Flags, this, Function);
+  return Symtab->addDefined(true, Sym.Name, Sym.Flags, this, Function);
 }
 
-Symbol *ObjFile::createDefinedGlobal(const WasmSymbol &Sym, InputChunk *Chunk,
-                                     uint32_t Address) {
+Symbol *ObjFile::createDefinedGlobal(const WasmSymbol &Sym,
+                                     InputSegment *Segment, uint32_t Address) {
   if (Sym.isBindingLocal())
-    return make<DefinedGlobal>(Sym.Name, Sym.Flags, this, Chunk, Address);
-  return Symtab->addDefined(false, Sym.Name, Sym.Flags, this, Chunk, Address);
+    return make<DefinedGlobal>(Sym.Name, Sym.Flags, this, Segment, Address);
+  return Symtab->addDefined(false, Sym.Name, Sym.Flags, this, Segment, Address);
 }
 
 void ArchiveFile::parse() {

Modified: lld/trunk/wasm/InputFiles.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/InputFiles.h?rev=325415&r1=325414&r2=325415&view=diff
==============================================================================
--- lld/trunk/wasm/InputFiles.h (original)
+++ lld/trunk/wasm/InputFiles.h Fri Feb 16 15:50:23 2018
@@ -121,9 +121,9 @@ private:
   uint32_t relocateGlobalIndex(uint32_t Original) const;
   uint32_t relocateTableIndex(uint32_t Original) const;
 
-  Symbol *createDefinedGlobal(const WasmSymbol &Sym, InputChunk *Chunk,
+  Symbol *createDefinedGlobal(const WasmSymbol &Sym, InputSegment *Segment,
                               uint32_t Address);
-  Symbol *createDefinedFunction(const WasmSymbol &Sym, InputChunk *Chunk);
+  Symbol *createDefinedFunction(const WasmSymbol &Sym, InputFunction *Function);
   Symbol *createUndefined(const WasmSymbol &Sym, Symbol::Kind Kind,
                           const WasmSignature *Signature = nullptr);
   void initializeSymbols();

Modified: lld/trunk/wasm/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/SymbolTable.cpp?rev=325415&r1=325414&r2=325415&view=diff
==============================================================================
--- lld/trunk/wasm/SymbolTable.cpp (original)
+++ lld/trunk/wasm/SymbolTable.cpp Fri Feb 16 15:50:23 2018
@@ -99,20 +99,21 @@ static void checkSymbolTypes(const Symbo
   if (!ExistingFunc || !Config->CheckSignatures)
     return;
 
+  const WasmSignature *OldSig = ExistingFunc->getFunctionType();
+
   // Skip the signature check if the existing function has no signature (e.g.
   // if it is an undefined symbol generated by --undefined command line flag).
-  if (!ExistingFunc->hasFunctionType())
+  if (OldSig == nullptr)
     return;
 
   DEBUG(dbgs() << "checkSymbolTypes: " << ExistingFunc->getName() << "\n");
   assert(NewSig);
 
-  const WasmSignature &OldSig = ExistingFunc->getFunctionType();
-  if (*NewSig == OldSig)
+  if (*NewSig == *OldSig)
     return;
 
   error("function signature mismatch: " + ExistingFunc->getName() +
-        "\n>>> defined as " + toString(OldSig) + " in " +
+        "\n>>> defined as " + toString(*OldSig) + " in " +
         toString(ExistingFunc->getFile()) + "\n>>> defined as " +
         toString(*NewSig) + " in " + F.getName());
 }
@@ -188,9 +189,11 @@ Symbol *SymbolTable::addDefined(bool IsF
     if (CheckTypes)
       checkSymbolTypes(*S, *F, IsFunction, Chunk);
     if (IsFunction)
-      replaceSymbol<DefinedFunction>(S, Name, Flags, F, Chunk);
+      replaceSymbol<DefinedFunction>(S, Name, Flags, F,
+                                     cast<InputFunction>(Chunk));
     else
-      replaceSymbol<DefinedGlobal>(S, Name, Flags, F, Chunk, Address);
+      replaceSymbol<DefinedGlobal>(S, Name, Flags, F, cast<InputSegment>(Chunk),
+                                   Address);
   }
   return S;
 }

Modified: lld/trunk/wasm/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Symbols.cpp?rev=325415&r1=325414&r2=325415&view=diff
==============================================================================
--- lld/trunk/wasm/Symbols.cpp (original)
+++ lld/trunk/wasm/Symbols.cpp Fri Feb 16 15:50:23 2018
@@ -69,19 +69,9 @@ void Symbol::setHidden(bool IsHidden) {
     Flags |= WASM_SYMBOL_VISIBILITY_DEFAULT;
 }
 
-const WasmSignature &FunctionSymbol::getFunctionType() const {
-  if (auto *F = dyn_cast_or_null<InputFunction>(Chunk))
-    return F->Signature;
-
-  assert(FunctionType != nullptr);
-  return *FunctionType;
-}
-
-void FunctionSymbol::setFunctionType(const WasmSignature *Type) {
-  assert(FunctionType == nullptr);
-  assert(!Chunk);
-  FunctionType = Type;
-}
+FunctionSymbol::FunctionSymbol(StringRef Name, Kind K, uint32_t Flags,
+                               InputFile *F, InputFunction *Function)
+    : Symbol(Name, K, Flags, F, Function), FunctionType(&Function->Signature) {}
 
 uint32_t FunctionSymbol::getTableIndex() const {
   if (auto *F = dyn_cast_or_null<InputFunction>(Chunk))

Modified: lld/trunk/wasm/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Symbols.h?rev=325415&r1=325414&r2=325415&view=diff
==============================================================================
--- lld/trunk/wasm/Symbols.h (original)
+++ lld/trunk/wasm/Symbols.h Fri Feb 16 15:50:23 2018
@@ -22,6 +22,7 @@ namespace wasm {
 
 class InputFile;
 class InputChunk;
+class InputFunction;
 
 #define INVALID_INDEX UINT32_MAX
 
@@ -94,8 +95,7 @@ public:
            S->kind() == UndefinedFunctionKind;
   }
 
-  bool hasFunctionType() const { return Chunk || FunctionType; }
-  const WasmSignature &getFunctionType() const;
+  const WasmSignature *getFunctionType() const { return FunctionType; }
 
   uint32_t getTableIndex() const;
 
@@ -106,28 +106,26 @@ public:
   void setTableIndex(uint32_t Index);
 
 protected:
-  void setFunctionType(const WasmSignature *Type);
+  FunctionSymbol(StringRef Name, Kind K, uint32_t Flags, InputFile *F,
+                 InputFunction *Function);
 
   FunctionSymbol(StringRef Name, Kind K, uint32_t Flags, InputFile *F,
-                 InputChunk *C)
-      : Symbol(Name, K, Flags, F, C) {}
+                 const WasmSignature* Type)
+      : Symbol(Name, K, Flags, F, nullptr), FunctionType(Type) {}
 
   uint32_t TableIndex = INVALID_INDEX;
 
-  // Explict function type, needed for undefined or synthetic functions only.
-  const WasmSignature *FunctionType = nullptr;
+  const WasmSignature *FunctionType;
 };
 
 class DefinedFunction : public FunctionSymbol {
 public:
-  DefinedFunction(StringRef Name, uint32_t Flags, InputFile *F = nullptr,
-                  InputChunk *C = nullptr)
-      : FunctionSymbol(Name, DefinedFunctionKind, Flags, F, C) {}
+  DefinedFunction(StringRef Name, uint32_t Flags, InputFile *F,
+                  InputFunction *Function)
+      : FunctionSymbol(Name, DefinedFunctionKind, Flags, F, Function) {}
 
   DefinedFunction(StringRef Name, uint32_t Flags, const WasmSignature *Type)
-      : FunctionSymbol(Name, DefinedFunctionKind, Flags, nullptr, nullptr) {
-    setFunctionType(Type);
-  }
+      : FunctionSymbol(Name, DefinedFunctionKind, Flags, nullptr, Type) {}
 
   static bool classof(const Symbol *S) {
     return S->kind() == DefinedFunctionKind;
@@ -138,9 +136,7 @@ class UndefinedFunction : public Functio
 public:
   UndefinedFunction(StringRef Name, uint32_t Flags, InputFile *File = nullptr,
                     const WasmSignature *Type = nullptr)
-      : FunctionSymbol(Name, UndefinedFunctionKind, Flags, File, nullptr) {
-    setFunctionType(Type);
-  }
+      : FunctionSymbol(Name, UndefinedFunctionKind, Flags, File, Type) {}
 
   static bool classof(const Symbol *S) {
     return S->kind() == UndefinedFunctionKind;

Modified: lld/trunk/wasm/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Writer.cpp?rev=325415&r1=325414&r2=325415&view=diff
==============================================================================
--- lld/trunk/wasm/Writer.cpp (original)
+++ lld/trunk/wasm/Writer.cpp Fri Feb 16 15:50:23 2018
@@ -169,7 +169,7 @@ void Writer::createImportSection() {
     Import.Module = "env";
     Import.Field = Sym->getName();
     Import.Kind = WASM_EXTERNAL_FUNCTION;
-    Import.SigIndex = lookupType(Sym->getFunctionType());
+    Import.SigIndex = lookupType(*Sym->getFunctionType());
     writeImport(OS, Import);
   }
 
@@ -713,7 +713,7 @@ void Writer::calculateTypes() {
   }
 
   for (const FunctionSymbol *Sym : ImportedFunctions)
-    registerType(Sym->getFunctionType());
+    registerType(*Sym->getFunctionType());
 
   for (const InputFunction *F : DefinedFunctions)
     registerType(F->Signature);




More information about the llvm-commits mailing list