-
Notifications
You must be signed in to change notification settings - Fork 699
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
c-writer.cc: Add local symbol prefix. #2171
Conversation
Add kLocalSymbolPrefix which is used for names of params, locals and stack vars. This allows c-writer to not assign global_sym_map_ to local_sym_map_ for writing each individual function, since local names can't duplicate global names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow! Impressive speedup.
Do you know where the huge speedup comes from? Was is just making N copies of the global symbol map?
src/c-writer.cc
Outdated
@@ -2360,7 +2361,7 @@ void CWriter::PushFuncSection(std::string_view include_condition) { | |||
void CWriter::Write(const Func& func) { | |||
func_ = &func; | |||
// Copy symbols from global symbol table so we don't shadow them. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this comment is not longer accurate?
I guess its not possible for a global symbol could start with var_
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Global symbols should either start with w2c_
or wasm2c_
, and therefore local symbols would not shadow global symbols. Deleted this comment in ce882d6.
src/c-writer.cc
Outdated
@@ -428,6 +428,7 @@ static constexpr char kParamSuffix = | |||
static constexpr char kLabelSuffix = kParamSuffix + 1; | |||
|
|||
static constexpr char kSymbolPrefix[] = "w2c_"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we rename this kGlobalSymbolPrefix
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in ce882d6.
@@ -428,6 +428,7 @@ static constexpr char kParamSuffix = | |||
static constexpr char kLabelSuffix = kParamSuffix + 1; | |||
|
|||
static constexpr char kSymbolPrefix[] = "w2c_"; | |||
static constexpr char kLocalSymbolPrefix[] = "var_"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess unlike the other prefixes, this one is 100% internal so changing it is not a user-visible change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. So should I change kLocalSymbolPrefix
to be a private field of CWriter
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So sorry, I just meant that if we decided to change var_
to local_
in the figure it would not be user visible?
This change lgtm.
2159896
to
ce882d6
Compare
Based on our perf report, when executing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm but maybe @keithw wants to take a look too.
Those performance numbers are hard to argue with though! Nice work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks great to me % comment
src/c-writer.cc
Outdated
@@ -830,9 +831,9 @@ std::string CWriter::DefineGlobalScopeName(ModuleFieldType type, | |||
/* Names for params, locals, and stack vars are formatted as "w2c_" + name. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's update this comment too...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in f4427d2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, setting to auto-merge.
This adds
kLocalSymbolPrefix
which is used for names of params, locals and stack vars. This allows c-writer to not assignglobal_syms_
tolocal_syms_
for writing each individual function, since local names can't duplicate global names.This speeds up the execution of
wasm2c
on large inputs.clang.wasm
is a 75M WASM module. Before this PR,wasm2c
onclang.wasm
would take ~63 minutes.After this PR, it takes ~2 minutes.