Skip to content

Commit 70ad473

Browse files
committed
[SILOptimizer] ProjectionTree can vend leaf types.
Added getAllLeafTypes to ProjectionTree. The new method vends, via an out paramter, a vector containing the types of all the leaves in a projection tree in the order that they appear. The method relies uses a new convenience on ProjectionTreeNode, isLeaf to include only the types of those nodes which are leaves. Excerpted from @GottesM's #16756.
1 parent 0673530 commit 70ad473

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

include/swift/SIL/Projection.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,8 @@ class ProjectionTreeNode {
761761
return NonProjUsers;
762762
};
763763

764+
bool isLeaf() const { return ChildProjections.empty(); }
765+
764766
SILType getType() const { return NodeType; }
765767

766768
bool isRoot() const {
@@ -914,6 +916,24 @@ class ProjectionTree {
914916
return false;
915917
}
916918

919+
void getAllLeafTypes(llvm::SmallVectorImpl<SILType> &outArray) const {
920+
llvm::SmallVector<const ProjectionTreeNode *, 32> worklist;
921+
worklist.push_back(getRoot());
922+
923+
while (!worklist.empty()) {
924+
auto *node = worklist.pop_back_val();
925+
// If we have a leaf node, add its type.
926+
if (node->isLeaf()) {
927+
outArray.push_back(node->getType());
928+
continue;
929+
}
930+
931+
// Otherwise, add the nodes children to the worklist.
932+
transform(node->getChildProjections(), std::back_inserter(worklist),
933+
[&](unsigned idx) { return getNode(idx); });
934+
}
935+
}
936+
917937
void getLiveLeafTypes(llvm::SmallVectorImpl<SILType> &OutArray) const {
918938
for (unsigned LeafIndex : LiveLeafIndices) {
919939
const ProjectionTreeNode *Node = getNode(LeafIndex);

0 commit comments

Comments
 (0)