This patch simplifies initializeSymbols. Since that function is called
at the tail context of ObjFile::parse, and the function is called only
once from that function, that's effectively just a continuation of
ObjFile::parse. So this patch merge it with ObjFile::parse.
Details
- Reviewers
sbc100 - Commits
- rG0a9583ce7980: [WebAssembly] Simplify initializeSymbols and merge it with ObjFile::parse. NFC.
rLLD326296: [WebAssembly] Simplify initializeSymbols and merge it with ObjFile::parse. NFC.
rL326296: [WebAssembly] Simplify initializeSymbols and merge it with ObjFile::parse. NFC.
Diff Detail
- Repository
- rL LLVM
Event Timeline
My comments only relate to the removal of the members and other refactoring. Maybe you want land this without those extra parts and make that a separate change?
lld/wasm/InputFiles.cpp | ||
---|---|---|
46 ↗ | (On Diff #136207) | Call this NumFuncs is a little deceptive since its the number of imported functions, which is doesn't include the defined functions. Perhaps just inline these calls below to avoid the variable? |
168 ↗ | (On Diff #136207) | This reads backwards to me. I'd prefer it to read "Assert that the symbol's element index is less than the number of imported functions"... which is the same thing as saying "Assert that the symbol points to an imported function rather than a defined one". Why not keep the more meaningful "NumFunctionImports" name? Or perhaps just call it twice since the first call is inside of an assert (so won't effect release performance)? |
lld/wasm/InputFiles.cpp | ||
---|---|---|
168 ↗ | (On Diff #136207) | The reason why I removed these member variables is because they don't do anything expensive and actually as cheap as member variables. They are defined as shown below. uint32_t getNumImportedGlobals() const { return NumImportedGlobals; } uint32_t getNumImportedFunctions() const { return NumImportedFunctions; } So, what "caching" results of these functions does is to make extra copies of these member variables in our instances, which doesn't make much sense to me. I'm not worried about the cost of having extra copies, but if we have two copies of the same data, that is error prone. |
lld/wasm/InputFiles.cpp | ||
---|---|---|
168 ↗ | (On Diff #136207) | Oh sorry I misread your comment. To me uint32_t N = WasmObj->getNumImportedFunctions(); assert(Sym.Info.ElementIndex >= N); return Functions[Sym.Info.ElementIndex - N]; is easier to read than assert(Sym.Info.ElementIndex >= WasmObj->getNumImportedFunctions()); return Functions[Sym.Info.ElementIndex - WasmObj->getNumImportedFunctions()]; because the latter is longer, and it isn't obvious to me that the two function calls are actually the same. The reason why I wrote N <= something instead of something >= N is because I'm always thinking on the number line. N is left if it is smaller than the other. But that's just my preference. If you feel strongly about it I can revert it. |
lld/wasm/InputFiles.cpp | ||
---|---|---|
168 ↗ | (On Diff #136207) | On second thought, I think we don't really need this assert. If assertion is enabled, out of bound should be caught by the container, and no explicit bound checking isn't needed. |