[WebAssembly] Reorder Symbol fields to make it smaller
On 64-bit systems, this decreases sizeof(SymbolUnion) from 112 to 96. Add a static_assert to avoid accidental increases in future. Reviewed By: sbc100 Differential Revision: https://reviews.llvm.org/D64208 llvm-svn: 365169
This commit is contained in:
parent
f0e5aa035e
commit
3d0193909b
|
@ -41,7 +41,7 @@ class OutputSection;
|
||||||
// The base class for real symbol classes.
|
// The base class for real symbol classes.
|
||||||
class Symbol {
|
class Symbol {
|
||||||
public:
|
public:
|
||||||
enum Kind {
|
enum Kind : uint8_t {
|
||||||
DefinedFunctionKind,
|
DefinedFunctionKind,
|
||||||
DefinedDataKind,
|
DefinedDataKind,
|
||||||
DefinedGlobalKind,
|
DefinedGlobalKind,
|
||||||
|
@ -107,6 +107,33 @@ public:
|
||||||
WasmSymbolType getWasmType() const;
|
WasmSymbolType getWasmType() const;
|
||||||
bool isExported() const;
|
bool isExported() const;
|
||||||
|
|
||||||
|
const WasmSignature* getSignature() const;
|
||||||
|
|
||||||
|
bool isInGOT() const { return GOTIndex != INVALID_INDEX; }
|
||||||
|
|
||||||
|
uint32_t getGOTIndex() const {
|
||||||
|
assert(GOTIndex != INVALID_INDEX);
|
||||||
|
return GOTIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setGOTIndex(uint32_t Index);
|
||||||
|
bool hasGOTIndex() const { return GOTIndex != INVALID_INDEX; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
Symbol(StringRef Name, Kind K, uint32_t Flags, InputFile *F)
|
||||||
|
: Name(Name), File(F), Flags(Flags), SymbolKind(K),
|
||||||
|
Referenced(!Config->GcSections), IsUsedInRegularObj(false),
|
||||||
|
ForceExport(false), CanInline(false), Traced(false) {}
|
||||||
|
|
||||||
|
StringRef Name;
|
||||||
|
InputFile *File;
|
||||||
|
uint32_t Flags;
|
||||||
|
uint32_t OutputSymbolIndex = INVALID_INDEX;
|
||||||
|
uint32_t GOTIndex = INVALID_INDEX;
|
||||||
|
Kind SymbolKind;
|
||||||
|
unsigned Referenced : 1;
|
||||||
|
|
||||||
|
public:
|
||||||
// True if the symbol was used for linking and thus need to be added to the
|
// True if the symbol was used for linking and thus need to be added to the
|
||||||
// output file's symbol table. This is true for all symbols except for
|
// output file's symbol table. This is true for all symbols except for
|
||||||
// unreferenced DSO symbols, lazy (archive) symbols, and bitcode symbols that
|
// unreferenced DSO symbols, lazy (archive) symbols, and bitcode symbols that
|
||||||
|
@ -124,32 +151,6 @@ public:
|
||||||
|
|
||||||
// True if this symbol is specified by --trace-symbol option.
|
// True if this symbol is specified by --trace-symbol option.
|
||||||
unsigned Traced : 1;
|
unsigned Traced : 1;
|
||||||
|
|
||||||
const WasmSignature* getSignature() const;
|
|
||||||
|
|
||||||
bool isInGOT() const { return GOTIndex != INVALID_INDEX; }
|
|
||||||
|
|
||||||
uint32_t getGOTIndex() const {
|
|
||||||
assert(GOTIndex != INVALID_INDEX);
|
|
||||||
return GOTIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setGOTIndex(uint32_t Index);
|
|
||||||
bool hasGOTIndex() const { return GOTIndex != INVALID_INDEX; }
|
|
||||||
|
|
||||||
protected:
|
|
||||||
Symbol(StringRef Name, Kind K, uint32_t Flags, InputFile *F)
|
|
||||||
: IsUsedInRegularObj(false), ForceExport(false), CanInline(false),
|
|
||||||
Traced(false), Name(Name), SymbolKind(K), Flags(Flags), File(F),
|
|
||||||
Referenced(!Config->GcSections) {}
|
|
||||||
|
|
||||||
StringRef Name;
|
|
||||||
Kind SymbolKind;
|
|
||||||
uint32_t Flags;
|
|
||||||
InputFile *File;
|
|
||||||
uint32_t OutputSymbolIndex = INVALID_INDEX;
|
|
||||||
uint32_t GOTIndex = INVALID_INDEX;
|
|
||||||
bool Referenced;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class FunctionSymbol : public Symbol {
|
class FunctionSymbol : public Symbol {
|
||||||
|
@ -474,6 +475,11 @@ union SymbolUnion {
|
||||||
alignas(SectionSymbol) char I[sizeof(SectionSymbol)];
|
alignas(SectionSymbol) char I[sizeof(SectionSymbol)];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// It is important to keep the size of SymbolUnion small for performance and
|
||||||
|
// memory usage reasons. 96 bytes is a soft limit based on the size of
|
||||||
|
// UndefinedFunction on a 64-bit system.
|
||||||
|
static_assert(sizeof(SymbolUnion) <= 96, "SymbolUnion too large");
|
||||||
|
|
||||||
void printTraceSymbol(Symbol *Sym);
|
void printTraceSymbol(Symbol *Sym);
|
||||||
void printTraceSymbolUndefined(StringRef Name, const InputFile* File);
|
void printTraceSymbolUndefined(StringRef Name, const InputFile* File);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue