[PATCH] D37550: WholeProgramDevirt: When promoting for single-impl devirt, also rename the comdat.

Peter Collingbourne via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 7 17:13:37 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL312767: WholeProgramDevirt: When promoting for single-impl devirt, also rename theā€¦ (authored by pcc).

Changed prior to commit:
  https://reviews.llvm.org/D37550?vs=114114&id=114289#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D37550

Files:
  llvm/trunk/lib/Transforms/IPO/WholeProgramDevirt.cpp
  llvm/trunk/test/Transforms/WholeProgramDevirt/export-single-impl.ll


Index: llvm/trunk/test/Transforms/WholeProgramDevirt/export-single-impl.ll
===================================================================
--- llvm/trunk/test/Transforms/WholeProgramDevirt/export-single-impl.ll
+++ llvm/trunk/test/Transforms/WholeProgramDevirt/export-single-impl.ll
@@ -27,7 +27,7 @@
 ; SUMMARY-NEXT:     WPDRes:
 ; SUMMARY-NEXT:       0:
 ; SUMMARY-NEXT:         Kind:            SingleImpl
-; SUMMARY-NEXT:         SingleImplName:  vf3
+; SUMMARY-NEXT:         SingleImplName:  'vf3$merged'
 ; SUMMARY-NEXT:         ResByArg:
 ; SUMMARY-NEXT:   typeid4:
 ; SUMMARY-NEXT:     TTRes:
@@ -41,16 +41,19 @@
 ; SUMMARY-NEXT: WithGlobalValueDeadStripping: false
 ; SUMMARY-NEXT: ...
 
+; CHECK: $"vf4$merged" = comdat largest
+$vf4 = comdat largest
+
 ; CHECK: @vt1 = constant void (i8*)* @vf1
 @vt1 = constant void (i8*)* @vf1, !type !0
 
 ; CHECK: @vt2 = constant void (i8*)* @vf2
 @vt2 = constant void (i8*)* @vf2, !type !1
 
 @vt3 = constant void (i8*)* @vf3, !type !2
 
-; CHECK: @vt4 = constant void (i8*)* @"vf4$merged"
- at vt4 = constant void (i8*)* @vf4, !type !3
+; CHECK: @vt4 = constant void (i8*)* @"vf4$merged", comdat($"vf4$merged")
+ at vt4 = constant void (i8*)* @vf4, comdat($vf4), !type !3
 
 @vt5 = constant void (i8*)* @vf5, !type !4
 
@@ -62,10 +65,13 @@
   ret void
 }
 
-declare void @vf3(i8*)
+; CHECK: define hidden void @"vf3$merged"(i8*) {
+define internal void @vf3(i8*) {
+  ret void
+}
 
-; CHECK: define hidden void @"vf4$merged"
-define internal void @vf4(i8*) {
+; CHECK: define hidden void @"vf4$merged"(i8*) comdat {
+define internal void @vf4(i8*) comdat {
   ret void
 }
 
Index: llvm/trunk/lib/Transforms/IPO/WholeProgramDevirt.cpp
===================================================================
--- llvm/trunk/lib/Transforms/IPO/WholeProgramDevirt.cpp
+++ llvm/trunk/lib/Transforms/IPO/WholeProgramDevirt.cpp
@@ -757,9 +757,24 @@
   // to make it visible to thin LTO objects. We can only get here during the
   // ThinLTO export phase.
   if (TheFn->hasLocalLinkage()) {
+    std::string NewName = (TheFn->getName() + "$merged").str();
+
+    // Since we are renaming the function, any comdats with the same name must
+    // also be renamed. This is required when targeting COFF, as the comdat name
+    // must match one of the names of the symbols in the comdat.
+    if (Comdat *C = TheFn->getComdat()) {
+      if (C->getName() == TheFn->getName()) {
+        Comdat *NewC = M.getOrInsertComdat(NewName);
+        NewC->setSelectionKind(C->getSelectionKind());
+        for (GlobalObject &GO : M.global_objects())
+          if (GO.getComdat() == C)
+            GO.setComdat(NewC);
+      }
+    }
+
     TheFn->setLinkage(GlobalValue::ExternalLinkage);
     TheFn->setVisibility(GlobalValue::HiddenVisibility);
-    TheFn->setName(TheFn->getName() + "$merged");
+    TheFn->setName(NewName);
   }
 
   Res->TheKind = WholeProgramDevirtResolution::SingleImpl;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37550.114289.patch
Type: text/x-patch
Size: 2921 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170908/096ae3c5/attachment.bin>


More information about the llvm-commits mailing list