summaryrefslogtreecommitdiff
path: root/src/passes/CoalesceLocals.cpp
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2016-06-01 12:33:55 -0700
committerAlon Zakai <alonzakai@gmail.com>2016-06-01 12:33:55 -0700
commitdb2ae40be2c52c0821da355285384aa0db8fc948 (patch)
tree219196901187a754333cb076ce786a5bea653371 /src/passes/CoalesceLocals.cpp
parent208959079a9c4b97a2457e8d6b11c5bc295c0754 (diff)
downloadbinaryen-db2ae40be2c52c0821da355285384aa0db8fc948.tar.gz
binaryen-db2ae40be2c52c0821da355285384aa0db8fc948.tar.bz2
binaryen-db2ae40be2c52c0821da355285384aa0db8fc948.zip
if we use the zero-init value of a local, we cannot coalesce it with a param (#556)
Diffstat (limited to 'src/passes/CoalesceLocals.cpp')
-rw-r--r--src/passes/CoalesceLocals.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/passes/CoalesceLocals.cpp b/src/passes/CoalesceLocals.cpp
index 39c480107..c36371ec0 100644
--- a/src/passes/CoalesceLocals.cpp
+++ b/src/passes/CoalesceLocals.cpp
@@ -183,7 +183,7 @@ struct CoalesceLocals : public WalkerPass<CFGWalker<CoalesceLocals, Visitor<Coal
void calculateInterferences();
- void calculateInterferences(LocalSet& locals);
+ void calculateInterferences(const LocalSet& locals);
// merge starts of a list of blocks, adding new interferences as necessary. return
// whether anything changed vs an old state (which indicates further processing is necessary).
@@ -282,8 +282,6 @@ void CoalesceLocals::flowLiveness() {
queue.insert(in);
}
}
- // live locals at the entry block include params, obviously, but also
- // vars, in which case the 0-init value is actually used.
#ifdef CFG_DEBUG
std::hash<std::vector<bool>> hasher;
std::cout << getFunction()->name << ": interference hash: " << hasher(*(std::vector<bool>*)&interferences) << "\n";
@@ -347,9 +345,17 @@ void CoalesceLocals::calculateInterferences() {
}
}
}
+ // Params have a value on entry, so mark them as live, as variables
+ // live at the entry expect their zero-init value.
+ LocalSet start = entry->contents.start;
+ auto numParams = getFunction()->getNumParams();
+ for (Index i = 0; i < numParams; i++) {
+ start.insert(i);
+ }
+ calculateInterferences(start);
}
-void CoalesceLocals::calculateInterferences(LocalSet& locals) {
+void CoalesceLocals::calculateInterferences(const LocalSet& locals) {
size_t size = locals.size();
for (size_t i = 0; i < size; i++) {
for (size_t j = i + 1; j < size; j++) {