summaryrefslogtreecommitdiff
path: root/src/passes/Directize.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/passes/Directize.cpp')
-rw-r--r--src/passes/Directize.cpp28
1 files changed, 11 insertions, 17 deletions
diff --git a/src/passes/Directize.cpp b/src/passes/Directize.cpp
index 21254cda7..3fc7d6c41 100644
--- a/src/passes/Directize.cpp
+++ b/src/passes/Directize.cpp
@@ -33,6 +33,7 @@
#include <unordered_map>
#include "call-utils.h"
+#include "ir/drop.h"
#include "ir/table-utils.h"
#include "ir/utils.h"
#include "pass.h"
@@ -170,12 +171,18 @@ private:
// We don't know anything here.
return;
}
- // If the index is invalid, or the type is wrong, we can
- // emit an unreachable here, since in Binaryen it is ok to
- // reorder/replace traps when optimizing (but never to
+ // If the index is invalid, or the type is wrong, we can skip the call and
+ // emit an unreachable here (with dropped children as needed), since in
+ // Binaryen it is ok to reorder/replace traps when optimizing (but never to
// remove them, at least not by default).
if (std::get_if<CallUtils::Trap>(&info)) {
- replaceCurrent(replaceWithUnreachable(operands));
+ replaceCurrent(
+ getDroppedChildrenAndAppend(original,
+ *getModule(),
+ getPassOptions(),
+ Builder(*getModule()).makeUnreachable(),
+ DropMode::IgnoreParentEffects));
+ changedTypes = true;
return;
}
@@ -185,19 +192,6 @@ private:
Builder(*getModule())
.makeCall(name, operands, original->type, original->isReturn));
}
-
- Expression* replaceWithUnreachable(const std::vector<Expression*>& operands) {
- // Emitting an unreachable means we must update parent types.
- changedTypes = true;
-
- Builder builder(*getModule());
- std::vector<Expression*> newOperands;
- for (auto* operand : operands) {
- newOperands.push_back(builder.makeDrop(operand));
- }
- return builder.makeSequence(builder.makeBlock(newOperands),
- builder.makeUnreachable());
- }
};
struct Directize : public Pass {