summaryrefslogtreecommitdiff
path: root/src/cfg/domtree.h
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2021-09-03 11:00:10 -0700
committerGitHub <noreply@github.com>2021-09-03 11:00:10 -0700
commit99ccc313b2c1d91bbfcee48fe99d70a2867befbc (patch)
treeb52a466a3d9eaf8685edfc52e393230c099cf8de /src/cfg/domtree.h
parent548d1971c3c844e8dab8c0da4e97aa5c339937df (diff)
downloadbinaryen-99ccc313b2c1d91bbfcee48fe99d70a2867befbc.tar.gz
binaryen-99ccc313b2c1d91bbfcee48fe99d70a2867befbc.tar.bz2
binaryen-99ccc313b2c1d91bbfcee48fe99d70a2867befbc.zip
Optimize away dominated calls to functions that run only once (#4111)
Some functions run only once with this pattern: function foo() { if (foo$ran) return; foo$ran = 1; ... } If that global is not ever set to 0, then the function's payload (after the initial if and return) will never execute more than once. That means we can optimize away dominated calls: foo(); foo(); // we can remove this To do this, we find which globals are "once", which means they can fit in that pattern, as they are never set to 0. If a function looks like the above pattern, and it's global is "once", then the function is "once" as well, and we can perform this optimization. This removes over 8% of static calls in j2cl.
Diffstat (limited to 'src/cfg/domtree.h')
-rw-r--r--src/cfg/domtree.h7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/cfg/domtree.h b/src/cfg/domtree.h
index 5e54f7c32..5753a3114 100644
--- a/src/cfg/domtree.h
+++ b/src/cfg/domtree.h
@@ -47,6 +47,10 @@ namespace wasm {
template<typename BasicBlock> struct DomTree {
std::vector<Index> iDoms;
+ // Use a nonsense value to indicate what has yet to be initialized or what is
+ // irrelevant.
+ enum { nonsense = Index(-1) };
+
DomTree(std::vector<std::unique_ptr<BasicBlock>>& blocks);
};
@@ -84,9 +88,6 @@ DomTree<BasicBlock>::DomTree(std::vector<std::unique_ptr<BasicBlock>>& blocks) {
blockIndices[blocks[i].get()] = i;
}
- // Use a nonsense value to indicate what has yet to be initialized.
- const Index nonsense = -1;
-
// Initialize the iDoms array. The entry starts with its own index, which is
// used as a guard value in effect (we will never process it, and we will fix
// up this value at the very end). All other nodes start with a nonsense value