diff options
author | Alon Zakai <azakai@google.com> | 2019-03-06 14:12:26 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2019-03-06 16:34:34 -0800 |
commit | 83aa0dc2daf327ed264cc22e51af1a866787a764 (patch) | |
tree | 70660819a1cd694c9776b0eb93db7c162eab274f /src/ir/parents.h | |
parent | 22fe3269f79c38c7954967ec303642b5168844c3 (diff) | |
download | binaryen-83aa0dc2daf327ed264cc22e51af1a866787a764.tar.gz binaryen-83aa0dc2daf327ed264cc22e51af1a866787a764.tar.bz2 binaryen-83aa0dc2daf327ed264cc22e51af1a866787a764.zip |
Optimize added constants with propagation only if we see we will remove all uses of the original add, as otherwise we may just be adding work (both an offset, and an add). Refactor local-utils.h, and make UnneededSetRemover also check for side effects, so it cleanly removes all traces of unneeded sets.
Diffstat (limited to 'src/ir/parents.h')
-rw-r--r-- | src/ir/parents.h | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/ir/parents.h b/src/ir/parents.h new file mode 100644 index 000000000..71f2ae1d4 --- /dev/null +++ b/src/ir/parents.h @@ -0,0 +1,44 @@ +/* + * Copyright 2019 WebAssembly Community Group participants + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef wasm_ir_parents_h +#define wasm_ir_parents_h + +namespace wasm { + +struct Parents { + Parents(Expression* expr) { + inner.walk(expr); + } + + Expression* getParent(Expression* curr) { + return inner.parentMap[curr]; + } + +private: + struct Inner : public ExpressionStackWalker<Inner, UnifiedExpressionVisitor<Inner>> { + void visitExpression(Expression* curr) { + parentMap[curr] = getParent(); + } + + std::map<Expression*, Expression *> parentMap; + } inner; +}; + +} // namespace wasm + +#endif // wasm_ir_parents_h + |