[PATCH] D18580: [PGO] handle invoke instr in IR instrumentation

David Li via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 29 15:00:40 PDT 2016


davidxl created this revision.
davidxl added a reviewer: xur.
davidxl added a subscriber: llvm-commits.

http://reviews.llvm.org/D18580

Files:
  lib/Transforms/Instrumentation/PGOInstrumentation.cpp
  test/Transforms/PGOProfile/indirect_call_profile.ll

Index: test/Transforms/PGOProfile/indirect_call_profile.ll
===================================================================
--- test/Transforms/PGOProfile/indirect_call_profile.ll
+++ test/Transforms/PGOProfile/indirect_call_profile.ll
@@ -15,3 +15,46 @@
   call void %tmp()
   ret void
 }
+
+ at bar2 = global void ()* null, align 8
+ at _ZTIi = external constant i8*
+
+; Function Attrs: uwtable
+define i32 @foo2(i32, i8** nocapture readnone) #0 personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
+  %3 = load void ()*, void ()** @bar2, align 8
+  invoke void %3()
+          to label %12 unwind label %4
+; GEN: [[ICALL_TARGET2:%[0-9]+]] = ptrtoint void ()* %3 to i64
+; GEN-NEXT: call void @llvm.instrprof.value.profile(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @__profn_foo2, i32 0, i32 0), i64 38432627612, i64 [[ICALL_TARGET2]], i32 0, i32 0)
+
+; <label>:4:                                      ; preds = %2
+  %5 = landingpad { i8*, i32 }
+          catch i8* bitcast (i8** @_ZTIi to i8*)
+  %6 = extractvalue { i8*, i32 } %5, 1
+  %7 = tail call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) #2
+  %8 = icmp eq i32 %6, %7
+  br i1 %8, label %9, label %13
+
+; <label>:9:                                      ; preds = %4
+  %10 = extractvalue { i8*, i32 } %5, 0
+  %11 = tail call i8* @__cxa_begin_catch(i8* %10) #2
+  tail call void @__cxa_end_catch() #2
+  br label %12
+
+; <label>:12:                                     ; preds = %2, %9
+  ret i32 0
+
+; <label>:13:                                     ; preds = %4
+  resume { i8*, i32 } %5
+}
+
+declare i32 @__gxx_personality_v0(...)
+
+; Function Attrs: nounwind readnone
+declare i32 @llvm.eh.typeid.for(i8*) #1
+
+declare i8* @__cxa_begin_catch(i8*)
+
+declare void @__cxa_end_catch()
+
+
Index: lib/Transforms/Instrumentation/PGOInstrumentation.cpp
===================================================================
--- lib/Transforms/Instrumentation/PGOInstrumentation.cpp
+++ lib/Transforms/Instrumentation/PGOInstrumentation.cpp
@@ -329,14 +329,16 @@
 // Visitor class that finds all indirect call sites.
 struct PGOIndirectCallSiteVisitor
     : public InstVisitor<PGOIndirectCallSiteVisitor> {
-  std::vector<CallInst *> IndirectCallInsts;
+  std::vector<Instruction *> IndirectCallInsts;
   PGOIndirectCallSiteVisitor() {}
 
-  void visitCallInst(CallInst &I) {
-    CallSite CS(&I);
-    if (CS.getCalledFunction() || !CS.getCalledValue() || I.isInlineAsm())
+  void visitCallSite(CallSite CS) {
+    Instruction *I = CS.getInstruction();
+    CallInst *CI = dyn_cast<CallInst>(I);
+    if (CS.getCalledFunction() || !CS.getCalledValue() ||
+        (CI && CI->isInlineAsm()))
       return;
-    IndirectCallInsts.push_back(&I);
+    IndirectCallInsts.push_back(I);
   }
 };
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18580.51989.patch
Type: text/x-patch
Size: 2791 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160329/707fa90f/attachment.bin>


More information about the llvm-commits mailing list