Coverage: improve efficiency of the counter propagation to the expansion regions.
authorAlex Lorenz <arphaman@gmail.com>
Tue, 29 Jul 2014 21:42:24 +0000 (21:42 +0000)
committerAlex Lorenz <arphaman@gmail.com>
Tue, 29 Jul 2014 21:42:24 +0000 (21:42 +0000)
This patch reduces the complexity of the two inner loops in order to speed up
the loading of coverage data for very large functions.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@214228 91177308-0d34-0410-b5e6-96231b3b80d8

lib/ProfileData/CoverageMappingReader.cpp

index 21acae1bbdd3aaf993e8003e1e346b2dceb64a77..75ade55e2ed148e98b81e92fff9e0f2ffcaa8249 100644 (file)
@@ -251,15 +251,19 @@ std::error_code RawCoverageMappingReader::read(CoverageMappingRecord &Record) {
   // from the expanded file.
   // Perform multiple passes to correctly propagate the counters through
   // all the nested expansion regions.
   // from the expanded file.
   // Perform multiple passes to correctly propagate the counters through
   // all the nested expansion regions.
+  SmallVector<CounterMappingRegion *, 8> FileIDExpansionRegionMapping;
+  FileIDExpansionRegionMapping.resize(VirtualFileMapping.size(), nullptr);
   for (unsigned Pass = 1, S = VirtualFileMapping.size(); Pass < S; ++Pass) {
   for (unsigned Pass = 1, S = VirtualFileMapping.size(); Pass < S; ++Pass) {
-    for (auto &I : MappingRegions) {
-      if (I.Kind == CounterMappingRegion::ExpansionRegion) {
-        for (const auto &J : MappingRegions) {
-          if (J.FileID == I.ExpandedFileID) {
-            I.Count = J.Count;
-            break;
-          }
-        }
+    for (auto &R : MappingRegions) {
+      if (R.Kind != CounterMappingRegion::ExpansionRegion)
+        continue;
+      assert(!FileIDExpansionRegionMapping[R.ExpandedFileID]);
+      FileIDExpansionRegionMapping[R.ExpandedFileID] = &R;
+    }
+    for (auto &R : MappingRegions) {
+      if (FileIDExpansionRegionMapping[R.FileID]) {
+        FileIDExpansionRegionMapping[R.FileID]->Count = R.Count;
+        FileIDExpansionRegionMapping[R.FileID] = nullptr;
       }
     }
   }
       }
     }
   }