[llvm] r297350 - WholeProgramDevirt: Implement importing for uniform ret val opt.

Peter Collingbourne via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 8 17:11:15 PST 2017


Author: pcc
Date: Wed Mar  8 19:11:15 2017
New Revision: 297350

URL: http://llvm.org/viewvc/llvm-project?rev=297350&view=rev
Log:
WholeProgramDevirt: Implement importing for uniform ret val opt.

Differential Revision: https://reviews.llvm.org/D29854

Added:
    llvm/trunk/test/Transforms/WholeProgramDevirt/Inputs/import-uniform-ret-val.yaml
Modified:
    llvm/trunk/lib/Transforms/IPO/WholeProgramDevirt.cpp
    llvm/trunk/test/Transforms/WholeProgramDevirt/import.ll

Modified: llvm/trunk/lib/Transforms/IPO/WholeProgramDevirt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/WholeProgramDevirt.cpp?rev=297350&r1=297349&r2=297350&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/WholeProgramDevirt.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/WholeProgramDevirt.cpp Wed Mar  8 19:11:15 2017
@@ -1126,6 +1126,24 @@ void DevirtModule::importResolution(VTab
     applySingleImplDevirt(SlotInfo, SingleImpl, IsExported);
     assert(!IsExported);
   }
+
+  for (auto &CSByConstantArg : SlotInfo.ConstCSInfo) {
+    auto I = Res.ResByArg.find(CSByConstantArg.first);
+    if (I == Res.ResByArg.end())
+      continue;
+    auto &ResByArg = I->second;
+    // FIXME: We should figure out what to do about the "function name" argument
+    // to the apply* functions, as the function names are unavailable during the
+    // importing phase. For now we just pass the empty string. This does not
+    // impact correctness because the function names are just used for remarks.
+    switch (ResByArg.TheKind) {
+    case WholeProgramDevirtResolution::ByArg::UniformRetVal:
+      applyUniformRetValOpt(CSByConstantArg.second, "", ResByArg.Info);
+      break;
+    default:
+      break;
+    }
+  }
 }
 
 void DevirtModule::removeRedundantTypeTests() {

Added: llvm/trunk/test/Transforms/WholeProgramDevirt/Inputs/import-uniform-ret-val.yaml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/WholeProgramDevirt/Inputs/import-uniform-ret-val.yaml?rev=297350&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/WholeProgramDevirt/Inputs/import-uniform-ret-val.yaml (added)
+++ llvm/trunk/test/Transforms/WholeProgramDevirt/Inputs/import-uniform-ret-val.yaml Wed Mar  8 19:11:15 2017
@@ -0,0 +1,19 @@
+---
+TypeIdMap:
+  typeid1:
+    WPDRes:
+      0:
+        Kind: Indir
+        ResByArg:
+          1:
+            Kind: UniformRetVal
+            Info: 42
+  typeid2:
+    WPDRes:
+      8:
+        Kind: Indir
+        ResByArg:
+          1:
+            Kind: UniformRetVal
+            Info: 42
+...

Modified: llvm/trunk/test/Transforms/WholeProgramDevirt/import.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/WholeProgramDevirt/import.ll?rev=297350&r1=297349&r2=297350&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/WholeProgramDevirt/import.ll (original)
+++ llvm/trunk/test/Transforms/WholeProgramDevirt/import.ll Wed Mar  8 19:11:15 2017
@@ -1,8 +1,12 @@
 ; RUN: opt -S -wholeprogramdevirt -wholeprogramdevirt-summary-action=import -wholeprogramdevirt-read-summary=%S/Inputs/import-single-impl.yaml < %s | FileCheck --check-prefixes=CHECK,SINGLE-IMPL %s
+; RUN: opt -S -wholeprogramdevirt -wholeprogramdevirt-summary-action=import -wholeprogramdevirt-read-summary=%S/Inputs/import-uniform-ret-val.yaml < %s | FileCheck --check-prefixes=CHECK,UNIFORM-RET-VAL %s
 
 target datalayout = "e-p:64:64"
 target triple = "x86_64-unknown-linux-gnu"
 
+; Test cases where the argument values are known and we can apply virtual
+; constant propagation.
+
 ; CHECK: define i32 @call1
 define i32 @call1(i8* %obj) {
   %vtableptr = bitcast i8* %obj to [3 x i8*]**
@@ -15,9 +19,13 @@ define i32 @call1(i8* %obj) {
   %fptr_casted = bitcast i8* %fptr to i32 (i8*, i32)*
   ; SINGLE-IMPL: call i32 bitcast (void ()* @singleimpl1 to i32 (i8*, i32)*)
   %result = call i32 %fptr_casted(i8* %obj, i32 1)
+  ; UNIFORM-RET-VAL: ret i32 42
   ret i32 %result
 }
 
+; Test cases where the argument values are unknown, so we cannot apply virtual
+; constant propagation.
+
 ; CHECK: define i1 @call2
 define i1 @call2(i8* %obj) {
   %vtableptr = bitcast i8* %obj to [1 x i8*]**
@@ -32,6 +40,7 @@ define i1 @call2(i8* %obj) {
 cont:
   %fptr_casted = bitcast i8* %fptr to i1 (i8*, i32)*
   ; SINGLE-IMPL: call i1 bitcast (void ()* @singleimpl2 to i1 (i8*, i32)*)
+  ; UNIFORM-RET-VAL: call i1 %
   %result = call i1 %fptr_casted(i8* %obj, i32 undef)
   ret i1 %result
 




More information about the llvm-commits mailing list