Skip to content

Commit 64c4d95

Browse files
Pull in DSE branch
1 parent 6a64cbc commit 64c4d95

File tree

7 files changed

+2219
-0
lines changed

7 files changed

+2219
-0
lines changed

scripts/fuzz_opt.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2430,6 +2430,7 @@ def write_commands(commands, filename):
24302430
("--remove-unused-names", "--heap2local",),
24312431
("--heap-store-optimization",),
24322432
("--generate-stack-ir",),
2433+
("--ldse",),
24332434
("--licm",),
24342435
("--local-subtyping",),
24352436
("--memory-packing",),

src/ir/replacer.h

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright 2021 WebAssembly Community Group participants
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#ifndef wasm_ir_replacer_h
18+
#define wasm_ir_replacer_h
19+
20+
#include <wasm-traversal.h>
21+
#include <wasm.h>
22+
23+
namespace wasm {
24+
25+
// A map of replacements to perform on expressions. After filling the map,
26+
// simply do a walk(..) and they will be replaced.
27+
//
28+
// This is useful for a general replacement of expressions. Some passes can
29+
// store pointers to expressions and update only those, but then there is the
30+
// nesting problem,
31+
//
32+
// (foo
33+
// (bar
34+
// (baz
35+
//
36+
// If we replace bar with something then the pointer to baz may change. Doing
37+
// the replacements in the order of a walk, as is done here, is always safe.
38+
struct ExpressionReplacer
39+
: PostWalker<ExpressionReplacer,
40+
UnifiedExpressionVisitor<ExpressionReplacer>> {
41+
std::unordered_map<Expression*, Expression*> replacements;
42+
43+
void visitExpression(Expression* curr) {
44+
auto iter = replacements.find(curr);
45+
if (iter != replacements.end()) {
46+
replaceCurrent(iter->second);
47+
}
48+
}
49+
};
50+
51+
} // namespace wasm
52+
53+
#endif // wasm_ir_replacer_h

src/passes/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ set(passes_SOURCES
3030
DeadArgumentElimination.cpp
3131
DeadArgumentElimination2.cpp
3232
DeadCodeElimination.cpp
33+
DeadStoreElimination.cpp
3334
DeAlign.cpp
3435
DebugLocationPropagation.cpp
3536
DeNaN.cpp

0 commit comments

Comments
 (0)