[llvm] 8eb617d - [SampleFDO] Allow forward compatibility when adding a new section for extbinary

Wei Mi via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 7 19:40:02 PDT 2021


Author: Wei Mi
Date: 2021-09-07T19:38:43-07:00
New Revision: 8eb617d719bdc6a4ed7773925d2421b9bbdd4b7a

URL: https://github.com/llvm/llvm-project/commit/8eb617d719bdc6a4ed7773925d2421b9bbdd4b7a
DIFF: https://github.com/llvm/llvm-project/commit/8eb617d719bdc6a4ed7773925d2421b9bbdd4b7a.diff

LOG: [SampleFDO] Allow forward compatibility when adding a new section for extbinary
format.

Currently when we add a new section in the profile format and generate a profile
containing the new section, older compiler which reads the new profile will
issue an error. The forward incompatibility can cause unnecessary churn when
extending the profile. This patch removes the incompatibility when adding a new
section for extbinary format.

Differential Revision: https://reviews.llvm.org/D109398

Added: 
    llvm/test/tools/llvm-profdata/Inputs/unknown.section.extbin.profdata
    llvm/test/tools/llvm-profdata/forward-compatible.test

Modified: 
    llvm/include/llvm/ProfileData/SampleProf.h
    llvm/include/llvm/ProfileData/SampleProfReader.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ProfileData/SampleProf.h b/llvm/include/llvm/ProfileData/SampleProf.h
index 043e402603075..124e07a930711 100644
--- a/llvm/include/llvm/ProfileData/SampleProf.h
+++ b/llvm/include/llvm/ProfileData/SampleProf.h
@@ -149,8 +149,9 @@ static inline std::string getSecName(SecType Type) {
     return "CSNameTableSection";
   case SecLBRProfile:
     return "LBRProfileSection";
+  default:
+    return "UnknownSection";
   }
-  llvm_unreachable("A SecType has no name for output");
 }
 
 // Entry type of section header table used by SampleProfileExtBinaryBaseReader

diff  --git a/llvm/include/llvm/ProfileData/SampleProfReader.h b/llvm/include/llvm/ProfileData/SampleProfReader.h
index f9a7830335bb7..169ba28965fb3 100644
--- a/llvm/include/llvm/ProfileData/SampleProfReader.h
+++ b/llvm/include/llvm/ProfileData/SampleProfReader.h
@@ -786,6 +786,8 @@ class SampleProfileReaderExtBinary : public SampleProfileReaderExtBinaryBase {
   virtual std::error_code verifySPMagic(uint64_t Magic) override;
   virtual std::error_code
   readCustomSection(const SecHdrTableEntry &Entry) override {
+    // Update the data reader pointer to the end of the section.
+    Data += Entry.Size;
     return sampleprof_error::success;
   };
 

diff  --git a/llvm/test/tools/llvm-profdata/Inputs/unknown.section.extbin.profdata b/llvm/test/tools/llvm-profdata/Inputs/unknown.section.extbin.profdata
new file mode 100644
index 0000000000000..b7d0ddbf36573
Binary files /dev/null and b/llvm/test/tools/llvm-profdata/Inputs/unknown.section.extbin.profdata 
diff er

diff  --git a/llvm/test/tools/llvm-profdata/forward-compatible.test b/llvm/test/tools/llvm-profdata/forward-compatible.test
new file mode 100644
index 0000000000000..50c79a0d3e511
--- /dev/null
+++ b/llvm/test/tools/llvm-profdata/forward-compatible.test
@@ -0,0 +1,26 @@
+RUN: llvm-profdata show -sample %S/Inputs/unknown.section.extbin.profdata | FileCheck %s
+RUN: llvm-profdata show -sample -show-sec-info-only %S/Inputs/unknown.section.extbin.profdata | FileCheck %s -check-prefix=HDR
+
+# The input unknown.section.extbin.profdata contains an unknown section type
+# which uses an enum value which won't be used in the near future. Check
+# llvm-profdata can read it without problem. This is to ensure adding new
+# section in extbinary format for SampleFDO won't cause forward compatibility
+# issue.
+
+CHECK: Function: main: 366846, 0, 3 sampled lines
+CHECK-NEXT: Samples collected in the function's body {
+CHECK-NEXT:   2.1: 60401
+CHECK-NEXT:   3: 0
+CHECK-NEXT:   4: 0
+CHECK-NEXT: }
+
+HDR: ProfileSummarySection - Offset: 242, Size: 121, Flags: {}
+HDR-NEXT: NameTableSection - Offset: 363, Size: 6, Flags: {}
+HDR-NEXT: UnknownSection - Offset: 369, Size: 1, Flags: {}
+HDR-NEXT: FuncOffsetTableSection - Offset: 391, Size: 3, Flags: {}
+HDR-NEXT: LBRProfileSection - Offset: 370, Size: 21, Flags: {}
+HDR-NEXT: ProfileSymbolListSection - Offset: 391, Size: 0, Flags: {}
+HDR-NEXT: FunctionMetadata - Offset: 394, Size: 0, Flags: {}
+HDR-NEXT: Header Size: 242
+HDR-NEXT: Total Sections Size: 152
+HDR-NEXT: File Size: 394


        


More information about the llvm-commits mailing list