forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ctx_prof] CtxProfAnalysis: populate module data (llvm#102930)
Continuing from llvm#102084, which introduced the analysis, we now populate it with info about functions contained in the module. When we will update the profile due to e.g. inlined callsites, we'll ingest the callee's counters and callsites to the caller. We'll move those to the caller's respective index space (counter and callers), so we need to know and maintain where those currently end. We also don't need to keep profiles not pertinent to this module. This patch also introduces an arguably much simpler way to track the GUID of a function from the frontend compilation, through ThinLTO, and into the post-thinlink compilation step, which doesn't rely on keeping names around. A separate RFC and patches will discuss extending this to the current PGO (instrumented and sampled) and other consumers as an infrastructural component.
- Loading branch information
Showing
9 changed files
with
385 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
; REQUIRES: x86_64-linux | ||
; | ||
; RUN: rm -rf %t | ||
; RUN: split-file %s %t | ||
; | ||
; Test that the GUID metadata survives through thinlink. | ||
; | ||
; RUN: llvm-ctxprof-util fromJSON --input=%t/profile.json --output=%t/profile.ctxprofdata | ||
; | ||
; RUN: opt -module-summary -passes='thinlto-pre-link<O2>' -use-ctx-profile=%t/profile.ctxprofdata -o %t/m1.bc %t/m1.ll | ||
; RUN: opt -module-summary -passes='thinlto-pre-link<O2>' -use-ctx-profile=%t/profile.ctxprofdata -o %t/m2.bc %t/m2.ll | ||
; | ||
; RUN: rm -rf %t/postlink | ||
; RUN: mkdir %t/postlink | ||
; | ||
; | ||
; RUN: llvm-lto2 run %t/m1.bc %t/m2.bc -o %t/ -thinlto-distributed-indexes \ | ||
; RUN: -use-ctx-profile=%t/profile.ctxprofdata \ | ||
; RUN: -r %t/m1.bc,f1,plx \ | ||
; RUN: -r %t/m2.bc,f1 \ | ||
; RUN: -r %t/m2.bc,entrypoint,plx | ||
; RUN: opt --passes='function-import,require<ctx-prof-analysis>,print<ctx-prof-analysis>' \ | ||
; RUN: -summary-file=%t/m2.bc.thinlto.bc -use-ctx-profile=%t/profile.ctxprofdata %t/m2.bc \ | ||
; RUN: -S -o %t/m2.post.ll 2> %t/profile.txt | ||
; RUN: diff %t/expected.txt %t/profile.txt | ||
;--- m1.ll | ||
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" | ||
target triple = "x86_64-pc-linux-gnu" | ||
|
||
source_filename = "random_path/m1.cc" | ||
|
||
define private void @f2() #0 !guid !0 { | ||
ret void | ||
} | ||
|
||
define void @f1() #0 { | ||
call void @f2() | ||
ret void | ||
} | ||
|
||
attributes #0 = { noinline } | ||
!0 = !{ i64 3087265239403591524 } | ||
|
||
;--- m2.ll | ||
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" | ||
target triple = "x86_64-pc-linux-gnu" | ||
|
||
source_filename = "random_path/m2.cc" | ||
|
||
declare void @f1() | ||
|
||
define void @entrypoint() { | ||
call void @f1() | ||
ret void | ||
} | ||
;--- profile.json | ||
[ | ||
{ | ||
"Callsites": [ | ||
[ | ||
{ | ||
"Callsites": [ | ||
[ | ||
{ | ||
"Counters": [ | ||
10 | ||
], | ||
"Guid": 3087265239403591524 | ||
} | ||
] | ||
], | ||
"Counters": [ | ||
7 | ||
], | ||
"Guid": 2072045998141807037 | ||
} | ||
] | ||
], | ||
"Counters": [ | ||
1 | ||
], | ||
"Guid": 10507721908651011566 | ||
} | ||
] | ||
;--- expected.txt | ||
Function Info: | ||
10507721908651011566 : entrypoint. MaxCounterID: 1. MaxCallsiteID: 1 | ||
3087265239403591524 : f2.llvm.0. MaxCounterID: 1. MaxCallsiteID: 0 | ||
2072045998141807037 : f1. MaxCounterID: 1. MaxCallsiteID: 1 | ||
|
||
Current Profile: | ||
[ | ||
{ | ||
"Callsites": [ | ||
[ | ||
{ | ||
"Callsites": [ | ||
[ | ||
{ | ||
"Counters": [ | ||
10 | ||
], | ||
"Guid": 3087265239403591524 | ||
} | ||
] | ||
], | ||
"Counters": [ | ||
7 | ||
], | ||
"Guid": 2072045998141807037 | ||
} | ||
] | ||
], | ||
"Counters": [ | ||
1 | ||
], | ||
"Guid": 10507721908651011566 | ||
} | ||
] |
Oops, something went wrong.