aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler/src/v3_kernel.erl
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2011-12-28 12:26:08 +0100
committerBjörn Gustavsson <[email protected]>2012-01-11 08:39:57 +0100
commit74c893f90ffc35c52cb4f9c62130a5b05aed5135 (patch)
tree527fbad6cb7d743b52906ca0b142d8ddd92d79e2 /lib/compiler/src/v3_kernel.erl
parent6c9fbc473bb7b5a98f0945678bc47bde39a75e8d (diff)
downloadotp-74c893f90ffc35c52cb4f9c62130a5b05aed5135.tar.gz
otp-74c893f90ffc35c52cb4f9c62130a5b05aed5135.tar.bz2
otp-74c893f90ffc35c52cb4f9c62130a5b05aed5135.zip
v3_codegen: Eliminate the special case of 'put' without destination
If we let v3_kernel make sure that a 'put' operation always has a destination register, the special case in v3_codegen is not needed.
Diffstat (limited to 'lib/compiler/src/v3_kernel.erl')
-rw-r--r--lib/compiler/src/v3_kernel.erl15
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/compiler/src/v3_kernel.erl b/lib/compiler/src/v3_kernel.erl
index 0638041950..67c5764abf 100644
--- a/lib/compiler/src/v3_kernel.erl
+++ b/lib/compiler/src/v3_kernel.erl
@@ -1546,11 +1546,12 @@ uguard_expr(#k_match{anno=A,vars=Vs,body=B0}, Rs, St0) ->
{B1,Bu,St1} = umatch(B0, Br, St0),
{#k_guard_match{anno=#k{us=Bu,ns=lit_list_vars(Rs),a=A},
vars=Vs,body=B1,ret=Rs},Bu,St1};
-uguard_expr(Lit, Rs, St) ->
+uguard_expr(Lit, Rs0, St0) ->
%% Transform literals to puts here.
Used = lit_vars(Lit),
+ {Rs,St1} = ensure_return_vars(Rs0, St0),
{#k_put{anno=#k{us=Used,ns=lit_list_vars(Rs),a=get_kanno(Lit)},
- arg=Lit,ret=Rs},Used,St}.
+ arg=Lit,ret=Rs},Used,St1}.
%% uexpr(Expr, Break, State) -> {Expr,[UsedVar],State}.
%% Tag an expression with its used variables.
@@ -1670,12 +1671,13 @@ uexpr(#ifun{anno=A,vars=Vs,body=B0}, {break,Rs}, St0) ->
#k_int{val=Index},#k_int{val=Uniq}|Fvs],
ret=Rs},
Free,add_local_function(Fun, St)};
-uexpr(Lit, {break,Rs}, St) ->
+uexpr(Lit, {break,Rs0}, St0) ->
%% Transform literals to puts here.
%%ok = io:fwrite("uexpr ~w:~p~n", [?LINE,Lit]),
Used = lit_vars(Lit),
+ {Rs,St1} = ensure_return_vars(Rs0, St0),
{#k_put{anno=#k{us=Used,ns=lit_list_vars(Rs),a=get_kanno(Lit)},
- arg=Lit,ret=Rs},Used,St}.
+ arg=Lit,ret=Rs},Used,St1}.
add_local_function(_, #kern{funs=ignore}=St) -> St;
add_local_function(F, #kern{funs=Funs}=St) -> St#kern{funs=[F|Funs]}.
@@ -1732,6 +1734,11 @@ bif_returns(#k_internal{name=N,arity=Ar}, Rs, St0) ->
{Ns,St1} = new_vars(bif_vals(N, Ar) - length(Rs), St0),
{Rs ++ Ns,St1}.
+%% ensure_return_vars([Ret], State) -> {[Ret],State}.
+
+ensure_return_vars([], St) -> new_vars(1, St);
+ensure_return_vars([_]=Rs, St) -> {Rs,St}.
+
%% umatch(Match, Break, State) -> {Match,[UsedVar],State}.
%% Tag a match expression with its used variables.