llvm.org GIT mirror llvm / bdc30c0
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 Aaron Ballman 1 year, 9 months ago
12 changed file(s) with 92 addition(s) and 89 deletion(s). Raw diff Collapse all Expand all
812812 C.clear();
813813 }
814814
815 /// Provide wrappers to std::for_each which take ranges instead of having to
816 /// pass begin/end explicitly.
817 template
818 UnaryPredicate for_each(R &&Range, UnaryPredicate P) {
819 return std::for_each(std::begin(Range), std::end(Range), P);
820 }
821
815822 /// Provide wrappers to std::all_of which take ranges instead of having to pass
816823 /// begin/end explicitly.
817824 template
468468 if (I == ExternalSymbols.end())
469469 return;
470470
471 GV.setLinkage(I->second);
472 };
473
474 std::for_each(MergedModule->begin(), MergedModule->end(), externalize);
475 std::for_each(MergedModule->global_begin(), MergedModule->global_end(),
476 externalize);
477 std::for_each(MergedModule->alias_begin(), MergedModule->alias_end(),
478 externalize);
479 }
480
481 void LTOCodeGenerator::verifyMergedModuleOnce() {
471 GV.setLinkage(I->second);
472 };
473
474 llvm::for_each(MergedModule->functions(), externalize);
475 llvm::for_each(MergedModule->globals(), externalize);
476 llvm::for_each(MergedModule->aliases(), externalize);
477 }
478
479 void LTOCodeGenerator::verifyMergedModuleOnce() {
482480 // Only run on the first call.
483481 if (HasVerifiedInput)
484482 return;
547547 findValueToReuse();
548548 if (ReuseCandidate.isDefined()) {
549549 reuseValue();
550 Changed = true;
551 Continue = true;
552 }
553 std::for_each(Dependences.begin(), Dependences.end(),
554 std::default_delete());
555 } while (Continue);
556 return Changed;
557 }
550 Changed = true;
551 Continue = true;
552 }
553 llvm::for_each(Dependences, std::default_delete());
554 } while (Continue);
555 return Changed;
556 }
558557
559558 void HexagonVectorLoopCarriedReuse::findDepChainFromPHI(Instruction *I,
560559 DepChain &D) {
140140 }
141141
142142 if (GV.hasLocalLinkage())
143 addAllGlobalValueUsers(GVtoClusterMap, &GV, &GV);
144 };
145
146 std::for_each(M->begin(), M->end(), recordGVSet);
147 std::for_each(M->global_begin(), M->global_end(), recordGVSet);
148 std::for_each(M->alias_begin(), M->alias_end(), recordGVSet);
149
150 // Assigned all GVs to merged clusters while balancing number of objects in
151 // each.
143 addAllGlobalValueUsers(GVtoClusterMap, &GV, &GV);
144 };
145
146 llvm::for_each(M->functions(), recordGVSet);
147 llvm::for_each(M->globals(), recordGVSet);
148 llvm::for_each(M->aliases(), recordGVSet);
149
150 // Assigned all GVs to merged clusters while balancing number of objects in
151 // each.
152152 auto CompareClusters = [](const std::pair &a,
153153 const std::pair &b) {
154154 if (a.second || b.second)
545545 cl::ParseCommandLineOptions(argc, argv, "LLVM C++ ABI Data Dumper\n");
546546
547547 // Default to stdin if no filename is specified.
548 if (opts::InputFilenames.size() == 0)
549 opts::InputFilenames.push_back("-");
550
551 std::for_each(opts::InputFilenames.begin(), opts::InputFilenames.end(),
552 dumpInput);
553
554 return EXIT_SUCCESS;
555 }
548 if (opts::InputFilenames.size() == 0)
549 opts::InputFilenames.push_back("-");
550
551 llvm::for_each(opts::InputFilenames, dumpInput);
552
553 return EXIT_SUCCESS;
554 }
216216 ToolName = argv[0];
217217
218218 // If no input files specified, read from stdin.
219 if (InputFilenames.size() == 0)
220 InputFilenames.push_back("-");
221
222 std::for_each(InputFilenames.begin(), InputFilenames.end(),
223 parseMCMarkup);
224 return 0;
225 }
219 if (InputFilenames.size() == 0)
220 InputFilenames.push_back("-");
221
222 llvm::for_each(InputFilenames, parseMCMarkup);
223 return 0;
224 }
19761976 if (NoDyldInfo && (AddDyldInfo || DyldInfoOnly))
19771977 error("-no-dyldinfo can't be used with -add-dyldinfo or -dyldinfo-only");
19781978
1979 std::for_each(InputFilenames.begin(), InputFilenames.end(),
1980 dumpSymbolNamesFromFile);
1979 llvm::for_each(InputFilenames, dumpSymbolNamesFromFile);
19811980
19821981 if (HadError)
19831982 return 1;
21822182 && !PrintFaultMaps
21832183 && DwarfDumpType == DIDT_Null) {
21842184 cl::PrintHelpMessage();
2185 return 2;
2186 }
2187
2188 std::for_each(InputFilenames.begin(), InputFilenames.end(),
2189 DumpInput);
2190
2191 return EXIT_SUCCESS;
2192 }
2185 return 2;
2186 }
2187
2188 llvm::for_each(InputFilenames, DumpInput);
2189
2190 return EXIT_SUCCESS;
2191 }
11981198 opts::pretty::ExcludeCompilands.push_back(
11991199 "f:\\\\binaries\\\\Intermediate\\\\vctools\\\\crt_bld");
12001200 opts::pretty::ExcludeCompilands.push_back("f:\\\\dd\\\\vctools\\\\crt");
1201 opts::pretty::ExcludeCompilands.push_back(
1202 "d:\\\\th.obj.x86fre\\\\minkernel");
1203 }
1204 std::for_each(opts::pretty::InputFilenames.begin(),
1205 opts::pretty::InputFilenames.end(), dumpPretty);
1206 } else if (opts::DumpSubcommand) {
1207 std::for_each(opts::dump::InputFilenames.begin(),
1208 opts::dump::InputFilenames.end(), dumpRaw);
1209 } else if (opts::BytesSubcommand) {
1210 std::for_each(opts::bytes::InputFilenames.begin(),
1211 opts::bytes::InputFilenames.end(), dumpBytes);
1212 } else if (opts::DiffSubcommand) {
1213 for (StringRef S : opts::diff::RawModiEquivalences) {
1214 StringRef Left;
1201 opts::pretty::ExcludeCompilands.push_back(
1202 "d:\\\\th.obj.x86fre\\\\minkernel");
1203 }
1204 llvm::for_each(opts::pretty::InputFilenames, dumpPretty);
1205 } else if (opts::DumpSubcommand) {
1206 llvm::for_each(opts::dump::InputFilenames, dumpRaw);
1207 } else if (opts::BytesSubcommand) {
1208 llvm::for_each(opts::bytes::InputFilenames, dumpBytes);
1209 } else if (opts::DiffSubcommand) {
1210 for (StringRef S : opts::diff::RawModiEquivalences) {
1211 StringRef Left;
12151212 StringRef Right;
12161213 std::tie(Left, Right) = S.split(',');
12171214 uint32_t X, Y;
565565 cl::ParseCommandLineOptions(argc, argv, "LLVM Object Reader\n");
566566
567567 // Default to stdin if no filename is specified.
568 if (opts::InputFilenames.size() == 0)
569 opts::InputFilenames.push_back("-");
570
571 std::for_each(opts::InputFilenames.begin(), opts::InputFilenames.end(),
572 dumpInput);
573
574 if (opts::CodeViewMergedTypes) {
575 ScopedPrinter W(outs());
568 if (opts::InputFilenames.size() == 0)
569 opts::InputFilenames.push_back("-");
570
571 llvm::for_each(opts::InputFilenames, dumpInput);
572
573 if (opts::CodeViewMergedTypes) {
574 ScopedPrinter W(outs());
576575 dumpCodeViewMergedTypes(W, CVTypes.IDTable, CVTypes.TypeTable);
577576 }
578577
879879 }
880880
881881 if (InputFilenames.size() == 0)
882 InputFilenames.push_back("a.out");
883
884 MoreThanOneFile = InputFilenames.size() > 1;
885 std::for_each(InputFilenames.begin(), InputFilenames.end(),
886 printFileSectionSizes);
887 if (OutputFormat == berkeley && TotalSizes)
888 printBerkelyTotals();
889
882 InputFilenames.push_back("a.out");
883
884 MoreThanOneFile = InputFilenames.size() > 1;
885 llvm::for_each(InputFilenames, printFileSectionSizes);
886 if (OutputFormat == berkeley && TotalSizes)
887 printBerkelyTotals();
888
890889 if (HadError)
891890 return 1;
892891 }
251251 EXPECT_EQ(3, count(v, 1));
252252 EXPECT_EQ(2, count(v, 2));
253253 EXPECT_EQ(1, count(v, 3));
254 EXPECT_EQ(1, count(v, 4));
255 }
256
257 TEST(STLExtrasTest, ToVector) {
258 std::vector v = {'a', 'b', 'c'};
259 auto Enumerated = to_vector<4>(enumerate(v));
254 EXPECT_EQ(1, count(v, 4));
255 }
256
257 TEST(STLExtrasTest, for_each) {
258 std::vector v{ 0, 1, 2, 3, 4 };
259 int count = 0;
260
261 llvm::for_each(v, [&count](int) { ++count; });
262 EXPECT_EQ(5, count);
263 }
264
265 TEST(STLExtrasTest, ToVector) {
266 std::vector v = {'a', 'b', 'c'};
267 auto Enumerated = to_vector<4>(enumerate(v));
260268 ASSERT_EQ(3u, Enumerated.size());
261269 for (size_t I = 0; I < v.size(); ++I) {
262270 EXPECT_EQ(I, Enumerated[I].index());