mirror of
https://github.com/RPCS3/llvm.git
synced 2025-04-12 19:18:48 +00:00
Add llvm::for_each as a range-based extensions to <algorithm> and make use of it in some cases where it is a more clear alternative to std::for_each.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@317356 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
b72a3a9da4
commit
bdc30c02fb
@ -813,6 +813,13 @@ void DeleteContainerSeconds(Container &C) {
|
||||
C.clear();
|
||||
}
|
||||
|
||||
/// Provide wrappers to std::for_each which take ranges instead of having to
|
||||
/// pass begin/end explicitly.
|
||||
template <typename R, typename UnaryPredicate>
|
||||
UnaryPredicate for_each(R &&Range, UnaryPredicate P) {
|
||||
return std::for_each(std::begin(Range), std::end(Range), P);
|
||||
}
|
||||
|
||||
/// Provide wrappers to std::all_of which take ranges instead of having to pass
|
||||
/// begin/end explicitly.
|
||||
template <typename R, typename UnaryPredicate>
|
||||
|
@ -472,11 +472,9 @@ void LTOCodeGenerator::restoreLinkageForExternals() {
|
||||
GV.setLinkage(I->second);
|
||||
};
|
||||
|
||||
std::for_each(MergedModule->begin(), MergedModule->end(), externalize);
|
||||
std::for_each(MergedModule->global_begin(), MergedModule->global_end(),
|
||||
externalize);
|
||||
std::for_each(MergedModule->alias_begin(), MergedModule->alias_end(),
|
||||
externalize);
|
||||
llvm::for_each(MergedModule->functions(), externalize);
|
||||
llvm::for_each(MergedModule->globals(), externalize);
|
||||
llvm::for_each(MergedModule->aliases(), externalize);
|
||||
}
|
||||
|
||||
void LTOCodeGenerator::verifyMergedModuleOnce() {
|
||||
|
@ -551,8 +551,7 @@ bool HexagonVectorLoopCarriedReuse::doVLCR() {
|
||||
Changed = true;
|
||||
Continue = true;
|
||||
}
|
||||
std::for_each(Dependences.begin(), Dependences.end(),
|
||||
std::default_delete<DepChain>());
|
||||
llvm::for_each(Dependences, std::default_delete<DepChain>());
|
||||
} while (Continue);
|
||||
return Changed;
|
||||
}
|
||||
|
@ -144,9 +144,9 @@ static void findPartitions(Module *M, ClusterIDMapType &ClusterIDMap,
|
||||
addAllGlobalValueUsers(GVtoClusterMap, &GV, &GV);
|
||||
};
|
||||
|
||||
std::for_each(M->begin(), M->end(), recordGVSet);
|
||||
std::for_each(M->global_begin(), M->global_end(), recordGVSet);
|
||||
std::for_each(M->alias_begin(), M->alias_end(), recordGVSet);
|
||||
llvm::for_each(M->functions(), recordGVSet);
|
||||
llvm::for_each(M->globals(), recordGVSet);
|
||||
llvm::for_each(M->aliases(), recordGVSet);
|
||||
|
||||
// Assigned all GVs to merged clusters while balancing number of objects in
|
||||
// each.
|
||||
|
@ -549,8 +549,7 @@ int main(int argc, const char *argv[]) {
|
||||
if (opts::InputFilenames.size() == 0)
|
||||
opts::InputFilenames.push_back("-");
|
||||
|
||||
std::for_each(opts::InputFilenames.begin(), opts::InputFilenames.end(),
|
||||
dumpInput);
|
||||
llvm::for_each(opts::InputFilenames, dumpInput);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
@ -220,7 +220,6 @@ int main(int argc, char **argv) {
|
||||
if (InputFilenames.size() == 0)
|
||||
InputFilenames.push_back("-");
|
||||
|
||||
std::for_each(InputFilenames.begin(), InputFilenames.end(),
|
||||
parseMCMarkup);
|
||||
llvm::for_each(InputFilenames, parseMCMarkup);
|
||||
return 0;
|
||||
}
|
||||
|
@ -1977,8 +1977,7 @@ int main(int argc, char **argv) {
|
||||
if (NoDyldInfo && (AddDyldInfo || DyldInfoOnly))
|
||||
error("-no-dyldinfo can't be used with -add-dyldinfo or -dyldinfo-only");
|
||||
|
||||
std::for_each(InputFilenames.begin(), InputFilenames.end(),
|
||||
dumpSymbolNamesFromFile);
|
||||
llvm::for_each(InputFilenames, dumpSymbolNamesFromFile);
|
||||
|
||||
if (HadError)
|
||||
return 1;
|
||||
|
@ -2186,8 +2186,7 @@ int main(int argc, char **argv) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
std::for_each(InputFilenames.begin(), InputFilenames.end(),
|
||||
DumpInput);
|
||||
llvm::for_each(InputFilenames, DumpInput);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
@ -1202,14 +1202,11 @@ int main(int argc_, const char *argv_[]) {
|
||||
opts::pretty::ExcludeCompilands.push_back(
|
||||
"d:\\\\th.obj.x86fre\\\\minkernel");
|
||||
}
|
||||
std::for_each(opts::pretty::InputFilenames.begin(),
|
||||
opts::pretty::InputFilenames.end(), dumpPretty);
|
||||
llvm::for_each(opts::pretty::InputFilenames, dumpPretty);
|
||||
} else if (opts::DumpSubcommand) {
|
||||
std::for_each(opts::dump::InputFilenames.begin(),
|
||||
opts::dump::InputFilenames.end(), dumpRaw);
|
||||
llvm::for_each(opts::dump::InputFilenames, dumpRaw);
|
||||
} else if (opts::BytesSubcommand) {
|
||||
std::for_each(opts::bytes::InputFilenames.begin(),
|
||||
opts::bytes::InputFilenames.end(), dumpBytes);
|
||||
llvm::for_each(opts::bytes::InputFilenames, dumpBytes);
|
||||
} else if (opts::DiffSubcommand) {
|
||||
for (StringRef S : opts::diff::RawModiEquivalences) {
|
||||
StringRef Left;
|
||||
|
@ -569,8 +569,7 @@ int main(int argc, const char *argv[]) {
|
||||
if (opts::InputFilenames.size() == 0)
|
||||
opts::InputFilenames.push_back("-");
|
||||
|
||||
std::for_each(opts::InputFilenames.begin(), opts::InputFilenames.end(),
|
||||
dumpInput);
|
||||
llvm::for_each(opts::InputFilenames, dumpInput);
|
||||
|
||||
if (opts::CodeViewMergedTypes) {
|
||||
ScopedPrinter W(outs());
|
||||
|
@ -883,8 +883,7 @@ int main(int argc, char **argv) {
|
||||
InputFilenames.push_back("a.out");
|
||||
|
||||
MoreThanOneFile = InputFilenames.size() > 1;
|
||||
std::for_each(InputFilenames.begin(), InputFilenames.end(),
|
||||
printFileSectionSizes);
|
||||
llvm::for_each(InputFilenames, printFileSectionSizes);
|
||||
if (OutputFormat == berkeley && TotalSizes)
|
||||
printBerkelyTotals();
|
||||
|
||||
|
@ -255,6 +255,14 @@ TEST(STLExtrasTest, CountAdaptor) {
|
||||
EXPECT_EQ(1, count(v, 4));
|
||||
}
|
||||
|
||||
TEST(STLExtrasTest, for_each) {
|
||||
std::vector<int> v{ 0, 1, 2, 3, 4 };
|
||||
int count = 0;
|
||||
|
||||
llvm::for_each(v, [&count](int) { ++count; });
|
||||
EXPECT_EQ(5, count);
|
||||
}
|
||||
|
||||
TEST(STLExtrasTest, ToVector) {
|
||||
std::vector<char> v = {'a', 'b', 'c'};
|
||||
auto Enumerated = to_vector<4>(enumerate(v));
|
||||
|
Loading…
x
Reference in New Issue
Block a user