diff options
Diffstat (limited to 'src/ir/ExpressionAnalyzer.cpp')
-rw-r--r-- | src/ir/ExpressionAnalyzer.cpp | 80 |
1 files changed, 53 insertions, 27 deletions
diff --git a/src/ir/ExpressionAnalyzer.cpp b/src/ir/ExpressionAnalyzer.cpp index aaab9050c..de37cd08b 100644 --- a/src/ir/ExpressionAnalyzer.cpp +++ b/src/ir/ExpressionAnalyzer.cpp @@ -35,22 +35,26 @@ bool ExpressionAnalyzer::isResultUsed(ExpressionStack& stack, Function* func) { if (curr->is<Block>()) { auto* block = curr->cast<Block>(); for (size_t j = 0; j < block->list.size() - 1; j++) { - if (block->list[j] == above) + if (block->list[j] == above) { return false; + } } assert(block->list.back() == above); // continue down } else if (curr->is<If>()) { auto* iff = curr->cast<If>(); - if (above == iff->condition) + if (above == iff->condition) { return true; - if (!iff->ifFalse) + } + if (!iff->ifFalse) { return false; + } assert(above == iff->ifTrue || above == iff->ifFalse); // continue down } else { - if (curr->is<Drop>()) + if (curr->is<Drop>()) { return false; + } return true; // all other node types use the result } } @@ -66,23 +70,27 @@ bool ExpressionAnalyzer::isResultDropped(ExpressionStack& stack) { if (curr->is<Block>()) { auto* block = curr->cast<Block>(); for (size_t j = 0; j < block->list.size() - 1; j++) { - if (block->list[j] == above) + if (block->list[j] == above) { return false; + } } assert(block->list.back() == above); // continue down } else if (curr->is<If>()) { auto* iff = curr->cast<If>(); - if (above == iff->condition) + if (above == iff->condition) { return false; - if (!iff->ifFalse) + } + if (!iff->ifFalse) { return false; + } assert(above == iff->ifTrue || above == iff->ifFalse); // continue down } else { - if (curr->is<Drop>()) + if (curr->is<Drop>()) { return true; // dropped - return false; // all other node types use the result + } + return false; // all other node types use the result } } return false; @@ -238,8 +246,9 @@ bool ExpressionAnalyzer::flexibleEqual(Expression* left, // Comparison is by value, except for names, which must match. bool operator==(const Immediates& other) { - if (scopeNames.size() != other.scopeNames.size()) + if (scopeNames.size() != other.scopeNames.size()) { return false; + } for (Index i = 0; i < scopeNames.size(); i++) { auto leftName = scopeNames[i]; auto rightName = other.scopeNames[i]; @@ -254,18 +263,24 @@ bool ExpressionAnalyzer::flexibleEqual(Expression* left, return false; } } - if (nonScopeNames != other.nonScopeNames) + if (nonScopeNames != other.nonScopeNames) { return false; - if (ints != other.ints) + } + if (ints != other.ints) { return false; - if (literals != other.literals) + } + if (literals != other.literals) { return false; - if (types != other.types) + } + if (types != other.types) { return false; - if (indexes != other.indexes) + } + if (indexes != other.indexes) { return false; - if (addresses != other.addresses) + } + if (addresses != other.addresses) { return false; + } return true; } @@ -283,8 +298,9 @@ bool ExpressionAnalyzer::flexibleEqual(Expression* left, }; bool noteNames(Name left, Name right) { - if (left.is() != right.is()) + if (left.is() != right.is()) { return false; + } if (left.is()) { assert(rightNames.find(left) == rightNames.end()); rightNames[left] = right; @@ -306,28 +322,35 @@ bool ExpressionAnalyzer::flexibleEqual(Expression* left, leftStack.pop_back(); right = rightStack.back(); rightStack.pop_back(); - if (!left != !right) + if (!left != !right) { return false; - if (!left) + } + if (!left) { continue; - if (comparer(left, right)) + } + if (comparer(left, right)) { continue; // comparison hook, before all the rest + } // continue with normal structural comparison - if (left->_id != right->_id) + if (left->_id != right->_id) { return false; + } // Blocks and loops introduce scoping. if (auto* block = left->dynCast<Block>()) { - if (!noteNames(block->name, right->cast<Block>()->name)) + if (!noteNames(block->name, right->cast<Block>()->name)) { return false; + } } else if (auto* loop = left->dynCast<Loop>()) { - if (!noteNames(loop->name, right->cast<Loop>()->name)) + if (!noteNames(loop->name, right->cast<Loop>()->name)) { return false; + } } else { // For all other nodes, compare their immediate values visitImmediates(left, leftImmediates); visitImmediates(right, rightImmediates); - if (leftImmediates != rightImmediates) + if (leftImmediates != rightImmediates) { return false; + } leftImmediates.clear(); rightImmediates.clear(); } @@ -343,11 +366,13 @@ bool ExpressionAnalyzer::flexibleEqual(Expression* left, } // The number of child nodes must match (e.g. return has an optional // one). - if (counter != 0) + if (counter != 0) { return false; + } } - if (leftStack.size() > 0 || rightStack.size() > 0) + if (leftStack.size() > 0 || rightStack.size() > 0) { return false; + } return true; } }; @@ -377,8 +402,9 @@ HashType ExpressionAnalyzer::hash(Expression* curr) { while (stack.size() > 0) { curr = stack.back(); stack.pop_back(); - if (!curr) + if (!curr) { continue; + } hash(curr->_id); // we often don't need to hash the type, as it is tied to other values // we are hashing anyhow, but there are exceptions: for example, a |