Skip to content

Commit b13a8e9

Browse files
authored
Merge pull request #34915 from gottesmm/forwarding-silinstruction
[ownership] Centralize all info about SILInstruction forwarding in the SILInstruction class hierarchy itself.
2 parents 0992e77 + 09ae2ef commit b13a8e9

File tree

14 files changed

+400
-153
lines changed

14 files changed

+400
-153
lines changed

include/swift/Basic/InlineBitfield.h

+26
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,32 @@ namespace swift {
8181
LLVM_PACKED_END \
8282
static_assert(sizeof(T##Bitfield) <= 8, "Bitfield overflow")
8383

84+
/// Define a full bitfield for type 'T' that uses all of the remaining bits in
85+
/// the inline bitfield. We allow for 'T' to have a single generic parameter.
86+
///
87+
/// For optimal code gen, place naturally sized fields at the end, with the
88+
/// largest naturally sized field at the very end. For example:
89+
///
90+
/// SWIFT_INLINE_BITFIELD_FULL(Foo, Bar, 1+8+16,
91+
/// flag : 1,
92+
/// : NumPadBits, // pad the center, not the end
93+
/// x : 8,
94+
/// y : 16
95+
/// );
96+
///
97+
/// NOTE: All instances of Foo will access via the same bitfield entry even if
98+
/// they differ in the templated value!
99+
#define SWIFT_INLINE_BITFIELD_FULL_TEMPLATE(T, U, C, ...) \
100+
LLVM_PACKED_START \
101+
class T##Bitfield { \
102+
template <typename TTy> \
103+
friend class T; \
104+
enum { NumPadBits = 64 - (Num##U##Bits + (C)) }; \
105+
uint64_t : Num##U##Bits, __VA_ARGS__; \
106+
} T; \
107+
LLVM_PACKED_END \
108+
static_assert(sizeof(T##Bitfield) <= 8, "Bitfield overflow")
109+
84110
/// Define an empty bitfield for type 'T'.
85111
#define SWIFT_INLINE_BITFIELD_EMPTY(T, U) \
86112
enum { Num##T##Bits = Num##U##Bits }

include/swift/SIL/OwnershipUtils.h

+14-20
Original file line numberDiff line numberDiff line change
@@ -32,33 +32,22 @@ class DeadEndBlocks;
3232
/// Returns true if v is an address or trivial.
3333
bool isValueAddressOrTrivial(SILValue v);
3434

35-
/// These operations forward both owned and guaranteed ownership.
36-
bool isOwnershipForwardingValueKind(SILNodeKind kind);
37-
38-
/// Is this an operand that can forward both owned and guaranteed ownership
39-
/// kinds.
35+
/// Is this an operand that can forward both owned and guaranteed ownership into
36+
/// one of the operand's owner instruction's result.
4037
bool isOwnershipForwardingUse(Operand *op);
4138

42-
/// Is this an operand that forwards guaranteed ownership from its value to a
43-
/// result of the using instruction.
39+
/// Is this an operand that can forward guaranteed ownership into one of the
40+
/// operand's owner instruction's result.
4441
bool isGuaranteedForwardingUse(Operand *op);
4542

46-
/// These operations forward guaranteed ownership, but don't necessarily forward
47-
/// owned values.
48-
bool isGuaranteedForwardingValueKind(SILNodeKind kind);
43+
/// Is this an operand that can forward owned ownership into one of the
44+
/// operand's owner instruction's result.
45+
bool isOwnedForwardingUse(Operand *use);
4946

50-
/// Is this a value that is the result of an operation that forwards owned
51-
/// ownership.
47+
/// Is this a value that is the result of an instruction that forwards
48+
/// guaranteed ownership from one of its operands.
5249
bool isGuaranteedForwardingValue(SILValue value);
5350

54-
/// Is this a node kind that can forward owned ownership, but may not be able to
55-
/// forward guaranteed ownership.
56-
bool isOwnedForwardingValueKind(SILNodeKind kind);
57-
58-
/// Does this operand 'forward' owned ownership, but may not be able to forward
59-
/// guaranteed ownership.
60-
bool isOwnedForwardingUse(Operand *use);
61-
6251
/// Is this value the result of an instruction that 'forward's owned ownership,
6352
/// but may not be able to forward guaranteed ownership.
6453
///
@@ -76,6 +65,11 @@ class ForwardingOperand {
7665
static Optional<ForwardingOperand> get(Operand *use);
7766

7867
Operand *getUse() const { return use; }
68+
OwnershipConstraint getOwnershipConstraint() const {
69+
// We use a force unwrap since a ForwardingOperand should always have an
70+
// ownership constraint.
71+
return *use->getOwnershipConstraint();
72+
}
7973
ValueOwnershipKind getOwnershipKind() const;
8074
void setOwnershipKind(ValueOwnershipKind newKind) const;
8175
void replaceOwnershipKind(ValueOwnershipKind oldKind,

0 commit comments

Comments
 (0)