diff options
author | Björn Gustavsson <[email protected]> | 2017-12-13 10:10:44 +0100 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2017-12-15 12:31:28 +0100 |
commit | 6a80fec6fdb754b82a9c92804802797195431729 (patch) | |
tree | 681a8ebbdfeb342d2d2a31119de179092fc1b7ea /lib/compiler/src/beam_utils.erl | |
parent | 46400bc3f3bf9ab5066723bd463989557bf2aabf (diff) | |
download | otp-6a80fec6fdb754b82a9c92804802797195431729.tar.gz otp-6a80fec6fdb754b82a9c92804802797195431729.tar.bz2 otp-6a80fec6fdb754b82a9c92804802797195431729.zip |
beam_utils: Add usage/3
To avoid having to call both is_killed/3 and is_not_used/3,
add usage/3 to answer both questions in one call.
Diffstat (limited to 'lib/compiler/src/beam_utils.erl')
-rw-r--r-- | lib/compiler/src/beam_utils.erl | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/lib/compiler/src/beam_utils.erl b/lib/compiler/src/beam_utils.erl index 1195a6b560..dcdbaa0bab 100644 --- a/lib/compiler/src/beam_utils.erl +++ b/lib/compiler/src/beam_utils.erl @@ -22,7 +22,7 @@ -module(beam_utils). -export([is_killed_block/2,is_killed/3,is_killed_at/3, - is_not_used/3, + is_not_used/3,usage/3, empty_label_index/0,index_label/3,index_labels/1,replace_labels/4, code_at/2,bif_to_test/3,is_pure_test/1, live_opt/1,delete_live_annos/1,combine_heap_needs/2, @@ -62,6 +62,23 @@ {lbl :: code_index(), %Label to code index. res :: result_cache()}). %Result cache for each label. +%% usage(Register, [Instruction], State) -> killed|not_used|used. +%% Determine the usage of Register in the instruction sequence. +%% The return value is one of: +%% +%% killed - The register is not used in any way. +%% not_used - The register is referenced only by an allocating instruction +%% (the actual value does not matter). +%% used - The register is used (its value do matter). + +-spec usage(beam_asm:reg(), [instruction()], code_index()) -> + 'killed' | 'not_used' | 'used'. + +usage(R, Is, D) -> + St = #live{lbl=D,res=gb_trees:empty()}, + {Usage,_} = check_liveness(R, Is, St), + Usage. + %% is_killed_block(Register, [Instruction]) -> true|false %% Determine whether a register is killed by the instruction sequence inside |