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 #include #include @@ -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 &ModuleToDefinedGVSummaries) const; }; +/// GraphTraits definition to build SCC for the index +template <> struct GraphTraits { + typedef const FunctionSummary *NodeRef; + static NodeRef fsumFromEdge(const FunctionSummary::EdgeTy &P) { + if (P.first.Ref && P.first.getSummaryList().size()) + return cast(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, FunctionSummary::FFlags{}, std::vector(), + std::vector(), + std::vector(), + std::vector(), + std::vector(), + std::vector(), + std::vector()); + F->setOriginalName(P.first.Ref ? P.first.getGUID() : 0); + return F.get(); + } + using ChildIteratorType = + mapped_iterator::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