Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
b9ca885
work
kripken Apr 4, 2024
b06f76e
work
kripken Apr 5, 2024
a75e5c1
work
kripken Apr 5, 2024
b86fcf3
builds
kripken Apr 5, 2024
3e728e6
todo
kripken Apr 5, 2024
5dfda8d
formt
kripken Apr 5, 2024
336dfcb
work
kripken Apr 5, 2024
fba8353
fix.comment
kripken Apr 5, 2024
dfe819d
typo
kripken Apr 5, 2024
517d02d
fix compiler warnings
kripken Apr 5, 2024
4608b29
exciting
kripken Apr 5, 2024
347ebe0
yolo
kripken Apr 5, 2024
90cabde
yolo
kripken Apr 5, 2024
eef7df5
prep
kripken Apr 5, 2024
86c98ad
work
kripken Apr 5, 2024
a51a7cb
test
kripken Apr 5, 2024
3b44e01
twork
kripken Apr 5, 2024
e21ce34
fix
kripken Apr 5, 2024
2962579
work
kripken Apr 5, 2024
1e01201
work
kripken Apr 5, 2024
6a39f6a
work
kripken Apr 5, 2024
faad72d
work
kripken Apr 5, 2024
d5383ad
work
kripken Apr 5, 2024
bfab495
work
kripken Apr 5, 2024
fd102dd
fix
kripken Apr 5, 2024
0dd4970
work
kripken Apr 5, 2024
4bd7a37
work
kripken Apr 5, 2024
bdb88d6
work
kripken Apr 5, 2024
3a195cf
work
kripken Apr 5, 2024
1b1cc3b
work
kripken Apr 5, 2024
996ab05
work
kripken Apr 5, 2024
7ebb094
test
kripken Apr 5, 2024
00616b8
fix
kripken Apr 5, 2024
e6480d6
format
kripken Apr 5, 2024
bffbdd8
fix
kripken Apr 5, 2024
1c9e1c5
commento
kripken Apr 5, 2024
d11f563
Merge remote-tracking branch 'origin/main' into heap2local.nfc.2
kripken Apr 6, 2024
db6780f
test
kripken Apr 6, 2024
e833122
test
kripken Apr 6, 2024
8a0431a
work
kripken Apr 8, 2024
c793aa8
test
kripken Apr 8, 2024
bfceeb8
work
kripken Apr 8, 2024
9b2be22
test?
kripken Apr 8, 2024
58253c7
fix
kripken Apr 8, 2024
08fe484
undo
kripken Apr 8, 2024
41c0765
nicer
kripken Apr 8, 2024
37de9a5
comment
kripken Apr 8, 2024
c6387b5
test.bad
kripken Apr 8, 2024
82038d3
test.bad
kripken Apr 8, 2024
de4c680
work
kripken Apr 8, 2024
22a18fb
work
kripken Apr 8, 2024
e6b8fcf
work
kripken Apr 8, 2024
606da66
work
kripken Apr 8, 2024
a06ac62
format
kripken Apr 8, 2024
7a57798
Merge remote-tracking branch 'origin/main' into heap2local.nfc.2
kripken Apr 9, 2024
f1e9013
fix
kripken Apr 9, 2024
5c17188
clarify
kripken Apr 9, 2024
becbf61
feedback
kripken Apr 9, 2024
4e279b0
feedback: remove unused code
kripken Apr 9, 2024
568856c
feedback: fix
kripken Apr 9, 2024
83b3b0b
feedback: test
kripken Apr 9, 2024
1e02354
feedback: test
kripken Apr 9, 2024
627da24
Merge branch 'heap2local.nfc.2' into heap2local.3
kripken Apr 9, 2024
560ad8b
Merge remote-tracking branch 'origin/main' into heap2local.3
kripken Apr 9, 2024
4433489
Another test was optimized, it appears
kripken Apr 9, 2024
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
Prev Previous commit
Next Next commit
twork
  • Loading branch information
kripken committed Apr 5, 2024
commit 3b44e01022fb3bd021d3d7235e2d6d2007f50d16
18 changes: 16 additions & 2 deletions src/passes/Heap2Local.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -795,13 +795,13 @@ struct Struct2Local : PostWalker<Struct2Local> {
struct Array2Struct : PostWalker<Array2Struct> {
Expression* allocation;
// TODO which of these do we need?
const EscapeAnalyzer& analyzer;
EscapeAnalyzer& analyzer;
Function* func;
Module& wasm;
Builder builder;

Array2Struct(Expression* allocation,
const EscapeAnalyzer& analyzer,
EscapeAnalyzer& analyzer,
Function* func,
Module& wasm)
: allocation(allocation), analyzer(analyzer), func(func), wasm(wasm),
Expand Down Expand Up @@ -855,12 +855,14 @@ struct Array2Struct : PostWalker<Array2Struct> {
void visitArrayNew(ArrayNew* curr) {
if (curr == allocation) {
replaceCurrent(structNew);
noteCurrentIsReached();
}
}

void visitArrayFixed(ArrayNewFixed* curr) {
if (curr == allocation) {
replaceCurrent(structNew);
noteCurrentIsReached();
}
}

Expand All @@ -872,6 +874,7 @@ struct Array2Struct : PostWalker<Array2Struct> {
// Convert the ArraySet into a StructSet.
// TODO: the actual chak that the index is constant, after escape anlysi and before opt!
replaceCurrent(builder.makeStructSet(getIndex(curr->index), curr->ref, curr->value));
noteCurrentIsReached();
}

void visitArrayGet(ArrayGet* curr) {
Expand All @@ -890,12 +893,20 @@ struct Array2Struct : PostWalker<Array2Struct> {

// Convert the ArrayGet into a StructGet.
replaceCurrent(builder.makeStructGet(getIndex(curr->index), curr->ref, curr->type, curr->signed_));
noteCurrentIsReached();
}

// Get the value in an expression we know must contain a constant index.
Index getIndex(Expression* curr) {
return curr->cast<Const>()->value.getUnsigned();
}

void noteCurrentIsReached() {
// Inform the analyzer that the current expression (which we just replaced)
// has been reached in its analysis. We are replacing something it reached,
// and want it to consider it as its equivalent.
analyzer.reached.insert(getCurrent());
}
};

// Core Heap2Local optimization that operates on a function: Builds up the data
Expand Down Expand Up @@ -968,8 +979,11 @@ struct Heap2Local {
if (!analyzer.escapes(allocation)) {
// Convert the allocation and all its uses into a struct. Then convert
// the struct into locals.
std::cout << "pre: " << *func << '\n';
auto* structNew = Array2Struct(allocation, analyzer, func, wasm).structNew;
std::cout << "mid: " << *func << '\n';
Struct2Local(structNew, analyzer, func, wasm);
std::cout << "post: " << *func << '\n';
}
}

Expand Down