[llvm] r259398 - [ThinLTO] Ensure function summary output order is stable

Teresa Johnson via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 1 12:16:35 PST 2016


Author: tejohnson
Date: Mon Feb  1 14:16:35 2016
New Revision: 259398

URL: http://llvm.org/viewvc/llvm-project?rev=259398&view=rev
Log:
[ThinLTO] Ensure function summary output order is stable

Iterate over the function list instead of a DenseMap of Function pointers
when emitting the function summary into the module.

This fixes PR26419.

Modified:
    llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp

Modified: llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp?rev=259398&r1=259397&r2=259398&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp (original)
+++ llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp Mon Feb  1 14:16:35 2016
@@ -2800,16 +2800,22 @@ static void WritePerModuleFunctionSummar
   unsigned FSAbbrev = Stream.EmitAbbrev(Abbv);
 
   SmallVector<unsigned, 64> NameVals;
-  for (auto &I : FunctionIndex) {
+  // Iterate over the list of functions instead of the FunctionIndex map to
+  // ensure the ordering is stable.
+  for (const Function &F : *M) {
+    if (F.isDeclaration())
+      continue;
     // Skip anonymous functions. We will emit a function summary for
     // any aliases below.
-    if (!I.first->hasName())
+    if (!F.hasName())
       continue;
 
+    assert(FunctionIndex.count(&F) == 1);
+
     WritePerModuleFunctionSummaryRecord(
-        NameVals, I.second->functionSummary(),
-        VE.getValueID(M->getValueSymbolTable().lookup(I.first->getName())),
-        FSAbbrev, Stream);
+        NameVals, FunctionIndex[&F]->functionSummary(),
+        VE.getValueID(M->getValueSymbolTable().lookup(F.getName())), FSAbbrev,
+        Stream);
   }
 
   for (const GlobalAlias &A : M->aliases()) {




More information about the llvm-commits mailing list