[llvm] f553764 - [llvm-profgen] Update total samples by accumulating all its body samples
via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 29 10:37:33 PDT 2021
Author: wlei
Date: 2021-10-29T10:36:57-07:00
New Revision: f5537643b88be7443917a7c7dc0602a97ff7438d
URL: https://github.com/llvm/llvm-project/commit/f5537643b88be7443917a7c7dc0602a97ff7438d
DIFF: https://github.com/llvm/llvm-project/commit/f5537643b88be7443917a7c7dc0602a97ff7438d.diff
LOG: [llvm-profgen] Update total samples by accumulating all its body samples
Like probe-based profile, the total samples is the sum of all its body samples. This patch fix it by a post-processing update for the line-number based profile. Tested it on our internal services, results showed no performance change.
Reviewed By: hoy, wenlei
Differential Revision: https://reviews.llvm.org/D112672
Added:
Modified:
llvm/include/llvm/ProfileData/SampleProf.h
llvm/test/tools/llvm-profgen/coroutine.test
llvm/test/tools/llvm-profgen/cs-interrupt.test
llvm/test/tools/llvm-profgen/cs-preinline.test
llvm/test/tools/llvm-profgen/fname-canonicalization.test
llvm/test/tools/llvm-profgen/func-split.test
llvm/test/tools/llvm-profgen/inline-cs-noprobe.test
llvm/test/tools/llvm-profgen/inline-force-dwarf.test
llvm/test/tools/llvm-profgen/inline-noprobe.test
llvm/test/tools/llvm-profgen/inline-noprobe2.test
llvm/test/tools/llvm-profgen/multi-load-segs.test
llvm/test/tools/llvm-profgen/noinline-cs-noprobe.test
llvm/test/tools/llvm-profgen/noinline-noprobe.test
llvm/test/tools/llvm-profgen/recursion-compression-noprobe.test
llvm/tools/llvm-profgen/ProfileGenerator.cpp
llvm/tools/llvm-profgen/ProfileGenerator.h
llvm/tools/llvm-profgen/ProfiledBinary.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/ProfileData/SampleProf.h b/llvm/include/llvm/ProfileData/SampleProf.h
index c61e334405c6..7ac9eccf8ac2 100644
--- a/llvm/include/llvm/ProfileData/SampleProf.h
+++ b/llvm/include/llvm/ProfileData/SampleProf.h
@@ -731,6 +731,20 @@ class FunctionSamples {
return BodySamples[LineLocation(Index, 0)].merge(S, Weight);
}
+ // Accumulate all body samples to set total samples.
+ void updateTotalSamples() {
+ setTotalSamples(0);
+ for (const auto &I : BodySamples)
+ addTotalSamples(I.second.getSamples());
+
+ for (auto &I : CallsiteSamples) {
+ for (auto &CS : I.second) {
+ CS.second.updateTotalSamples();
+ addTotalSamples(CS.second.getTotalSamples());
+ }
+ }
+ }
+
/// Return the number of samples collected at the given location.
/// Each location is specified by \p LineOffset and \p Discriminator.
/// If the location is not found in profile, return error.
diff --git a/llvm/test/tools/llvm-profgen/coroutine.test b/llvm/test/tools/llvm-profgen/coroutine.test
index 981237c6e244..dd57c3ffe0c8 100644
--- a/llvm/test/tools/llvm-profgen/coroutine.test
+++ b/llvm/test/tools/llvm-profgen/coroutine.test
@@ -2,7 +2,7 @@
; RUN: FileCheck %s --input-file %t --check-prefix=CHECK
; Check that the head sample count for ticker is 0.
-; CHECK: _Z6tickeri:353:0
+; CHECK: _Z6tickeri:67:0
; CHECK-NOT: _Z6tickeri.resume
diff --git a/llvm/test/tools/llvm-profgen/cs-interrupt.test b/llvm/test/tools/llvm-profgen/cs-interrupt.test
index 95f38376e28d..b029e372ec33 100644
--- a/llvm/test/tools/llvm-profgen/cs-interrupt.test
+++ b/llvm/test/tools/llvm-profgen/cs-interrupt.test
@@ -6,14 +6,14 @@
>>>>>>> 02ea7084c370 ([llvm-profgen] Support LBR only perf script)
; RUN: FileCheck %s --input-file %t
-; CHECK:[main:1 @ foo]:88:0
-; CHECK: 2: 5
-; CHECK: 3: 5 bar:5
-; CHECK:[main:1 @ foo:3 @ bar]:74:5
+; CHECK:[main:1 @ foo:3 @ bar]:17:5
; CHECK: 0: 5
; CHECK: 1: 5
; CHECK: 2: 3
; CHECK: 5: 4
+; CHECK:[main:1 @ foo]:10:0
+; CHECK: 2: 5
+; CHECK: 3: 5 bar:5
; CHECK-UNWINDER: [main:1 @ foo]
; CHECK-UNWINDER-NEXT: 3
diff --git a/llvm/test/tools/llvm-profgen/cs-preinline.test b/llvm/test/tools/llvm-profgen/cs-preinline.test
index eda62e891cc0..3d7d59ae214f 100644
--- a/llvm/test/tools/llvm-profgen/cs-preinline.test
+++ b/llvm/test/tools/llvm-profgen/cs-preinline.test
@@ -15,37 +15,37 @@
; RUN: FileCheck %s --input-file %t --check-prefix=CHECK-TRIM
-; CHECK-DEFAULT: [main:1 @ foo]:225:0
+; CHECK-DEFAULT: [main:1 @ foo]:44:0
; CHECK-DEFAULT-NEXT: 2.1: 14
; CHECK-DEFAULT-NEXT: 3: 15
; CHECK-DEFAULT-NEXT: 3.1: 14 bar:14
; CHECK-DEFAULT-NEXT: 3.2: 1
; CHECK-DEFAULT-NEXT: !Attributes: 1
-; CHECK-DEFAULT-NEXT:[main:1 @ foo:3.1 @ bar]:84:0
+; CHECK-DEFAULT-NEXT:[main:1 @ foo:3.1 @ bar]:14:0
; CHECK-DEFAULT-NEXT: 1: 14
; CHECK-DEFAULT-NEXT: !Attributes: 1
-; CHECK-PREINL: [foo]:225:0
+; CHECK-PREINL: [foo]:44:0
; CHECK-PREINL-NEXT: 2.1: 14
; CHECK-PREINL-NEXT: 3: 15
; CHECK-PREINL-NEXT: 3.1: 14 bar:14
; CHECK-PREINL-NEXT: 3.2: 1
; CHECK-PREINL-NEXT: !Attributes: 1
-; CHECK-PREINL-NEXT:[foo:3.1 @ bar]:84:0
+; CHECK-PREINL-NEXT:[foo:3.1 @ bar]:14:0
; CHECK-PREINL-NEXT: 1: 14
; CHECK-PREINL-NEXT: !Attributes: 3
-; CHECK-NO-PREINL: [foo]:225:0
+; CHECK-NO-PREINL: [foo]:44:0
; CHECK-NO-PREINL-NEXT: 2.1: 14
; CHECK-NO-PREINL-NEXT: 3: 15
; CHECK-NO-PREINL-NEXT: 3.1: 14 bar:14
; CHECK-NO-PREINL-NEXT: 3.2: 1
; CHECK-NO-PREINL-NEXT: !Attributes: 1
-; CHECK-NO-PREINL-NEXT:[bar]:84:0
+; CHECK-NO-PREINL-NEXT:[bar]:14:0
; CHECK-NO-PREINL-NEXT: 1: 14
; CHECK-NO-PREINL-NEXT: !Attributes: 1
-; CHECK-TRIM-NOT: [foo]:225:0
-; CHECK-TRIM:[foo:3.1 @ bar]:84:0
+; CHECK-TRIM-NOT: [foo]
+; CHECK-TRIM:[foo:3.1 @ bar]:14:0
; CHECK-TRIM-NEXT: 1: 14
; CHECK-TRIM-NEXT: !Attributes: 3
diff --git a/llvm/test/tools/llvm-profgen/fname-canonicalization.test b/llvm/test/tools/llvm-profgen/fname-canonicalization.test
index 408fad09f48d..21b43a8f4fb2 100644
--- a/llvm/test/tools/llvm-profgen/fname-canonicalization.test
+++ b/llvm/test/tools/llvm-profgen/fname-canonicalization.test
@@ -2,10 +2,10 @@
; RUN: llvm-profgen --format=text --perfscript=%S/Inputs/unique-linkage-name-dwarf.perfscript --binary=%S/Inputs/unique-linkage-name-dwarf.perfbin --output=%t --profile-summary-cold-count=0
; RUN: FileCheck %s --input-file %t --check-prefix=CHECK-DWARF-FNAME
-; CHECK-DWARF-FNAME:[main:1 @ foo]:225:0
+; CHECK-DWARF-FNAME:[main:1 @ foo]:43:0
; CHECK-DWARF-FNAME: 2: 14
; CHECK-DWARF-FNAME: 3: 29 bar.__uniq.26267048767521081047744692097241227776:14
-; CHECK-DWARF-FNAME:[main:1 @ foo:3 @ bar.__uniq.26267048767521081047744692097241227776]:84:0
+; CHECK-DWARF-FNAME:[main:1 @ foo:3 @ bar.__uniq.26267048767521081047744692097241227776]:14:0
; CHECK-DWARF-FNAME: 1: 14
diff --git a/llvm/test/tools/llvm-profgen/func-split.test b/llvm/test/tools/llvm-profgen/func-split.test
index 49c77a24ecb6..6ace0cd0ab60 100644
--- a/llvm/test/tools/llvm-profgen/func-split.test
+++ b/llvm/test/tools/llvm-profgen/func-split.test
@@ -3,26 +3,26 @@
; RUN: llvm-profgen --format=text --perfscript=%S/Inputs/func-split.perfscript --binary=%S/Inputs/func-split.perfbin --output=%t --ignore-stack-samples
; RUN: FileCheck %s --input-file %t --check-prefix=CHECK-STRIP-CTX
-;CHECK: [foo]:408:0
+;CHECK: [foo]:82:0
;CHECK: 2.1: 27
;CHECK: 3: 27
;CHECK: 3.1: 2 bar:2
;CHECK: 3.2: 26
-;CHECK: [foo:3.1 @ bar]:8:0
+;CHECK: [foo:3.1 @ bar]:2:0
;CHECK: 1: 1
;CHECK: 5: 1
;CHECK: [bar]:0:1
;CHECK-NOT: foo.cold
-;CHECK-STRIP-CTX: foo:408:0
+;CHECK-STRIP-CTX: foo:81:0
;CHECK-STRIP-CTX: 0: 0
;CHECK-STRIP-CTX: 2.1: 27
;CHECK-STRIP-CTX: 3: 27
;CHECK-STRIP-CTX: 3.1: 1 bar:1
;CHECK-STRIP-CTX: 3.2: 26
;CHECK-STRIP-CTX: 4: 0
-;CHECK-STRIP-CTX: bar:8:1
+;CHECK-STRIP-CTX: bar:2:1
;CHECK-STRIP-CTX: 1: 1
;CHECK-STRIP-CTX: 5: 1
diff --git a/llvm/test/tools/llvm-profgen/inline-cs-noprobe.test b/llvm/test/tools/llvm-profgen/inline-cs-noprobe.test
index c7657ef348a3..cd8dae192e9e 100644
--- a/llvm/test/tools/llvm-profgen/inline-cs-noprobe.test
+++ b/llvm/test/tools/llvm-profgen/inline-cs-noprobe.test
@@ -13,12 +13,12 @@
; CHECK-SYM-LIST: foo
; CHECK-SYM-LIST: main
-; CHECK:[main:1 @ foo]:225:0
+; CHECK:[main:1 @ foo]:44:0
; CHECK: 2.1: 14
; CHECK: 3: 15
; CHECK: 3.1: 14 bar:14
; CHECK: 3.2: 1
-; CHECK:[main:1 @ foo:3.1 @ bar]:84:0
+; CHECK:[main:1 @ foo:3.1 @ bar]:14:0
; CHECK: 1: 14
; CHECK-UNWINDER: [main:1 @ foo]
@@ -34,16 +34,16 @@
; CHECK-UNWINDER: 6af-6bb:14
; CHECK-UNWINDER: 0
-; CHECK-STRIP-CTX: main:295:0
+; CHECK-STRIP-CTX: main:44:0
; CHECK-STRIP-CTX: 0: 0
; CHECK-STRIP-CTX: 2: 0
-; CHECK-STRIP-CTX: 1: foo:295
+; CHECK-STRIP-CTX: 1: foo:44
; CHECK-STRIP-CTX: 2.1: 14
; CHECK-STRIP-CTX: 3: 15
; CHECK-STRIP-CTX: 3.2: 1
; CHECK-STRIP-CTX: 4: 0
; CHECK-STRIP-CTX: 7: 0
-; CHECK-STRIP-CTX: 3.1: bar:84
+; CHECK-STRIP-CTX: 3.1: bar:14
; CHECK-STRIP-CTX: 1: 14
; original code:
diff --git a/llvm/test/tools/llvm-profgen/inline-force-dwarf.test b/llvm/test/tools/llvm-profgen/inline-force-dwarf.test
index ddca6aff6532..05cb91f26def 100644
--- a/llvm/test/tools/llvm-profgen/inline-force-dwarf.test
+++ b/llvm/test/tools/llvm-profgen/inline-force-dwarf.test
@@ -1,14 +1,14 @@
; RUN: llvm-profgen --format=text --ignore-stack-samples --use-dwarf-correlation --perfscript=%S/Inputs/inline-cs-pseudoprobe.perfscript --binary=%S/Inputs/inline-cs-pseudoprobe.perfbin --output=%t --profile-summary-cold-count=0
; RUN: FileCheck %s --input-file %t
-; CHECK: main:295:0
+; CHECK: main:43:0
; CHECK-NEXT: 0: 0
; CHECK-NEXT: 2: 0
-; CHECK-NEXT: 1: foo:295
+; CHECK-NEXT: 1: foo:43
; CHECK-NEXT: 2: 14
; CHECK-NEXT: 3: 15
; CHECK-NEXT: 4: 0
-; CHECK-NEXT: 3: bar:84
+; CHECK-NEXT: 3: bar:14
; CHECK-NEXT: 1: 14
diff --git a/llvm/test/tools/llvm-profgen/inline-noprobe.test b/llvm/test/tools/llvm-profgen/inline-noprobe.test
index f7a61470f261..5203a5968ff9 100644
--- a/llvm/test/tools/llvm-profgen/inline-noprobe.test
+++ b/llvm/test/tools/llvm-profgen/inline-noprobe.test
@@ -7,17 +7,17 @@
; RUN: llvm-profgen --format=text --use-dwarf-correlation --perfscript=%S/Inputs/inline-noprobe.perfscript --binary=%S/Inputs/inline-noprobe.perfbin --output=%t
; RUN: FileCheck %s --input-file %t --check-prefix=CHECK
-CHECK: main:669:0
+CHECK: main:188:0
CHECK: 0: 0
CHECK: 2: 0
-CHECK: 1: foo:669
+CHECK: 1: foo:188
CHECK: 2.1: 42
CHECK: 3: 62
CHECK: 3.2: 21
CHECK: 4: 0
-CHECK: 3.1: bar:210
+CHECK: 3.1: bar:42
CHECK: 1: 42
-CHECK: 3.2: bar:63
+CHECK: 3.2: bar:21
CHECK: 1: 21
CHECK-RAW-PROFILE: 3
diff --git a/llvm/test/tools/llvm-profgen/inline-noprobe2.test b/llvm/test/tools/llvm-profgen/inline-noprobe2.test
index 27019a468a84..d8c73ffad83d 100644
--- a/llvm/test/tools/llvm-profgen/inline-noprobe2.test
+++ b/llvm/test/tools/llvm-profgen/inline-noprobe2.test
@@ -27,7 +27,7 @@
;CHECK-RAW-PROFILE-NOT: 7f7448e889e4
;CHECK-RAW-PROFILE-NOT: 7f7448e88826
-;CHECK: partition_pivot_first:1045:5
+;CHECK: partition_pivot_first:367:5
;CHECK-NEXT: 0: 5
;CHECK-NEXT: 1: 5
;CHECK-NEXT: 2: 5
@@ -39,15 +39,15 @@
;CHECK-NEXT: 4.3: 26
;CHECK-NEXT: 5: 6
;CHECK-NEXT: 6: 6
-;CHECK-NEXT: 4.2: swap:100
+;CHECK-NEXT: 4.2: swap:75
;CHECK-NEXT: 1: 25
;CHECK-NEXT: 2: 25
;CHECK-NEXT: 3: 25
-;CHECK-NEXT: 5: swap:24
+;CHECK-NEXT: 5: swap:18
;CHECK-NEXT: 1: 6
;CHECK-NEXT: 2: 6
;CHECK-NEXT: 3: 6
-;CHECK-NEXT: partition_pivot_last:389:7
+;CHECK-NEXT: partition_pivot_last:225:7
;CHECK-NEXT: 1: 6
;CHECK-NEXT: 2: 6
;CHECK-NEXT: 3: 6
@@ -63,7 +63,7 @@
;CHECK-NEXT: 6: 5
;CHECK-NEXT: 7: 5
-;CHECK-NEXT: 5: swap:61
+;CHECK-NEXT: 5: swap:54
;w/o duplication factor : 1: 9
;w/o duplication factor : 2: 9
@@ -72,17 +72,17 @@
;CHECK-NEXT: 2: 18
;CHECK-NEXT: 3: 18
-;CHECK-NEXT: 6: swap:20
+;CHECK-NEXT: 6: swap:15
;CHECK-NEXT: 1: 5
;CHECK-NEXT: 2: 5
;CHECK-NEXT: 3: 5
-;CHECK-NEXT: quick_sort:318:25
+;CHECK-NEXT: quick_sort:83:25
;CHECK-NEXT: 1: 24
;CHECK-NEXT: 2: 12 partition_pivot_last:7 partition_pivot_first:5
;CHECK-NEXT: 3: 11 quick_sort:12
;CHECK-NEXT: 4: 12 quick_sort:12
;CHECK-NEXT: 6: 24
-;CHECK-NEXT: main:213:0
+;CHECK-NEXT: main:52:0
;CHECK-NEXT: 0: 0
;CHECK-NEXT: 3: 0
;CHECK-NEXT: 4.1: 0
diff --git a/llvm/test/tools/llvm-profgen/multi-load-segs.test b/llvm/test/tools/llvm-profgen/multi-load-segs.test
index 657a15097415..7af50d3feb05 100644
--- a/llvm/test/tools/llvm-profgen/multi-load-segs.test
+++ b/llvm/test/tools/llvm-profgen/multi-load-segs.test
@@ -9,7 +9,7 @@
;; LOAD 0x000e10 0x0000000000203e10 0x0000000000203e10 0x000040 0x000058 RW 0x1000
;; LOAD 0x200000 0x0000000000400000 0x0000000000400000 0x0005e8 0x0005e8 R E 0x200000
-; CHECK: [main:2 @ _Z10sort_arrayv:6 @ _Z11bubble_sortPii]:434:0
+; CHECK: [main:2 @ _Z10sort_arrayv:6 @ _Z11bubble_sortPii]:124:0
; CHECK-NEXT: 4: 31
; CHECK-NEXT: 5: 31
; CHECK-NEXT: 7: 31
diff --git a/llvm/test/tools/llvm-profgen/noinline-cs-noprobe.test b/llvm/test/tools/llvm-profgen/noinline-cs-noprobe.test
index 9f4918741d85..cff82f7b52ae 100644
--- a/llvm/test/tools/llvm-profgen/noinline-cs-noprobe.test
+++ b/llvm/test/tools/llvm-profgen/noinline-cs-noprobe.test
@@ -19,15 +19,16 @@
; RUN:
diff -b %t.summary %t2.summary
-; CHECK-AGG:[main:1 @ foo]:108:0
-; CHECK-AGG: 2: 6
-; CHECK-AGG: 3: 6 bar:6
-; CHECK-AGG:[main:1 @ foo:3 @ bar]:100:6
+; CHECK-AGG:[main:1 @ foo:3 @ bar]:24:6
; CHECK-AGG: 0: 6
; CHECK-AGG: 1: 6
; CHECK-AGG: 2: 4
; CHECK-AGG: 4: 2
; CHECK-AGG: 5: 6
+; CHECK-AGG:[main:1 @ foo]:12:0
+; CHECK-AGG: 2: 6
+; CHECK-AGG: 3: 6 bar:6
+
; CHECK-AGG-UNWINDER: [main:1 @ foo]
; CHECK-AGG-UNWINDER-NEXT: 3
@@ -50,29 +51,29 @@
; CHECK-AGG-UNWINDER-NEXT: 5e9->634:6
-; CHECK:[main:1 @ foo]:54:0
-; CHECK: 2: 3
-; CHECK: 3: 3 bar:3
-; CHECK:[main:1 @ foo:3 @ bar]:50:3
+; CHECK:[main:1 @ foo:3 @ bar]:12:3
; CHECK: 0: 3
; CHECK: 1: 3
; CHECK: 2: 2
; CHECK: 4: 1
; CHECK: 5: 3
+; CHECK:[main:1 @ foo]:6:0
+; CHECK: 2: 3
+; CHECK: 3: 3 bar:3
-; CHECK-STRIP-CTX: foo:57:0
+; CHECK-STRIP-CTX: bar:12:3
+; CHECK-STRIP-CTX: 0: 3
+; CHECK-STRIP-CTX: 1: 3
+; CHECK-STRIP-CTX: 2: 2
+; CHECK-STRIP-CTX: 4: 1
+; CHECK-STRIP-CTX: 5: 3
+; CHECK-STRIP-CTX: foo:6:0
; CHECK-STRIP-CTX: 0: 0
; CHECK-STRIP-CTX: 1: 0
; CHECK-STRIP-CTX: 2: 3
; CHECK-STRIP-CTX: 3: 3 bar:3
; CHECK-STRIP-CTX: 4: 0
; CHECK-STRIP-CTX: 5: 0
-; CHECK-STRIP-CTX: bar:50:3
-; CHECK-STRIP-CTX: 0: 3
-; CHECK-STRIP-CTX: 1: 3
-; CHECK-STRIP-CTX: 2: 2
-; CHECK-STRIP-CTX: 4: 1
-; CHECK-STRIP-CTX: 5: 3
; CHECK-UNWINDER: [main:1 @ foo]
; CHECK-UNWINDER-NEXT: 3
diff --git a/llvm/test/tools/llvm-profgen/noinline-noprobe.test b/llvm/test/tools/llvm-profgen/noinline-noprobe.test
index b4cc5476fef0..ff2b5a55c3b7 100644
--- a/llvm/test/tools/llvm-profgen/noinline-noprobe.test
+++ b/llvm/test/tools/llvm-profgen/noinline-noprobe.test
@@ -7,15 +7,19 @@
; RUN: llvm-profgen --format=text --perfscript=%S/Inputs/noprobe.perfscript --binary=%S/Inputs/noprobe.perfbin --output=%t
; RUN: FileCheck %s --input-file %t --check-prefix=CHECK
-CHECK: foo:360:0
-CHECK: 2: 19
-CHECK: 3: 19 bar:21
-CHECK: bar:324:21
+CHECK: bar:77:21
CHECK: 0: 20
CHECK: 1: 20
CHECK: 2: 13
CHECK: 4: 6
CHECK: 5: 18
+CHECK: foo:38:0
+CHECK: 0: 0
+CHECK: 1: 0
+CHECK: 2: 19
+CHECK: 3: 19 bar:21
+CHECK: 4: 0
+CHECK: 5: 0
CHECK-RAW-PROFILE: 7
CHECK-RAW-PROFILE-NEXT: 5b0-5c8:7
diff --git a/llvm/test/tools/llvm-profgen/recursion-compression-noprobe.test b/llvm/test/tools/llvm-profgen/recursion-compression-noprobe.test
index ba01bd348114..b45e91b846fd 100644
--- a/llvm/test/tools/llvm-profgen/recursion-compression-noprobe.test
+++ b/llvm/test/tools/llvm-profgen/recursion-compression-noprobe.test
@@ -6,48 +6,51 @@
; RUN: llvm-profgen --format=text --perfscript=%S/Inputs/recursion-compression-noprobe.perfscript --binary=%S/Inputs/recursion-compression-noprobe.perfbin --output=%t --compress-recursion=0 --profile-summary-cold-count=0 --csprof-max-context-depth=2
; RUN: FileCheck %s --input-file %t -check-prefix=CHECK-MAX-CTX-DEPTH
-; CHECK-UNCOMPRESS:[main:1 @ foo:3 @ fa:2 @ fb]:37:0
-; CHECK-UNCOMPRESS: 1: 11
-; CHECK-UNCOMPRESS: 2: 1 fa:1
-; CHECK-UNCOMPRESS:[main:1 @ foo:3 @ fa]:21:0
+; CHECK-UNCOMPRESS:[main:1 @ foo:3 @ fa]:14:0
; CHECK-UNCOMPRESS: 1: 1
; CHECK-UNCOMPRESS: 2: 13 fb:11
-; CHECK-UNCOMPRESS:[main:1 @ foo]:7:0
+; CHECK-UNCOMPRESS:[main:1 @ foo:3 @ fa:2 @ fb]:12:0
+; CHECK-UNCOMPRESS: 1: 11
+; CHECK-UNCOMPRESS: 2: 1 fa:1
+; CHECK-UNCOMPRESS:[main:1 @ foo]:3:0
; CHECK-UNCOMPRESS: 2: 1
; CHECK-UNCOMPRESS: 3: 2 fa:1
-; CHECK-UNCOMPRESS:[main:1 @ foo:3 @ fa:2 @ fb:2 @ fa]:6:0
+; CHECK-UNCOMPRESS:[main:1 @ foo:3 @ fa:2 @ fb:2 @ fa]:2:0
; CHECK-UNCOMPRESS: 1: 1
; CHECK-UNCOMPRESS: 2: 1
-; CHECK-UNCOMPRESS:[main:1 @ foo:3 @ fa:2 @ fb:2 @ fa:2 @ fb:2 @ fa]:2:0
+; CHECK-UNCOMPRESS:[main:1 @ foo:3 @ fa:2 @ fb:2 @ fa:2 @ fb:2 @ fa]:1:0
; CHECK-UNCOMPRESS: 4: 1
-; CHECK-MAX-CTX-DEPTH:[foo:3 @ fa:2 @ fb]:36:0
+; CHECK-MAX-CTX-DEPTH:[foo:3 @ fa:2 @ fb]:11:0
; CHECK-MAX-CTX-DEPTH: 1: 11
-; CHECK-MAX-CTX-DEPTH:[main:1 @ foo:3 @ fa]:10:0
-; CHECK-MAX-CTX-DEPTH: 1: 1
-; CHECK-MAX-CTX-DEPTH: 2: 2
-; CHECK-MAX-CTX-DEPTH:[fa:2 @ fb:2 @ fa]:8:0
+; CHECK-MAX-CTX-DEPTH:[fa:2 @ fb:2 @ fa]:3:0
; CHECK-MAX-CTX-DEPTH: 1: 1
; CHECK-MAX-CTX-DEPTH: 2: 1
; CHECK-MAX-CTX-DEPTH: 4: 1
-; CHECK-MAX-CTX-DEPTH:[main:1 @ foo]:7:0
+; CHECK-MAX-CTX-DEPTH:[main:1 @ foo]:3:0
; CHECK-MAX-CTX-DEPTH: 2: 1
; CHECK-MAX-CTX-DEPTH: 3: 2 fa:1
+; CHECK-MAX-CTX-DEPTH:[main:1 @ foo:3 @ fa]:3:0
+; CHECK-MAX-CTX-DEPTH: 1: 1
+; CHECK-MAX-CTX-DEPTH: 2: 2
-; CHECK: [main:1 @ foo:3 @ fa:2 @ fb]:37:0
-; CHECK: 1: 11
-; CHECK: 2: 1 fa:1
-; CHECK: [main:1 @ foo:3 @ fa]:21:0
+
+
+; CHECK: [main:1 @ foo:3 @ fa]:14:0
; CHECK: 1: 1
; CHECK: 2: 13 fb:11
-; CHECK: [main:1 @ foo:3 @ fa:2 @ fb:2 @ fa]:8:0
+; CHECK: [main:1 @ foo:3 @ fa:2 @ fb]:12:0
+; CHECK: 1: 11
+; CHECK: 2: 1 fa:1
+; CHECK: [main:1 @ foo]:3:0
+; CHECK: 2: 1
+; CHECK: 3: 2 fa:1
+; CHECK: [main:1 @ foo:3 @ fa:2 @ fb:2 @ fa]:3:0
; CHECK: 1: 1
; CHECK: 2: 1
; CHECK: 4: 1
-; CHECK: [main:1 @ foo]:7:0
-; CHECK: 2: 1
-; CHECK: 3: 2 fa:1
+
; original code:
; clang -O3 -g test.c -o a.out
diff --git a/llvm/tools/llvm-profgen/ProfileGenerator.cpp b/llvm/tools/llvm-profgen/ProfileGenerator.cpp
index 88e96348cba4..1e857a6d917d 100644
--- a/llvm/tools/llvm-profgen/ProfileGenerator.cpp
+++ b/llvm/tools/llvm-profgen/ProfileGenerator.cpp
@@ -282,6 +282,13 @@ void ProfileGeneratorBase::updateBodySamplesforFunctionProfile(
}
}
+void ProfileGeneratorBase::updateTotalSamples() {
+ for (auto &Item : ProfileMap) {
+ FunctionSamples &FunctionProfile = Item.second;
+ FunctionProfile.updateTotalSamples();
+ }
+}
+
FunctionSamples &
ProfileGenerator::getTopLevelFunctionProfile(StringRef FuncName) {
SampleContext Context(FuncName);
@@ -309,14 +316,15 @@ void ProfileGenerator::generateLineNumBasedProfile() {
populateBodySamplesForAllFunctions(SC.RangeCounter);
// Fill in boundary sample counts as well as call site samples for calls
populateBoundarySamplesForAllFunctions(SC.BranchCounter);
+
+ updateTotalSamples();
}
-FunctionSamples &ProfileGenerator::getLeafProfileAndAddTotalSamples(
- const SampleContextFrameVector &FrameVec, uint64_t Count) {
+FunctionSamples &ProfileGenerator::getLeafFrameProfile(
+ const SampleContextFrameVector &FrameVec) {
// Get top level profile
FunctionSamples *FunctionProfile =
&getTopLevelFunctionProfile(FrameVec[0].FuncName);
- FunctionProfile->addTotalSamples(Count);
for (size_t I = 1; I < FrameVec.size(); I++) {
LineLocation Callsite(
@@ -331,7 +339,6 @@ FunctionSamples &ProfileGenerator::getLeafProfileAndAddTotalSamples(
Ret.first->second.setContext(Context);
}
FunctionProfile = &Ret.first->second;
- FunctionProfile->addTotalSamples(Count);
}
return *FunctionProfile;
@@ -370,8 +377,7 @@ void ProfileGenerator::populateBodySamplesForAllFunctions(
const SampleContextFrameVector &FrameVec =
Binary->getFrameLocationStack(Offset);
if (!FrameVec.empty()) {
- FunctionSamples &FunctionProfile =
- getLeafProfileAndAddTotalSamples(FrameVec, Count);
+ FunctionSamples &FunctionProfile = getLeafFrameProfile(FrameVec);
updateBodySamplesforFunctionProfile(FunctionProfile, FrameVec.back(),
Count);
}
@@ -408,8 +414,7 @@ void ProfileGenerator::populateBoundarySamplesForAllFunctions(
const SampleContextFrameVector &FrameVec =
Binary->getFrameLocationStack(SourceOffset);
if (!FrameVec.empty()) {
- FunctionSamples &FunctionProfile =
- getLeafProfileAndAddTotalSamples(FrameVec, Count);
+ FunctionSamples &FunctionProfile = getLeafFrameProfile(FrameVec);
FunctionProfile.addCalledTargetSamples(
FrameVec.back().Location.LineOffset,
getBaseDiscriminator(FrameVec.back().Location.Discriminator),
@@ -497,6 +502,8 @@ void CSProfileGenerator::generateLineNumBasedProfile() {
// functions, we estimate it from inlinee's profile using the entry of the
// body sample.
populateInferredFunctionSamples();
+
+ updateTotalSamples();
}
void CSProfileGenerator::populateBodySamplesForFunction(
@@ -524,7 +531,6 @@ void CSProfileGenerator::populateBodySamplesForFunction(
if (LeafLoc.hasValue()) {
// Recording body sample for this specific context
updateBodySamplesforFunctionProfile(FunctionProfile, *LeafLoc, Count);
- FunctionProfile.addTotalSamples(Count);
}
// Move to next IP within the range
@@ -619,7 +625,6 @@ void CSProfileGenerator::populateInferredFunctionSamples() {
CallerProfile.addBodySamples(CallerLeafFrameLoc.Location.LineOffset,
CallerLeafFrameLoc.Location.Discriminator,
EstimatedCallCount);
- CallerProfile.addTotalSamples(EstimatedCallCount);
}
}
diff --git a/llvm/tools/llvm-profgen/ProfileGenerator.h b/llvm/tools/llvm-profgen/ProfileGenerator.h
index 9e5aecef8847..a0609b0a33af 100644
--- a/llvm/tools/llvm-profgen/ProfileGenerator.h
+++ b/llvm/tools/llvm-profgen/ProfileGenerator.h
@@ -74,6 +74,7 @@ class ProfileGeneratorBase {
void updateBodySamplesforFunctionProfile(FunctionSamples &FunctionProfile,
const SampleContextFrame &LeafLoc,
uint64_t Count);
+ void updateTotalSamples();
StringRef getCalleeNameForOffset(uint64_t TargetOffset);
// Used by SampleProfileWriter
SampleProfileMap ProfileMap;
@@ -99,8 +100,7 @@ class ProfileGenerator : public ProfileGeneratorBase {
// inline stack and meanwhile it adds the total samples for each frame's
// function profile.
FunctionSamples &
- getLeafProfileAndAddTotalSamples(const SampleContextFrameVector &FrameVec,
- uint64_t Count);
+ getLeafFrameProfile(const SampleContextFrameVector &FrameVec);
void populateBodySamplesForAllFunctions(const RangeSample &RangeCounter);
void
populateBoundarySamplesForAllFunctions(const BranchSample &BranchCounters);
diff --git a/llvm/tools/llvm-profgen/ProfiledBinary.cpp b/llvm/tools/llvm-profgen/ProfiledBinary.cpp
index 6d8dd78d04ae..bf5c914c5daa 100644
--- a/llvm/tools/llvm-profgen/ProfiledBinary.cpp
+++ b/llvm/tools/llvm-profgen/ProfiledBinary.cpp
@@ -10,7 +10,6 @@
#include "ErrorHandling.h"
#include "ProfileGenerator.h"
#include "llvm/ADT/Triple.h"
-#include "llvm/DebugInfo/DWARF/DWARFContext.h"
#include "llvm/Demangle/Demangle.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/MC/TargetRegistry.h"
More information about the llvm-commits
mailing list