sway icon indicating copy to clipboard operation
sway copied to clipboard

Remove constants as explicit SSA values from IR serialisation.

Open otrho opened this issue 3 years ago • 0 comments

When reading the printed IR it can get a bit verbose, as constants are always assigned to values. E.g.,

        v54 = const u64 3, !62
        v55 = const u64 2, !63
        v56 = const u64 1, !64
        v57 = call sum_test_13(v54, v55, v56), !54
        v58 = const u64 6, !65
        v59 = cmp eq v57 v58, !66

It's also a pain in the serialisation code itself. Each instruction which takes a value as an argument needs to be sure to print the argument first in case it's a constant, because constants themselves aren't instructions. E.g., https://github.com/FuelLabs/sway/blob/master/sway-ir/src/printer.rs#L510-L528

If we plan to remove non-copy-type constants as immediates (as even reference-type constants are still references) in #2819 it should be simpler and easier to read if we inline the constants, so the above code would become:

        v57 = call sum_test_13(const u64 3, const u64 2, const u64 1), !54
        v58 = cmp eq v57 const u64 6, !66

otrho avatar Sep 21 '22 06:09 otrho