-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[ctx_prof] Fix ProfileAnnotator::allTakenPathsExit
#109183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mtrofin
merged 1 commit into
main
from
users/mtrofin/09-17-_ctx_prof_fix_profileannotator_alltakenpathsexit_
Sep 19, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,85 @@ | ||
; REQUIRES: asserts && x86_64-linux | ||
; Check that the profile annotator works: we hit an exit and non-zero paths to | ||
; already visited blocks count as taken (i.e. the flow continues through them). | ||
; | ||
; RUN: split-file %s %t | ||
; RUN: llvm-ctxprof-util fromJSON --input=%t/profile_ok.json --output=%t/profile_ok.ctxprofdata | ||
; RUN: llvm-ctxprof-util fromJSON --input=%t/profile_pump.json --output=%t/profile_pump.ctxprofdata | ||
; RUN: llvm-ctxprof-util fromJSON --input=%t/profile_unreachable.json --output=%t/profile_unreachable.ctxprofdata | ||
; | ||
; RUN: opt -passes=ctx-prof-flatten %t/example_ok.ll -use-ctx-profile=%t/profile_ok.ctxprofdata -S -o - | FileCheck %s | ||
; RUN: not --crash opt -passes=ctx-prof-flatten %t/message_pump.ll -use-ctx-profile=%t/profile_pump.ctxprofdata -S 2>&1 | FileCheck %s --check-prefix=ASSERTION | ||
; RUN: not --crash opt -passes=ctx-prof-flatten %t/unreachable.ll -use-ctx-profile=%t/profile_unreachable.ctxprofdata -S 2>&1 | FileCheck %s --check-prefix=ASSERTION | ||
|
||
; CHECK: br i1 %x, label %b1, label %exit, !prof ![[PROF1:[0-9]+]] | ||
; CHECK: br i1 %y, label %blk, label %exit, !prof ![[PROF2:[0-9]+]] | ||
; CHECK: ![[PROF1]] = !{!"branch_weights", i32 1, i32 1} | ||
; CHECK: ![[PROF2]] = !{!"branch_weights", i32 0, i32 1} | ||
; ASSERTION: Assertion `allTakenPathsExit() | ||
|
||
; b1->exit is the only way out from b1, but the exit block would have been | ||
; already visited from blk. That should not result in an assertion, though. | ||
;--- example_ok.ll | ||
define void @foo(i32 %t) !guid !0 { | ||
entry: | ||
call void @llvm.instrprof.increment(ptr @foo, i64 42, i32 42, i32 0) | ||
br label %blk | ||
blk: | ||
call void @llvm.instrprof.increment(ptr @foo, i64 42, i32 42, i32 1) | ||
%x = icmp eq i32 %t, 0 | ||
br i1 %x, label %b1, label %exit | ||
b1: | ||
call void @llvm.instrprof.increment(ptr @foo, i64 42, i32 42, i32 2) | ||
%y = icmp eq i32 %t, 0 | ||
br i1 %y, label %blk, label %exit | ||
exit: | ||
call void @llvm.instrprof.increment(ptr @foo, i64 42, i32 42, i32 3) | ||
ret void | ||
} | ||
!0 = !{i64 1234} | ||
|
||
;--- profile_ok.json | ||
[{"Guid":1234, "Counters":[2, 2, 1, 2]}] | ||
|
||
;--- message_pump.ll | ||
; This is a message pump: the loop never exits. This should result in an | ||
; assertion because we can't reach an exit BB | ||
|
||
define void @foo(i32 %t) !guid !0 { | ||
entry: | ||
call void @llvm.instrprof.increment(ptr @foo, i64 42, i32 42, i32 0) | ||
br label %blk | ||
blk: | ||
call void @llvm.instrprof.increment(ptr @foo, i64 42, i32 42, i32 1) | ||
%x = icmp eq i32 %t, 0 | ||
br i1 %x, label %blk, label %exit | ||
exit: | ||
call void @llvm.instrprof.increment(ptr @foo, i64 42, i32 42, i32 2) | ||
ret void | ||
} | ||
!0 = !{i64 1234} | ||
|
||
;--- profile_pump.json | ||
[{"Guid":1234, "Counters":[2, 10, 0]}] | ||
|
||
;--- unreachable.ll | ||
; An unreachable block is reached, that's an error | ||
define void @foo(i32 %t) !guid !0 { | ||
entry: | ||
call void @llvm.instrprof.increment(ptr @foo, i64 42, i32 42, i32 0) | ||
br label %blk | ||
blk: | ||
call void @llvm.instrprof.increment(ptr @foo, i64 42, i32 42, i32 1) | ||
%x = icmp eq i32 %t, 0 | ||
br i1 %x, label %b1, label %exit | ||
b1: | ||
call void @llvm.instrprof.increment(ptr @foo, i64 42, i32 42, i32 2) | ||
unreachable | ||
exit: | ||
call void @llvm.instrprof.increment(ptr @foo, i64 42, i32 42, i32 3) | ||
ret void | ||
} | ||
!0 = !{i64 1234} | ||
|
||
;--- profile_unreachable.json | ||
[{"Guid":1234, "Counters":[2, 1, 1, 2]}] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this use succ_size as used above, for consistency? And maybe call that once and save the result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer using this current API (
getNumSuccessors
) here, they should be the same, but this is "closer" to the API used below (BB->getTerminator()->getSuccessor
).