Skip to content

[nfc] [util] add util to check if an instruction dominates all uses of a value #30464

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/swift/SILOptimizer/Utils/InstOptUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,8 @@ bool tryOptimizeApplyOfPartialApply(
PartialApplyInst *pai, SILBuilderContext &builderCtxt,
InstModCallbacks callbacks = InstModCallbacks());

bool dominatesAllUses(SILInstruction *a, SILValue b);

} // end namespace swift

#endif
12 changes: 12 additions & 0 deletions lib/SILOptimizer/Utils/InstOptUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1943,3 +1943,15 @@ AbstractFunctionDecl *swift::getBaseMethod(AbstractFunctionDecl *FD) {
}
return FD;
}

/// Checks that "a" dominates all uses of "b".
/// \param a the instruction who's expected to dominate.
/// \param b the instruction who's uses are expected to be dominated.
/// \returns true if all uses of "b" are dominated by "a". Otherwise, false.
bool swift::dominatesAllUses(SILInstruction *a, SILValue b) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should take an optional dominanceInfo argument.

DominanceInfo dominanceInfo(a->getFunction());
return std::all_of(b->use_begin(), b->use_end(),
[&a, &dominanceInfo](Operand *use) {
return dominanceInfo.dominates(a, use->getUser());
});
}