summaryrefslogtreecommitdiff
path: root/src/passes/SignatureRefining.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [GC] Ignore public types in SignatureRefining (#7022)Alon Zakai2024-10-181-12/+5
| | | Similar to #7017 and #7018
* SignatureRefining: Notice LUB requirements of intrinsic calls (#6122)Alon Zakai2023-11-141-0/+26
| | | | | | call.without.effects implies a call to the function reference in the last parameter, so the values sent in the other parameters must be taken into account when computing LUBs for refining arguments, otherwise we might refine so much that the intrinsic call no longer validates.
* [NFC] Rename getSuperType to getDeclaredSuperType (#6015)Alon Zakai2023-10-171-1/+1
| | | | A later PR will add getSuperType which will mean "get the general super type - either declared, or not".
* SignatureRefining: Handle updates to call.without.effects (#5884)Alon Zakai2023-08-231-0/+68
| | | | | | | If we refine a signature type that is used in a call.without.effects then that call's results may need to be updated. In the IR it looks like a normal call that happens to pass a function reference as the last param, but it actually means that we call that function (without side effects), so we need to have the same results, and the validator already verified that (so the new testcase here fails without this fix).
* [NFC] Fix the use of "strict" in subtypes.h (#5804)Thomas Lively2023-07-061-1/+1
| | | | | | | | Previously we incorrectly used "strict" to mean the immediate subtypes of a type, when in fact a strict subtype of a type is any subtype excluding the type itself. Rename the incorrect `getStrictSubTypes` to `getImmediateSubTypes`, rename the redundant `getAllStrictSubTypes` to `getStrictSubTypes`, and rename the redundant `getAllSubTypes` to `getSubTypes`. Fixing the capitalization of "SubType" to "Subtype" is left as future work.
* [Wasm GC] Always refinalize in SignatureRefining (#5694)Alon Zakai2023-05-011-9/+2
| | | | We used to refine only for result changes, but param changes can also lead to opportunities.
* SignatureRefining: Skip types with supertypes for now (#5548)Alon Zakai2023-03-061-0/+6
| | | We'd need to handle contravariance to optimize them.
* [Wasm GC] Skip types with subtypes in SignatureRefining (#5544)Alon Zakai2023-03-031-0/+11
| | | | | | | For now just skip them, to avoid problems. In the future we should look into modifying their children, when possible. Fixes #5463
* Do not special case ref.null in `LUBFinder` (#5307)Thomas Lively2022-12-011-10/+3
| | | | | | | | | | | | Before we implemented bottom heap types, `ref.null` had to be annotated with specific types. The `LUBFinder` utility ignored these types so that it could find the best LUB from all considered non-null expressions, then go back and update the type annotations on the nulls to match that LUB. Now that we have bottom types, however, none of that is necessary, and in fact ignoring nulls can miss possible refinements to bottom types. Update and simplify `LUBFinder` so that it is a simple wrapper around the underlying `Type::getLeastUpperBound` utility with no additional logic. Update tests to account for the more powerful optimizations.
* Remove equirecursive typing (#5240)Thomas Lively2022-11-231-4/+0
| | | | Equirecursive is no longer standards track and its implementation is extremely complex. Remove it.
* Refactor interaction between Pass and PassRunner (#5093)Thomas Lively2022-09-301-4/+6
| | | | | | | | | | | | | | Previously only WalkerPasses had access to the `getPassRunner` and `getPassOptions` methods. Move those methods to `Pass` so all passes can use them. As a result, the `PassRunner` passed to `Pass::run` and `Pass::runOnFunction` is no longer necessary, so remove it. Also update `Pass::create` to return a unique_ptr, which is more efficient than having it return a raw pointer only to have the `PassRunner` wrap that raw pointer in a `unique_ptr`. Delete the unused template `PassRunner::getLast()`, which looks like it was intended to enable retrieving previous analyses and has been in the code base since 2015 but is not implemented anywhere.
* [Wasm GC] Support non-nullable locals in the "1a" form (#4959)Alon Zakai2022-08-311-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | An overview of this is in the README in the diff here (conveniently, it is near the top of the diff). Basically, we fix up nn locals after each pass, by default. This keeps things easy to reason about - what validates is what is valid wasm - but there are some minor nuances as mentioned there, in particular, we ignore nameless blocks (which are commonly added by various passes; ignoring them means we can keep more locals non-nullable). The key addition here is LocalStructuralDominance which checks which local indexes have the "structural dominance" property of 1a, that is, that each get has a set in its block or an outer block that precedes it. I optimized that function quite a lot to reduce the overhead of running that logic after each pass. The overhead is something like 2% on J2Wasm and 0% on Dart (0%, because in this mode we shrink code size, so there is less work actually, and it balances out). Since we run fixups after each pass, this PR removes logic to manually call the fixup code from various places we used to call it (like eh-utils and various passes). Various passes are now marked as requiresNonNullableLocalFixups => false. That lets us skip running the fixups after them, which we normally do automatically. This helps avoid overhead. Most passes still need the fixups, though - any pass that adds a local, or a named block, or moves code around, likely does. This removes a hack in SimplifyLocals that is no longer needed. Before we worked to avoid moving a set into a try, as it might not validate. Now, we just do it and let fixups happen automatically if they need to: in the common code they probably don't, so the extra complexity seems not worth it. Also removes a hack from StackIR. That hack tried to avoid roundtrip adding a nondefaultable local. But we have the logic to fix that up now, and opts will likely keep it non-nullable as well. Various tests end up updated here because now a local can be non-nullable - previous fixups are no longer needed. Note that this doesn't remove the gc-nn-locals feature. That has been useful for testing, and may still be useful in the future - it basically just allows nn locals in all positions (that can't read the null default value at the entry). We can consider removing it separately. Fixes #4824
* Make `GlobalTypeRewriter` work for isorecursive types (#4829)Thomas Lively2022-07-261-2/+3
| | | | | | | | | | | | | | | | | | | There are two new potential problems that `GlobalTypeRewriter` can run into when working with isorecursive types instead of nominal types. First, the refined types may have replaced generic references with references to specific other types, potentially creating new recursions and making the existing recursion groups insufficient. Second, distinct types may be refined to structurally identical types and those distinct input types may map the same output type, potentially changing cast behavior. Both of these problems are solved by putting all the new types in a single large recursion group. We do not currently account for the fact that types may be used in the external interface of the module, but when we do, externalized types will be excluded from optimizations and will not be affected by the creation of this single large rec group. Fixes #4816.
* Disallow --nominal with GC (#4758)Thomas Lively2022-06-281-0/+3
| | | | | | | | | | | Nominal types don't make much sense without GC, and in particular trying to emit them with typed function references but not GC enabled can result in invalid binaries because nominal types do not respect the type ordering constraints required by the typed function references proposal. Making this change was mostly straightforward, but required fixing the fuzzer to use --nominal only when GC is enabled and required exiting early from nominal-only optimizations when GC was not enabled. Fixes #4756.
* SignatureRefining: Do not refine types of imported functions (#4727)Alon Zakai2022-06-141-0/+9
| | | | Spec and VM support for that is not yet stable (atm VMs do not allow complex user- defined types to be passed around).
* [Nominal Fuzzing] Fix SignatureRefining by updating types fully at once (#4665)Alon Zakai2022-05-231-1/+9
| | | | | | | | | | Optionally avoid updating types in TypeUpdating::updateParamTypes(). That update is incomplete if the function signature is also changing, which is the case in SignatureRefining (but not DeadArgumentElimination). "Incomplete" means that we updated the local.get type, but the function signature does not match yet. That incomplete state can hit an internal error in GlobalTypeRewriter::updateSignatures where it updates types. To avoid that, do the entire full update only there (in GlobalTypeRewriter::updateSignatures).
* [NominalFuzzing] SignatureRefining can modify the IR while running a ↵Alon Zakai2022-04-281-1/+3
| | | | | | | | | parallel analysis (#4620) Normally ParallelFunctionAnalysis is just an analysis, and has no effects. However, in SignatureRefining we actually do have side effects, due to an internal limitation of the helper code it runs. This adds a template parameter to the class so users can note that they do modify the IR. The parameter is added in the middle as it is easier to add this param than to add the last one (the map).
* [NominalFuzzing] SignatureRefining: Ignore exported functions (#4601)Alon Zakai2022-04-221-1/+24
| | | This hits the fuzzer when it tries to call reference exports with a null.
* [Wasm GC] Signature Pruning (#4545)Alon Zakai2022-03-251-19/+1
| | | | | | | | | | | | | This adds a new signature-pruning pass that prunes parameters from signature types where those parameters are never used in any function that has that type. This is similar to DeadArgumentElimination but works on a set of functions, and it can handle indirect calls. Also move a little code from SignatureRefining into a shared place to avoid duplication of logic to update signature types. This pattern happens in j2wasm code, for example if all method functions for some virtual method just return a constant and do not use the this pointer.
* [Wasm GC] Refine results in SignatureRefining (#4380)Alon Zakai2021-12-141-17/+70
| | | | | | Similar to what DeadArgumentElimination does for individual functions, this can refine the results of a set of functions all using the same heap type, when they all return something more specific. After this PR SignatureRefining can refine both params and results and is basically complete.
* [Wasm GC] Signature Refining pass (#4326)Alon Zakai2021-11-191-0/+207
This is fairly short and simple after the recent refactorings. This basically just finds all uses of each signature/function type, and then sees if it receives more specific types as params. It then rewrites the types if so. This just handles arguments so far, and not return types. This differs from DeadArgumentElimination's refineArguments() in that that pass modifies each function by itself, changing the type of the function as needed. That is only valid if the type is not observable, that is, if the function is called indirectly then DAE ignores it. This pass will work on the types themselves, so it considers all functions sharing a type as a whole, and when it upgrades that type it ends up affecting them all. This finds optimization opportunities on 4% of the total signature types in j2wasm. Those lead to some benefits in later opts, but the effect is not huge.