From 2ad768bb1326a2a05ab3f89c22208d083ad304fd Mon Sep 17 00:00:00 2001 From: Volodymyr Sapsai Date: Mon, 12 Feb 2018 20:43:31 +0000 Subject: [PATCH] Revert "[ThinLTO] Add GraphTraits for FunctionSummaries" It caused assertion failure Assertion failed: (!DD.IsLambda && !MergeDD.IsLambda && "faked up lambda definition?"), function MergeDefinitionData, file /Users/buildslave/jenkins/workspace/clang-stage1-configure-RA/llvm/tools/clang/lib/Serialization/ASTReaderDecl.cpp, line 1675. on the second stage build bots. llvm-svn: 324932 --- llvm/include/llvm/IR/ModuleSummaryIndex.h | 150 +---------------------------- llvm/lib/IR/ModuleSummaryIndex.cpp | 24 ----- llvm/lib/LTO/LTO.cpp | 7 -- llvm/lib/Transforms/IPO/FunctionImport.cpp | 2 +- 4 files changed, 2 insertions(+), 181 deletions(-) diff --git a/llvm/include/llvm/IR/ModuleSummaryIndex.h b/llvm/include/llvm/IR/ModuleSummaryIndex.h index e99b20d..d75986b 100644 --- a/llvm/include/llvm/IR/ModuleSummaryIndex.h +++ b/llvm/include/llvm/IR/ModuleSummaryIndex.h @@ -162,24 +162,6 @@ struct ValueInfo { bool isDSOLocal() const; }; -inline bool operator==(const ValueInfo &A, const ValueInfo &B) { - assert(A.getRef() && B.getRef() && - "Need ValueInfo with non-null Ref to compare GUIDs"); - return A.getRef() == B.getRef(); -} - -inline bool operator!=(const ValueInfo &A, const ValueInfo &B) { - assert(A.getRef() && B.getRef() && - "Need ValueInfo with non-null Ref to compare GUIDs"); - return A.getGUID() != B.getGUID(); -} - -inline bool operator<(const ValueInfo &A, const ValueInfo &B) { - assert(A.getRef() && B.getRef() && - "Need ValueInfo with non-null Ref to compare GUIDs"); - return A.getGUID() < B.getGUID(); -} - template <> struct DenseMapInfo { static inline ValueInfo getEmptyKey() { return ValueInfo(false, (GlobalValueSummaryMapTy::value_type *)-8); @@ -415,25 +397,6 @@ public: unsigned ReturnDoesNotAlias : 1; }; - /// Create an empty FunctionSummary (with specified call edges). - /// Used to represent external nodes and the dummy root node. - static FunctionSummary - makeDummyFunctionSummary(std::vector Edges) { - return FunctionSummary( - FunctionSummary::GVFlags( - GlobalValue::LinkageTypes::AvailableExternallyLinkage, - /*NotEligibleToImport=*/true, /*Live=*/true, /*IsLocal=*/false), - 0, FunctionSummary::FFlags{}, std::vector(), - std::move(Edges), std::vector(), - std::vector(), - std::vector(), - std::vector(), - std::vector()); - } - - /// A dummy node to reference external functions that aren't in the index - static FunctionSummary ExternalNode; - private: /// Number of instructions (ignoring debug instructions, e.g.) computed /// during the initial compile step when the summary index is first built. @@ -553,8 +516,6 @@ public: TIdInfo = llvm::make_unique(); TIdInfo->TypeTests.push_back(Guid); } - - friend struct GraphTraits; }; template <> struct DenseMapInfo { @@ -751,65 +712,6 @@ public: const_gvsummary_iterator end() const { return GlobalValueMap.end(); } size_t size() const { return GlobalValueMap.size(); } - // Calculate the callgraph root - FunctionSummary calculateCallGraphRoot() { - // Functions that have a parent will be marked in FunctionHasParent pair. - // Once we've marked all functions, the functions in the map that are false - // have no parent (so they're the roots) - std::map FunctionHasParent; - std::function discoverNodes = [&](ValueInfo V) { - if (!V.getSummaryList().size()) - return; // skip external functions that don't have summaries - - // Mark discovered if we haven't yet - auto S = FunctionHasParent.emplace(V, false); - - // Stop if we've already discovered this node - if (!S.second) - return; - - FunctionSummary *F = - dyn_cast(V.getSummaryList().front().get()); - assert(F != nullptr && "Expected FunctionSummary node"); - - for (auto &C : F->calls()) { - // Insert node if necessary - auto S = FunctionHasParent.emplace(C.first, true); - - // Skip nodes that we're sure have parents - if (!S.second && S.first->second) - continue; - - if (S.second) - discoverNodes(C.first); - else - S.first->second = true; - } - }; - - for (auto &S : *this) { - // Skip external functions - if (!S.second.SummaryList.size() || - !isa(S.second.SummaryList.front().get())) - continue; - discoverNodes(ValueInfo(IsAnalysis, &S)); - } - - std::vector Edges; - // create edges to all roots in the Index - for (auto &P : FunctionHasParent) { - if (P.second) - continue; // skip over non-root nodes - Edges.push_back(std::make_pair(P.first, CalleeInfo{})); - } - if (Edges.empty()) { - // Failed to find root - return an empty node - return FunctionSummary::makeDummyFunctionSummary({}); - } - auto CallGraphRoot = FunctionSummary::makeDummyFunctionSummary(Edges); - return CallGraphRoot; - } - bool withGlobalValueDeadStripping() const { return WithGlobalValueDeadStripping; } @@ -833,7 +735,7 @@ public: return ValueInfo(IsAnalysis, getOrInsertValuePtr(GUID)); } - /// Return a ValueInfo for \p GUID setting value \p Name. + /// Return a ValueInfo for \p GUID setting value \p Name. ValueInfo getOrInsertValueInfo(GlobalValue::GUID GUID, StringRef Name) { assert(!IsAnalysis); auto VP = getOrInsertValuePtr(GUID); @@ -1008,56 +910,6 @@ public: /// Export summary to dot file for GraphViz. void exportToDot(raw_ostream& OS) const; - - /// Print out strongly connected components for debugging. - void dumpSCCs(raw_ostream &OS); -}; - -/// GraphTraits definition to build SCC for the index -template <> struct GraphTraits { - typedef ValueInfo NodeRef; - - static NodeRef valueInfoFromEdge(FunctionSummary::EdgeTy &P) { - return P.first; - } - using ChildIteratorType = - mapped_iterator::iterator, - decltype(&valueInfoFromEdge)>; - - static NodeRef getEntryNode(ValueInfo V) { return V; } - - static ChildIteratorType child_begin(NodeRef N) { - if (!N.getSummaryList().size()) // handle external function - return ChildIteratorType( - FunctionSummary::ExternalNode.CallGraphEdgeList.begin(), - &valueInfoFromEdge); - FunctionSummary *F = - cast(N.getSummaryList().front()->getBaseObject()); - return ChildIteratorType(F->CallGraphEdgeList.begin(), &valueInfoFromEdge); - } - - static ChildIteratorType child_end(NodeRef N) { - if (!N.getSummaryList().size()) // handle external function - return ChildIteratorType( - FunctionSummary::ExternalNode.CallGraphEdgeList.end(), - &valueInfoFromEdge); - FunctionSummary *F = - cast(N.getSummaryList().front()->getBaseObject()); - return ChildIteratorType(F->CallGraphEdgeList.end(), &valueInfoFromEdge); - } -}; - -template <> -struct GraphTraits : public GraphTraits { - static NodeRef getEntryNode(ModuleSummaryIndex *I) { - std::unique_ptr Root = - make_unique(I->calculateCallGraphRoot()); - GlobalValueSummaryInfo G(I->isPerformingAnalysis()); - G.SummaryList.push_back(std::move(Root)); - static auto P = - GlobalValueSummaryMapTy::value_type(GlobalValue::GUID(0), std::move(G)); - return ValueInfo(I->isPerformingAnalysis(), &P); - } }; } // end namespace llvm diff --git a/llvm/lib/IR/ModuleSummaryIndex.cpp b/llvm/lib/IR/ModuleSummaryIndex.cpp index 4c4466f..ce74c00 100644 --- a/llvm/lib/IR/ModuleSummaryIndex.cpp +++ b/llvm/lib/IR/ModuleSummaryIndex.cpp @@ -13,14 +13,10 @@ //===----------------------------------------------------------------------===// #include "llvm/IR/ModuleSummaryIndex.h" -#include "llvm/ADT/SCCIterator.h" #include "llvm/ADT/StringMap.h" #include "llvm/Support/Path.h" -#include "llvm/Support/raw_ostream.h" using namespace llvm; -FunctionSummary FunctionSummary::ExternalNode = - FunctionSummary::makeDummyFunctionSummary({}); bool ValueInfo::isDSOLocal() const { // Need to check all summaries are local in case of hash collisions. return getSummaryList().size() && @@ -84,26 +80,6 @@ bool ModuleSummaryIndex::isGUIDLive(GlobalValue::GUID GUID) const { return false; } -// TODO: write a graphviz dumper for SCCs (see ModuleSummaryIndex::exportToDot) -// then delete this function and update its tests -LLVM_DUMP_METHOD -void ModuleSummaryIndex::dumpSCCs(raw_ostream &O) { - for (scc_iterator I = - scc_begin(this); - !I.isAtEnd(); ++I) { - O << "SCC (" << utostr(I->size()) << " node" << (I->size() == 1 ? "" : "s") - << ") {\n"; - for (const ValueInfo V : *I) { - FunctionSummary *F = nullptr; - if (V.getSummaryList().size()) - F = cast(V.getSummaryList().front().get()); - O << " " << (F == nullptr ? "External" : "") << " " << utostr(V.getGUID()) - << (I.hasLoop() ? " (has loop)" : "") << "\n"; - } - O << "}\n"; - } -} - namespace { struct Attributes { void add(const Twine &Name, const Twine &Value, diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp index 94baee6..1047b8d 100644 --- a/llvm/lib/LTO/LTO.cpp +++ b/llvm/lib/LTO/LTO.cpp @@ -50,10 +50,6 @@ using namespace object; #define DEBUG_TYPE "lto" -static cl::opt - DumpThinCGSCCs("dump-thin-cg-sccs", cl::init(false), cl::Hidden, - cl::desc("Dump the SCCs in the ThinLTO index's callgraph")); - // The values are (type identifier, summary) pairs. typedef DenseMap< GlobalValue::GUID, @@ -1145,9 +1141,6 @@ Error LTO::runThinLTO(AddStreamFn AddStream, NativeObjectCache Cache) { ThinLTO.ModuleMap.size()); StringMap> ResolvedODR; - if (DumpThinCGSCCs) - ThinLTO.CombinedIndex.dumpSCCs(outs()); - if (Conf.OptLevel > 0) ComputeCrossModuleImport(ThinLTO.CombinedIndex, ModuleToDefinedGVSummaries, ImportLists, ExportLists); diff --git a/llvm/lib/Transforms/IPO/FunctionImport.cpp b/llvm/lib/Transforms/IPO/FunctionImport.cpp index b68058c..b92f798 100644 --- a/llvm/lib/Transforms/IPO/FunctionImport.cpp +++ b/llvm/lib/Transforms/IPO/FunctionImport.cpp @@ -18,8 +18,8 @@ #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/Statistic.h" #include "llvm/ADT/StringMap.h" -#include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringSet.h" +#include "llvm/ADT/StringRef.h" #include "llvm/Bitcode/BitcodeReader.h" #include "llvm/IR/AutoUpgrade.h" #include "llvm/IR/Constants.h" -- 2.7.4