diff options
author | Björn Gustavsson <[email protected]> | 2019-05-14 10:11:31 +0200 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2019-05-22 10:47:22 +0200 |
commit | 18dc9a8099d1ad8f52b9db7bd251bcbfd632ce5e (patch) | |
tree | cb7d2a6d3620c53cc098a2cb863bd3adf9427d0c /lib/compiler/src/beam_validator.erl | |
parent | fe2b1323a3866ed0a9712e9d12e1f8f84793ec47 (diff) | |
download | otp-18dc9a8099d1ad8f52b9db7bd251bcbfd632ce5e.tar.gz otp-18dc9a8099d1ad8f52b9db7bd251bcbfd632ce5e.tar.bz2 otp-18dc9a8099d1ad8f52b9db7bd251bcbfd632ce5e.zip |
Make the swap instruction known to the compiler
BEAM has had a `swap` instruction for several releases, but it was not
known to the compiler. The loader would translate a sequence of three
`move` instructions to the `swap` instructions, but only when it was
possible to determine that it would be safe.
By making `swap` known to the compiler, it can be applied in more
situations since it is easier for the compiler than for the loader
to ensure that the usage is safe, and the loader shenanigans can be
eliminated.
Diffstat (limited to 'lib/compiler/src/beam_validator.erl')
-rw-r--r-- | lib/compiler/src/beam_validator.erl | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/compiler/src/beam_validator.erl b/lib/compiler/src/beam_validator.erl index 09a5a6c104..b4acebbfae 100644 --- a/lib/compiler/src/beam_validator.erl +++ b/lib/compiler/src/beam_validator.erl @@ -392,6 +392,23 @@ valfun_1(build_stacktrace=I, Vst) -> call(I, 1, Vst); valfun_1({move,Src,Dst}, Vst) -> assign(Src, Dst, Vst); +valfun_1({swap,RegA,RegB}, Vst0) -> + assert_movable(RegA, Vst0), + assert_movable(RegB, Vst0), + + %% We don't expect fragile registers to be swapped. + %% Therefore, we can conservatively make both registers + %% fragile if one of the register is fragile instead of + %% swapping the fragility of the registers. + Sources = [RegA,RegB], + Vst1 = propagate_fragility(RegA, Sources, Vst0), + Vst2 = propagate_fragility(RegB, Sources, Vst1), + + %% Swap the value references. + VrefA = get_reg_vref(RegA, Vst2), + VrefB = get_reg_vref(RegB, Vst2), + Vst = set_reg_vref(VrefB, RegA, Vst2), + set_reg_vref(VrefA, RegB, Vst); valfun_1({fmove,Src,{fr,_}=Dst}, Vst) -> assert_type(float, Src, Vst), set_freg(Dst, Vst); |