[PATCH] D36311: [ThinLTO] Add GraphTraits for FunctionSummaries

Charles Saternos via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 8 10:27:38 PDT 2017


ncharlie updated this revision to Diff 110226.
ncharlie added a comment.

simplify code by using mapped_iterator rather than custom implementation.


https://reviews.llvm.org/D36311

Files:
  include/llvm/IR/ModuleSummaryIndex.h


Index: include/llvm/IR/ModuleSummaryIndex.h
===================================================================
--- include/llvm/IR/ModuleSummaryIndex.h
+++ include/llvm/IR/ModuleSummaryIndex.h
@@ -25,6 +25,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/IR/GlobalValue.h"
 #include "llvm/IR/Module.h"
+#include "llvm/Transforms/IPO/FunctionAttrs.h"
 #include <algorithm>
 #include <array>
 #include <cassert>
@@ -193,6 +194,7 @@
   /// Returns the hash of the original name, it is identical to the GUID for
   /// externally visible symbols, but not for local ones.
   GlobalValue::GUID getOriginalName() { return OriginalName; }
+  GlobalValue::GUID getOriginalName() const { return OriginalName; }
 
   /// Initialize the original name hash in this summary.
   void setOriginalName(GlobalValue::GUID Name) { OriginalName = Name; }
@@ -771,6 +773,44 @@
       StringMap<GVSummaryMapTy> &ModuleToDefinedGVSummaries) const;
 };
 
+/// GraphTraits definition to build SCC for the index
+template <> struct GraphTraits<const FunctionSummary *> {
+  typedef const FunctionSummary *NodeRef;
+  static NodeRef fsumFromEdge(const FunctionSummary::EdgeTy &P) {
+    if (P.first.Ref && P.first.getSummaryList().size())
+      return cast<FunctionSummary>(P.first.getSummaryList().front().get());
+
+    // Create an empty functionsummary in the case of an external function
+    // (since scc_iterator doesn't accept nullptrs)
+    auto F = llvm::make_unique<FunctionSummary>(
+        FunctionSummary::GVFlags(
+            GlobalValue::LinkageTypes::AvailableExternallyLinkage, true, false),
+        0, FunctionSummary::FFlags{}, std::vector<ValueInfo>(),
+        std::vector<FunctionSummary::EdgeTy>(),
+        std::vector<GlobalValue::GUID>(),
+        std::vector<FunctionSummary::VFuncId>(),
+        std::vector<FunctionSummary::VFuncId>(),
+        std::vector<FunctionSummary::ConstVCall>(),
+        std::vector<FunctionSummary::ConstVCall>());
+    F->setOriginalName(P.first.Ref ? P.first.getGUID() : 0);
+    return F.get();
+  }
+  using ChildIteratorType =
+      mapped_iterator<ArrayRef<FunctionSummary::EdgeTy>::iterator,
+                      decltype(&fsumFromEdge)>;
+
+  // Use the first callee as the entry node
+  static NodeRef getEntryNode(const FunctionSummary *F) { return F; }
+
+  static ChildIteratorType child_begin(NodeRef N) {
+    return ChildIteratorType(N->calls().begin(), &fsumFromEdge);
+  }
+
+  static ChildIteratorType child_end(NodeRef N) {
+    return ChildIteratorType(N->calls().end(), &fsumFromEdge);
+  }
+};
+
 } // end namespace llvm
 
 #endif // LLVM_IR_MODULESUMMARYINDEX_H


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36311.110226.patch
Type: text/x-patch
Size: 2629 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170808/b6accf16/attachment.bin>


More information about the llvm-commits mailing list