Skip to content
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

Use SmallVector in TypeUpdating::updateParamTypes() #5579

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/ir/type-updating.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "ir/local-structural-dominance.h"
#include "ir/module-utils.h"
#include "ir/utils.h"
#include "support/small_vector.h"
#include "support/topological_sort.h"
#include "wasm-type-ordering.h"
#include "wasm-type.h"
Expand Down Expand Up @@ -443,7 +444,9 @@ void updateParamTypes(Function* func,
if (!paramFixups.empty()) {
// Write the params immediately to the fixups.
Builder builder(wasm);
std::vector<Expression*> contents;
// Use a small vector as functions generally have a reasonable number of
// parameters.
SmallVector<Expression*, 10> contents;
for (Index index = 0; index < func->getNumParams(); index++) {
auto iter = paramFixups.find(index);
if (iter != paramFixups.end()) {
Expand Down
8 changes: 8 additions & 0 deletions src/wasm-builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "ir/manipulation.h"
#include "parsing.h"
#include "support/small_vector.h"
#include "wasm.h"

namespace wasm {
Expand Down Expand Up @@ -229,6 +230,13 @@ class Builder {
ret->finalize(type);
return ret;
}
template<size_t N>
Block* makeBlock(const SmallVector<Expression*, N>& items) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be worth deduplicating all the different versions of makeBlock into a few templatized versions that can take any iterable for the items?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried again yesterday actually, but I just run into C++ stuff I can't figure out, sadly.

The problem is that we have a version makeBlock(Expression* first) and others that take a list as their single parameter, and it gets confused - it tries to use the list versions for subtypes of Expression, and then errors on not having .size() in them. To fix that, I've tried all manner of std::is_base_of inside of the C++ magic to ignore a template. I also tried more basic SFINAE stuff like ordering them so the erroring one is first. But nothing seems to work for me, and after an hour or so I gave up. Maybe that just isn't possible for some reason?

If you can figure it out though that would be incredible!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

auto* ret = wasm.allocator.alloc<Block>();
ret->list.set(items);
ret->finalize();
return ret;
}
If* makeIf(Expression* condition,
Expression* ifTrue,
Expression* ifFalse = nullptr) {
Expand Down