betulb created this revision.
betulb added reviewers: davidxl, bogner.
betulb added subscribers: llvm-commits, cfe-commits.
betulb set the repository for this revision to rL LLVM.
betulb changed the visibility of this Differential Revision from "Public (No 
Login Required)" to "All Users".

Value profiling should not profile constants and/or constant expressions when 
they appear as callees in call instructions. Constant expressions form when a 
direct callee has bitcasts or inttoptr(ptrtint (callee)) nests surrounding it. 
Value profiling should avoid instrumenting such cases. Mostly NFC.


Repository:
  rL LLVM

http://reviews.llvm.org/D18636

Files:
  lib/CodeGen/CodeGenPGO.cpp
  test/Profile/c-avoid-direct-call.c

Index: test/Profile/c-avoid-direct-call.c
===================================================================
--- /dev/null
+++ test/Profile/c-avoid-direct-call.c
@@ -0,0 +1,11 @@
+// Check the value profiling instrinsics emitted by instrumentation.
+
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name 
c-avoid-direct-call.c %s -o - -emit-llvm -fprofile-instrument=clang -mllvm 
-enable-value-profiling | FileCheck %s
+
+void foo();
+
+int main(void) {
+// CHECK-NOT: call void @__llvm_profile_instrument_target(i64 ptrtoint (void 
(...)* @foo to i64), i8* bitcast ({{.*}}* @__profd_main to i8*), i32 0)
+  foo(21);
+  return 0;
+}
Index: lib/CodeGen/CodeGenPGO.cpp
===================================================================
--- lib/CodeGen/CodeGenPGO.cpp
+++ lib/CodeGen/CodeGenPGO.cpp
@@ -755,6 +755,9 @@
   if (!ValuePtr || !ValueSite || !Builder.GetInsertBlock())
     return;
 
+  if (dyn_cast<llvm::Constant>(ValuePtr))
+    return;
+
   bool InstrumentValueSites = CGM.getCodeGenOpts().hasProfileClangInstr();
   if (InstrumentValueSites && RegionCounterMap) {
     auto BuilderInsertPoint = Builder.saveIP();


Index: test/Profile/c-avoid-direct-call.c
===================================================================
--- /dev/null
+++ test/Profile/c-avoid-direct-call.c
@@ -0,0 +1,11 @@
+// Check the value profiling instrinsics emitted by instrumentation.
+
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-avoid-direct-call.c %s -o - -emit-llvm -fprofile-instrument=clang -mllvm -enable-value-profiling | FileCheck %s
+
+void foo();
+
+int main(void) {
+// CHECK-NOT: call void @__llvm_profile_instrument_target(i64 ptrtoint (void (...)* @foo to i64), i8* bitcast ({{.*}}* @__profd_main to i8*), i32 0)
+  foo(21);
+  return 0;
+}
Index: lib/CodeGen/CodeGenPGO.cpp
===================================================================
--- lib/CodeGen/CodeGenPGO.cpp
+++ lib/CodeGen/CodeGenPGO.cpp
@@ -755,6 +755,9 @@
   if (!ValuePtr || !ValueSite || !Builder.GetInsertBlock())
     return;
 
+  if (dyn_cast<llvm::Constant>(ValuePtr))
+    return;
+
   bool InstrumentValueSites = CGM.getCodeGenOpts().hasProfileClangInstr();
   if (InstrumentValueSites && RegionCounterMap) {
     auto BuilderInsertPoint = Builder.saveIP();
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to