Permalink
Browse files

It's not really SSA without a phi function, is it?

  • Loading branch information...
1 parent ce67bb2 commit c864772e5eeb6bb76496d4bd17728186967ff4d3 Tony Arcieri committed Dec 29, 2010
Showing with 10 additions and 7 deletions.
  1. +10 −7 src/compiler/reia_ssa.erl
View
17 src/compiler/reia_ssa.erl
@@ -25,13 +25,7 @@ transform_node(#bindings{
Patterns2 = reia_syntax:map_subtrees(fun transform_node/1, Patterns),
Exprs = reia_syntax:map_subtrees(fun transform_node/1, BindingExprs),
- UnsafeVariables = enumerate_unsafe_variables(FinalBinding, OutputBinding),
- Exprs2 = case UnsafeVariables of
- [] -> Exprs;
- _ -> annotate_return_value(Exprs, UnsafeVariables)
- end,
-
- #clause{line=Line, patterns=Patterns2, exprs=Exprs2};
+ #clause{line=Line, patterns=Patterns2, exprs=phi(Exprs, FinalBinding, OutputBinding)};
transform_node(#bindings{
node=#var{line=Line, name=Name}=Node,
@@ -56,6 +50,15 @@ transform_node(#bindings{node=Node}) ->
transform_node(Node) ->
reia_syntax:map_subtrees(fun transform_node/1, Node).
+% Look for version number discrepancies between various clauses and bind all
+% variables to uniform version numbers
+phi(Exprs, FinalBinding, OutputBinding) ->
+ UnsafeVariables = enumerate_unsafe_variables(FinalBinding, OutputBinding),
+ case UnsafeVariables of
+ [] -> Exprs;
+ _ -> annotate_return_value(Exprs, UnsafeVariables)
+ end.
+
% Generate the SSA name for a given variable, which takes the form name_version
ssa_name(Name, Version) ->
Name2 = lists:flatten(io_lib:format("~s_~w", [Name, Version])),

0 comments on commit c864772

Please sign in to comment.