[llvm] r323444 - [LTO] - Introduce GlobalResolution::Prevailing flag.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 25 09:23:28 PST 2018


Author: grimar
Date: Thu Jan 25 09:23:27 2018
New Revision: 323444

URL: http://llvm.org/viewvc/llvm-project?rev=323444&view=rev
Log:
[LTO] - Introduce GlobalResolution::Prevailing flag.

It is NFC refactoring change that will make
D42107 a bit smaller.

Differential revision: https://reviews.llvm.org/D42528

Modified:
    llvm/trunk/include/llvm/LTO/LTO.h
    llvm/trunk/lib/LTO/LTO.cpp

Modified: llvm/trunk/include/llvm/LTO/LTO.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/LTO/LTO.h?rev=323444&r1=323443&r2=323444&view=diff
==============================================================================
--- llvm/trunk/include/llvm/LTO/LTO.h (original)
+++ llvm/trunk/include/llvm/LTO/LTO.h Thu Jan 25 09:23:27 2018
@@ -320,6 +320,9 @@ private:
 
     bool UnnamedAddr = true;
 
+    /// True if IR contains the prevailing definition.
+    bool Prevailing = false;
+
     /// This field keeps track of the partition number of this global. The
     /// regular LTO object is partition 0, while each ThinLTO object has its own
     /// partition number from 1 onwards.

Modified: llvm/trunk/lib/LTO/LTO.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/LTO.cpp?rev=323444&r1=323443&r2=323444&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/LTO.cpp (original)
+++ llvm/trunk/lib/LTO/LTO.cpp Thu Jan 25 09:23:27 2018
@@ -419,8 +419,9 @@ void LTO::addModuleToGlobalRes(ArrayRef<
     auto &GlobalRes = GlobalResolutions[Sym.getName()];
     GlobalRes.UnnamedAddr &= Sym.isUnnamedAddr();
     if (Res.Prevailing) {
-      assert(GlobalRes.IRName.empty() &&
+      assert(!GlobalRes.Prevailing &&
              "Multiple prevailing defs are not allowed");
+      GlobalRes.Prevailing = true;
       GlobalRes.IRName = Sym.getIRName();
     }
 
@@ -746,14 +747,10 @@ unsigned LTO::getMaxTasks() const {
 Error LTO::run(AddStreamFn AddStream, NativeObjectCache Cache) {
   // Compute "dead" symbols, we don't want to import/export these!
   DenseSet<GlobalValue::GUID> GUIDPreservedSymbols;
-  for (auto &Res : GlobalResolutions) {
-    if (Res.second.VisibleOutsideSummary &&
-        // IRName will be defined if we have seen the prevailing copy of
-        // this value. If not, no need to preserve any ThinLTO copies.
-        !Res.second.IRName.empty())
+  for (auto &Res : GlobalResolutions)
+    if (Res.second.VisibleOutsideSummary && Res.second.Prevailing)
       GUIDPreservedSymbols.insert(GlobalValue::getGUID(
           GlobalValue::dropLLVMManglingEscape(Res.second.IRName)));
-  }
 
   computeDeadSymbols(ThinLTO.CombinedIndex, GUIDPreservedSymbols);
 
@@ -803,7 +800,7 @@ Error LTO::runRegularLTO(AddStreamFn Add
 
   if (!Conf.CodeGenOnly) {
     for (const auto &R : GlobalResolutions) {
-      if (R.second.IRName.empty())
+      if (!R.second.Prevailing)
         continue;
       if (R.second.Partition != 0 &&
           R.second.Partition != GlobalResolution::External)
@@ -1114,13 +1111,10 @@ Error LTO::runThinLTO(AddStreamFn AddStr
   // undefined references during the final link.
   std::set<GlobalValue::GUID> ExportedGUIDs;
   for (auto &Res : GlobalResolutions) {
-    // First check if the symbol was flagged as having external references.
-    if (Res.second.Partition != GlobalResolution::External)
-      continue;
-    // IRName will be defined if we have seen the prevailing copy of
-    // this value. If not, no need to mark as exported from a ThinLTO
-    // partition (and we can't get the GUID).
-    if (Res.second.IRName.empty())
+    // If the symbol does not have external references or it is not prevailing,
+    // then not need to mark it as exported from a ThinLTO partition.
+    if (Res.second.Partition != GlobalResolution::External ||
+        !Res.second.Prevailing)
       continue;
     auto GUID = GlobalValue::getGUID(
         GlobalValue::dropLLVMManglingEscape(Res.second.IRName));




More information about the llvm-commits mailing list