Skip to content

[BPI] Reuse the AsmWriter's BB naming scheme in BranchProbabilityPrinterPass #73593

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
merged 4 commits into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions llvm/lib/Analysis/BranchProbabilityInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1188,8 +1188,11 @@ BranchProbabilityInfo::printEdgeProbability(raw_ostream &OS,
const BasicBlock *Src,
const BasicBlock *Dst) const {
const BranchProbability Prob = getEdgeProbability(Src, Dst);
OS << "edge " << Src->getName() << " -> " << Dst->getName()
<< " probability is " << Prob
OS << "edge ";
Src->printAsOperand(OS, false, Src->getModule());
OS << " -> ";
Dst->printAsOperand(OS, false, Dst->getModule());
OS << " probability is " << Prob
<< (isEdgeHot(Src, Dst) ? " [HOT edge]\n" : "\n");

return OS;
Expand Down
29 changes: 29 additions & 0 deletions llvm/test/Analysis/BranchProbabilityInfo/anonymous-bb.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py
; RUN: opt < %s -passes='print<branch-prob>' -disable-output 2>&1 | FileCheck %s

define void @fct() {
; CHECK-LABEL: 'fct'
; CHECK-NEXT: ---- Branch Probabilities ----
; CHECK-NEXT: edge %entry -> %0 probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
; CHECK-NEXT: edge %0 -> %1 probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
;
entry:
br label %0
0:
br label %1
1:
ret void
}

define void @fct2() {
; CHECK-LABEL: 'fct2'
; CHECK-NEXT: ---- Branch Probabilities ----
; CHECK-NEXT: edge %0 -> %1 probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
; CHECK-NEXT: edge %1 -> %2 probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
;
br label %1
1:
br label %2
2:
ret void
}
240 changes: 120 additions & 120 deletions llvm/test/Analysis/BranchProbabilityInfo/basic.ll

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions llvm/test/Analysis/BranchProbabilityInfo/deopt-intrinsic.ll
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ entry:
%cond = icmp eq i32 %a, 42
br i1 %cond, label %exit, label %deopt

; CHECK: edge entry -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
; CHECK: edge entry -> deopt probability is 0x00000000 / 0x80000000 = 0.00%
; CHECK: edge %entry -> %exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
; CHECK: edge %entry -> %deopt probability is 0x00000000 / 0x80000000 = 0.00%

deopt:
%rval = call i32(...) @llvm.experimental.deoptimize.i32() [ "deopt"() ]
Expand Down
30 changes: 15 additions & 15 deletions llvm/test/Analysis/BranchProbabilityInfo/deopt-invoke.ll
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ declare void @cold() cold
; Even though the likeliness of 'invoke' to throw an exception is assessed as low
; all other paths are even less likely. Check that hot paths leads to excepion handler.
define void @test1(i32 %0) personality ptr @"personality_function" !prof !1 {
;CHECK: edge entry -> unreached probability is 0x00000001 / 0x80000000 = 0.00%
;CHECK: edge entry -> invoke probability is 0x7fffffff / 0x80000000 = 100.00% [HOT edge]
;CHECK: edge invoke -> invoke.cont.unreached probability is 0x00000000 / 0x80000000 = 0.00%
;CHECK: edge invoke -> land.pad probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
;CHECK: edge land.pad -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
;CHECK: edge %entry -> %unreached probability is 0x00000001 / 0x80000000 = 0.00%
;CHECK: edge %entry -> %invoke probability is 0x7fffffff / 0x80000000 = 100.00% [HOT edge]
;CHECK: edge %invoke -> %invoke.cont.unreached probability is 0x00000000 / 0x80000000 = 0.00%
;CHECK: edge %invoke -> %land.pad probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
;CHECK: edge %land.pad -> %exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]

entry:
br i1 undef, label %unreached, label %invoke, !prof !2
Expand All @@ -39,11 +39,11 @@ exit:
}

define void @test2(i32 %0) personality ptr @"personality_function" {
;CHECK: edge entry -> unreached probability is 0x00000000 / 0x80000000 = 0.00%
;CHECK: edge entry -> invoke probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
;CHECK: edge invoke -> invoke.cont.cold probability is 0x7fff8000 / 0x80000000 = 100.00% [HOT edge]
;CHECK: edge invoke -> land.pad probability is 0x00008000 / 0x80000000 = 0.00%
;CHECK: edge land.pad -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
;CHECK: edge %entry -> %unreached probability is 0x00000000 / 0x80000000 = 0.00%
;CHECK: edge %entry -> %invoke probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
;CHECK: edge %invoke -> %invoke.cont.cold probability is 0x7fff8000 / 0x80000000 = 100.00% [HOT edge]
;CHECK: edge %invoke -> %land.pad probability is 0x00008000 / 0x80000000 = 0.00%
;CHECK: edge %land.pad -> %exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]

entry:
br i1 undef, label %unreached, label %invoke
Expand All @@ -69,11 +69,11 @@ exit:
}

define void @test3(i32 %0) personality ptr @"personality_function" {
;CHECK: edge entry -> unreached probability is 0x00000000 / 0x80000000 = 0.00%
;CHECK: edge entry -> invoke probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
;CHECK: edge invoke -> invoke.cont.cold probability is 0x7fff8000 / 0x80000000 = 100.00% [HOT edge]
;CHECK: edge invoke -> land.pad probability is 0x00008000 / 0x80000000 = 0.00%
;CHECK: edge land.pad -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
;CHECK: edge %entry -> %unreached probability is 0x00000000 / 0x80000000 = 0.00%
;CHECK: edge %entry -> %invoke probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
;CHECK: edge %invoke -> %invoke.cont.cold probability is 0x7fff8000 / 0x80000000 = 100.00% [HOT edge]
;CHECK: edge %invoke -> %land.pad probability is 0x00008000 / 0x80000000 = 0.00%
;CHECK: edge %land.pad -> %exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
entry:
br i1 undef, label %unreached, label %invoke
invoke:
Expand Down
8 changes: 4 additions & 4 deletions llvm/test/Analysis/BranchProbabilityInfo/fcmp.ll
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
; This function tests the floating point unorder comparison. The probability
; of NaN should be extremely small.
; CHECK: Printing analysis {{.*}} for function 'uno'
; CHECK: edge -> a probability is 0x00000800 / 0x80000000 = 0.00%
; CHECK: edge -> b probability is 0x7ffff800 / 0x80000000 = 100.00% [HOT edge]
; CHECK: edge %0 -> %a probability is 0x00000800 / 0x80000000 = 0.00%
; CHECK: edge %0 -> %b probability is 0x7ffff800 / 0x80000000 = 100.00% [HOT edge]

define void @uno(float %val1, float %val2) {
%cond = fcmp uno float %val1, %val2
Expand All @@ -21,8 +21,8 @@ b:

; This function tests the floating point order comparison.
; CHECK: Printing analysis {{.*}} for function 'ord'
; CHECK: edge -> a probability is 0x7ffff800 / 0x80000000 = 100.00% [HOT edge]
; CHECK: edge -> b probability is 0x00000800 / 0x80000000 = 0.00%
; CHECK: edge %0 -> %a probability is 0x7ffff800 / 0x80000000 = 100.00% [HOT edge]
; CHECK: edge %0 -> %b probability is 0x00000800 / 0x80000000 = 0.00%

define void @ord(float %val1, float %val2) {
%cond = fcmp ord float %val1, %val2
Expand Down
16 changes: 8 additions & 8 deletions llvm/test/Analysis/BranchProbabilityInfo/hoist.ll
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
; RUN: opt < %s -passes='print<branch-prob>' -disable-output 2>&1 | FileCheck %s

; CHECK-LABEL: no_hoist
; CHECK: edge entry -> if.end probability is 0x40000000 / 0x80000000 = 50.00%
; CHECK: edge entry -> if.then probability is 0x40000000 / 0x80000000 = 50.00%
; CHECK: edge if.end -> if.end4 probability is 0x40000000 / 0x80000000 = 50.00%
; CHECK: edge if.end -> if.then3 probability is 0x40000000 / 0x80000000 = 50.00%
; CHECK: edge %entry -> %if.end probability is 0x40000000 / 0x80000000 = 50.00%
; CHECK: edge %entry -> %if.then probability is 0x40000000 / 0x80000000 = 50.00%
; CHECK: edge %if.end -> %if.end4 probability is 0x40000000 / 0x80000000 = 50.00%
; CHECK: edge %if.end -> %if.then3 probability is 0x40000000 / 0x80000000 = 50.00%
define dso_local void @no_hoist(i64 %arg1, i64 %arg2) local_unnamed_addr #0 {
entry:
%and = and i64 %arg1, 1152921504606846976
Expand All @@ -29,10 +29,10 @@ if.end4: ; preds = %if.then3, %if.end
}

; CHECK-LABEL: hoist
; CHECK: edge entry -> if.end probability is 0x40000000 / 0x80000000 = 50.00%
; CHECK: edge entry -> if.then probability is 0x40000000 / 0x80000000 = 50.00%
; CHECK: edge if.end -> if.end4 probability is 0x40000000 / 0x80000000 = 50.00%
; CHECK: edge if.end -> if.then3 probability is 0x40000000 / 0x80000000 = 50.00%
; CHECK: edge %entry -> %if.end probability is 0x40000000 / 0x80000000 = 50.00%
; CHECK: edge %entry -> %if.then probability is 0x40000000 / 0x80000000 = 50.00%
; CHECK: edge %if.end -> %if.end4 probability is 0x40000000 / 0x80000000 = 50.00%
; CHECK: edge %if.end -> %if.then3 probability is 0x40000000 / 0x80000000 = 50.00%
define dso_local void @hoist(i64 %arg1, i64 %arg2) local_unnamed_addr #0 {
entry:
%const = bitcast i64 1152921504606846976 to i64
Expand Down
Loading