Skip to content

Conversation

kripken
Copy link
Member

@kripken kripken commented Jun 14, 2024

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.

@kripken kripken requested a review from tlively June 14, 2024 16:16
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
Copy link
Member

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.

Copy link
Member Author

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;
Copy link
Member

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?

Copy link
Member Author

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.


function $53() {
var wasm2js_i32$0 = 0, wasm2js_i32$1 = 0;
var wasm2js_i32$0 = 0, wasm2js_i32$2 = 0;
Copy link
Member

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?

Copy link
Member Author

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.

@kripken kripken merged commit 1dd0520 into WebAssembly:main Jun 17, 2024
@kripken kripken deleted the wasm2js.types branch June 17, 2024 21:36
@gkdn gkdn mentioned this pull request Aug 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants