Skip to content

Commit dc98f92

Browse files
committed
Return probe id for probe discriminator
1 parent 6678f60 commit dc98f92

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed

llvm/include/llvm/IR/DebugInfoMetadata.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "llvm/ADT/iterator_range.h"
2323
#include "llvm/IR/Constants.h"
2424
#include "llvm/IR/Metadata.h"
25+
#include "llvm/IR/PseudoProbe.h"
2526
#include "llvm/Support/Casting.h"
2627
#include "llvm/Support/CommandLine.h"
2728
#include "llvm/Support/Discriminator.h"
@@ -2075,6 +2076,14 @@ class DILocation : public MDNode {
20752076
static unsigned
20762077
getBaseDiscriminatorFromDiscriminator(unsigned D,
20772078
bool IsFSDiscriminator = false) {
2079+
// Return the probe id instead of zero for a pseudo probe discriminator.
2080+
// This should help differenciate callsites with same line numbers to
2081+
// achieve a decent AutoFDO profile under -fpseudo-probe-for-profiling,
2082+
// where the original callsite dwarf discriminator is overwritten by
2083+
// callsite probe information.
2084+
if (isPseudoProbeDiscriminator(D))
2085+
return PseudoProbeDwarfDiscriminator::extractProbeIndex(D);
2086+
20782087
if (IsFSDiscriminator)
20792088
return getMaskedDiscriminator(D, getBaseDiscriminatorBits());
20802089
return getUnsignedFromPrefixEncoding(D);

llvm/test/Transforms/SampleProfile/pseudo-probe-inline.ll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ if.end:
106106
;YAML-NEXT: - Line: '1'
107107
;YAML-NEXT: - String: ':'
108108
;YAML-NEXT: - Column: '11'
109+
;YAML-NEXT: - String: .
110+
;YAML-NEXT: - Disc: '2'
109111
;YAML-NEXT: - String: ';'
110112
;YAML-NEXT: ...
111113
;YAML: --- !Analysis
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
; RUN: llvm-profgen --format=text --use-dwarf-correlation --ignore-stack-samples --perfscript=%S/Inputs/cs-preinline-cost.perfscript --binary=%S/Inputs/cs-preinline-cost.perfbin --output %t
2+
; RUN: FileCheck %s --input-file %t
3+
4+
; CHECK: main:947937:0
5+
; CHECK-NEXT: 2: 545
6+
; CHECK-NEXT: 3: 545
7+
; CHECK-NEXT: 5: 545
8+
; CHECK-NEXT: 7: 0
9+
; CHECK-NEXT: 65496: 545
10+
; CHECK-NEXT: 3.7: _Z3fooi:915794
11+
; CHECK-NEXT: 1: 545
12+
; CHECK-NEXT: 5: 545
13+
; CHECK-NEXT: 6: 272
14+
; CHECK-NEXT: 10: 273
15+
; CHECK-NEXT: 11: 180
16+
; CHECK-NEXT: 12: 6965
17+
; CHECK-NEXT: 13: 6965
18+
; CHECK-NEXT: 14: 6965
19+
; CHECK-NEXT: 15: 6965
20+
; CHECK-NEXT: 20: 182
21+
; CHECK-NEXT: 21: 6958
22+
; CHECK-NEXT: 22: 6958
23+
; CHECK-NEXT: 23: 6958
24+
; CHECK-NEXT: 24: 6958
25+
; CHECK-NEXT: 29: 272
26+
; CHECK-NEXT: 65529: 182
27+
; CHECK-NEXT: 4.8: _Z3fooi:16338
28+
; CHECK-NEXT: 1: 272
29+
; CHECK-NEXT: 6: 545
30+
31+
32+
33+
34+
; binary is built with the source below using the following command line:
35+
; clang -O3 -g -fpseudo-probe-for-profiling test.cpp
36+
;
37+
;#include <stdio.h>
38+
;
39+
;volatile int state = 9000;
40+
;
41+
;int foo(int x) {
42+
; if (x == 0) {
43+
; return 7;
44+
; }
45+
;
46+
; if ((x & 1) == 0) {
47+
; state--;
48+
; return 9;
49+
; }
50+
;
51+
; if (state > 5000) {
52+
; while (state > 5000) {
53+
; for (int i = 50; i >= 0; i--) {
54+
; state *= 6;
55+
; state /= 7;
56+
; state -= 1;
57+
; }
58+
; }
59+
; }
60+
; else {
61+
; while (state < 5000) {
62+
; for (int i = 50; i >= 0; i--) {
63+
; state *= 6;
64+
; state /= 5;
65+
; state += 1;
66+
; }
67+
; }
68+
; }
69+
;
70+
; return state;
71+
;}
72+
;
73+
;volatile int cnt = 10000000;//10000000;
74+
;int main() {
75+
; int r = 0;
76+
; for (int i = 0; i < cnt; i++) {
77+
; r += foo(i);
78+
; r -= foo(i & (~1));
79+
; r += foo(0);
80+
; }
81+
; return r;
82+
;}

0 commit comments

Comments
 (0)