aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler/src/beam_z.erl
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2016-04-07 12:43:06 +0200
committerBjörn Gustavsson <[email protected]>2016-04-08 10:28:42 +0200
commitab03678e87732407625150c202e177a85a025beb (patch)
tree881f543c0f7ca0cb099fe3eec71a7b37b0bf27be /lib/compiler/src/beam_z.erl
parent3c0f98c1b0e74eb58a4e4e82a3ec89dc7ecdb579 (diff)
downloadotp-ab03678e87732407625150c202e177a85a025beb.tar.gz
otp-ab03678e87732407625150c202e177a85a025beb.tar.bz2
otp-ab03678e87732407625150c202e177a85a025beb.zip
Remove unreachable code after 'raise' instructions
Remove the unreachable instructions after a 'raise' instruction (e.g. a 'jump' or 'deallocate', 'return') to decrease code size.
Diffstat (limited to 'lib/compiler/src/beam_z.erl')
-rw-r--r--lib/compiler/src/beam_z.erl12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/compiler/src/beam_z.erl b/lib/compiler/src/beam_z.erl
index 8381578b68..e44423d257 100644
--- a/lib/compiler/src/beam_z.erl
+++ b/lib/compiler/src/beam_z.erl
@@ -24,6 +24,8 @@
-export([module/2]).
+-import(lists, [dropwhile/2]).
+
module({Mod,Exp,Attr,Fs0,Lc}, _Opt) ->
Fs = [function(F) || F <- Fs0],
{ok,{Mod,Exp,Attr,Fs,Lc}}.
@@ -51,6 +53,16 @@ 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([{bif,raise,_,_,_}=I|Is0]) ->
+ %% A minor optimization. Done here because:
+ %% (1) beam_jump may move or share 'raise' instructions, and that
+ %% may confuse beam_validator.
+ %% (2) beam_trim cannot do its optimization if the 'deallocate'
+ %% instruction after 'raise' has been removed.
+ Is = dropwhile(fun({label,_}) -> false;
+ (_) -> true
+ end, Is0),
+ [I|undo_renames(Is)];
undo_renames([I|Is]) ->
[undo_rename(I)|undo_renames(Is)];
undo_renames([]) -> [].