mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-06 09:06:21 +01:00
[NFC][OpenMPOpt] Provide function-specific foreachUse.
This commit is contained in:
@@ -118,24 +118,32 @@ struct OpenMPOpt {
|
||||
/// true. The callback will be fed the function in which the use was
|
||||
/// encountered as second argument.
|
||||
void foreachUse(function_ref<bool(Use &, Function &)> CB) {
|
||||
SmallVector<unsigned, 8> ToBeDeleted;
|
||||
for (auto &It : UsesMap) {
|
||||
ToBeDeleted.clear();
|
||||
unsigned Idx = 0;
|
||||
UseVector &UV = *It.second;
|
||||
for (Use *U : UV) {
|
||||
if (CB(*U, *It.first))
|
||||
ToBeDeleted.push_back(Idx);
|
||||
++Idx;
|
||||
}
|
||||
for (auto &It : UsesMap)
|
||||
foreachUse(CB, It.first, It.second.get());
|
||||
}
|
||||
|
||||
// Remove the to-be-deleted indices in reverse order as prior
|
||||
// modifcations will not modify the smaller indices.
|
||||
while (!ToBeDeleted.empty()) {
|
||||
unsigned Idx = ToBeDeleted.pop_back_val();
|
||||
UV[Idx] = UV.back();
|
||||
UV.pop_back();
|
||||
}
|
||||
/// Run the callback \p CB on each use within the function \p F and forget
|
||||
/// the use if the result is true.
|
||||
void foreachUse(function_ref<bool(Use &, Function &)> CB, Function *F,
|
||||
UseVector *Uses = nullptr) {
|
||||
SmallVector<unsigned, 8> ToBeDeleted;
|
||||
ToBeDeleted.clear();
|
||||
|
||||
unsigned Idx = 0;
|
||||
UseVector &UV = Uses ? *Uses : getOrCreateUseVector(F);
|
||||
|
||||
for (Use *U : UV) {
|
||||
if (CB(*U, *F))
|
||||
ToBeDeleted.push_back(Idx);
|
||||
++Idx;
|
||||
}
|
||||
|
||||
// Remove the to-be-deleted indices in reverse order as prior
|
||||
// modifcations will not modify the smaller indices.
|
||||
while (!ToBeDeleted.empty()) {
|
||||
unsigned Idx = ToBeDeleted.pop_back_val();
|
||||
UV[Idx] = UV.back();
|
||||
UV.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user