]> granicus.if.org Git - llvm/commitdiff
WholeProgramDevirt: When promoting for single-impl devirt, also rename the comdat.
authorPeter Collingbourne <peter@pcc.me.uk>
Fri, 8 Sep 2017 00:10:53 +0000 (00:10 +0000)
committerPeter Collingbourne <peter@pcc.me.uk>
Fri, 8 Sep 2017 00:10:53 +0000 (00:10 +0000)
This is required when targeting COFF, as the comdat name must match
one of the names of the symbols in the comdat.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@312767 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/IPO/WholeProgramDevirt.cpp
test/Transforms/WholeProgramDevirt/export-single-impl.ll

index c4e6e3957d096eabb4f23daa0c7d85eea4a6ef55..f2e01b43b76c6bd208a6f280f4f44d03457c7c4c 100644 (file)
@@ -757,9 +757,24 @@ bool DevirtModule::trySingleImplDevirt(
   // 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;
index 15de77381ed15589246b348e16e91ea87396fdbc..6c83c30ae28edd37a8b1b6c7c87473217631f443 100644 (file)
@@ -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,6 +41,9 @@
 ; 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
 
@@ -49,8 +52,8 @@
 
 @vt3 = constant void (i8*)* @vf3, !type !2
 
-; CHECK: @vt4 = constant void (i8*)* @"vf4$merged"
-@vt4 = constant void (i8*)* @vf4, !type !3
+; CHECK: @vt4 = constant void (i8*)* @"vf4$merged", comdat($"vf4$merged")
+@vt4 = constant void (i8*)* @vf4, comdat($vf4), !type !3
 
 @vt5 = constant void (i8*)* @vf5, !type !4
 
@@ -62,10 +65,13 @@ define void @vf2(i8*) {
   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
 }