Repository navigation
Relax bodies of functions when their signature can't be changed - #9380
stevenfontanella wants to merge 1 commit into
Conversation
f0c0337 to
40d698d
Compare
| bool isFunctionParallel() override { return true; } | ||
|
|
||
| bool runsOnFunction(Function* func) const override { | ||
| return func->vars.size() > 0 || isRelaxable(func, referencedFuncs); |
There was a problem hiding this comment.
[MEDIUM | Confidence: 5/5 | PERFORMANCE]
Checking func->vars.size() > 0 causes runsOnFunction to return true for every unrelaxable function (e.g. exported or referenced functions) that declares any local variables, even if all declared locals are primitive types (i32, i64, f32, f64) or already nullable.
For these functions, PassRunner instantiates the pass and performs a full AST traversal in Super::doWalkFunction(func). Because signatureWasUpdated is false and none of func->vars are non-nullable references, makeNullable does nothing and changed remains false, making the entire AST walk a redundant no-op.
To avoid traversing functions with only primitive or nullable locals, check whether any variable in func->vars is a non-nullable reference:
| return func->vars.size() > 0 || isRelaxable(func, referencedFuncs); | |
| bool runsOnFunction(Function* func) const override { | |
| return isRelaxable(func, referencedFuncs) || | |
| std::any_of(func->vars.begin(), func->vars.end(), [](Type t) { | |
| return t.isNonNullableRef(); | |
| }); | |
| } |
26be07b to
3a51486
Compare
| ;; CHECK-NEXT: (local.get $ref) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: (local.get $l) | ||
| ;; CHECK-NEXT: ) |
There was a problem hiding this comment.
[HIGH | Confidence: 5/5 | BUG]
The lit test assertions for $exported-not-relaxed will fail under FileCheck. Line 231 adds (drop (local.tee $l (local.get $ref))) to the test input, but lines 222-223 in the CHECK directives expect CHECK-NEXT: (local.get $l) immediately after the local.set, omitting the dropped tee.
Because CHECK-NEXT enforces contiguous lines, FileCheck will fail when encountering (drop ...) in the output. Please update the test assertions using scripts/update_lit_checks.py -a (or include the expected (drop (local.tee ...)) checks before (local.get $l)).
3a51486 to
da06787
Compare
Part of #9352. Resolves some TODOs in the code. For exported and possibly-indirectly-called functions, we can't change their signature. However we can still relax locals in their bodies.
As a drive-by fix, make
runsOnFunctionconstso that subclasses aren't tempted to set class state in this method (as I was in this PR). It isn't guaranteed to be called on the particular instance that optimizes the function and in practice is not in our code (link, this is not the instance that we created withcreate()link).