aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler/src/beam_a.erl
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2018-01-25 10:09:59 +0100
committerBjörn Gustavsson <[email protected]>2018-01-26 15:57:57 +0100
commitfbcff5a137e37edd80aca9c5fe18ce6880648169 (patch)
treefb846d82599a3e52230f1b028b59f63cb0dd09ec /lib/compiler/src/beam_a.erl
parent5b58d9e2d3262160b7f10d8b6798f89f0618c5f6 (diff)
downloadotp-fbcff5a137e37edd80aca9c5fe18ce6880648169.tar.gz
otp-fbcff5a137e37edd80aca9c5fe18ce6880648169.tar.bz2
otp-fbcff5a137e37edd80aca9c5fe18ce6880648169.zip
Eliminate get_list/3 internally in the compiler
Instructions that produce more than one result complicate optimizations. get_list/3 is one of two instructions that produce multiple results (get_map_elements/3 is the other). Introduce the get_hd/2 and get_tl/2 instructions that return the head and tail of a cons cell, respectively, and use it internally in all optimization passes. For efficiency, we still want to use get_list/3 if both head and tail are used, so we will translate matching pairs of get_hd and get_tl back to get_list instructions.
Diffstat (limited to 'lib/compiler/src/beam_a.erl')
-rw-r--r--lib/compiler/src/beam_a.erl8
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/compiler/src/beam_a.erl b/lib/compiler/src/beam_a.erl
index 7df2edd714..91acb19971 100644
--- a/lib/compiler/src/beam_a.erl
+++ b/lib/compiler/src/beam_a.erl
@@ -61,6 +61,14 @@ rename_instrs([{'%live',_}|Is]) ->
%% Ignore old type of live annotation. Only happens when compiling
%% from very old .S files.
rename_instrs(Is);
+rename_instrs([{get_list,S,D1,D2}|Is]) ->
+ %% Only happens when compiling from old .S files.
+ if
+ D1 =:= S ->
+ [{get_tl,S,D2},{get_hd,S,D1}|rename_instrs(Is)];
+ true ->
+ [{get_hd,S,D1},{get_tl,S,D2}|rename_instrs(Is)]
+ end;
rename_instrs([I|Is]) ->
[rename_instr(I)|rename_instrs(Is)];
rename_instrs([]) -> [].