[PGO] Avoid instrumenting direct callee's at value sites.
authorBetul Buyukkurt <betulb@codeaurora.org>
Mon, 4 Apr 2016 18:56:36 +0000 (18:56 +0000)
committerBetul Buyukkurt <betulb@codeaurora.org>
Mon, 4 Apr 2016 18:56:36 +0000 (18:56 +0000)
Direct callees' that are cast to other function prototypes,
show up in the Call/Invoke instructions as ConstantExpr's.
Currently llvm::CallSite's getCalledFunction() fails
to return the callees in such expressions as direct calls.
Value profiling should avoid instrumenting such cases. Mostly NFC.

llvm-svn: 265330

llvm/lib/Transforms/Instrumentation/IndirectCallSiteVisitor.h
llvm/test/Transforms/PGOProfile/do-not-instrument.ll

index baf49c7..71a8cb8 100644 (file)
@@ -28,6 +28,8 @@ struct PGOIndirectCallSiteVisitor
       if (CI->isInlineAsm())
         return;
     }
+    if (isa<Constant>(CS.getCalledValue()))
+      return;
     IndirectCallInsts.push_back(I);
   }
 };
index 98a3eec..a42969c 100644 (file)
@@ -14,4 +14,14 @@ entry:
   ret i32 0
 }
 
+define i32 @f2() {
+entry:
+; CHECK: call void @llvm.instrprof.increment
+; CHECK-NOT: call void @llvm.instrprof.value.profile
+  call void (i32, ...) bitcast (void (...)* @foo to void (i32, ...)*)(i32 21)
+  ret i32 0
+}
+
+declare void @foo(...) #0
+
 attributes #0 = { nounwind }