Skip to content

[PGO] Use isScopedEHPersonality for funclet check #85671

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 1 commit into from
Mar 20, 2024
Merged

Conversation

aheejin
Copy link
Member

@aheejin aheejin commented Mar 18, 2024

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.

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.
@aheejin aheejin requested a review from dschuff March 18, 2024 17:38
@llvmbot llvmbot added PGO Profile Guided Optimizations llvm:transforms labels Mar 18, 2024
@llvmbot
Copy link
Member

llvmbot commented Mar 18, 2024

@llvm/pr-subscribers-pgo

@llvm/pr-subscribers-llvm-transforms

Author: Heejin Ahn (aheejin)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/85671.diff

2 Files Affected:

  • (modified) llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp (+1-1)
  • (added) llvm/test/Transforms/PGOProfile/memop_profile_funclet_wasm.ll (+48)
diff --git a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
index 55728709cde556..50eccc69a38a00 100644
--- a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
+++ b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
@@ -920,7 +920,7 @@ static void instrumentOneFunc(
   // on the instrumentation call based on the funclet coloring.
   DenseMap<BasicBlock *, ColorVector> BlockColors;
   if (F.hasPersonalityFn() &&
-      isFuncletEHPersonality(classifyEHPersonality(F.getPersonalityFn())))
+      isScopedEHPersonality(classifyEHPersonality(F.getPersonalityFn())))
     BlockColors = colorEHFunclets(F);
 
   // For each VP Kind, walk the VP candidates and instrument each one.
diff --git a/llvm/test/Transforms/PGOProfile/memop_profile_funclet_wasm.ll b/llvm/test/Transforms/PGOProfile/memop_profile_funclet_wasm.ll
new file mode 100644
index 00000000000000..f8dcb768c94cab
--- /dev/null
+++ b/llvm/test/Transforms/PGOProfile/memop_profile_funclet_wasm.ll
@@ -0,0 +1,48 @@
+; RUN: opt < %s -passes=pgo-instr-gen -S | FileCheck %s --check-prefixes=CHECK,GEN
+; RUN: opt < %s -passes=pgo-instr-gen,instrprof -S | FileCheck %s --check-prefixes=CHECK,LOWER
+
+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
+target triple = "wasm32-unknown-unknown"
+
+define void @wasm_funclet_op_bundle(ptr %p, ptr %dst, ptr %src) personality ptr @__gxx_wasm_personality_v0 {
+entry:
+  invoke void @foo()
+          to label %try.cont unwind label %catch.dispatch
+
+catch.dispatch:                                   ; preds = %entry
+  %0 = catchswitch within none [label %catch.start] unwind to caller
+
+catch.start:                                      ; preds = %catch.dispatch
+  %1 = catchpad within %0 [ptr null]
+; CHECK: %[[CATCHPAD:.*]] = catchpad
+  %2 = call ptr @llvm.wasm.get.exception(token %1)
+  %3 = call i32 @llvm.wasm.get.ehselector(token %1)
+  %4 = call ptr @__cxa_begin_catch(ptr %2) #3 [ "funclet"(token %1) ]
+  %tmp = load i32, ptr %p, align 4
+  call void @llvm.memcpy.p0.p0.i32(ptr %dst, ptr %src, i32 %tmp, i1 false)
+; GEN: call void @llvm.instrprof.value.profile({{.*}}) [ "funclet"(token %[[CATCHPAD]]) ]
+; LOWER: call void @__llvm_profile_instrument_memop({{.*}}) [ "funclet"(token %[[CATCHPAD]]) ]
+  call void @__cxa_end_catch() [ "funclet"(token %1) ]
+  catchret from %1 to label %try.cont
+
+try.cont:                                         ; preds = %catch.start, %entry
+  ret void
+}
+
+declare void @foo()
+declare i32 @__gxx_wasm_personality_v0(...)
+; Function Attrs: nocallback nofree nosync nounwind willreturn
+declare ptr @llvm.wasm.get.exception(token) #0
+; Function Attrs: nocallback nofree nosync nounwind willreturn
+declare i32 @llvm.wasm.get.ehselector(token) #0
+; Function Attrs: nounwind memory(none)
+declare i32 @llvm.eh.typeid.for(ptr) #1
+declare ptr @__cxa_begin_catch(ptr)
+declare void @__cxa_end_catch()
+; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
+declare void @llvm.memcpy.p0.p0.i32(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i32, i1 immarg) #2
+
+attributes #0 = { nocallback nofree nosync nounwind willreturn }
+attributes #1 = { nounwind memory(none) }
+attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
+attributes #3 = { nounwind }

@aheejin
Copy link
Member Author

aheejin commented Mar 19, 2024

Ping just in case you haven't seen it 😀

@aheejin aheejin merged commit 2b7289d into llvm:main Mar 20, 2024
@aheejin aheejin deleted the pgo_wasm branch March 20, 2024 21:22
chencha3 pushed a commit to chencha3/llvm-project that referenced this pull request Mar 23, 2024
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
llvm:transforms PGO Profile Guided Optimizations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants