diff options
Diffstat (limited to 'src/ir/utils.h')
-rw-r--r-- | src/ir/utils.h | 88 |
1 files changed, 0 insertions, 88 deletions
diff --git a/src/ir/utils.h b/src/ir/utils.h index 72aa701bb..8051cb1a3 100644 --- a/src/ir/utils.h +++ b/src/ir/utils.h @@ -181,94 +181,6 @@ struct ReFinalizeNode : public OverriddenVisitor<ReFinalizeNode> { } }; -// Adds drop() operations where necessary. This lets you not worry about adding -// drop when generating code. This also refinalizes before and after, as -// dropping can change types, and depends on types being cleaned up - no -// unnecessary block/if/loop types (see refinalize) -// TODO: optimize that, interleave them -struct AutoDrop : public WalkerPass<ExpressionStackWalker<AutoDrop>> { - bool isFunctionParallel() override { return true; } - - std::unique_ptr<Pass> create() override { - return std::make_unique<AutoDrop>(); - } - - AutoDrop() { name = "autodrop"; } - - bool maybeDrop(Expression*& child) { - bool acted = false; - if (child->type.isConcrete()) { - expressionStack.push_back(child); - if (!ExpressionAnalyzer::isResultUsed(expressionStack, getFunction()) && - !ExpressionAnalyzer::isResultDropped(expressionStack)) { - child = Builder(*getModule()).makeDrop(child); - acted = true; - } - expressionStack.pop_back(); - } - return acted; - } - - void reFinalize() { ReFinalizeNode::updateStack(expressionStack); } - - void visitBlock(Block* curr) { - if (curr->list.size() == 0) { - return; - } - for (Index i = 0; i < curr->list.size() - 1; i++) { - auto* child = curr->list[i]; - if (child->type.isConcrete()) { - curr->list[i] = Builder(*getModule()).makeDrop(child); - } - } - if (maybeDrop(curr->list.back())) { - reFinalize(); - assert(curr->type == Type::none || curr->type == Type::unreachable); - } - } - - void visitIf(If* curr) { - bool acted = false; - if (maybeDrop(curr->ifTrue)) { - acted = true; - } - if (curr->ifFalse) { - if (maybeDrop(curr->ifFalse)) { - acted = true; - } - } - if (acted) { - reFinalize(); - assert(curr->type == Type::none); - } - } - - void visitTry(Try* curr) { - bool acted = false; - if (maybeDrop(curr->body)) { - acted = true; - } - for (auto* catchBody : curr->catchBodies) { - if (maybeDrop(catchBody)) { - acted = true; - } - } - if (acted) { - reFinalize(); - assert(curr->type == Type::none); - } - } - - void doWalkFunction(Function* curr) { - ReFinalize().walkFunctionInModule(curr, getModule()); - walk(curr->body); - if (curr->getResults() == Type::none && curr->body->type.isConcrete()) { - curr->body = Builder(*getModule()).makeDrop(curr->body); - } - ReFinalize().walkFunctionInModule(curr, getModule()); - } -}; - struct I64Utilities { static Expression* recreateI64(Builder& builder, Expression* low, Expression* high) { |