Skip to content

Commit 78f6793

Browse files
authored
Merge pull request #12612 from gottesmm/pr-ecca9752729a232b491c1343641f4e81a2a3262a
2 parents 5f2eb82 + 4c80c4d commit 78f6793

File tree

5 files changed

+25
-45
lines changed

5 files changed

+25
-45
lines changed

include/swift/SIL/SILInstruction.h

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -355,17 +355,6 @@ class SILInstruction
355355
return SILInstructionKind(SILNode::getKind());
356356
}
357357

358-
SILNode *getCanonicalSILNodeInObject() {
359-
assert(isRepresentativeSILNodeInObject() &&
360-
"the SILInstruction subobject is always canonical");
361-
return this;
362-
}
363-
const SILNode *getCanonicalSILNodeInObject() const {
364-
assert(isRepresentativeSILNodeInObject() &&
365-
"the SILInstruction subobject is always canonical");
366-
return this;
367-
}
368-
369358
const SILBasicBlock *getParent() const { return ParentBB; }
370359
SILBasicBlock *getParent() { return ParentBB; }
371360

@@ -687,17 +676,6 @@ class SingleValueInstruction : public SILInstruction, public ValueBase {
687676
return ValueBase::getKind();
688677
}
689678

690-
SILNode *getCanonicalSILNodeInObject() {
691-
assert(SILInstruction::isRepresentativeSILNodeInObject() &&
692-
"the SILInstruction subobject is always canonical");
693-
return static_cast<SILInstruction*>(this);
694-
}
695-
const SILNode *getCanonicalSILNodeInObject() const {
696-
assert(SILInstruction::isRepresentativeSILNodeInObject() &&
697-
"the SILInstruction subobject is always canonical");
698-
return static_cast<const SILInstruction*>(this);
699-
}
700-
701679
SingleValueInstruction *clone(SILInstruction *insertPt = nullptr) {
702680
return cast<SingleValueInstruction>(SILInstruction::clone(insertPt));
703681
}
@@ -771,16 +749,15 @@ class MultipleValueInstructionResult : public ValueBase {
771749
return const_cast<MultipleValueInstructionResult *>(this)->getParent();
772750
}
773751

774-
unsigned getIndex() const;
752+
unsigned getIndex() const {
753+
return unsigned((getSubclassData() >> IndexBitOffset) & IndexMask);
754+
}
775755

776756
/// Get the ownership kind assigned to this result by its parent.
777757
///
778758
/// This is stored in the bottom 3 bits of ValueBase's subclass data.
779759
ValueOwnershipKind getOwnershipKind() const;
780760

781-
SILNode *getCanonicalSILNodeInObject();
782-
const SILNode *getCanonicalSILNodeInObject() const;
783-
784761
static bool classof(const SILInstruction *) = delete;
785762
static bool classof(const SILUndef *) = delete;
786763
static bool classof(const SILArgument *) = delete;
@@ -906,6 +883,13 @@ class MultipleValueInstructionTrailingObjects
906883
if (!NumResults)
907884
return;
908885
auto *DataPtr = this->template getTrailingObjects<DerivedResult>();
886+
// We call the DerivedResult destructors to ensure that:
887+
//
888+
// 1. If our derived results have any stored data that need to be cleaned
889+
// up, we clean them up. *NOTE* Today, no results have this property.
890+
// 2. In ~ValueBase, we validate via an assert that a ValueBase no longer
891+
// has any uses when it is being destroyed. Rather than re-implement that in
892+
// result, we get that for free.
909893
for (unsigned i : range(NumResults))
910894
DataPtr[i].~DerivedResult();
911895
}

include/swift/SIL/SILNode.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ static_assert(unsigned(SILNodeKind::Last_SILNode) < (1 << NumSILNodeKindBits),
8181
/// These precautions only apply to SILNode* and not its subclasses.
8282
///
8383
/// - There may have multiple SILNode* values that refer to the same
84-
/// instruction. Data structures and algorithms that rely on
85-
/// uniqueness of a SILNode* should generally make sure that they're
86-
/// working with the canonical SILNode*; see getCanonicalSILNodeInObject().
84+
/// instruction. Data structures and algorithms that rely on uniqueness of a
85+
/// SILNode* should generally make sure that they're working with the
86+
/// representative SILNode*; see getRepresentativeSILNodeInObject().
8787
///
8888
/// - Do not use builtin C++ casts to downcast a SILNode*. A static_cast
8989
/// from SILNode* to SILInstruction* only works if the referenced
@@ -97,10 +97,12 @@ class alignas(8) SILNode {
9797
/// static assertion purposes.
9898
static constexpr unsigned NumTotalSILNodeBits = 64;
9999

100-
protected:
100+
private:
101101
static constexpr unsigned NumKindBits = NumSILNodeKindBits;
102102
static constexpr unsigned NumStorageLocBits = 1;
103103
static constexpr unsigned NumIsRepresentativeBits = 1;
104+
105+
protected:
104106
static constexpr unsigned NumSubclassDataBits =
105107
NumTotalSILNodeBits - NumKindBits - NumStorageLocBits -
106108
NumIsRepresentativeBits;
@@ -113,9 +115,9 @@ class alignas(8) SILNode {
113115
};
114116

115117
private:
116-
const unsigned Kind : NumKindBits;
117-
const unsigned StorageLoc : NumStorageLocBits;
118-
const unsigned IsRepresentativeNode : NumIsRepresentativeBits;
118+
const uint64_t Kind : NumKindBits;
119+
const uint64_t StorageLoc : NumStorageLocBits;
120+
const uint64_t IsRepresentativeNode : NumIsRepresentativeBits;
119121
uint64_t SubclassData : NumSubclassDataBits;
120122

121123
SILNodeStorageLocation getStorageLoc() const {
@@ -140,7 +142,7 @@ class alignas(8) SILNode {
140142

141143
public:
142144
/// Does the given kind of node inherit from multiple multiple SILNode base
143-
/// classes.
145+
/// classes?
144146
///
145147
/// This enables one to know if their is a diamond in the inheritence
146148
/// hierarchy for this SILNode.
@@ -151,10 +153,10 @@ class alignas(8) SILNode {
151153
kind <= SILNodeKind::Last_SingleValueInstruction;
152154
}
153155

154-
/// Is this SILNode the canonical SILNode subobject in this object?
156+
/// Is this SILNode the representative SILNode subobject in this object?
155157
bool isRepresentativeSILNodeInObject() const { return IsRepresentativeNode; }
156158

157-
/// Return a pointer to the canonical SILNode subobject in this object.
159+
/// Return a pointer to the representative SILNode subobject in this object.
158160
SILNode *getRepresentativeSILNodeInObject() {
159161
if (isRepresentativeSILNodeInObject())
160162
return this;
@@ -172,9 +174,7 @@ class alignas(8) SILNode {
172174
return SILNodeKind(Kind);
173175
}
174176

175-
/// Return the SILNodeKind of this node's canonical SILNode.
176-
///
177-
/// TODO: Find a better name for this.
177+
/// Return the SILNodeKind of this node's representative SILNode.
178178
SILNodeKind getKindOfRepresentativeSILNodeInObject() const {
179179
return getRepresentativeSILNodeInObject()->getKind();
180180
}

include/swift/SILOptimizer/Utils/SCCVisitor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ class SCCVisitor {
161161
}
162162

163163
void maybeDFS(SILInstruction *inst) {
164-
(void) maybeDFSCanonicalNode(inst->getCanonicalSILNodeInObject());
164+
(void) maybeDFSCanonicalNode(inst->getRepresentativeSILNodeInObject());
165165
}
166166

167167
/// Continue a DFS from the given node, finding the strongly

lib/SIL/SILInstruction.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,10 +1365,6 @@ void MultipleValueInstructionResult::setOwnershipKind(
13651365
setSubclassData(NewData);
13661366
}
13671367

1368-
unsigned MultipleValueInstructionResult::getIndex() const {
1369-
return unsigned((getSubclassData() >> IndexBitOffset) & IndexMask);
1370-
}
1371-
13721368
void MultipleValueInstructionResult::setIndex(unsigned NewIndex) {
13731369
// We only take the last 3 bytes for simplicity. If more bits are needed at
13741370
// some point, we can take 5 bits we are burning here and combine them with

lib/SILOptimizer/Analysis/MemoryBehavior.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ MemBehaviorKeyTy AliasAnalysis::toMemoryBehaviorKey(SILInstruction *V1,
357357
SILValue V2,
358358
RetainObserveKind M) {
359359
size_t idx1 =
360-
MemoryBehaviorNodeToIndex.getIndex(V1->getCanonicalSILNodeInObject());
360+
MemoryBehaviorNodeToIndex.getIndex(V1->getRepresentativeSILNodeInObject());
361361
assert(idx1 != std::numeric_limits<size_t>::max() &&
362362
"~0 index reserved for empty/tombstone keys");
363363
size_t idx2 = MemoryBehaviorNodeToIndex.getIndex(

0 commit comments

Comments
 (0)