[X86][Haswell][SchedModel] Add architecture specific scheduling models.
[oota-llvm.git] / lib / ProfileData / CoverageMappingReader.cpp
index 21acae1bbdd3aaf993e8003e1e346b2dceb64a77..c8108d4ce9945e9759c38c71e0559261cff5d3ff 100644 (file)
@@ -170,13 +170,17 @@ std::error_code RawCoverageMappingReader::readMappingRegionsSubArray(
     }
 
     // Read the source range.
-    uint64_t LineStartDelta, ColumnStart, NumLines, ColumnEnd;
+    uint64_t LineStartDelta, CodeBeforeColumnStart, NumLines, ColumnEnd;
     if (auto Err =
             readIntMax(LineStartDelta, std::numeric_limits<unsigned>::max()))
       return Err;
-    if (auto Err =
-            readIntMax(ColumnStart, std::numeric_limits<unsigned>::max()))
+    if (auto Err = readULEB128(CodeBeforeColumnStart))
       return Err;
+    bool HasCodeBefore = CodeBeforeColumnStart & 1;
+    uint64_t ColumnStart = CodeBeforeColumnStart >>
+                           CounterMappingRegion::EncodingHasCodeBeforeBits;
+    if (ColumnStart > std::numeric_limits<unsigned>::max())
+      return error(instrprof_error::malformed);
     if (auto Err = readIntMax(NumLines, std::numeric_limits<unsigned>::max()))
       return Err;
     if (auto Err = readIntMax(ColumnEnd, std::numeric_limits<unsigned>::max()))
@@ -194,9 +198,9 @@ std::error_code RawCoverageMappingReader::readMappingRegionsSubArray(
       ColumnStart = 1;
       ColumnEnd = std::numeric_limits<unsigned>::max();
     }
-    MappingRegions.push_back(
-        CounterMappingRegion(C, InferredFileID, LineStart, ColumnStart,
-                             LineStart + NumLines, ColumnEnd, Kind));
+    MappingRegions.push_back(CounterMappingRegion(
+        C, InferredFileID, LineStart, ColumnStart, LineStart + NumLines,
+        ColumnEnd, HasCodeBefore, Kind));
     MappingRegions.back().ExpandedFileID = ExpandedFileID;
   }
   return success();
@@ -251,15 +255,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.
+  SmallVector<CounterMappingRegion *, 8> FileIDExpansionRegionMapping;
+  FileIDExpansionRegionMapping.resize(VirtualFileMapping.size(), nullptr);
   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;
       }
     }
   }
@@ -278,7 +286,7 @@ ObjectFileCoverageMappingReader::ObjectFileCoverageMappingReader(
   if (!File)
     error(File.getError());
   else
-    Object.reset(File.get());
+    Object = std::move(File.get());
 }
 
 ObjectFileCoverageMappingReader::ObjectFileCoverageMappingReader(
@@ -288,7 +296,7 @@ ObjectFileCoverageMappingReader::ObjectFileCoverageMappingReader(
   if (!File)
     error(File.getError());
   else
-    Object.reset(File.get());
+    Object = std::move(File.get());
 }
 
 namespace {