[llvm] 3dbccca - [Support] Use range-based for loops (NFC)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 10 08:53:25 PST 2021
Author: Kazu Hirata
Date: 2021-12-10T08:53:14-08:00
New Revision: 3dbcccab303a586791fb8bb2455dd15a7eda5477
URL: https://github.com/llvm/llvm-project/commit/3dbcccab303a586791fb8bb2455dd15a7eda5477
DIFF: https://github.com/llvm/llvm-project/commit/3dbcccab303a586791fb8bb2455dd15a7eda5477.diff
LOG: [Support] Use range-based for loops (NFC)
Added:
Modified:
llvm/lib/Support/CommandLine.cpp
llvm/lib/Support/ConvertUTFWrapper.cpp
llvm/lib/Support/DAGDeltaAlgorithm.cpp
llvm/lib/Support/DeltaAlgorithm.cpp
llvm/lib/Support/Signals.cpp
llvm/lib/Support/SourceMgr.cpp
llvm/lib/Support/Statistic.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Support/CommandLine.cpp b/llvm/lib/Support/CommandLine.cpp
index 5b7004c86f5a8..4153a69abf5d5 100644
--- a/llvm/lib/Support/CommandLine.cpp
+++ b/llvm/lib/Support/CommandLine.cpp
@@ -1538,10 +1538,8 @@ bool CommandLineParser::ParseCommandLineOptions(int argc,
ErrorParsing = true;
} else {
- for (SmallVectorImpl<Option *>::iterator I = SinkOpts.begin(),
- E = SinkOpts.end();
- I != E; ++I)
- (*I)->addOccurrence(i, "", StringRef(argv[i]));
+ for (Option *SinkOpt : SinkOpts)
+ SinkOpt->addOccurrence(i, "", StringRef(argv[i]));
}
continue;
}
@@ -2303,11 +2301,8 @@ class CategorizedHelpPrinter : public HelpPrinter {
// Collect registered option categories into vector in preparation for
// sorting.
- for (auto I = GlobalParser->RegisteredOptionCategories.begin(),
- E = GlobalParser->RegisteredOptionCategories.end();
- I != E; ++I) {
- SortedCategories.push_back(*I);
- }
+ for (OptionCategory *Category : GlobalParser->RegisteredOptionCategories)
+ SortedCategories.push_back(Category);
// Sort the
diff erent option categories alphabetically.
assert(SortedCategories.size() > 0 && "No option categories registered!");
@@ -2315,11 +2310,8 @@ class CategorizedHelpPrinter : public HelpPrinter {
OptionCategoryCompare);
// Create map to empty vectors.
- for (std::vector<OptionCategory *>::const_iterator
- I = SortedCategories.begin(),
- E = SortedCategories.end();
- I != E; ++I)
- CategorizedOptions[*I] = std::vector<Option *>();
+ for (OptionCategory *Category : SortedCategories)
+ CategorizedOptions[Category] = std::vector<Option *>();
// Walk through pre-sorted options and assign into categories.
// Because the options are already alphabetically sorted the
@@ -2334,23 +2326,20 @@ class CategorizedHelpPrinter : public HelpPrinter {
}
// Now do printing.
- for (std::vector<OptionCategory *>::const_iterator
- Category = SortedCategories.begin(),
- E = SortedCategories.end();
- Category != E; ++Category) {
+ for (OptionCategory *Category : SortedCategories) {
// Hide empty categories for --help, but show for --help-hidden.
- const auto &CategoryOptions = CategorizedOptions[*Category];
+ const auto &CategoryOptions = CategorizedOptions[Category];
bool IsEmptyCategory = CategoryOptions.empty();
if (!ShowHidden && IsEmptyCategory)
continue;
// Print category information.
outs() << "\n";
- outs() << (*Category)->getName() << ":\n";
+ outs() << Category->getName() << ":\n";
// Check if description is set.
- if (!(*Category)->getDescription().empty())
- outs() << (*Category)->getDescription() << "\n\n";
+ if (!Category->getDescription().empty())
+ outs() << Category->getDescription() << "\n\n";
else
outs() << "\n";
diff --git a/llvm/lib/Support/ConvertUTFWrapper.cpp b/llvm/lib/Support/ConvertUTFWrapper.cpp
index d8d46712a5935..392c4c4890e16 100644
--- a/llvm/lib/Support/ConvertUTFWrapper.cpp
+++ b/llvm/lib/Support/ConvertUTFWrapper.cpp
@@ -103,8 +103,8 @@ bool convertUTF16ToUTF8String(ArrayRef<char> SrcBytes, std::string &Out) {
std::vector<UTF16> ByteSwapped;
if (Src[0] == UNI_UTF16_BYTE_ORDER_MARK_SWAPPED) {
ByteSwapped.insert(ByteSwapped.end(), Src, SrcEnd);
- for (unsigned I = 0, E = ByteSwapped.size(); I != E; ++I)
- ByteSwapped[I] = llvm::ByteSwap_16(ByteSwapped[I]);
+ for (UTF16 &I : ByteSwapped)
+ I = llvm::ByteSwap_16(I);
Src = &ByteSwapped[0];
SrcEnd = &ByteSwapped[ByteSwapped.size() - 1] + 1;
}
diff --git a/llvm/lib/Support/DAGDeltaAlgorithm.cpp b/llvm/lib/Support/DAGDeltaAlgorithm.cpp
index e5e6301d41cc5..a6daee00bd431 100644
--- a/llvm/lib/Support/DAGDeltaAlgorithm.cpp
+++ b/llvm/lib/Support/DAGDeltaAlgorithm.cpp
@@ -180,22 +180,19 @@ DAGDeltaAlgorithmImpl::DAGDeltaAlgorithmImpl(
DAGDeltaAlgorithm &DDA, const changeset_ty &Changes,
const std::vector<edge_ty> &Dependencies)
: DDA(DDA) {
- for (changeset_ty::const_iterator it = Changes.begin(),
- ie = Changes.end(); it != ie; ++it) {
- Predecessors.insert(std::make_pair(*it, std::vector<change_ty>()));
- Successors.insert(std::make_pair(*it, std::vector<change_ty>()));
+ for (change_ty Change : Changes) {
+ Predecessors.insert(std::make_pair(Change, std::vector<change_ty>()));
+ Successors.insert(std::make_pair(Change, std::vector<change_ty>()));
}
- for (std::vector<edge_ty>::const_iterator it = Dependencies.begin(),
- ie = Dependencies.end(); it != ie; ++it) {
- Predecessors[it->second].push_back(it->first);
- Successors[it->first].push_back(it->second);
+ for (const edge_ty &Dep : Dependencies) {
+ Predecessors[Dep.second].push_back(Dep.first);
+ Successors[Dep.first].push_back(Dep.second);
}
// Compute the roots.
- for (changeset_ty::const_iterator it = Changes.begin(),
- ie = Changes.end(); it != ie; ++it)
- if (succ_begin(*it) == succ_end(*it))
- Roots.push_back(*it);
+ for (change_ty Change : Changes)
+ if (succ_begin(Change) == succ_end(Change))
+ Roots.push_back(Change);
// Pre-compute the closure of the successor relation.
std::vector<change_ty> Worklist(Roots.begin(), Roots.end());
@@ -213,14 +210,13 @@ DAGDeltaAlgorithmImpl::DAGDeltaAlgorithmImpl(
}
// Invert to form the predecessor closure map.
- for (changeset_ty::const_iterator it = Changes.begin(),
- ie = Changes.end(); it != ie; ++it)
- PredClosure.insert(std::make_pair(*it, std::set<change_ty>()));
- for (changeset_ty::const_iterator it = Changes.begin(),
- ie = Changes.end(); it != ie; ++it)
- for (succ_closure_iterator_ty it2 = succ_closure_begin(*it),
- ie2 = succ_closure_end(*it); it2 != ie2; ++it2)
- PredClosure[*it2].insert(*it);
+ for (change_ty Change : Changes)
+ PredClosure.insert(std::make_pair(Change, std::set<change_ty>()));
+ for (change_ty Change : Changes)
+ for (succ_closure_iterator_ty it2 = succ_closure_begin(Change),
+ ie2 = succ_closure_end(Change);
+ it2 != ie2; ++it2)
+ PredClosure[*it2].insert(Change);
// Dump useful debug info.
LLVM_DEBUG({
@@ -256,13 +252,12 @@ DAGDeltaAlgorithmImpl::DAGDeltaAlgorithmImpl(
llvm::errs() << "]\n";
llvm::errs() << "Predecessor Closure:\n";
- for (changeset_ty::const_iterator it = Changes.begin(), ie = Changes.end();
- it != ie; ++it) {
- llvm::errs() << format(" %-4d: [", *it);
- for (pred_closure_iterator_ty it2 = pred_closure_begin(*it),
- ie2 = pred_closure_end(*it);
+ for (change_ty Change : Changes) {
+ llvm::errs() << format(" %-4d: [", Change);
+ for (pred_closure_iterator_ty it2 = pred_closure_begin(Change),
+ ie2 = pred_closure_end(Change);
it2 != ie2; ++it2) {
- if (it2 != pred_closure_begin(*it))
+ if (it2 != pred_closure_begin(Change))
llvm::errs() << ", ";
llvm::errs() << *it2;
}
@@ -270,13 +265,12 @@ DAGDeltaAlgorithmImpl::DAGDeltaAlgorithmImpl(
}
llvm::errs() << "Successor Closure:\n";
- for (changeset_ty::const_iterator it = Changes.begin(), ie = Changes.end();
- it != ie; ++it) {
- llvm::errs() << format(" %-4d: [", *it);
- for (succ_closure_iterator_ty it2 = succ_closure_begin(*it),
- ie2 = succ_closure_end(*it);
+ for (change_ty Change : Changes) {
+ llvm::errs() << format(" %-4d: [", Change);
+ for (succ_closure_iterator_ty it2 = succ_closure_begin(Change),
+ ie2 = succ_closure_end(Change);
it2 != ie2; ++it2) {
- if (it2 != succ_closure_begin(*it))
+ if (it2 != succ_closure_begin(Change))
llvm::errs() << ", ";
llvm::errs() << *it2;
}
@@ -291,9 +285,8 @@ bool DAGDeltaAlgorithmImpl::GetTestResult(const changeset_ty &Changes,
const changeset_ty &Required) {
changeset_ty Extended(Required);
Extended.insert(Changes.begin(), Changes.end());
- for (changeset_ty::const_iterator it = Changes.begin(),
- ie = Changes.end(); it != ie; ++it)
- Extended.insert(pred_closure_begin(*it), pred_closure_end(*it));
+ for (change_ty Change : Changes)
+ Extended.insert(pred_closure_begin(Change), pred_closure_end(Change));
if (FailedTestsCache.count(Extended))
return false;
@@ -340,9 +333,8 @@ DAGDeltaAlgorithmImpl::Run() {
// Replace the current set with the predecssors of the minimized set of
// active changes.
CurrentSet.clear();
- for (changeset_ty::const_iterator it = CurrentMinSet.begin(),
- ie = CurrentMinSet.end(); it != ie; ++it)
- CurrentSet.insert(pred_begin(*it), pred_end(*it));
+ for (change_ty CT : CurrentMinSet)
+ CurrentSet.insert(pred_begin(CT), pred_end(CT));
// FIXME: We could enforce CurrentSet intersect Required == {} here if we
// wanted to protect against cyclic graphs.
diff --git a/llvm/lib/Support/DeltaAlgorithm.cpp b/llvm/lib/Support/DeltaAlgorithm.cpp
index 6aee69f434054..a2017a10ab3f7 100644
--- a/llvm/lib/Support/DeltaAlgorithm.cpp
+++ b/llvm/lib/Support/DeltaAlgorithm.cpp
@@ -57,9 +57,8 @@ DeltaAlgorithm::Delta(const changeset_ty &Changes,
// Otherwise, partition the sets if possible; if not we are done.
changesetlist_ty SplitSets;
- for (changesetlist_ty::const_iterator it = Sets.begin(),
- ie = Sets.end(); it != ie; ++it)
- Split(*it, SplitSets);
+ for (const changeset_ty &Set : Sets)
+ Split(Set, SplitSets);
if (SplitSets.size() == Sets.size())
return Changes;
diff --git a/llvm/lib/Support/Signals.cpp b/llvm/lib/Support/Signals.cpp
index dd4dded4cd1d8..c018dc92bf408 100644
--- a/llvm/lib/Support/Signals.cpp
+++ b/llvm/lib/Support/Signals.cpp
@@ -87,8 +87,7 @@ static CallbackAndCookie CallBacksToRun[MaxSignalHandlerCallbacks];
// Signal-safe.
void sys::RunSignalHandlers() {
- for (size_t I = 0; I < MaxSignalHandlerCallbacks; ++I) {
- auto &RunMe = CallBacksToRun[I];
+ for (CallbackAndCookie &RunMe : CallBacksToRun) {
auto Expected = CallbackAndCookie::Status::Initialized;
auto Desired = CallbackAndCookie::Status::Executing;
if (!RunMe.Flag.compare_exchange_strong(Expected, Desired))
@@ -103,8 +102,7 @@ void sys::RunSignalHandlers() {
// Signal-safe.
static void insertSignalHandler(sys::SignalHandlerCallback FnPtr,
void *Cookie) {
- for (size_t I = 0; I < MaxSignalHandlerCallbacks; ++I) {
- auto &SetMe = CallBacksToRun[I];
+ for (CallbackAndCookie &SetMe : CallBacksToRun) {
auto Expected = CallbackAndCookie::Status::Empty;
auto Desired = CallbackAndCookie::Status::Initializing;
if (!SetMe.Flag.compare_exchange_strong(Expected, Desired))
diff --git a/llvm/lib/Support/SourceMgr.cpp b/llvm/lib/Support/SourceMgr.cpp
index 89b7dc939dfcb..2eb2989b200b0 100644
--- a/llvm/lib/Support/SourceMgr.cpp
+++ b/llvm/lib/Support/SourceMgr.cpp
@@ -292,8 +292,7 @@ SMDiagnostic SourceMgr::GetMessage(SMLoc Loc, SourceMgr::DiagKind Kind,
// Convert any ranges to column ranges that only intersect the line of the
// location.
- for (unsigned i = 0, e = Ranges.size(); i != e; ++i) {
- SMRange R = Ranges[i];
+ for (SMRange R : Ranges) {
if (!R.isValid())
continue;
diff --git a/llvm/lib/Support/Statistic.cpp b/llvm/lib/Support/Statistic.cpp
index d95c8642c16e7..95ee885d2f8f5 100644
--- a/llvm/lib/Support/Statistic.cpp
+++ b/llvm/lib/Support/Statistic.cpp
@@ -177,11 +177,10 @@ void llvm::PrintStatistics(raw_ostream &OS) {
// Figure out how long the biggest Value and Name fields are.
unsigned MaxDebugTypeLen = 0, MaxValLen = 0;
- for (size_t i = 0, e = Stats.Stats.size(); i != e; ++i) {
- MaxValLen = std::max(MaxValLen,
- (unsigned)utostr(Stats.Stats[i]->getValue()).size());
- MaxDebugTypeLen = std::max(MaxDebugTypeLen,
- (unsigned)std::strlen(Stats.Stats[i]->getDebugType()));
+ for (TrackingStatistic *Stat : Stats.Stats) {
+ MaxValLen = std::max(MaxValLen, (unsigned)utostr(Stat->getValue()).size());
+ MaxDebugTypeLen =
+ std::max(MaxDebugTypeLen, (unsigned)std::strlen(Stat->getDebugType()));
}
Stats.sort();
@@ -192,11 +191,9 @@ void llvm::PrintStatistics(raw_ostream &OS) {
<< "===" << std::string(73, '-') << "===\n\n";
// Print all of the statistics.
- for (size_t i = 0, e = Stats.Stats.size(); i != e; ++i)
- OS << format("%*u %-*s - %s\n",
- MaxValLen, Stats.Stats[i]->getValue(),
- MaxDebugTypeLen, Stats.Stats[i]->getDebugType(),
- Stats.Stats[i]->getDesc());
+ for (TrackingStatistic *Stat : Stats.Stats)
+ OS << format("%*u %-*s - %s\n", MaxValLen, Stat->getValue(),
+ MaxDebugTypeLen, Stat->getDebugType(), Stat->getDesc());
OS << '\n'; // Flush the output stream.
OS.flush();
More information about the llvm-commits
mailing list