Fix bug in basic block generation

(JUMPIF ends a basic block)
This commit is contained in:
Ulf Norell 2019-06-03 10:30:25 +02:00
parent 05256eeb60
commit 80ed24a4f6

View File

@ -1361,7 +1361,7 @@ tweak_returns(['RETURN' | Code = [{'ABORT', _} | _]]) -> Code;
tweak_returns(Code) -> Code. tweak_returns(Code) -> Code.
%% -- Split basic blocks at CALL instructions -- %% -- Split basic blocks at CALL instructions --
%% Calls can only return to a new basic block. %% Calls can only return to a new basic block. Also splits at JUMPIF instructions.
split_calls({Ref, Code}) -> split_calls({Ref, Code}) ->
split_calls(Ref, Code, [], []). split_calls(Ref, Code, [], []).
@ -1370,7 +1370,8 @@ split_calls(Ref, [], Acc, Blocks) ->
lists:reverse([{Ref, lists:reverse(Acc)} | Blocks]); lists:reverse([{Ref, lists:reverse(Acc)} | Blocks]);
split_calls(Ref, [I | Code], Acc, Blocks) when element(1, I) == 'CALL'; split_calls(Ref, [I | Code], Acc, Blocks) when element(1, I) == 'CALL';
element(1, I) == 'CALL_R'; element(1, I) == 'CALL_R';
element(1, I) == 'CALL_GR' -> element(1, I) == 'CALL_GR';
element(1, I) == 'jumpif' ->
split_calls(make_ref(), Code, [], [{Ref, lists:reverse([I | Acc])} | Blocks]); split_calls(make_ref(), Code, [], [{Ref, lists:reverse([I | Acc])} | Blocks]);
split_calls(Ref, [I | Code], Acc, Blocks) -> split_calls(Ref, [I | Code], Acc, Blocks) ->
split_calls(Ref, Code, [I | Acc], Blocks). split_calls(Ref, Code, [I | Acc], Blocks).