-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
compiler: Do strength reduction of the hint for update_record
Change the hint from `reuse` to `copy` when reusing clearly will not work. Extending this optimization to be module-global, and not just work at the function level, increases the time spent on this pass by a factor of between 4 and 5 and only triggers infrequently, and for example, never allows for additional destructive updates. For the moment this is considered good enough. Co-authored-by: Frej Drejhammar <[email protected]>
- Loading branch information
Showing
4 changed files
with
194 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
lib/compiler/test/beam_ssa_check_SUITE_data/no_reuse_hint.erl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
%% %CopyrightBegin% | ||
%% | ||
%% Copyright Ericsson AB 2024. All Rights Reserved. | ||
%% | ||
%% Licensed under the Apache License, Version 2.0 (the "License"); | ||
%% you may not use this file except in compliance with the License. | ||
%% You may obtain a copy of the License at | ||
%% | ||
%% http://www.apache.org/licenses/LICENSE-2.0 | ||
%% | ||
%% Unless required by applicable law or agreed to in writing, software | ||
%% distributed under the License is distributed on an "AS IS" BASIS, | ||
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
%% See the License for the specific language governing permissions and | ||
%% limitations under the License. | ||
%% | ||
%% %CopyrightEnd% | ||
%% | ||
%% This module tests the ssa_opt_no_reuse compiler pass. The test | ||
%% strategy is to ensure 100% coverage of the pass and to check for | ||
%% correct functioning for each of the different categories of | ||
%% operations inhibiting reuse: phis, known bifs, functions and | ||
%% instructions. | ||
%% | ||
|
||
-module(no_reuse_hint). | ||
|
||
-export([coverage0/0, | ||
inhibit_by_known_bif/2, | ||
inhibit_by_known_fun/1, | ||
inhibit_by_known_op/2, | ||
inhibit_by_map/4, | ||
inhibit_by_map_key/2, | ||
inhibit_by_map_value/2, | ||
inhibit_by_phi/1]). | ||
|
||
inhibit_by_known_bif({_}=X, Y) -> | ||
%ssa% (X, Y) when post_ssa_opt -> | ||
%ssa% Bif = bif:'+'(...), | ||
%ssa% R = update_record(copy, 1, X, 1, Bif), | ||
%ssa% ret(R). | ||
setelement(1, X, Y + 1). | ||
|
||
inhibit_by_known_fun(X) -> | ||
case X of | ||
{_} -> | ||
%ssa% (X) when post_ssa_opt -> | ||
%ssa% KnownFun = call(fun erlang:'++'/2, ...), | ||
%ssa% R = update_record(copy, 1, X, 1, KnownFun), | ||
%ssa% ret(R). | ||
setelement(1, X, e:f() ++ e:f()) | ||
end. | ||
|
||
inhibit_by_known_op({_, _}=X, Y) -> | ||
%ssa% (X, Y) when post_ssa_opt -> | ||
%ssa% Op = put_tuple(...), | ||
%ssa% R = update_record(copy, 2, X, 1, Op), | ||
%ssa% ret(R). | ||
setelement(1, X, {Y}). | ||
|
||
inhibit_by_map(A, B, C, {_}=D) -> | ||
%ssa% (A, B, C, D) when post_ssa_opt -> | ||
%ssa% Map1 = put_map(_, C, B, _), | ||
%ssa% Map = put_map(_, Map1, A, _), | ||
%ssa% R = update_record(copy, 1, D, 1, Map), | ||
%ssa% ret(R). | ||
setelement(1, D, C#{B => {e:f()}, A => e:f()}). | ||
|
||
inhibit_by_map_key({Y0}=Z, K) -> | ||
%ssa% (X, Y) when post_ssa_opt -> | ||
%ssa% Key = put_tuple(...), | ||
%ssa% Map = put_map(_, _, Key, value), | ||
%ssa% R = update_record(copy, 1, Z, 1, Map), | ||
%ssa% ret(R). | ||
Y = Y0#{{K} => value}, | ||
setelement(1, Z, Y). | ||
|
||
inhibit_by_map_value(X, {Y}=Z) -> | ||
%ssa% (X, Y) when post_ssa_opt -> | ||
%ssa% T = put_tuple(...), | ||
%ssa% Map = put_map(_, _, key, T), | ||
%ssa% R = update_record(copy, 1, Z, 1, Map), | ||
%ssa% ret(R). | ||
M = Y#{key => {X}}, | ||
setelement(1, Z, M). | ||
|
||
inhibit_by_phi({_}=X) -> | ||
%ssa% (X) when post_ssa_opt -> | ||
%ssa% Phi = phi(...), | ||
%ssa% R = update_record(copy, 1, X, 1, Phi), | ||
%ssa% ret(R). | ||
Y = case e:f() of | ||
a -> {e:f(), 1}; | ||
b -> {e:f(), 2} | ||
end, | ||
setelement(1, X, Y). | ||
|
||
%% | ||
%% Ensure full coverage of the functions in the ssa_opt_no_reuse pass. | ||
%% | ||
coverage0() -> | ||
erlang:send_after(500, self(), fun() -> ok end). |