Revision bf97c297435104ff8a3ed265757874e2f63268e9 authored by Shuhei Kadowaki on 21 December 2021, 17:05:57 UTC, committed by Shuhei Kadowaki on 08 January 2022, 04:57:06 UTC
This commit allows elimination of mutable φ-node (and its predecessor mutables allocations). As an contrived example, it allows this `mutable_ϕ_elim(::String, ::Vector{String})` to run without any allocations at all: ```julia function mutable_ϕ_elim(x, xs) r = Ref(x) for x in xs r = Ref(x) end return r[] end let xs = String[string(gensym()) for _ in 1:100] mutable_ϕ_elim("init", xs) @test @allocated(mutable_ϕ_elim("init", xs)) == 0 end ``` This mutable ϕ-node elimination is still limited though. Most notably, the current implementation doesn't work if a mutable allocation forms multiple ϕ-nodes, since we check allocation eliminability (i.e. escapability) by counting usages counts and thus it's hard to reason about multiple ϕ-nodes at a time. For example, currently mutable allocations involved in cases like below will still not be eliminated: ```julia code_typed((Bool,String,String),) do cond, x, y if cond ϕ2 = ϕ1 = Ref(x) else ϕ2 = ϕ1 = Ref(y) end ϕ1[], ϕ2[] end \# more realistic example mutable struct Point{T} x::T y::T end add(a::Point, b::Point) = Point(a.x + b.x, a.y + b.y) function compute(a::Point{ComplexF64}, b::Point{ComplexF64}) for i in 0:(100000000-1) a = add(add(a, b), b) end a.x, a.y end ``` I'd say this limitation should be addressed by first introducing a better abstraction for reasoning escape information. More specifically, I'd like introduce EscapeAnalysis.jl into Julia base first, and then gradually adapt it to improve our SROA pass, since EA will allow us to reason about all escape information imposed on whatever object more easily and should help us get rid of the complexities of our current SROA implementation. For now, I'd like to get in this enhancement even though it has the limitation elaborated above, as far as this commit doesn't introduce latency problem (which is unlikely).
1 parent a9c6daf
File | Mode | Size |
---|---|---|
.buildkite | ||
.devcontainer | ||
.github | ||
base | ||
cli | ||
contrib | ||
deps | ||
doc | ||
etc | ||
src | ||
stdlib | ||
test | ||
.clang-format | -rw-r--r-- | 3.3 KB |
.codecov.yml | -rw-r--r-- | 52 bytes |
.gitattributes | -rw-r--r-- | 65 bytes |
.gitignore | -rw-r--r-- | 433 bytes |
.mailmap | -rw-r--r-- | 11.1 KB |
CITATION.bib | -rw-r--r-- | 513 bytes |
CITATION.cff | -rw-r--r-- | 942 bytes |
CONTRIBUTING.md | -rw-r--r-- | 22.5 KB |
HISTORY.md | -rw-r--r-- | 333.2 KB |
LICENSE.md | -rw-r--r-- | 1.3 KB |
Make.inc | -rw-r--r-- | 49.3 KB |
Makefile | -rw-r--r-- | 25.6 KB |
NEWS.md | -rw-r--r-- | 9.9 KB |
README.md | -rw-r--r-- | 7.4 KB |
THIRDPARTY.md | -rw-r--r-- | 3.7 KB |
VERSION | -rw-r--r-- | 10 bytes |
julia.spdx.json | -rw-r--r-- | 35.0 KB |
sysimage.mk | -rw-r--r-- | 4.0 KB |
Computing file changes ...