Skip to content

ImmutableArrays#42465

Closed
ianatol wants to merge 58 commits intoJuliaLang:masterfrom
ianatol:kf/immutablearray
Closed

ImmutableArrays#42465
ianatol wants to merge 58 commits intoJuliaLang:masterfrom
ianatol:kf/immutablearray

Conversation

@ianatol
Copy link
Copy Markdown
Member

@ianatol ianatol commented Oct 2, 2021

This PR extends #41777 to provide a dynamically sized immutable array ImmutableArray.

The ImmutableArray constructor creates an immutable copy of another array, allowing users to get the performance of a mutable array locally, but with the compositionality and safety of an immutable array at the inter-procedural level. In the cases where the compiler can prove (using info from a novel escape analysis pass) that the original array is dead after copying, this benefit comes at no cost to the user.

See the following for an example of a function that utilizes performant, mutating operations while only exposing an immutable array:

function simple()
    a = Vector{Float64}(undef, 5)
    for i = 1:5
        a[i] = i
    end
    return ImmutableArray(a)
end

Using information gathered by the escape analysis pass, the compiler can prove that a is dead after the return, and thus this function is neatly optimized to have the same memory allocation as one that returns a mutable object.

This rebases JuliaLang#31630 with several fixed and modifications.
After JuliaLang#31630, we had originally decided to hold off on said
PR in favor of implementing either more efficient layouts for
tuples or some sort of variable-sized struct type. However, in
the two years since, neither of those have happened (I had a go
at improving tuples and made some progress, but there is much
still to be done there). In the meantime, all across the package
ecosystem, we've seen an increasing creep of pre-allocation and
mutating operations, primarily caused by our lack of sufficiently
powerful immutable array abstractions and array optimizations.

This works fine for the individual packages in question, but it
causes a fair bit of trouble when trying to compose these packages
with transformation passes such as AD or domain specific optimizations,
since many of those passes do not play well with mutation. More
generally, we would like to avoid people needing to pierce
abstractions for performance reasons.

Given these developments, I think it's getting quite important
that we start to seriously look at arrays and try to provide
performant and well-optimized arrays in the language. More
importantly, I think this is somewhat independent from the
actual implementation details. To be sure, it would be nice
to move more of the array implementation into Julia by making
use of one of the abovementioned langugage features, but that
is a bit of an orthogonal concern and not absolutely required.

This PR provides an `ImmutableArray` type that is identical
in functionality and implementation to `Array`, except that
it is immutable. Two new intrinsics `Core.arrayfreeze` and
`Core.arraythaw` are provided which are semantically copies
and turn a mutable array into an immutable array and vice
versa.

In the original PR, I additionally provided generic functions
`freeze` and `thaw` that would simply forward to these
intrinsics. However, said generic functions have been omitted
from this PR in favor of simply using constructors to go
between mutable and immutable arrays at the high level.
Generic `freeze`/`thaw` functions can always be added later,
once we have a more complete picture of how these functions
would work on non-Array datatypes.

Some basic compiler support is provided to elide these copies
when the compiler can prove that the original object is
dead after the copy. For instance, in the following example:
```
function simple()
    a = Vector{Float64}(undef, 5)
    for i = 1:5
        a[i] = i
    end
    ImmutableArray(a)
end
```

the compiler will recognize that the array `a` is dead after
its use in `ImmutableArray` and the optimized implementation
will simply rewrite the type tag in the originally allocated
array to now mark it as immutable. It should be pointed out
however, that *semantically* there is still no mutation of the
original array, this is simply an optimization.

At the moment this compiler transform is rather limited, since
the analysis requires escape information in order to compute
whether or not the copy may be elided. However, more complete
escape analysis is being worked on at the moment, so hopefully
this analysis should become more powerful in the very near future.

I would like to get this cleaned up and merged resonably quickly,
and then crowdsource some improvements to the Array APIs more
generally. There are still a number of APIs that are quite bound
to the notion of mutable `Array`s. StaticArrays and other packages
have been inventing conventions for how to generalize those, but
we should form a view in Base what those APIs should look like and
harmonize them. Having the `ImmutableArray` in Base should help
with that.
Comment on lines +1426 to +1430
# Now handle the remaining values
# The typeassert gives inference a helping hand on the element type and dimensionality
# (work-around for #28382)
ElType′ = ElType === Union{} ? Any : ElType <: Type ? Type : ElType
RT = dest isa AbstractArray ? AbstractArray{<:ElType′, ndims(dest)} : Any
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not directly related to this PR, but might be a good opportunity to check whether this still holds true with the recent inference improvements.

@vtjnash vtjnash marked this pull request as draft October 2, 2021 17:17
@ianatol ianatol requested a review from vtjnash October 6, 2021 15:47
@vtjnash vtjnash removed their request for review October 7, 2021 17:06
@ianatol ianatol requested a review from vtjnash October 7, 2021 22:17
@aviatesk aviatesk self-requested a review October 13, 2021 13:59
@ianatol ianatol force-pushed the kf/immutablearray branch 2 times, most recently from 1724ee8 to a164ef4 Compare October 16, 2021 09:53
@ianatol ianatol requested a review from aviatesk October 25, 2021 20:13
@ianatol ianatol marked this pull request as ready for review October 25, 2021 20:14
@ianatol ianatol marked this pull request as draft October 25, 2021 20:20
@ianatol ianatol force-pushed the kf/immutablearray branch 3 times, most recently from e67ae7c to 29681b6 Compare October 29, 2021 18:40
aviatesk added a commit that referenced this pull request Jan 22, 2022
This commit ports [EscapeAnalysis.jl](https://github.com/aviatesk/EscapeAnalysis.jl) into Julia base.
You can find the documentation of this escape analysis at [this GitHub page](https://aviatesk.github.io/EscapeAnalysis.jl/dev/)[^1].

[^1]: The same documentation will be included into Julia's developer
      documentation by this commit.

This escape analysis will hopefully be an enabling technology for various
memory-related optimizations at Julia's high level compilation pipeline.
Possible target optimization includes mutable ϕ-node aware SROA,
`mutating_arrayfreeze` optimization (#42465), stack allocation of mutables,
dead array elimination, finalizer elision and so on[^2].

[^2]: It would be also interesting if LLVM-level optimizations can consume
      some IPO information derived by this escape analysis to broaden
      optimization possibilities.

The primary motivation for porting EA in this PR is to check its impact
on latency as well as to get feedbacks from a broader range of developers.
If there are no serious problems, EA will be used by #42465 for `mutating_arrayfreeze`
optimization for `ImmutableArray` construction.

This commit simply defines EA inside Julia base compiler and enables the
existing test suite with it. The plan is to validate EA's accuracy and
correctness and to check the latency impact by running EA before the
existing SROA pass and checking if it can detect all objects eliminated
by the SROA pass as "SROA-eliminatable".
aviatesk added a commit that referenced this pull request Jan 22, 2022
This commit ports [EscapeAnalysis.jl](https://github.com/aviatesk/EscapeAnalysis.jl) into Julia base.
You can find the documentation of this escape analysis at [this GitHub page](https://aviatesk.github.io/EscapeAnalysis.jl/dev/)[^1].

[^1]: The same documentation will be included into Julia's developer
      documentation by this commit.

This escape analysis will hopefully be an enabling technology for various
memory-related optimizations at Julia's high level compilation pipeline.
Possible target optimization includes mutable ϕ-node aware SROA,
`mutating_arrayfreeze` optimization (#42465), stack allocation of mutables,
dead array elimination, finalizer elision and so on[^2].

[^2]: It would be also interesting if LLVM-level optimizations can consume
      some IPO information derived by this escape analysis to broaden
      optimization possibilities.

The primary motivation for porting EA in this PR is to check its impact
on latency as well as to get feedbacks from a broader range of developers.
If there are no serious problems, EA will be used by #42465 for `mutating_arrayfreeze`
optimization for `ImmutableArray` construction.

This commit simply defines EA inside Julia base compiler and enables the
existing test suite with it. The plan is to validate EA's accuracy and
correctness and to check the latency impact by running EA before the
existing SROA pass and checking if it can detect all objects eliminated
by the SROA pass as "SROA-eliminatable".
aviatesk added a commit that referenced this pull request Jan 22, 2022
This commit ports [EscapeAnalysis.jl](https://github.com/aviatesk/EscapeAnalysis.jl) into Julia base.
You can find the documentation of this escape analysis at [this GitHub page](https://aviatesk.github.io/EscapeAnalysis.jl/dev/)[^1].

[^1]: The same documentation will be included into Julia's developer
      documentation by this commit.

This escape analysis will hopefully be an enabling technology for various
memory-related optimizations at Julia's high level compilation pipeline.
Possible target optimization includes mutable ϕ-node aware SROA,
`mutating_arrayfreeze` optimization (#42465), stack allocation of mutables,
dead array elimination, finalizer elision and so on[^2].

[^2]: It would be also interesting if LLVM-level optimizations can consume
      some IPO information derived by this escape analysis to broaden
      optimization possibilities.

The primary motivation for porting EA in this PR is to check its impact
on latency as well as to get feedbacks from a broader range of developers.
If there are no serious problems, EA will be used by #42465 for `mutating_arrayfreeze`
optimization for `ImmutableArray` construction.

This commit simply defines EA inside Julia base compiler and enables the
existing test suite with it. The plan is to validate EA's accuracy and
correctness and to check the latency impact by running EA before the
existing SROA pass and checking if it can detect all objects eliminated
by the SROA pass as "SROA-eliminatable".
aviatesk added a commit to aviatesk/EscapeAnalysis.jl that referenced this pull request Jan 22, 2022
aviatesk added a commit that referenced this pull request Jan 22, 2022
This commit ports [EscapeAnalysis.jl](https://github.com/aviatesk/EscapeAnalysis.jl) into Julia base.
You can find the documentation of this escape analysis at [this GitHub page](https://aviatesk.github.io/EscapeAnalysis.jl/dev/)[^1].

[^1]: The same documentation will be included into Julia's developer
      documentation by this commit.

This escape analysis will hopefully be an enabling technology for various
memory-related optimizations at Julia's high level compilation pipeline.
Possible target optimization includes mutable ϕ-node aware SROA,
`mutating_arrayfreeze` optimization (#42465), stack allocation of mutables,
dead array elimination, finalizer elision and so on[^2].

[^2]: It would be also interesting if LLVM-level optimizations can consume
      some IPO information derived by this escape analysis to broaden
      optimization possibilities.

The primary motivation for porting EA in this PR is to check its impact
on latency as well as to get feedbacks from a broader range of developers.
If there are no serious problems, EA will be used by #42465 for `mutating_arrayfreeze`
optimization for `ImmutableArray` construction.

This commit simply defines EA inside Julia base compiler and enables the
existing test suite with it. The plan is to validate EA's accuracy and
correctness and to check the latency impact by running EA before the
existing SROA pass and checking if it can detect all objects eliminated
by the SROA pass as "SROA-eliminatable".
aviatesk added a commit that referenced this pull request Jan 24, 2022
This commit ports [EscapeAnalysis.jl](https://github.com/aviatesk/EscapeAnalysis.jl) into Julia base.
You can find the documentation of this escape analysis at [this GitHub page](https://aviatesk.github.io/EscapeAnalysis.jl/dev/)[^1].

[^1]: The same documentation will be included into Julia's developer
      documentation by this commit.

This escape analysis will hopefully be an enabling technology for various
memory-related optimizations at Julia's high level compilation pipeline.
Possible target optimization includes mutable ϕ-node aware SROA,
`mutating_arrayfreeze` optimization (#42465), stack allocation of mutables,
dead array elimination, finalizer elision and so on[^2].

[^2]: It would be also interesting if LLVM-level optimizations can consume
      some IPO information derived by this escape analysis to broaden
      optimization possibilities.

The primary motivation for porting EA in this PR is to check its impact
on latency as well as to get feedbacks from a broader range of developers.
If there are no serious problems, EA will be used by #42465 for `mutating_arrayfreeze`
optimization for `ImmutableArray` construction.

This commit simply defines EA inside Julia base compiler and enables the
existing test suite with it. The plan is to validate EA's accuracy and
correctness and to check the latency impact by running EA before the
existing SROA pass and checking if it can detect all objects eliminated
by the SROA pass as "SROA-eliminatable".
aviatesk added a commit that referenced this pull request Jan 24, 2022
This commit ports [EscapeAnalysis.jl](https://github.com/aviatesk/EscapeAnalysis.jl) into Julia base.
You can find the documentation of this escape analysis at [this GitHub page](https://aviatesk.github.io/EscapeAnalysis.jl/dev/)[^1].

[^1]: The same documentation will be included into Julia's developer
      documentation by this commit.

This escape analysis will hopefully be an enabling technology for various
memory-related optimizations at Julia's high level compilation pipeline.
Possible target optimization includes mutable ϕ-node aware SROA,
`mutating_arrayfreeze` optimization (#42465), stack allocation of mutables,
dead array elimination, finalizer elision and so on[^2].

[^2]: It would be also interesting if LLVM-level optimizations can consume
      some IPO information derived by this escape analysis to broaden
      optimization possibilities.

The primary motivation for porting EA in this PR is to check its impact
on latency as well as to get feedbacks from a broader range of developers.
If there are no serious problems, EA will be used by #42465 for `mutating_arrayfreeze`
optimization for `ImmutableArray` construction.

This commit simply defines EA inside Julia base compiler and enables the
existing test suite with it. The plan is to validate EA's accuracy and
correctness and to check the latency impact by running EA before the
existing SROA pass and checking if it can detect all objects eliminated
by the SROA pass as "SROA-eliminatable".
aviatesk added a commit that referenced this pull request Jan 25, 2022
This commit ports [EscapeAnalysis.jl](https://github.com/aviatesk/EscapeAnalysis.jl) into Julia base.
You can find the documentation of this escape analysis at [this GitHub page](https://aviatesk.github.io/EscapeAnalysis.jl/dev/)[^1].

[^1]: The same documentation will be included into Julia's developer
      documentation by this commit.

This escape analysis will hopefully be an enabling technology for various
memory-related optimizations at Julia's high level compilation pipeline.
Possible target optimization includes mutable ϕ-node aware SROA,
`mutating_arrayfreeze` optimization (#42465), stack allocation of mutables,
dead array elimination, finalizer elision and so on[^2].

[^2]: It would be also interesting if LLVM-level optimizations can consume
      some IPO information derived by this escape analysis to broaden
      optimization possibilities.

The primary motivation for porting EA in this PR is to check its impact
on latency as well as to get feedbacks from a broader range of developers.
If there are no serious problems, EA will be used by #42465 for `mutating_arrayfreeze`
optimization for `ImmutableArray` construction.

This commit simply defines EA inside Julia base compiler and enables the
existing test suite with it. The plan is to validate EA's accuracy and
correctness and to check the latency impact by running EA before the
existing SROA pass and checking if it can detect all objects eliminated
by the SROA pass as "SROA-eliminatable".
aviatesk added a commit that referenced this pull request Jan 25, 2022
This commit ports [EscapeAnalysis.jl](https://github.com/aviatesk/EscapeAnalysis.jl) into Julia base.
You can find the documentation of this escape analysis at [this GitHub page](https://aviatesk.github.io/EscapeAnalysis.jl/dev/)[^1].

[^1]: The same documentation will be included into Julia's developer
      documentation by this commit.

This escape analysis will hopefully be an enabling technology for various
memory-related optimizations at Julia's high level compilation pipeline.
Possible target optimization includes mutable ϕ-node aware SROA,
`mutating_arrayfreeze` optimization (#42465), stack allocation of mutables,
dead array elimination, finalizer elision and so on[^2].

[^2]: It would be also interesting if LLVM-level optimizations can consume
      some IPO information derived by this escape analysis to broaden
      optimization possibilities.

The primary motivation for porting EA in this PR is to check its impact
on latency as well as to get feedbacks from a broader range of developers.
If there are no serious problems, EA will be used by #42465 for `mutating_arrayfreeze`
optimization for `ImmutableArray` construction.

This commit simply defines EA inside Julia base compiler and enables the
existing test suite with it. The plan is to validate EA's accuracy and
correctness and to check the latency impact by running EA before the
existing SROA pass and checking if it can detect all objects eliminated
by the SROA pass as "SROA-eliminatable".
aviatesk added a commit that referenced this pull request Jan 26, 2022
This commit ports [EscapeAnalysis.jl](https://github.com/aviatesk/EscapeAnalysis.jl) into Julia base.
You can find the documentation of this escape analysis at [this GitHub page](https://aviatesk.github.io/EscapeAnalysis.jl/dev/)[^1].

[^1]: The same documentation will be included into Julia's developer
      documentation by this commit.

This escape analysis will hopefully be an enabling technology for various
memory-related optimizations at Julia's high level compilation pipeline.
Possible target optimization includes mutable ϕ-node aware SROA,
`mutating_arrayfreeze` optimization (#42465), stack allocation of mutables,
dead array elimination, finalizer elision and so on[^2].

[^2]: It would be also interesting if LLVM-level optimizations can consume
      some IPO information derived by this escape analysis to broaden
      optimization possibilities.

The primary motivation for porting EA in this PR is to check its impact
on latency as well as to get feedbacks from a broader range of developers.
If there are no serious problems, EA will be used by #42465 for `mutating_arrayfreeze`
optimization for `ImmutableArray` construction.

This commit simply defines EA inside Julia base compiler and enables the
existing test suite with it. The plan is to validate EA's accuracy and
correctness and to check the latency impact by running EA before the
existing SROA pass and checking if it can detect all objects eliminated
by the SROA pass as "SROA-eliminatable".
aviatesk added a commit that referenced this pull request Jan 27, 2022
This commit ports [EscapeAnalysis.jl](https://github.com/aviatesk/EscapeAnalysis.jl) into Julia base.
You can find the documentation of this escape analysis at [this GitHub page](https://aviatesk.github.io/EscapeAnalysis.jl/dev/)[^1].

[^1]: The same documentation will be included into Julia's developer
      documentation by this commit.

This escape analysis will hopefully be an enabling technology for various
memory-related optimizations at Julia's high level compilation pipeline.
Possible target optimization includes mutable ϕ-node aware SROA,
`mutating_arrayfreeze` optimization (#42465), stack allocation of mutables,
dead array elimination, finalizer elision and so on[^2].

[^2]: It would be also interesting if LLVM-level optimizations can consume
      some IPO information derived by this escape analysis to broaden
      optimization possibilities.

The primary motivation for porting EA in this PR is to check its impact
on latency as well as to get feedbacks from a broader range of developers.
If there are no serious problems, EA will be used by #42465 for `mutating_arrayfreeze`
optimization for `ImmutableArray` construction.

This commit simply defines EA inside Julia base compiler and enables the
existing test suite with it. The plan is to validate EA's accuracy and
correctness and to check the latency impact by running EA before the
existing SROA pass and checking if it can detect all objects eliminated
by the SROA pass as "SROA-eliminatable".
@ianatol ianatol marked this pull request as draft January 28, 2022 00:01
@ianatol
Copy link
Copy Markdown
Member Author

ianatol commented Jan 28, 2022

Setting this as a draft until #43800 is merged, since this relies on that and for now just has an outdated version to work internally.

aviatesk added a commit that referenced this pull request Jan 28, 2022
This commit ports [EscapeAnalysis.jl](https://github.com/aviatesk/EscapeAnalysis.jl) into Julia base.
You can find the documentation of this escape analysis at [this GitHub page](https://aviatesk.github.io/EscapeAnalysis.jl/dev/)[^1].

[^1]: The same documentation will be included into Julia's developer
      documentation by this commit.

This escape analysis will hopefully be an enabling technology for various
memory-related optimizations at Julia's high level compilation pipeline.
Possible target optimization includes mutable ϕ-node aware SROA,
`mutating_arrayfreeze` optimization (#42465), stack allocation of mutables,
dead array elimination, finalizer elision and so on[^2].

[^2]: It would be also interesting if LLVM-level optimizations can consume
      some IPO information derived by this escape analysis to broaden
      optimization possibilities.

The primary motivation for porting EA in this PR is to check its impact
on latency as well as to get feedbacks from a broader range of developers.
If there are no serious problems, EA will be used by #42465 for `mutating_arrayfreeze`
optimization for `ImmutableArray` construction.

This commit simply defines EA inside Julia base compiler and enables the
existing test suite with it. The plan is to validate EA's accuracy and
correctness and to check the latency impact by running EA before the
existing SROA pass and checking if it can detect all objects eliminated
by the SROA pass as "SROA-eliminatable".
aviatesk added a commit that referenced this pull request Feb 1, 2022
This commit ports [EscapeAnalysis.jl](https://github.com/aviatesk/EscapeAnalysis.jl) into Julia base.
You can find the documentation of this escape analysis at [this GitHub page](https://aviatesk.github.io/EscapeAnalysis.jl/dev/)[^1].

[^1]: The same documentation will be included into Julia's developer
      documentation by this commit.

This escape analysis will hopefully be an enabling technology for various
memory-related optimizations at Julia's high level compilation pipeline.
Possible target optimization includes mutable ϕ-node aware SROA,
`mutating_arrayfreeze` optimization (#42465), stack allocation of mutables,
dead array elimination, finalizer elision and so on[^2].

[^2]: It would be also interesting if LLVM-level optimizations can consume
      some IPO information derived by this escape analysis to broaden
      optimization possibilities.

The primary motivation for porting EA in this PR is to check its impact
on latency as well as to get feedbacks from a broader range of developers.
If there are no serious problems, EA will be used by #42465 for `mutating_arrayfreeze`
optimization for `ImmutableArray` construction.

This commit simply defines EA inside Julia base compiler and enables the
existing test suite with it. The plan is to validate EA's accuracy and
correctness and to check the latency impact by running EA before the
existing SROA pass and checking if it can detect all objects eliminated
by the SROA pass as "SROA-eliminatable".
aviatesk added a commit that referenced this pull request Feb 1, 2022
This commit ports [EscapeAnalysis.jl](https://github.com/aviatesk/EscapeAnalysis.jl) into Julia base.
You can find the documentation of this escape analysis at [this GitHub page](https://aviatesk.github.io/EscapeAnalysis.jl/dev/)[^1].

[^1]: The same documentation will be included into Julia's developer
      documentation by this commit.

This escape analysis will hopefully be an enabling technology for various
memory-related optimizations at Julia's high level compilation pipeline.
Possible target optimization includes mutable ϕ-node aware SROA,
`mutating_arrayfreeze` optimization (#42465), stack allocation of mutables,
dead array elimination, finalizer elision and so on[^2].

[^2]: It would be also interesting if LLVM-level optimizations can consume
      some IPO information derived by this escape analysis to broaden
      optimization possibilities.

The primary motivation for porting EA in this PR is to check its impact
on latency as well as to get feedbacks from a broader range of developers.
If there are no serious problems, EA will be used by #42465 for `mutating_arrayfreeze`
optimization for `ImmutableArray` construction.

This commit simply defines EA inside Julia base compiler and enables the
existing test suite with it. The plan is to validate EA's accuracy and
correctness and to check the latency impact by running EA before the
existing SROA pass and checking if it can detect all objects eliminated
by the SROA pass as "SROA-eliminatable".
aviatesk added a commit that referenced this pull request Feb 2, 2022
This commit ports [EscapeAnalysis.jl](https://github.com/aviatesk/EscapeAnalysis.jl) into Julia base.
You can find the documentation of this escape analysis at [this GitHub page](https://aviatesk.github.io/EscapeAnalysis.jl/dev/)[^1].

[^1]: The same documentation will be included into Julia's developer
      documentation by this commit.

This escape analysis will hopefully be an enabling technology for various
memory-related optimizations at Julia's high level compilation pipeline.
Possible target optimization includes mutable ϕ-node aware SROA,
`mutating_arrayfreeze` optimization (#42465), stack allocation of mutables,
dead array elimination, finalizer elision and so on[^2].

[^2]: It would be also interesting if LLVM-level optimizations can consume
      some IPO information derived by this escape analysis to broaden
      optimization possibilities.

The primary motivation for porting EA in this PR is to check its impact
on latency as well as to get feedbacks from a broader range of developers.
If there are no serious problems, EA will be used by #42465 for `mutating_arrayfreeze`
optimization for `ImmutableArray` construction.

This commit simply defines EA inside Julia base compiler and enables the
existing test suite with it. The plan is to validate EA's accuracy and
correctness and to check the latency impact by running EA before the
existing SROA pass and checking if it can detect all objects eliminated
by the SROA pass as "SROA-eliminatable".
aviatesk added a commit that referenced this pull request Feb 2, 2022
This commit ports [EscapeAnalysis.jl](https://github.com/aviatesk/EscapeAnalysis.jl) into Julia base.
You can find the documentation of this escape analysis at [this GitHub page](https://aviatesk.github.io/EscapeAnalysis.jl/dev/)[^1].

[^1]: The same documentation will be included into Julia's developer
      documentation by this commit.

This escape analysis will hopefully be an enabling technology for various
memory-related optimizations at Julia's high level compilation pipeline.
Possible target optimization includes alias aware SROA (#43888),
array SROA (#43909), `mutating_arrayfreeze` optimization (#42465),
stack allocation of mutables, finalizer elision and so on[^2].

[^2]: It would be also interesting if LLVM-level optimizations can consume
      IPO information derived by this escape analysis to broaden
      optimization possibilities.

The primary motivation for porting EA in this PR is to check its impact
on latency as well as to get feedbacks from a broader range of developers.
The plan is that we first introduce EA in this commit, and then merge the
depending PRs built on top of this commit like #43888, #43909 and #42465

This commit simply defines and runs EA inside Julia base compiler and
enables the existing test suite with it. In this commit, we just run EA
before inlining to generate IPO cache. The depending PRs, EA will be
reran after inlining to be used for various local optimizations.
aviatesk added a commit that referenced this pull request Feb 2, 2022
This commit ports [EscapeAnalysis.jl](https://github.com/aviatesk/EscapeAnalysis.jl) into Julia base.
You can find the documentation of this escape analysis at [this GitHub page](https://aviatesk.github.io/EscapeAnalysis.jl/dev/)[^1].

[^1]: The same documentation will be included into Julia's developer
      documentation by this commit.

This escape analysis will hopefully be an enabling technology for various
memory-related optimizations at Julia's high level compilation pipeline.
Possible target optimization includes alias aware SROA (#43888),
array SROA (#43909), `mutating_arrayfreeze` optimization (#42465),
stack allocation of mutables, finalizer elision and so on[^2].

[^2]: It would be also interesting if LLVM-level optimizations can consume
      IPO information derived by this escape analysis to broaden
      optimization possibilities.

The primary motivation for porting EA in this PR is to check its impact
on latency as well as to get feedbacks from a broader range of developers.
The plan is that we first introduce EA in this commit, and then merge the
depending PRs built on top of this commit like #43888, #43909 and #42465

This commit simply defines and runs EA inside Julia base compiler and
enables the existing test suite with it. In this commit, we just run EA
before inlining to generate IPO cache. The depending PRs, EA will be
reran after inlining to be used for various local optimizations.
aviatesk added a commit that referenced this pull request Feb 2, 2022
This commit ports [EscapeAnalysis.jl](https://github.com/aviatesk/EscapeAnalysis.jl) into Julia base.
You can find the documentation of this escape analysis at [this GitHub page](https://aviatesk.github.io/EscapeAnalysis.jl/dev/)[^1].

[^1]: The same documentation will be included into Julia's developer
      documentation by this commit.

This escape analysis will hopefully be an enabling technology for various
memory-related optimizations at Julia's high level compilation pipeline.
Possible target optimization includes alias aware SROA (#43888),
array SROA (#43909), `mutating_arrayfreeze` optimization (#42465),
stack allocation of mutables, finalizer elision and so on[^2].

[^2]: It would be also interesting if LLVM-level optimizations can consume
      IPO information derived by this escape analysis to broaden
      optimization possibilities.

The primary motivation for porting EA in this PR is to check its impact
on latency as well as to get feedbacks from a broader range of developers.
The plan is that we first introduce EA in this commit, and then merge the
depending PRs built on top of this commit like #43888, #43909 and #42465

This commit simply defines and runs EA inside Julia base compiler and
enables the existing test suite with it. In this commit, we just run EA
before inlining to generate IPO cache. The depending PRs, EA will be
reran after inlining to be used for various local optimizations.
aviatesk added a commit that referenced this pull request Feb 2, 2022
This commit ports [EscapeAnalysis.jl](https://github.com/aviatesk/EscapeAnalysis.jl) into Julia base.
You can find the documentation of this escape analysis at [this GitHub page](https://aviatesk.github.io/EscapeAnalysis.jl/dev/)[^1].

[^1]: The same documentation will be included into Julia's developer
      documentation by this commit.

This escape analysis will hopefully be an enabling technology for various
memory-related optimizations at Julia's high level compilation pipeline.
Possible target optimization includes alias aware SROA (#43888),
array SROA (#43909), `mutating_arrayfreeze` optimization (#42465),
stack allocation of mutables, finalizer elision and so on[^2].

[^2]: It would be also interesting if LLVM-level optimizations can consume
      IPO information derived by this escape analysis to broaden
      optimization possibilities.

The primary motivation for porting EA in this PR is to check its impact
on latency as well as to get feedbacks from a broader range of developers.
The plan is that we first introduce EA in this commit, and then merge the
depending PRs built on top of this commit like #43888, #43909 and #42465

This commit simply defines and runs EA inside Julia base compiler and
enables the existing test suite with it. In this commit, we just run EA
before inlining to generate IPO cache. The depending PRs, EA will be
reran after inlining to be used for various local optimizations.
aviatesk added a commit that referenced this pull request Feb 3, 2022
This commit ports [EscapeAnalysis.jl](https://github.com/aviatesk/EscapeAnalysis.jl) into Julia base.
You can find the documentation of this escape analysis at [this GitHub page](https://aviatesk.github.io/EscapeAnalysis.jl/dev/)[^1].

[^1]: The same documentation will be included into Julia's developer
      documentation by this commit.

This escape analysis will hopefully be an enabling technology for various
memory-related optimizations at Julia's high level compilation pipeline.
Possible target optimization includes alias aware SROA (#43888),
array SROA (#43909), `mutating_arrayfreeze` optimization (#42465),
stack allocation of mutables, finalizer elision and so on[^2].

[^2]: It would be also interesting if LLVM-level optimizations can consume
      IPO information derived by this escape analysis to broaden
      optimization possibilities.

The primary motivation for porting EA in this PR is to check its impact
on latency as well as to get feedbacks from a broader range of developers.
The plan is that we first introduce EA in this commit, and then merge the
depending PRs built on top of this commit like #43888, #43909 and #42465

This commit simply defines and runs EA inside Julia base compiler and
enables the existing test suite with it. In this commit, we just run EA
before inlining to generate IPO cache. The depending PRs, EA will be
reran after inlining to be used for various local optimizations.
@ianatol
Copy link
Copy Markdown
Member Author

ianatol commented Feb 28, 2022

Superseded by #44381

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arrays [a, r, r, a, y, s] compiler:optimizer Optimization passes (mostly in base/compiler/ssair/)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants