-
Notifications
You must be signed in to change notification settings - Fork 743
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
wasm2js: Support arbitrary temp variable types #6661
Conversation
src/wasm2js.h
Outdated
// Which are currently free to use | ||
std::vector<std::vector<IString>> frees; // type => list of free names | ||
std::unordered_map<Type, std::vector<IString>> | ||
frees; // type => list of free 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.
If the comment is placed on its own line, we won't need this odd line break before the variable 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.
Done.
frees.resize(std::max(Type::i32, std::max(Type::f32, Type::f64)) + 1); | ||
temps.clear(); | ||
temps.resize(std::max(Type::i32, std::max(Type::f32, Type::f64)) + 1); | ||
temps[Type::i32] = temps[Type::f32] = temps[Type::f64] = 0; |
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.
Was this resetting only necessary for the asserts below?
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.
Good catch, turns out it was not. I did not realize this class reused the instance for all the functions. What made me miss this in the outputs is that any excess temp vars that were added get removed by later optimizations... so it seemed like manually clearing was not needed, but it was. Fixed.
test/wasm2js/left-to-right.2asm.js
Outdated
@@ -942,23 +942,23 @@ function asmFunc(imports) { | |||
} | |||
|
|||
function $53() { | |||
var wasm2js_i32$0 = 0, wasm2js_i32$1 = 0; | |||
var wasm2js_i32$0 = 0, wasm2js_i32$2 = 0; |
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.
Do you know why the names changed?
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.
This diff was because of the extra temp vars - unneeded ones get optimized out, but the optimizer happened to pick other ones here. Anyhow, this part of the diff goes away in the last commit.
Previously only basic types were allowed.
Generalizing this to arbitrary types means we use a map instead of a vector,
which is slower, but I can't measure any noticeable difference. Temp vars are
pretty rare, and there are just much slower parts of wasm2js, I think.