[llvm-branch-commits] [llvm-branch] r352856 - Merging r352770:

Hans Wennborg via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Feb 1 03:01:13 PST 2019


Author: hans
Date: Fri Feb  1 03:01:12 2019
New Revision: 352856

URL: http://llvm.org/viewvc/llvm-project?rev=352856&view=rev
Log:
Merging r352770:
------------------------------------------------------------------------
r352770 | tejohnson | 2019-01-31 18:18:11 +0100 (Thu, 31 Jan 2019) | 3 lines

Recommit "[ThinLTO] Rename COMDATs for COFF when promoting/renaming COMDAT leader"

Recommit of r352763 with fix for use after free.
------------------------------------------------------------------------

Added:
    llvm/branches/release_80/test/Transforms/FunctionImport/Inputs/comdat.ll
      - copied unchanged from r352770, llvm/trunk/test/Transforms/FunctionImport/Inputs/comdat.ll
    llvm/branches/release_80/test/Transforms/FunctionImport/comdat.ll
      - copied unchanged from r352770, llvm/trunk/test/Transforms/FunctionImport/comdat.ll
Modified:
    llvm/branches/release_80/   (props changed)
    llvm/branches/release_80/include/llvm/Transforms/Utils/FunctionImportUtils.h
    llvm/branches/release_80/lib/Transforms/Utils/FunctionImportUtils.cpp

Propchange: llvm/branches/release_80/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Feb  1 03:01:12 2019
@@ -1,3 +1,3 @@
 /llvm/branches/Apple/Pertwee:110850,110961
 /llvm/branches/type-system-rewrite:133420-134817
-/llvm/trunk:155241,351325,351344-351345,351349,351351,351370,351381,351421,351426,351436,351475,351485,351753-351754,351910,351930,351932,352034,352204,352374
+/llvm/trunk:155241,351325,351344-351345,351349,351351,351370,351381,351421,351426,351436,351475,351485,351753-351754,351910,351930,351932,352034,352204,352374,352770

Modified: llvm/branches/release_80/include/llvm/Transforms/Utils/FunctionImportUtils.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_80/include/llvm/Transforms/Utils/FunctionImportUtils.h?rev=352856&r1=352855&r2=352856&view=diff
==============================================================================
--- llvm/branches/release_80/include/llvm/Transforms/Utils/FunctionImportUtils.h (original)
+++ llvm/branches/release_80/include/llvm/Transforms/Utils/FunctionImportUtils.h Fri Feb  1 03:01:12 2019
@@ -44,6 +44,11 @@ class FunctionImportGlobalProcessing {
   /// to promote any non-renamable values.
   SmallPtrSet<GlobalValue *, 8> Used;
 
+  /// Keep track of any COMDATs that require renaming (because COMDAT
+  /// leader was promoted and renamed). Maps from original COMDAT to one
+  /// with new name.
+  DenseMap<const Comdat *, Comdat *> RenamedComdats;
+
   /// Check if we should promote the given local value to global scope.
   bool shouldPromoteLocalToGlobal(const GlobalValue *SGV);
 

Modified: llvm/branches/release_80/lib/Transforms/Utils/FunctionImportUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_80/lib/Transforms/Utils/FunctionImportUtils.cpp?rev=352856&r1=352855&r2=352856&view=diff
==============================================================================
--- llvm/branches/release_80/lib/Transforms/Utils/FunctionImportUtils.cpp (original)
+++ llvm/branches/release_80/lib/Transforms/Utils/FunctionImportUtils.cpp Fri Feb  1 03:01:12 2019
@@ -249,6 +249,8 @@ void FunctionImportGlobalProcessing::pro
   bool DoPromote = false;
   if (GV.hasLocalLinkage() &&
       ((DoPromote = shouldPromoteLocalToGlobal(&GV)) || isPerformingImport())) {
+    // Save the original name string before we rename GV below.
+    auto Name = GV.getName().str();
     // Once we change the name or linkage it is difficult to determine
     // again whether we should promote since shouldPromoteLocalToGlobal needs
     // to locate the summary (based on GUID from name and linkage). Therefore,
@@ -257,6 +259,12 @@ void FunctionImportGlobalProcessing::pro
     GV.setLinkage(getLinkage(&GV, DoPromote));
     if (!GV.hasLocalLinkage())
       GV.setVisibility(GlobalValue::HiddenVisibility);
+
+    // If we are renaming a COMDAT leader, ensure that we record the COMDAT
+    // for later renaming as well. This is required for COFF.
+    if (const auto *C = GV.getComdat())
+      if (C->getName() == Name)
+        RenamedComdats.try_emplace(C, M.getOrInsertComdat(GV.getName()));
   } else
     GV.setLinkage(getLinkage(&GV, /* DoPromote */ false));
 
@@ -281,6 +289,16 @@ void FunctionImportGlobalProcessing::pro
     processGlobalForThinLTO(SF);
   for (GlobalAlias &GA : M.aliases())
     processGlobalForThinLTO(GA);
+
+  // Replace any COMDATS that required renaming (because the COMDAT leader was
+  // promoted and renamed).
+  if (!RenamedComdats.empty())
+    for (auto &GO : M.global_objects())
+      if (auto *C = GO.getComdat()) {
+        auto Replacement = RenamedComdats.find(C);
+        if (Replacement != RenamedComdats.end())
+          GO.setComdat(Replacement->second);
+      }
 }
 
 bool FunctionImportGlobalProcessing::run() {




More information about the llvm-branch-commits mailing list