[PATCH] D26049: [ThinLTO] Create AliasSummary when building index

Teresa Johnson via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 27 19:49:12 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL285379: [ThinLTO] Create AliasSummary when building index (authored by tejohnson).

Changed prior to commit:
  https://reviews.llvm.org/D26049?vs=76130&id=76160#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26049

Files:
  llvm/trunk/lib/Analysis/ModuleSummaryAnalysis.cpp
  llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp


Index: llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp
===================================================================
--- llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -3434,7 +3434,9 @@
     auto AliasId = VE.getValueID(&A);
     auto AliaseeId = VE.getValueID(Aliasee);
     NameVals.push_back(AliasId);
-    NameVals.push_back(getEncodedGVSummaryFlags(A));
+    auto *Summary = Index->getGlobalValueSummary(A);
+    AliasSummary *AS = cast<AliasSummary>(Summary);
+    NameVals.push_back(getEncodedGVSummaryFlags(AS->flags()));
     NameVals.push_back(AliaseeId);
     Stream.EmitRecord(bitc::FS_ALIAS, NameVals, FSAliasAbbrev);
     NameVals.clear();
Index: llvm/trunk/lib/Analysis/ModuleSummaryAnalysis.cpp
===================================================================
--- llvm/trunk/lib/Analysis/ModuleSummaryAnalysis.cpp
+++ llvm/trunk/lib/Analysis/ModuleSummaryAnalysis.cpp
@@ -78,10 +78,9 @@
 static void computeFunctionSummary(ModuleSummaryIndex &Index, const Module &M,
                                    const Function &F, BlockFrequencyInfo *BFI,
                                    ProfileSummaryInfo *PSI) {
-  // Summary not currently supported for anonymous functions, they must
-  // be renamed.
-  if (!F.hasName())
-    return;
+  // Summary not currently supported for anonymous functions, they should
+  // have been named.
+  assert(F.hasName());
 
   unsigned NumInsts = 0;
   // Map from callee ValueId to profile count. Used to accumulate profile
@@ -111,9 +110,11 @@
       }
       // Check if this is a direct call to a known function.
       if (CalledFunction) {
-        // Skip nameless and intrinsics.
-        if (!CalledFunction->hasName() || CalledFunction->isIntrinsic())
+        // Skip intrinsics.
+        if (CalledFunction->isIntrinsic())
           continue;
+        // We should have named any anonymous globals
+        assert(CalledFunction->hasName());
         auto ScaledCount = BFI ? BFI->getBlockProfileCount(&BB) : None;
         // Use the original CalledValue, in case it was an alias. We want
         // to record the call edge to the alias in that case. Eventually
@@ -166,6 +167,17 @@
   Index.addGlobalValueSummary(V.getName(), std::move(GVarSummary));
 }
 
+static void computeAliasSummary(ModuleSummaryIndex &Index,
+                                const GlobalAlias &A) {
+  GlobalValueSummary::GVFlags Flags(A);
+  std::unique_ptr<AliasSummary> AS = llvm::make_unique<AliasSummary>(Flags);
+  auto *Aliasee = A.getBaseObject();
+  auto *AliaseeSummary = Index.getGlobalValueSummary(*Aliasee);
+  assert(AliaseeSummary && "Alias expects aliasee summary to be parsed");
+  AS->setAliasee(AliaseeSummary);
+  Index.addGlobalValueSummary(A.getName(), std::move(AS));
+}
+
 ModuleSummaryIndex llvm::buildModuleSummaryIndex(
     const Module &M,
     std::function<BlockFrequencyInfo *(const Function &F)> GetBFICallback,
@@ -204,6 +216,12 @@
       continue;
     computeVariableSummary(Index, G);
   }
+
+  // Compute summaries for all aliases defined in module, and save in the
+  // index.
+  for (const GlobalAlias &A : M.aliases())
+    computeAliasSummary(Index, A);
+
   return Index;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26049.76160.patch
Type: text/x-patch
Size: 3228 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161028/e1f8d0f3/attachment.bin>


More information about the llvm-commits mailing list