Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 4 additions & 6 deletions src/ir/ExpressionManipulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,14 @@ Expression* flexibleCopy(Expression* original, Module& wasm, CustomCopier custom
}

Expression* visitBlock(Block *curr) {
auto* ret = builder.makeBlock();
ExpressionList list(wasm.allocator);
for (Index i = 0; i < curr->list.size(); i++) {
ret->list.push_back(copy(curr->list[i]));
list.push_back(copy(curr->list[i]));
}
ret->name = curr->name;
ret->finalize(curr->type);
return ret;
return builder.makeBlock(curr->name, list, curr->type);
}
Expression* visitIf(If *curr) {
return builder.makeIf(copy(curr->condition), copy(curr->ifTrue), copy(curr->ifFalse));
return builder.makeIf(copy(curr->condition), copy(curr->ifTrue), copy(curr->ifFalse), curr->type);
}
Expression* visitLoop(Loop *curr) {
return builder.makeLoop(curr->name, copy(curr->body));
Expand Down
32 changes: 32 additions & 0 deletions src/wasm-builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,44 @@ class Builder {
ret->finalize();
return ret;
}
Block* makeBlock(const ExpressionList& items) {
auto* ret = allocator.alloc<Block>();
ret->list.set(items);
ret->finalize();
return ret;
}
Block* makeBlock(const ExpressionList& items, WasmType type) {
auto* ret = allocator.alloc<Block>();
ret->list.set(items);
ret->finalize(type);
return ret;
}
Block* makeBlock(Name name, const ExpressionList& items) {
auto* ret = allocator.alloc<Block>();
ret->name = name;
ret->list.set(items);
ret->finalize();
return ret;
}
Block* makeBlock(Name name, const ExpressionList& items, WasmType type) {
auto* ret = allocator.alloc<Block>();
ret->name = name;
ret->list.set(items);
ret->finalize(type);
return ret;
}
If* makeIf(Expression* condition, Expression* ifTrue, Expression* ifFalse = nullptr) {
auto* ret = allocator.alloc<If>();
ret->condition = condition; ret->ifTrue = ifTrue; ret->ifFalse = ifFalse;
ret->finalize();
return ret;
}
If* makeIf(Expression* condition, Expression* ifTrue, Expression* ifFalse, WasmType type) {
auto* ret = allocator.alloc<If>();
ret->condition = condition; ret->ifTrue = ifTrue; ret->ifFalse = ifFalse;
ret->finalize(type);
return ret;
}
Loop* makeLoop(Name name, Expression* body) {
auto* ret = allocator.alloc<Loop>();
ret->name = name; ret->body = body;
Expand Down
31 changes: 31 additions & 0 deletions test/passes/inlining.txt
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,34 @@
)
)
)
(module
(type $T (func (param i32)))
(type $1 (func))
(table 10 anyfunc)
(memory $0 0)
(func $0 (; 0 ;) (type $1)
(block $__inlined_func$1
(call_indirect $T
(if (result i32)
(i32.const 0)
(unreachable)
(unreachable)
)
(i32.const 1)
)
)
)
)
(module
(type $0 (func))
(memory $0 0)
(func $1 (; 0 ;) (type $0)
(block $__inlined_func$0
(block $label$1
(br_table $label$1 $label$1
(i32.const 0)
)
)
)
)
)
29 changes: 29 additions & 0 deletions test/passes/inlining.wast
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,33 @@
)
)
)
(module
(type $T (func (param i32)))
(table 10 anyfunc)
(func $0
(call $1)
)
(func $1
(call_indirect $T
(if (result i32) ;; if copy must preserve the forced type
(i32.const 0)
(unreachable)
(unreachable)
)
(i32.const 1)
)
)
)
(module
(func $0
(block $label$1 ;; copy this name
(br_table $label$1 $label$1
(i32.const 0)
)
)
)
(func $1
(call $0)
)
)