Skip to content

Commit 9bd6fec

Browse files
committed
[SILOptimizer] Projection tree can vend users.
Added getUsers to ProjectionTree. The new method vands, via an out parameter, a set of all the users of all of the nodes in the projection tree that are themselves not in the projection tree by way of getNonProjUsers. Took this opportunity to tweak getNonProjUsers to vend a const ArrayRef rather than a SmallVector. Excerpted from @GottesM's #16756.
1 parent 70ad473 commit 9bd6fec

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

include/swift/SIL/Projection.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -757,9 +757,9 @@ class ProjectionTreeNode {
757757

758758
llvm::Optional<Projection> &getProjection() { return Proj; }
759759

760-
llvm::SmallVector<Operand *, 4> getNonProjUsers() const {
761-
return NonProjUsers;
762-
};
760+
const ArrayRef<Operand *> getNonProjUsers() const {
761+
return llvm::makeArrayRef(NonProjUsers);
762+
}
763763

764764
bool isLeaf() const { return ChildProjections.empty(); }
765765

@@ -960,7 +960,9 @@ class ProjectionTree {
960960
void
961961
replaceValueUsesWithLeafUses(SILBuilder &B, SILLocation Loc,
962962
llvm::SmallVectorImpl<SILValue> &Leafs);
963-
963+
964+
void getUsers(SmallPtrSetImpl<SILInstruction *> &users) const;
965+
964966
private:
965967
void createRoot(SILType BaseTy) {
966968
assert(ProjectionTreeNodes.empty() &&

lib/SIL/Projection.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,3 +1514,11 @@ replaceValueUsesWithLeafUses(SILBuilder &Builder, SILLocation Loc,
15141514
NewNodes.clear();
15151515
}
15161516
}
1517+
1518+
void ProjectionTree::getUsers(SmallPtrSetImpl<SILInstruction *> &users) const {
1519+
for (auto *node : ProjectionTreeNodes) {
1520+
for (auto *op : node->getNonProjUsers()) {
1521+
users.insert(op->getUser());
1522+
}
1523+
}
1524+
}

0 commit comments

Comments
 (0)