Skip to content

Commit ba6b019

Browse files
committed
[AddressLowering] NFC: Comment projection chains.
Describe what all chains look like by analyzing the four theoretically possible kinds of links--only three of the four are actually possible.
1 parent 053cc77 commit ba6b019

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

lib/SILOptimizer/Mandatory/AddressLowering.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,53 @@ namespace swift {
6969
/// a place-holder value and updating the map entry. This works because the
7070
/// value storage map holds no direct references to any SIL entities, such as
7171
/// Operands or SILValues.
72+
///
73+
/// An opaque value's storage will be a def-projection if it's the result of
74+
/// some disaggregation. If %o = disaggregate %p then %o's storage will be
75+
/// a def-projection out of %p's storage.
76+
///
77+
/// An opaque value's storage _may_ be a use-projection if it's an operand of
78+
/// some aggregation. If %p = aggregate %o, then %o's storage may be a
79+
/// use-projection out of %p's storage.
80+
///
81+
/// Projections naturally form chains. A value's storage may be a projection
82+
/// out of the storage of some other value's storage which is itself a
83+
/// projection out of a third value's storage. This can happen in three ways:
84+
///
85+
/// (1) %o -def-> %p -def-> %q
86+
/// %p = disaggregate %q
87+
/// %o = disaggregate %p
88+
/// (2) %o -use-> %p -use-> %q
89+
/// %p = aggregate %o
90+
/// %q = aggregate %p
91+
/// (3) %o -def-> %p -use-> %q
92+
/// %p = ...
93+
/// cond_br left, right
94+
/// left:
95+
/// %o = disaggregate %p
96+
/// right:
97+
/// %q = aggregate %p
98+
///
99+
/// Branching like this is actually necessary. It's not legal to aggregate
100+
/// guaranteed opaque values since doing so changes representation which
101+
/// implies a copy.
102+
///
103+
/// It is NOT possible to have links like
104+
///
105+
/// (4) %o -use-> %p -def-> %q
106+
///
107+
/// The reason is that the links mean contradictory things:
108+
/// %o -use-> %p means %p = aggregate %o
109+
/// %p -def-> %q means %p = disaggregate %q
110+
/// There is no overlap between the "aggregate" and the "disaggregate"
111+
/// opcodes.
112+
///
113+
/// This means that any chain of projections looks like
114+
///
115+
/// %d_0 -def-> ... -def-> %d_N -use-> %u_0 -use-> ... -use-> %u_M
116+
///
117+
/// a sequence (possibly empty) of def projections followed by a sequence
118+
/// (possibly emtpy) of use projections [projection_chain_structure].
72119
struct ValueStorage {
73120
enum : uint32_t { InvalidID = uint32_t(~0) };
74121
enum : uint16_t { InvalidOper = uint16_t(~0) };

0 commit comments

Comments
 (0)