[InstrProf] Stabilize --show-prof-sym-list dump order
authorFangrui Song <i@maskray.me>
Sat, 22 Jul 2023 22:47:44 +0000 (15:47 -0700)
committerFangrui Song <i@maskray.me>
Sat, 22 Jul 2023 22:47:44 +0000 (15:47 -0700)
D118181 leverages the iteration order of StringSet, which is not
guaranteed to be deterministic.

compiler-rt/test/profile/Linux/instrprof-show-debug-info-correlation.c
llvm/include/llvm/ProfileData/InstrProf.h
llvm/lib/ProfileData/InstrProf.cpp

index b42f3b3..226d678 100644 (file)
@@ -34,8 +34,8 @@ void b() {}
 // YAML:     Line:            [[@LINE+1]]
 int main() { return 0; }
 
-// CHECK: main
-// CHECK: a
-// CHECK: b
+// CHECK:      a
+// CHECK-NEXT: b
+// CHECK-NEXT: main
 // CHECK: Counters section size: 0x18 bytes
 // CHECK: Found 3 functions
index a3e21b2..f64d2e6 100644 (file)
@@ -525,10 +525,7 @@ public:
   inline StringRef getNameData() const { return Data; }
 
   /// Dump the symbols in this table.
-  void dumpNames(raw_ostream &OS) const {
-    for (StringRef S : NameTab.keys())
-      OS << S << "\n";
-  }
+  void dumpNames(raw_ostream &OS) const;
 };
 
 Error InstrProfSymtab::create(StringRef D, uint64_t BaseAddr) {
index 5ce474b..0f9c33d 100644 (file)
@@ -415,6 +415,13 @@ uint64_t InstrProfSymtab::getFunctionHashFromAddress(uint64_t Address) {
   return 0;
 }
 
+void InstrProfSymtab::dumpNames(raw_ostream &OS) const {
+  SmallVector<StringRef, 0> Sorted(NameTab.keys());
+  llvm::sort(Sorted);
+  for (StringRef S : Sorted)
+    OS << S << '\n';
+}
+
 Error collectPGOFuncNameStrings(ArrayRef<std::string> NameStrs,
                                 bool doCompression, std::string &Result) {
   assert(!NameStrs.empty() && "No name data to emit");