aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler/src/beam_z.erl
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2012-09-05 12:38:45 +0200
committerBjörn Gustavsson <[email protected]>2012-10-10 15:37:49 +0200
commite199e2471a6468a1908638d1b9fb863ea39e4d0e (patch)
tree41a7c081e26843d0638783fcef753d1de9aaabab /lib/compiler/src/beam_z.erl
parent47d109fc4eda1288e8d21a31b603b3cfc300536a (diff)
downloadotp-e199e2471a6468a1908638d1b9fb863ea39e4d0e.tar.gz
otp-e199e2471a6468a1908638d1b9fb863ea39e4d0e.tar.bz2
otp-e199e2471a6468a1908638d1b9fb863ea39e4d0e.zip
Break apart tail-recursive call instructions
Somewhat reduce the code bloat by eliminating special cases.
Diffstat (limited to 'lib/compiler/src/beam_z.erl')
-rw-r--r--lib/compiler/src/beam_z.erl20
1 files changed, 17 insertions, 3 deletions
diff --git a/lib/compiler/src/beam_z.erl b/lib/compiler/src/beam_z.erl
index f45f7abf38..8c6b0c916d 100644
--- a/lib/compiler/src/beam_z.erl
+++ b/lib/compiler/src/beam_z.erl
@@ -29,7 +29,7 @@ module({Mod,Exp,Attr,Fs0,Lc}, _Opt) ->
function({function,Name,Arity,CLabel,Is0}) ->
try
- Is = [undo_rename(I) || I <- Is0],
+ Is = undo_renames(Is0),
{function,Name,Arity,CLabel,Is}
catch
Class:Error ->
@@ -38,6 +38,22 @@ function({function,Name,Arity,CLabel,Is0}) ->
erlang:raise(Class, Error, Stack)
end.
+undo_renames([{call_ext,2,send}|Is]) ->
+ [send|undo_renames(Is)];
+undo_renames([{apply,A},{deallocate,N},return|Is]) ->
+ [{apply_last,A,N}|undo_renames(Is)];
+undo_renames([{call,A,F},{deallocate,N},return|Is]) ->
+ [{call_last,A,F,N}|undo_renames(Is)];
+undo_renames([{call_ext,A,F},{deallocate,N},return|Is]) ->
+ [{call_ext_last,A,F,N}|undo_renames(Is)];
+undo_renames([{call,A,F},return|Is]) ->
+ [{call_only,A,F}|undo_renames(Is)];
+undo_renames([{call_ext,A,F},return|Is]) ->
+ [{call_ext_only,A,F}|undo_renames(Is)];
+undo_renames([I|Is]) ->
+ [undo_rename(I)|undo_renames(Is)];
+undo_renames([]) -> [].
+
undo_rename({bs_put,F,{I,U,Fl},[Sz,Src]}) ->
{I,F,Sz,U,Fl,Src};
undo_rename({bs_put,F,{I,Fl},[Src]}) ->
@@ -60,6 +76,4 @@ undo_rename({bs_init,_,bs_init_writable=I,_,_,_}) ->
I;
undo_rename({select,I,Reg,Fail,List}) ->
{I,Reg,Fail,{list,List}};
-undo_rename({call_ext,2,send}) ->
- send;
undo_rename(I) -> I.