[llvm] r275145 - Print remarks from WholeProgramDevirt pass for each call site.

Ivan Krasin via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 11 19:38:38 PDT 2016


Author: krasin
Date: Mon Jul 11 21:38:37 2016
New Revision: 275145

URL: http://llvm.org/viewvc/llvm-project?rev=275145&view=rev
Log:
Print remarks from WholeProgramDevirt pass for each call site.

Summary:
It's useful to have some visibility about which call sites are devirtualized,
especially for debug purposes. Another use case is a regression test on the
application side (like, Chromium).

Reviewers: pcc

Differential Revision: http://reviews.llvm.org/D22252

Modified:
    llvm/trunk/lib/Transforms/IPO/WholeProgramDevirt.cpp
    llvm/trunk/test/Transforms/WholeProgramDevirt/devirt-single-impl-check.ll
    llvm/trunk/test/Transforms/WholeProgramDevirt/non-constant-vtable.ll
    llvm/trunk/test/Transforms/WholeProgramDevirt/virtual-const-prop-check.ll

Modified: llvm/trunk/lib/Transforms/IPO/WholeProgramDevirt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/WholeProgramDevirt.cpp?rev=275145&r1=275144&r2=275145&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/WholeProgramDevirt.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/WholeProgramDevirt.cpp Mon Jul 11 21:38:37 2016
@@ -35,6 +35,7 @@
 #include "llvm/IR/CallSite.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/DataLayout.h"
+#include "llvm/IR/DiagnosticInfo.h"
 #include "llvm/IR/IRBuilder.h"
 #include "llvm/IR/Instructions.h"
 #include "llvm/IR/Intrinsics.h"
@@ -215,7 +216,15 @@ struct VirtualCallSite {
   // of that field for details.
   unsigned *NumUnsafeUses;
 
+  void emitRemark() {
+    Function *F = CS.getCaller();
+    emitOptimizationRemark(F->getContext(), DEBUG_TYPE, *F,
+                           CS.getInstruction()->getDebugLoc(),
+                           "devirtualized call");
+  }
+
   void replaceAndErase(Value *New) {
+    emitRemark();
     CS->replaceAllUsesWith(New);
     if (auto II = dyn_cast<InvokeInst>(CS.getInstruction())) {
       BranchInst::Create(II->getNormalDest(), CS.getInstruction());
@@ -394,6 +403,7 @@ bool DevirtModule::trySingleImplDevirt(
 
   // If so, update each call site to call that implementation directly.
   for (auto &&VCallSite : CallSites) {
+    VCallSite.emitRemark();
     VCallSite.CS.setCalledFunction(ConstantExpr::getBitCast(
         TheFn, VCallSite.CS.getCalledValue()->getType()));
     // This use is no longer unsafe.

Modified: llvm/trunk/test/Transforms/WholeProgramDevirt/devirt-single-impl-check.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/WholeProgramDevirt/devirt-single-impl-check.ll?rev=275145&r1=275144&r2=275145&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/WholeProgramDevirt/devirt-single-impl-check.ll (original)
+++ llvm/trunk/test/Transforms/WholeProgramDevirt/devirt-single-impl-check.ll Mon Jul 11 21:38:37 2016
@@ -1,8 +1,11 @@
-; RUN: opt -S -wholeprogramdevirt %s | FileCheck %s
+; RUN: opt -S -wholeprogramdevirt -pass-remarks=wholeprogramdevirt %s 2>&1 | FileCheck %s
 
 target datalayout = "e-p:64:64"
 target triple = "x86_64-unknown-linux-gnu"
 
+; CHECK: remark: <unknown>:0:0: devirtualized call
+; CHECK-NOT: devirtualized call
+
 @vt1 = constant [1 x i8*] [i8* bitcast (void (i8*)* @vf to i8*)], !type !0
 @vt2 = constant [1 x i8*] [i8* bitcast (void (i8*)* @vf to i8*)], !type !0
 

Modified: llvm/trunk/test/Transforms/WholeProgramDevirt/non-constant-vtable.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/WholeProgramDevirt/non-constant-vtable.ll?rev=275145&r1=275144&r2=275145&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/WholeProgramDevirt/non-constant-vtable.ll (original)
+++ llvm/trunk/test/Transforms/WholeProgramDevirt/non-constant-vtable.ll Mon Jul 11 21:38:37 2016
@@ -1,4 +1,6 @@
-; RUN: opt -S -wholeprogramdevirt %s | FileCheck %s
+; RUN: opt -S -wholeprogramdevirt -pass-remarks=wholeprogramdevirt %s 2>&1 | FileCheck %s
+
+; CHECK-NOT: devirtualized call
 
 target datalayout = "e-p:64:64"
 target triple = "x86_64-unknown-linux-gnu"

Modified: llvm/trunk/test/Transforms/WholeProgramDevirt/virtual-const-prop-check.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/WholeProgramDevirt/virtual-const-prop-check.ll?rev=275145&r1=275144&r2=275145&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/WholeProgramDevirt/virtual-const-prop-check.ll (original)
+++ llvm/trunk/test/Transforms/WholeProgramDevirt/virtual-const-prop-check.ll Mon Jul 11 21:38:37 2016
@@ -1,8 +1,13 @@
-; RUN: opt -S -wholeprogramdevirt %s | FileCheck %s
+; RUN: opt -S -wholeprogramdevirt -pass-remarks=wholeprogramdevirt %s 2>&1 | FileCheck %s
 
 target datalayout = "e-p:64:64"
 target triple = "x86_64-unknown-linux-gnu"
 
+; CHECK: remark: <unknown>:0:0: devirtualized call
+; CHECK: remark: <unknown>:0:0: devirtualized call
+; CHECK: remark: <unknown>:0:0: devirtualized call
+; CHECK-NOT: devirtualized call
+
 ; CHECK: [[VT1DATA:@[^ ]*]] = private constant { [8 x i8], [3 x i8*], [0 x i8] } { [8 x i8] c"\00\00\00\01\01\00\00\00", [3 x i8*] [i8* bitcast (i1 (i8*)* @vf0i1 to i8*), i8* bitcast (i1 (i8*)* @vf1i1 to i8*), i8* bitcast (i32 (i8*)* @vf1i32 to i8*)], [0 x i8] zeroinitializer }, section "vt1sec", !type [[T8:![0-9]+]]
 @vt1 = constant [3 x i8*] [
 i8* bitcast (i1 (i8*)* @vf0i1 to i8*),




More information about the llvm-commits mailing list