aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler/src/beam_flatten.erl
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2018-09-01 10:57:33 +0200
committerBjörn Gustavsson <[email protected]>2018-09-03 10:47:24 +0200
commit47a2ff39ac75c69b41f90f05a63fd9a2e6c0b36a (patch)
treef6ac446058b62541b7ec14dfc28a21a06c5cbc7e /lib/compiler/src/beam_flatten.erl
parent31e7b5ab0b72acbbca649b99ade82bba145cc390 (diff)
downloadotp-47a2ff39ac75c69b41f90f05a63fd9a2e6c0b36a.tar.gz
otp-47a2ff39ac75c69b41f90f05a63fd9a2e6c0b36a.tar.bz2
otp-47a2ff39ac75c69b41f90f05a63fd9a2e6c0b36a.zip
Introduce a put_tuple2 instruction
Sometimes when building a tuple, there is no way to avoid an extra `move` instruction. Consider this code: make_tuple(A) -> {ok,A}. The corresponding BEAM code looks like this: {test_heap,3,1}. {put_tuple,2,{x,1}}. {put,{atom,ok}}. {put,{x,0}}. {move,{x,1},{x,0}}. return. To avoid overwriting the source register `{x,0}`, a `move` instruction is necessary. The problem doesn't exist when building a list: %% build_list(A) -> [A]. {test_heap,2,1}. {put_list,{x,0},nil,{x,0}}. return. Introduce a new `put_tuple2` instruction that builds a tuple in a single instruction, so that the `move` instruction can be eliminated: %% make_tuple(A) -> {ok,A}. {test_heap,3,1}. {put_tuple2,{x,0},{list,[{atom,ok},{x,0}]}}. return. Note that the BEAM loader already combines `put_tuple` and `put` instructions into an internal instruction similar to `put_tuple2`. Therefore the introduction of the new instruction will not speed up execution of tuple building itself, but it will be less work for the loader to load the new instruction.
Diffstat (limited to 'lib/compiler/src/beam_flatten.erl')
-rw-r--r--lib/compiler/src/beam_flatten.erl1
1 files changed, 1 insertions, 0 deletions
diff --git a/lib/compiler/src/beam_flatten.erl b/lib/compiler/src/beam_flatten.erl
index 9a1c5a1021..973d16a1bc 100644
--- a/lib/compiler/src/beam_flatten.erl
+++ b/lib/compiler/src/beam_flatten.erl
@@ -65,6 +65,7 @@ norm({set,[D],[S],move}) -> {move,S,D};
norm({set,[D],[S],fmove}) -> {fmove,S,D};
norm({set,[D],[S],fconv}) -> {fconv,S,D};
norm({set,[D],[S1,S2],put_list}) -> {put_list,S1,S2,D};
+norm({set,[D],Els,put_tuple2}) -> {put_tuple2,D,{list,Els}};
norm({set,[D],[],{put_tuple,A}}) -> {put_tuple,A,D};
norm({set,[],[S],put}) -> {put,S};
norm({set,[D],[S],{get_tuple_element,I}}) -> {get_tuple_element,S,I,D};