[llvm] 7a31ac3 - [InstrProf] Stabilize --show-prof-sym-list dump order

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 22 15:47:48 PDT 2023


Author: Fangrui Song
Date: 2023-07-22T15:47:44-07:00
New Revision: 7a31ac311824011a39ab1e2cf5d2a7a116b0960c

URL: https://github.com/llvm/llvm-project/commit/7a31ac311824011a39ab1e2cf5d2a7a116b0960c
DIFF: https://github.com/llvm/llvm-project/commit/7a31ac311824011a39ab1e2cf5d2a7a116b0960c.diff

LOG: [InstrProf] Stabilize --show-prof-sym-list dump order

D118181 leverages the iteration order of StringSet, which is not
guaranteed to be deterministic.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/compiler-rt/test/profile/Linux/instrprof-show-debug-info-correlation.c b/compiler-rt/test/profile/Linux/instrprof-show-debug-info-correlation.c
index b42f3b3b08e2e1..226d678aca347a 100644
--- a/compiler-rt/test/profile/Linux/instrprof-show-debug-info-correlation.c
+++ b/compiler-rt/test/profile/Linux/instrprof-show-debug-info-correlation.c
@@ -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

diff  --git a/llvm/include/llvm/ProfileData/InstrProf.h b/llvm/include/llvm/ProfileData/InstrProf.h
index a3e21b26a428d8..f64d2e6cb73924 100644
--- a/llvm/include/llvm/ProfileData/InstrProf.h
+++ b/llvm/include/llvm/ProfileData/InstrProf.h
@@ -525,10 +525,7 @@ class InstrProfSymtab {
   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) {

diff  --git a/llvm/lib/ProfileData/InstrProf.cpp b/llvm/lib/ProfileData/InstrProf.cpp
index 5ce474b3bf583c..0f9c33de3f5229 100644
--- a/llvm/lib/ProfileData/InstrProf.cpp
+++ b/llvm/lib/ProfileData/InstrProf.cpp
@@ -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");


        


More information about the llvm-commits mailing list