LocalRef is an optimization pass for the SSA IntermediateLanguage, invoked from SSASimplify.
Description
Implementation
Details and Notes
Moving a global ref
requires the Multi analysis, because a
global ref
can only be moved into a function that is executed at
most once.
Conversion of non-escaping ref
-s is structured in three phases:
-
analysis — a variable
r = Ref_ref x
escapes if-
r
is used in any context besidesRef_assign (r, _)
orRef_deref r
-
all uses
r
reachable from a (direct or indirect) call toThread_copyCurrent
are of the same flavor (eitherRef_assign
orRef_deref
); this also requires the Multi analysis.
-
-
transformation
-
rewrites
r = Ref_ref x
tor = x
-
rewrites
_ = Ref_assign (r, y)
tor = y
-
rewrites
z = Ref_deref r
toz = r
Note that the resulting program violates the SSA condition.
-
-
Restore — restore the SSA condition.