[lld] r325603 - [WebAssembly] Remove InputChunk from Symbol baseclass
Sam Clegg via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 20 09:45:38 PST 2018
Author: sbc
Date: Tue Feb 20 09:45:38 2018
New Revision: 325603
URL: http://llvm.org/viewvc/llvm-project?rev=325603&view=rev
Log:
[WebAssembly] Remove InputChunk from Symbol baseclass
Instead include InputFuction and InputSegment directly
in the subclasses that use them (DefinedFunction and
DefinedGlobal).
Differential Revision: https://reviews.llvm.org/D43493
Modified:
lld/trunk/wasm/Symbols.cpp
lld/trunk/wasm/Symbols.h
Modified: lld/trunk/wasm/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Symbols.cpp?rev=325603&r1=325602&r2=325603&view=diff
==============================================================================
--- lld/trunk/wasm/Symbols.cpp (original)
+++ lld/trunk/wasm/Symbols.cpp Tue Feb 20 09:45:38 2018
@@ -29,21 +29,30 @@ DefinedGlobal *WasmSym::HeapBase;
DefinedGlobal *WasmSym::StackPointer;
bool Symbol::hasOutputIndex() const {
- if (auto *F = dyn_cast_or_null<InputFunction>(Chunk))
- return F->hasOutputIndex();
+ if (auto *F = dyn_cast<DefinedFunction>(this))
+ if (F->Function)
+ return F->Function->hasOutputIndex();
return OutputIndex != INVALID_INDEX;
}
uint32_t Symbol::getOutputIndex() const {
- if (auto *F = dyn_cast_or_null<InputFunction>(Chunk))
- return F->getOutputIndex();
+ if (auto *F = dyn_cast<DefinedFunction>(this))
+ if (F->Function)
+ return F->Function->getOutputIndex();
assert(OutputIndex != INVALID_INDEX);
return OutputIndex;
}
+InputChunk *Symbol::getChunk() const {
+ if (auto *F = dyn_cast<DefinedFunction>(this))
+ return F->Function;
+ if (auto *G = dyn_cast<DefinedGlobal>(this))
+ return G->Segment;
+ return nullptr;
+}
+
void Symbol::setOutputIndex(uint32_t Index) {
DEBUG(dbgs() << "setOutputIndex " << Name << " -> " << Index << "\n");
- assert(!dyn_cast_or_null<InputFunction>(Chunk));
assert(OutputIndex == INVALID_INDEX);
OutputIndex = Index;
}
@@ -69,20 +78,16 @@ void Symbol::setHidden(bool IsHidden) {
Flags |= WASM_SYMBOL_VISIBILITY_DEFAULT;
}
-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))
- return F->getTableIndex();
+ if (auto *F = dyn_cast<DefinedFunction>(this))
+ return F->Function->getTableIndex();
assert(TableIndex != INVALID_INDEX);
return TableIndex;
}
bool FunctionSymbol::hasTableIndex() const {
- if (auto *F = dyn_cast_or_null<InputFunction>(Chunk))
- return F->hasTableIndex();
+ if (auto *F = dyn_cast<DefinedFunction>(this))
+ return F->Function->hasTableIndex();
return TableIndex != INVALID_INDEX;
}
@@ -90,8 +95,8 @@ void FunctionSymbol::setTableIndex(uint3
// For imports, we set the table index here on the Symbol; for defined
// functions we set the index on the InputFunction so that we don't export
// the same thing twice (keeps the table size down).
- if (auto *F = dyn_cast_or_null<InputFunction>(Chunk)) {
- F->setTableIndex(Index);
+ if (auto *F = dyn_cast<DefinedFunction>(this)) {
+ F->Function->setTableIndex(Index);
return;
}
DEBUG(dbgs() << "setTableIndex " << Name << " -> " << Index << "\n");
@@ -99,10 +104,15 @@ void FunctionSymbol::setTableIndex(uint3
TableIndex = Index;
}
+DefinedFunction::DefinedFunction(StringRef Name, uint32_t Flags, InputFile *F,
+ InputFunction *Function)
+ : FunctionSymbol(Name, DefinedFunctionKind, Flags, F,
+ Function ? &Function->Signature : nullptr),
+ Function(Function) {}
+
uint32_t DefinedGlobal::getVirtualAddress() const {
DEBUG(dbgs() << "getVirtualAddress: " << getName() << "\n");
- return Chunk ? dyn_cast<InputSegment>(Chunk)->translateVA(VirtualAddress)
- : VirtualAddress;
+ return Segment ? Segment->translateVA(VirtualAddress) : VirtualAddress;
}
void DefinedGlobal::setVirtualAddress(uint32_t Value) {
Modified: lld/trunk/wasm/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Symbols.h?rev=325603&r1=325602&r2=325603&view=diff
==============================================================================
--- lld/trunk/wasm/Symbols.h (original)
+++ lld/trunk/wasm/Symbols.h Tue Feb 20 09:45:38 2018
@@ -22,6 +22,7 @@ namespace wasm {
class InputFile;
class InputChunk;
+class InputSegment;
class InputFunction;
#define INVALID_INDEX UINT32_MAX
@@ -58,7 +59,7 @@ public:
// Returns the file from which this symbol was created.
InputFile *getFile() const { return File; }
- InputChunk *getChunk() const { return Chunk; }
+ InputChunk *getChunk() const;
void setHidden(bool IsHidden);
@@ -72,14 +73,13 @@ public:
void setOutputIndex(uint32_t Index);
protected:
- Symbol(StringRef Name, Kind K, uint32_t Flags, InputFile *F, InputChunk *C)
- : Name(Name), SymbolKind(K), Flags(Flags), File(F), Chunk(C) {}
+ Symbol(StringRef Name, Kind K, uint32_t Flags, InputFile *F)
+ : Name(Name), SymbolKind(K), Flags(Flags), File(F) {}
StringRef Name;
Kind SymbolKind;
uint32_t Flags;
InputFile *File;
- InputChunk *Chunk;
uint32_t OutputIndex = INVALID_INDEX;
};
@@ -102,11 +102,8 @@ public:
protected:
FunctionSymbol(StringRef Name, Kind K, uint32_t Flags, InputFile *F,
- InputFunction *Function);
-
- FunctionSymbol(StringRef Name, Kind K, uint32_t Flags, InputFile *F,
- const WasmSignature* Type)
- : Symbol(Name, K, Flags, F, nullptr), FunctionType(Type) {}
+ const WasmSignature *Type)
+ : Symbol(Name, K, Flags, F), FunctionType(Type) {}
uint32_t TableIndex = INVALID_INDEX;
@@ -116,8 +113,7 @@ protected:
class DefinedFunction : public FunctionSymbol {
public:
DefinedFunction(StringRef Name, uint32_t Flags, InputFile *F,
- InputFunction *Function)
- : FunctionSymbol(Name, DefinedFunctionKind, Flags, F, Function) {}
+ InputFunction *Function);
DefinedFunction(StringRef Name, uint32_t Flags, const WasmSignature *Type)
: FunctionSymbol(Name, DefinedFunctionKind, Flags, nullptr, Type) {}
@@ -125,6 +121,8 @@ public:
static bool classof(const Symbol *S) {
return S->kind() == DefinedFunctionKind;
}
+
+ InputFunction *Function;
};
class UndefinedFunction : public FunctionSymbol {
@@ -145,16 +143,15 @@ public:
}
protected:
- GlobalSymbol(StringRef Name, Kind K, uint32_t Flags, InputFile *F,
- InputChunk *C)
- : Symbol(Name, K, Flags, F, C) {}
+ GlobalSymbol(StringRef Name, Kind K, uint32_t Flags, InputFile *F)
+ : Symbol(Name, K, Flags, F) {}
};
class DefinedGlobal : public GlobalSymbol {
public:
DefinedGlobal(StringRef Name, uint32_t Flags, InputFile *F = nullptr,
- InputChunk *C = nullptr, uint32_t Address = 0)
- : GlobalSymbol(Name, DefinedGlobalKind, Flags, F, C),
+ InputSegment *Segment = nullptr, uint32_t Address = 0)
+ : GlobalSymbol(Name, DefinedGlobalKind, Flags, F), Segment(Segment),
VirtualAddress(Address) {}
static bool classof(const Symbol *S) {
@@ -162,9 +159,10 @@ public:
}
uint32_t getVirtualAddress() const;
-
void setVirtualAddress(uint32_t VA);
+ InputSegment *Segment;
+
protected:
uint32_t VirtualAddress;
};
@@ -172,7 +170,7 @@ protected:
class UndefinedGlobal : public GlobalSymbol {
public:
UndefinedGlobal(StringRef Name, uint32_t Flags, InputFile *File = nullptr)
- : GlobalSymbol(Name, UndefinedGlobalKind, Flags, File, nullptr) {}
+ : GlobalSymbol(Name, UndefinedGlobalKind, Flags, File) {}
static bool classof(const Symbol *S) {
return S->kind() == UndefinedGlobalKind;
}
@@ -181,7 +179,7 @@ public:
class LazySymbol : public Symbol {
public:
LazySymbol(StringRef Name, InputFile *File, const Archive::Symbol &Sym)
- : Symbol(Name, LazyKind, 0, File, nullptr), ArchiveSymbol(Sym) {}
+ : Symbol(Name, LazyKind, 0, File), ArchiveSymbol(Sym) {}
static bool classof(const Symbol *S) { return S->kind() == LazyKind; }
More information about the llvm-commits
mailing list