SamplePGO - Sort samples by source location when emitting as text.
[oota-llvm.git] / lib / ProfileData / SampleProf.cpp
index 3d75d230fb6f0ee65a7d1e9ccb575f8201d354bf..c376a8bbd98d06ae68ef3a6f47e2299753245045 100644 (file)
@@ -108,15 +108,18 @@ void FunctionSamples::print(raw_ostream &OS, unsigned Indent) const {
   OS << TotalSamples << ", " << TotalHeadSamples << ", " << BodySamples.size()
      << " sampled lines\n";
 
-  for (const auto &SI : BodySamples) {
+  SampleSorter<LineLocation, SampleRecord> SortedBodySamples(BodySamples);
+  for (const auto &SI : SortedBodySamples.get()) {
     OS.indent(Indent);
-    OS << SI.first << ": " << SI.second;
+    OS << SI->first << ": " << SI->second;
   }
 
-  for (const auto &CS : CallsiteSamples) {
+  SampleSorter<CallsiteLocation, FunctionSamples> SortedCallsiteSamples(
+      CallsiteSamples);
+  for (const auto &CS : SortedCallsiteSamples.get()) {
     OS.indent(Indent);
-    OS << CS.first << ": ";
-    CS.second.print(OS, Indent + 2);
+    OS << CS->first << ": ";
+    CS->second.print(OS, Indent + 2);
   }
 }