[NFC][OpenMPOpt] Provide function-specific foreachUse.

This commit is contained in:
sstefan1
2020-06-16 12:33:15 +02:00
parent f6189da938
commit e099c7b64a
+25 -17
View File
@@ -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();
}
}