Skip to content

Commit 64ba6fd

Browse files
committed
SIL: simplify the SILNode inline bitfields.
The use of the SWIFT_INLINE_BITFIELD macros in SILNode were a constant source of confusion and bugs. With this refactoring I tried to simplify the definition of "shared fields" in SILNode, SILValue and SILInstruction classes: * Move `kind`, `locationKindAndFlags` and the 32-bit fields out of the 64-bitfield into their own member variables. This avoids _a lot_ of manual bit position computations. * Now we have two separate "shared fields": an 8-bit field (e.g. for boolean flags) and a 32-bit field (e.g. for indices, which can potentially get large). Both fields can be used independently. Also, they are not "bit fields" per se. Instructions can use the field e.g. as a `bool`, `uint32_t`, or - if multiple flags are to be stored - as a packed bit field. * With these two separate fields, we don't have the need for defining bitfields both in a base class _and_ in a derived value/instruction class. We can get rid of the complex logic which handles such cases. Just keep a check to catch accidental overlaps of fields in base and derived classes. * Still use preprocessor macros for the implementation, but much simpler ones than before. * Add documentation.
1 parent f4c26c3 commit 64ba6fd

File tree

7 files changed

+486
-631
lines changed

7 files changed

+486
-631
lines changed

include/swift/SIL/SILArgument.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class SILArgument : public ValueBase {
6868

6969
SILBasicBlock *parentBlock;
7070
const ValueDecl *decl;
71+
USE_SHARED_UINT8;
7172

7273
protected:
7374
SILArgument(ValueKind subClassKind, SILBasicBlock *inputParentBlock,
@@ -81,19 +82,19 @@ class SILArgument : public ValueBase {
8182
const ValueDecl *inputDecl = nullptr)
8283
: ValueBase(subClassKind, type),
8384
parentBlock(nullptr), decl(inputDecl) {
84-
Bits.SILArgument.VOKind = static_cast<unsigned>(ownershipKind);
85+
sharedUInt8().SILArgument.valueOwnershipKind = uint8_t(ownershipKind);
8586
}
8687

8788
public:
8889
void operator=(const SILArgument &) = delete;
8990
void operator delete(void *, size_t) = delete;
9091

9192
ValueOwnershipKind getOwnershipKind() const {
92-
return static_cast<ValueOwnershipKind>(Bits.SILArgument.VOKind);
93+
return ValueOwnershipKind(sharedUInt8().SILArgument.valueOwnershipKind);
9394
}
9495

9596
void setOwnershipKind(ValueOwnershipKind newKind) {
96-
Bits.SILArgument.VOKind = static_cast<unsigned>(newKind);
97+
sharedUInt8().SILArgument.valueOwnershipKind = uint8_t(newKind);
9798
}
9899

99100
SILBasicBlock *getParent() const { return parentBlock; }

0 commit comments

Comments
 (0)