-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[WPD] Change Devirt Cutoff to use DebugCounter #170009
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
boomanaiden154
merged 2 commits into
llvm:main
from
boomanaiden154:wpd-global-state-11-29-25
Dec 1, 2025
+86
−21
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
81 changes: 81 additions & 0 deletions
81
llvm/test/Transforms/WholeProgramDevirt/calls-to-devirt.ll
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,81 @@ | ||
| ; REQUIRES: asserts | ||
|
|
||
| ; Devirt calls debug counter is not explicitly set. Expect 3 remark messages. | ||
| ; RUN: opt -S -passes=wholeprogramdevirt -wholeprogramdevirt-summary-action=import \ | ||
| ; RUN: -pass-remarks=wholeprogramdevirt \ | ||
| ; RUN: -wholeprogramdevirt-read-summary=%S/Inputs/import-single-impl.yaml \ | ||
| ; RUN: -print-debug-counter-queries < %s 2>&1 \ | ||
| ; RUN: | grep "remark" | count 3 | ||
| ; Devirt calls debug counter is set to 1. Expect one remark messages. | ||
| ; RUN: opt -S -passes=wholeprogramdevirt -wholeprogramdevirt-summary-action=import \ | ||
| ; RUN: -pass-remarks=wholeprogramdevirt -debug-counter=calls-to-devirt=0 \ | ||
| ; RUN: -wholeprogramdevirt-read-summary=%S/Inputs/import-single-impl.yaml \ | ||
| ; RUN: -print-debug-counter-queries < %s 2>&1 \ | ||
| ; RUN: | FileCheck --check-prefix=CHECK-SINGLE %s | ||
| ; Devirt calls debug counter is set outside the range of calls. Expect no remark message. | ||
| ; RUN: opt -S -passes=wholeprogramdevirt -wholeprogramdevirt-summary-action=import \ | ||
| ; RUN: -pass-remarks=wholeprogramdevirt -debug-counter=calls-to-devirt=9999 \ | ||
| ; RUN: -wholeprogramdevirt-read-summary=%S/Inputs/import-single-impl.yaml \ | ||
| ; RUN: -print-debug-counter-queries < %s 2>&1 \ | ||
| ; RUN: | FileCheck -implicit-check-not="remark" --check-prefix=CHECK-NONE %s | ||
|
|
||
| ; CHECK-SINGLE: DebugCounter calls-to-devirt=0 execute | ||
| ; CHECK-SINGLE: remark | ||
| ; CHECK-SINGLE-SAME: devirtualized a call | ||
| ; CHECK-SINGLE: DebugCounter calls-to-devirt=1 skip | ||
| ; CHECK-SINGLE: DebugCounter calls-to-devirt=2 skip | ||
|
|
||
| ; CHECK-NONE: DebugCounter calls-to-devirt=0 skip | ||
| ; CHECK-NONE: DebugCounter calls-to-devirt=1 skip | ||
| ; CHECK-NONE: DebugCounter calls-to-devirt=2 skip | ||
|
|
||
| target datalayout = "e-p:64:64" | ||
| target triple = "x86_64-unknown-linux-gnu" | ||
|
|
||
| define i32 @call1(ptr %obj) #0 { | ||
| %vtable = load ptr, ptr %obj | ||
| %p = call i1 @llvm.type.test(ptr %vtable, metadata !"typeid1") | ||
| call void @llvm.assume(i1 %p) | ||
| %fptr = load ptr, ptr %vtable | ||
| %result = call i32 %fptr(ptr %obj, i32 1) | ||
| ret i32 %result | ||
| } | ||
|
|
||
| define i1 @call2(ptr %obj) #0 { | ||
| %vtable = load ptr, ptr %obj | ||
| %pair = call {ptr, i1} @llvm.type.checked.load(ptr %vtable, i32 8, metadata !"typeid2") | ||
| %fptr = extractvalue {ptr, i1} %pair, 0 | ||
| %p = extractvalue {ptr, i1} %pair, 1 | ||
| br i1 %p, label %cont, label %trap | ||
|
|
||
| cont: | ||
| %result = call i1 %fptr(ptr %obj, i32 undef) | ||
| ret i1 %result | ||
|
|
||
| trap: | ||
| call void @llvm.trap() | ||
| unreachable | ||
| } | ||
|
|
||
| define i1 @call3(ptr %obj) #0 { | ||
| %vtable = load ptr, ptr %obj | ||
| %pair = call {ptr, i1} @llvm.type.checked.load(ptr %vtable, i32 8, metadata !"typeid2") | ||
| %fptr = extractvalue {ptr, i1} %pair, 0 | ||
| %p = extractvalue {ptr, i1} %pair, 1 | ||
| br i1 %p, label %cont, label %trap | ||
|
|
||
| cont: | ||
| %result = call i1 %fptr(ptr %obj, i32 3) | ||
| ret i1 %result | ||
|
|
||
| trap: | ||
| call void @llvm.trap() | ||
| unreachable | ||
| } | ||
|
|
||
| declare void @llvm.assume(i1) | ||
| declare void @llvm.trap() | ||
| declare {ptr, i1} @llvm.type.checked.load(ptr, i32, metadata) | ||
| declare i1 @llvm.type.test(ptr, metadata) | ||
|
|
||
| attributes #0 = { "target-features"="+retpoline" } |
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
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.
My understanding of
llvm-project/llvm/include/llvm/Support/DebugCounter.h
Lines 156 to 163 in 24b87b8
is that debug counter needs
-DLLVM_ENABLE_ASSERTIONS=ON, and the test will need something like 'REQUIRES: asserts'.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.
Good point. I've split this into a separate test so that we can require assertions only where needed.
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.
Does this mean that we can no longer use this option to bisect on a release compiler?
Uh oh!
There was an error while loading. Please reload this page.
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.
We cannot bisect on a release compiler.
Fortunately, our internal infrastructure has a compiler that enables debug assertions and also supports enabling assertions on a per-file basis, which should help us work around the limitation internally.
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.
Is there an alternative that would have maintained the ability to bisect with a release compiler? Could the counter have been moved into the DevirtModule class?
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.
We can probably just make DebugCounters always available in release builds. I tried this a while ago (https://llvm-compile-time-tracker.com/compare.php?from=100a1d0c4caad0d0f2ec26b07d3cc73f59b9a9a8&to=341c03268229f2982df1fd7ddb5e3db7a2e7731a&stat=instructions:u) and while there is measurable overhead, it's probably acceptably small (and possibly optimizable).
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.
This will help debugging a release-build compiler. Are you interested in driving this?
If upstream is not ready to enable debug counters in a release build very soon, I can look into this.
Uh oh!
There was an error while loading. Please reload this page.
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.
FWIW I also followed up in the original RFC in https://discourse.llvm.org/t/rfc-reducing-process-creation-overhead-in-llvm-regression-tests/88612/14