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

Charles Saternos via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 4 07:59:55 PDT 2017


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

Diff against https://reviews.llvm.org/D36233 rather than master.


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
@@ -359,6 +359,45 @@
   /// Get function attribute flags.
   FFlags &fflags() { return FunFlags; }
 
+  /// Iterator for a callees in a function summary.
+  class const_iterator
+      : public std::iterator<std::input_iterator_tag, FunctionSummary *> {
+    std::vector<EdgeTy>::const_iterator I;
+    const FunctionSummary *fsumFromEdge(const 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>(
+          GVFlags(GlobalValue::LinkageTypes::AvailableExternallyLinkage, true,
+                  false),
+          0, FFlags{}, std::vector<ValueInfo>(), std::vector<EdgeTy>(),
+          std::vector<GlobalValue::GUID>(), std::vector<VFuncId>(),
+          std::vector<VFuncId>(), std::vector<ConstVCall>(),
+          std::vector<ConstVCall>());
+      F->setOriginalName(P.first.Ref ? P.first.getGUID() : 0);
+      return F.get();
+    }
+
+  public:
+    const_iterator(std::vector<EdgeTy>::const_iterator I) : I(I){};
+    const_iterator operator++(int) {
+      I++;
+      return *this;
+    }
+    bool operator==(const const_iterator &rhs) const { return I == rhs.I; }
+    bool operator!=(const const_iterator &rhs) const { return I != rhs.I; }
+    const FunctionSummary *operator*() { return fsumFromEdge(*I); }
+  };
+
+  const_iterator call_summaries_begin() const {
+    return const_iterator(CallGraphEdgeList.begin());
+  }
+  const_iterator call_summaries_end() const {
+    return const_iterator(CallGraphEdgeList.end());
+  }
+
   /// Get the instruction count recorded for this function.
   unsigned instCount() const { return InstCount; }
 
@@ -772,6 +811,39 @@
       StringMap<GVSummaryMapTy> &ModuleToDefinedGVSummaries) const;
 };
 
+/// GraphTraits definition to build SCC for the index
+template <> struct GraphTraits<const FunctionSummary *> {
+  typedef const FunctionSummary *NodeRef;
+  typedef FunctionSummary::const_iterator ChildIteratorType;
+
+  // Use the first callee as the entry node
+  static NodeRef getEntryNode(const FunctionSummary *F) {
+    if (F->call_summaries_begin() != F->call_summaries_end())
+      return *(F->call_summaries_begin());
+
+    // use a dummy functionsummary when there is no entry node
+    auto S = 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>());
+    return S.get();
+  }
+
+  static ChildIteratorType child_begin(NodeRef N) {
+    return N->call_summaries_begin();
+  }
+
+  static ChildIteratorType child_end(NodeRef N) {
+    return N->call_summaries_end();
+  }
+};
+
 } // end namespace llvm
 
 #endif // LLVM_IR_MODULESUMMARYINDEX_H


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36311.109736.patch
Type: text/x-patch
Size: 3461 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170804/0e4fbba7/attachment.bin>


More information about the llvm-commits mailing list