Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ Current Trunk
- The --mod-asyncify-never-unwind and --mod-asyncify-always-and-only-unwind
passed were deleted. They only existed to support the lazy code loading
support in emscripten that was removed. (#7893)
- The cost modeling of calls was increased to a high number. That cost is
usually not something you can notice (as calls have effects that make
removing/replacing them impossible), but you may notice this when using
call.without.effects (calls will no longer be assumed to be cheap enough to
run unconditionally) or monomorphize (which inputs a cost factor as a
number). (#8047)

v124
----
Expand Down
16 changes: 11 additions & 5 deletions src/ir/cost.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ struct CostAnalyzer : public OverriddenVisitor<CostAnalyzer, CostType> {
// cost due to shortening the time to the next collection.
static const CostType AllocationCost = 100;

// Calls can have unpredictable, unknown cost. Model it as a large number.
// TODO: For calls to functions in this module, we could in principle scan
// them. However, call effects generally mean the cost is a moot point,
// except for call.without.effects, which is rare.
static const CostType CallCost = 100;

CostType maybeVisit(Expression* curr) { return curr ? visit(curr) : 0; }

CostType visitBlock(Block* curr) {
Expand All @@ -68,23 +74,23 @@ struct CostAnalyzer : public OverriddenVisitor<CostAnalyzer, CostType> {
return 2 + visit(curr->condition) + maybeVisit(curr->value);
}
CostType visitCall(Call* curr) {
// XXX this does not take into account if the call is to an import, which
// may be costlier in general
CostType ret = 4;
CostType ret = CallCost;
for (auto* child : curr->operands) {
ret += visit(child);
}
return ret;
}
CostType visitCallIndirect(CallIndirect* curr) {
CostType ret = 6 + visit(curr->target);
// Model indirect calls as more expensive than direct ones.
CostType ret = CallCost + 1 + visit(curr->target);
for (auto* child : curr->operands) {
ret += visit(child);
}
return ret;
}
CostType visitCallRef(CallRef* curr) {
CostType ret = 5 + visit(curr->target);
// Model call_refs as more expensive than direct calls.
CostType ret = CallCost + 1 + visit(curr->target);
for (auto* child : curr->operands) {
ret += visit(child);
}
Expand Down
Loading
Loading