From 5ebd2c4e0a12af57287b0bba390fb226c7209fb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Mon, 10 Sep 2018 15:01:05 +0200 Subject: beam_ssa: Add trim_unreachable/1 Add trim_unreachable/1 to remove unreachable blocks and adjust phi nodes. --- lib/compiler/src/beam_ssa.erl | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'lib') diff --git a/lib/compiler/src/beam_ssa.erl b/lib/compiler/src/beam_ssa.erl index 75d567ff87..b0818b1092 100644 --- a/lib/compiler/src/beam_ssa.erl +++ b/lib/compiler/src/beam_ssa.erl @@ -33,6 +33,7 @@ rpo/1,rpo/2, split_blocks/3, successors/1,successors/2, + trim_unreachable/1, update_phi_labels/4,used/1]). -export_type([b_module/0,b_function/0,b_blk/0,b_set/0, @@ -448,6 +449,19 @@ split_blocks(P, Blocks, Count) -> Ls = beam_ssa:rpo(Blocks), split_blocks_1(Ls, P, Blocks, Count). +-spec trim_unreachable(Blocks0) -> Blocks when + Blocks0 :: block_map(), + Blocks :: block_map(). + +%% trim_unreachable(Blocks0) -> Blocks. +%% Remove all unreachable blocks. Adjust all phi nodes so +%% they don't refer to blocks that has been removed or no +%% no longer branch to the phi node in question. + +trim_unreachable(Blocks) -> + %% Could perhaps be optimized if there is any need. + maps:from_list(linearize(Blocks)). + %% update_phi_labels([BlockLabel], Old, New, Blocks0) -> Blocks. %% In the given blocks, replace label Old in with New in all %% phi nodes. This is useful after merging or splitting -- cgit v1.2.3