Skip to content

Commit 2b7289d

Browse files
authored
[PGO] Use isScopedEHPersonality for funclet check (#85671)
This line should be `isScopedEHPersonality` rather than `isFuncletEHPersonality` because this line is used for checking whether we need to add `funclet` op bundles to newly added calls, and Wasm EH needs that too. The new test case is adapted from https://github.com/llvm/llvm-project/blob/main/llvm/test/Transforms/PGOProfile/memop_profile_funclet.ll.
1 parent de4ce5d commit 2b7289d

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,7 @@ static void instrumentOneFunc(
920920
// on the instrumentation call based on the funclet coloring.
921921
DenseMap<BasicBlock *, ColorVector> BlockColors;
922922
if (F.hasPersonalityFn() &&
923-
isFuncletEHPersonality(classifyEHPersonality(F.getPersonalityFn())))
923+
isScopedEHPersonality(classifyEHPersonality(F.getPersonalityFn())))
924924
BlockColors = colorEHFunclets(F);
925925

926926
// For each VP Kind, walk the VP candidates and instrument each one.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
; RUN: opt < %s -passes=pgo-instr-gen -S | FileCheck %s --check-prefixes=CHECK,GEN
2+
; RUN: opt < %s -passes=pgo-instr-gen,instrprof -S | FileCheck %s --check-prefixes=CHECK,LOWER
3+
4+
target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
5+
target triple = "wasm32-unknown-unknown"
6+
7+
define void @wasm_funclet_op_bundle(ptr %p, ptr %dst, ptr %src) personality ptr @__gxx_wasm_personality_v0 {
8+
entry:
9+
invoke void @foo()
10+
to label %try.cont unwind label %catch.dispatch
11+
12+
catch.dispatch: ; preds = %entry
13+
%0 = catchswitch within none [label %catch.start] unwind to caller
14+
15+
catch.start: ; preds = %catch.dispatch
16+
%1 = catchpad within %0 [ptr null]
17+
; CHECK: %[[CATCHPAD:.*]] = catchpad
18+
%2 = call ptr @llvm.wasm.get.exception(token %1)
19+
%3 = call i32 @llvm.wasm.get.ehselector(token %1)
20+
%4 = call ptr @__cxa_begin_catch(ptr %2) #3 [ "funclet"(token %1) ]
21+
%tmp = load i32, ptr %p, align 4
22+
call void @llvm.memcpy.p0.p0.i32(ptr %dst, ptr %src, i32 %tmp, i1 false)
23+
; GEN: call void @llvm.instrprof.value.profile({{.*}}) [ "funclet"(token %[[CATCHPAD]]) ]
24+
; LOWER: call void @__llvm_profile_instrument_memop({{.*}}) [ "funclet"(token %[[CATCHPAD]]) ]
25+
call void @__cxa_end_catch() [ "funclet"(token %1) ]
26+
catchret from %1 to label %try.cont
27+
28+
try.cont: ; preds = %catch.start, %entry
29+
ret void
30+
}
31+
32+
declare void @foo()
33+
declare i32 @__gxx_wasm_personality_v0(...)
34+
; Function Attrs: nocallback nofree nosync nounwind willreturn
35+
declare ptr @llvm.wasm.get.exception(token) #0
36+
; Function Attrs: nocallback nofree nosync nounwind willreturn
37+
declare i32 @llvm.wasm.get.ehselector(token) #0
38+
; Function Attrs: nounwind memory(none)
39+
declare i32 @llvm.eh.typeid.for(ptr) #1
40+
declare ptr @__cxa_begin_catch(ptr)
41+
declare void @__cxa_end_catch()
42+
; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
43+
declare void @llvm.memcpy.p0.p0.i32(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i32, i1 immarg) #2
44+
45+
attributes #0 = { nocallback nofree nosync nounwind willreturn }
46+
attributes #1 = { nounwind memory(none) }
47+
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
48+
attributes #3 = { nounwind }

0 commit comments

Comments
 (0)