]> granicus.if.org Git - llvm/commitdiff
Add llvm::for_each as a range-based extensions to <algorithm> and make use of it...
authorAaron Ballman <aaron@aaronballman.com>
Fri, 3 Nov 2017 20:01:25 +0000 (20:01 +0000)
committerAaron Ballman <aaron@aaronballman.com>
Fri, 3 Nov 2017 20:01:25 +0000 (20:01 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@317356 91177308-0d34-0410-b5e6-96231b3b80d8

12 files changed:
include/llvm/ADT/STLExtras.h
lib/LTO/LTOCodeGenerator.cpp
lib/Target/Hexagon/HexagonVectorLoopCarriedReuse.cpp
lib/Transforms/Utils/SplitModule.cpp
tools/llvm-cxxdump/llvm-cxxdump.cpp
tools/llvm-mcmarkup/llvm-mcmarkup.cpp
tools/llvm-nm/llvm-nm.cpp
tools/llvm-objdump/llvm-objdump.cpp
tools/llvm-pdbutil/llvm-pdbutil.cpp
tools/llvm-readobj/llvm-readobj.cpp
tools/llvm-size/llvm-size.cpp
unittests/ADT/STLExtrasTest.cpp

index 3ec9dfe5de0a80087c69530954989b4df34eeb59..c42d976f46784a25e64a9920ccf7c23cbd8e739d 100644 (file)
@@ -813,6 +813,13 @@ void DeleteContainerSeconds(Container &C) {
   C.clear();
 }
 
+/// Provide wrappers to std::for_each which take ranges instead of having to\r
+/// pass begin/end explicitly.\r
+template <typename R, typename UnaryPredicate>\r
+UnaryPredicate for_each(R &&Range, UnaryPredicate P) {\r
+  return std::for_each(std::begin(Range), std::end(Range), P);\r
+}\r
+
 /// Provide wrappers to std::all_of which take ranges instead of having to pass
 /// begin/end explicitly.
 template <typename R, typename UnaryPredicate>
index 9759c0c6c1d9830f0fa5901024587cd008b84f70..87867c54fad20a12f4dbd8f8e119dccb1515da7c 100644 (file)
@@ -469,17 +469,15 @@ void LTOCodeGenerator::restoreLinkageForExternals() {
     if (I == ExternalSymbols.end())
       return;
 
-    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);
-}
-
-void LTOCodeGenerator::verifyMergedModuleOnce() {
+    GV.setLinkage(I->second);\r
+  };\r
+\r
+  llvm::for_each(MergedModule->functions(), externalize);\r
+  llvm::for_each(MergedModule->globals(), externalize);\r
+  llvm::for_each(MergedModule->aliases(), externalize);\r
+}\r
+\r
+void LTOCodeGenerator::verifyMergedModuleOnce() {\r
   // Only run on the first call.
   if (HasVerifiedInput)
     return;
index a0fdc70e141a53ff4c9e10050d4956a561915314..52e5dcd46388b8bda49fab3bb3f9f8868d49e5cd 100644 (file)
@@ -548,14 +548,13 @@ bool HexagonVectorLoopCarriedReuse::doVLCR() {
     findValueToReuse();
     if (ReuseCandidate.isDefined()) {
       reuseValue();
-      Changed = true;
-      Continue = true;
-    }
-    std::for_each(Dependences.begin(), Dependences.end(),
-                  std::default_delete<DepChain>());
-  } while (Continue);
-  return Changed;
-}
+      Changed = true;\r
+      Continue = true;\r
+    }\r
+    llvm::for_each(Dependences, std::default_delete<DepChain>());\r
+  } while (Continue);\r
+  return Changed;\r
+}\r
 
 void HexagonVectorLoopCarriedReuse::findDepChainFromPHI(Instruction *I,
                                                         DepChain &D) {
index 07157069518ad07b68c34d8e794f5592da5208f6..934a1bd73c248368d98734401874e3b560c973b9 100644 (file)
@@ -141,15 +141,15 @@ static void findPartitions(Module *M, ClusterIDMapType &ClusterIDMap,
     }
 
     if (GV.hasLocalLinkage())
-      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);
-
-  // Assigned all GVs to merged clusters while balancing number of objects in
-  // each.
+      addAllGlobalValueUsers(GVtoClusterMap, &GV, &GV);\r
+  };\r
+\r
+  llvm::for_each(M->functions(), recordGVSet);\r
+  llvm::for_each(M->globals(), recordGVSet);\r
+  llvm::for_each(M->aliases(), recordGVSet);\r
+\r
+  // Assigned all GVs to merged clusters while balancing number of objects in\r
+  // each.\r
   auto CompareClusters = [](const std::pair<unsigned, unsigned> &a,
                             const std::pair<unsigned, unsigned> &b) {
     if (a.second || b.second)
index b10759ad05c03779b95b1ee0385bc0d3d7a47785..69b1a8ef2099a5a0aaafe48e6afe007b462fc113 100644 (file)
@@ -546,11 +546,10 @@ int main(int argc, const char *argv[]) {
   cl::ParseCommandLineOptions(argc, argv, "LLVM C++ ABI Data Dumper\n");
 
   // Default to stdin if no filename is specified.
-  if (opts::InputFilenames.size() == 0)
-    opts::InputFilenames.push_back("-");
-
-  std::for_each(opts::InputFilenames.begin(), opts::InputFilenames.end(),
-                dumpInput);
-
-  return EXIT_SUCCESS;
-}
+  if (opts::InputFilenames.size() == 0)\r
+    opts::InputFilenames.push_back("-");\r
+\r
+  llvm::for_each(opts::InputFilenames, dumpInput);\r
+\r
+  return EXIT_SUCCESS;\r
+}\r
index 0be3c715eee4ee08466d26f4e013ff0e83ae038a..db57a6bdaa82fdb058dd48d3bdd18b2858db68a0 100644 (file)
@@ -217,10 +217,9 @@ int main(int argc, char **argv) {
   ToolName = argv[0];
 
   // If no input files specified, read from stdin.
-  if (InputFilenames.size() == 0)
-    InputFilenames.push_back("-");
-
-  std::for_each(InputFilenames.begin(), InputFilenames.end(),
-                parseMCMarkup);
-  return 0;
-}
+  if (InputFilenames.size() == 0)\r
+    InputFilenames.push_back("-");\r
+\r
+  llvm::for_each(InputFilenames, parseMCMarkup);\r
+  return 0;\r
+}\r
index 852043002846a6ff781aa2ccd91537a9b57a423d..d2909644628c77e4b4d607915e525d3ff6b60e10 100644 (file)
@@ -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;
index 09396466c40e5030217b800f2dead63f62422e78..d80f1cb049da66ac972cbaed650aa4fc1ae387ab 100644 (file)
@@ -2183,11 +2183,10 @@ int main(int argc, char **argv) {
       && !PrintFaultMaps
       && DwarfDumpType == DIDT_Null) {
     cl::PrintHelpMessage();
-    return 2;
-  }
-
-  std::for_each(InputFilenames.begin(), InputFilenames.end(),
-                DumpInput);
-
-  return EXIT_SUCCESS;
-}
+    return 2;\r
+  }\r
+\r
+  llvm::for_each(InputFilenames, DumpInput);\r
+\r
+  return EXIT_SUCCESS;\r
+}\r
index 8b2d5ce179f44d5af233e21bc404eb9aa5f811ec..bee9f182e3fb58c44e8c759800fd8fe962f78bc1 100644 (file)
@@ -1199,20 +1199,17 @@ int main(int argc_, const char *argv_[]) {
       opts::pretty::ExcludeCompilands.push_back(
           "f:\\\\binaries\\\\Intermediate\\\\vctools\\\\crt_bld");
       opts::pretty::ExcludeCompilands.push_back("f:\\\\dd\\\\vctools\\\\crt");
-      opts::pretty::ExcludeCompilands.push_back(
-          "d:\\\\th.obj.x86fre\\\\minkernel");
-    }
-    std::for_each(opts::pretty::InputFilenames.begin(),
-                  opts::pretty::InputFilenames.end(), dumpPretty);
-  } else if (opts::DumpSubcommand) {
-    std::for_each(opts::dump::InputFilenames.begin(),
-                  opts::dump::InputFilenames.end(), dumpRaw);
-  } else if (opts::BytesSubcommand) {
-    std::for_each(opts::bytes::InputFilenames.begin(),
-                  opts::bytes::InputFilenames.end(), dumpBytes);
-  } else if (opts::DiffSubcommand) {
-    for (StringRef S : opts::diff::RawModiEquivalences) {
-      StringRef Left;
+      opts::pretty::ExcludeCompilands.push_back(\r
+          "d:\\\\th.obj.x86fre\\\\minkernel");\r
+    }\r
+    llvm::for_each(opts::pretty::InputFilenames, dumpPretty);\r
+  } else if (opts::DumpSubcommand) {\r
+    llvm::for_each(opts::dump::InputFilenames, dumpRaw);\r
+  } else if (opts::BytesSubcommand) {\r
+    llvm::for_each(opts::bytes::InputFilenames, dumpBytes);\r
+  } else if (opts::DiffSubcommand) {\r
+    for (StringRef S : opts::diff::RawModiEquivalences) {\r
+      StringRef Left;\r
       StringRef Right;
       std::tie(Left, Right) = S.split(',');
       uint32_t X, Y;
index 05b7c800cc1b954a39440c80056c98bdbab5cb03..851988110ea71e91ab274a62596992fc43a71cb4 100644 (file)
@@ -566,14 +566,13 @@ int main(int argc, const char *argv[]) {
   cl::ParseCommandLineOptions(argc, argv, "LLVM Object Reader\n");
 
   // Default to stdin if no filename is specified.
-  if (opts::InputFilenames.size() == 0)
-    opts::InputFilenames.push_back("-");
-
-  std::for_each(opts::InputFilenames.begin(), opts::InputFilenames.end(),
-                dumpInput);
-
-  if (opts::CodeViewMergedTypes) {
-    ScopedPrinter W(outs());
+  if (opts::InputFilenames.size() == 0)\r
+    opts::InputFilenames.push_back("-");\r
+\r
+  llvm::for_each(opts::InputFilenames, dumpInput);\r
+\r
+  if (opts::CodeViewMergedTypes) {\r
+    ScopedPrinter W(outs());\r
     dumpCodeViewMergedTypes(W, CVTypes.IDTable, CVTypes.TypeTable);
   }
 
index bdb118a264e8cf2ba77715f6ae19544cb04a0285..7a8e744d2e6e9dee30a66bdaafc8f67f919d1ab6 100644 (file)
@@ -880,14 +880,13 @@ int main(int argc, char **argv) {
   }
 
   if (InputFilenames.size() == 0)
-    InputFilenames.push_back("a.out");
-
-  MoreThanOneFile = InputFilenames.size() > 1;
-  std::for_each(InputFilenames.begin(), InputFilenames.end(),
-                printFileSectionSizes);
-  if (OutputFormat == berkeley && TotalSizes)
-    printBerkelyTotals();
-
+    InputFilenames.push_back("a.out");\r
+\r
+  MoreThanOneFile = InputFilenames.size() > 1;\r
+  llvm::for_each(InputFilenames, printFileSectionSizes);\r
+  if (OutputFormat == berkeley && TotalSizes)\r
+    printBerkelyTotals();\r
+\r
   if (HadError)
     return 1;
 }
index 2e6eb6f413f6cb05cd2944bca69665af27ee5699..68cd9f5d2c8b43a692243e13746aba820fa31c96 100644 (file)
@@ -252,12 +252,20 @@ TEST(STLExtrasTest, CountAdaptor) {
   EXPECT_EQ(3, count(v, 1));
   EXPECT_EQ(2, count(v, 2));
   EXPECT_EQ(1, count(v, 3));
-  EXPECT_EQ(1, count(v, 4));
-}
-
-TEST(STLExtrasTest, ToVector) {
-  std::vector<char> v = {'a', 'b', 'c'};
-  auto Enumerated = to_vector<4>(enumerate(v));
+  EXPECT_EQ(1, count(v, 4));\r
+}\r
+\r
+TEST(STLExtrasTest, for_each) {\r
+  std::vector<int> v{ 0, 1, 2, 3, 4 };\r
+  int count = 0;\r
+\r
+  llvm::for_each(v, [&count](int) { ++count; });\r
+  EXPECT_EQ(5, count);\r
+}\r
+\r
+TEST(STLExtrasTest, ToVector) {\r
+  std::vector<char> v = {'a', 'b', 'c'};\r
+  auto Enumerated = to_vector<4>(enumerate(v));\r
   ASSERT_EQ(3u, Enumerated.size());
   for (size_t I = 0; I < v.size(); ++I) {
     EXPECT_EQ(I, Enumerated[I].index());