From: Arnaud A. de Grandmaison Date: Thu, 5 Mar 2015 09:12:59 +0000 (+0000) Subject: [PBQP] Use a local bit-matrix to speedup searching an edge in the graph. X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=d1d594bee0b39fd793ebf62153847c17c8475b63;p=oota-llvm.git [PBQP] Use a local bit-matrix to speedup searching an edge in the graph. Build time (user time) for building llvm+clang+lldb in release mode: - default allocator: 9086 seconds - with PBQP: 9126 seconds - with PBQP + local bit matrix cache: 9097 seconds git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@231360 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/RegAllocPBQP.cpp b/lib/CodeGen/RegAllocPBQP.cpp index 54b67abd7df..eeff73d0f2a 100644 --- a/lib/CodeGen/RegAllocPBQP.cpp +++ b/lib/CodeGen/RegAllocPBQP.cpp @@ -181,6 +181,8 @@ private: typedef std::pair IKey; typedef DenseMap IMatrixCache; typedef DenseSet DisjointAllowedRegsCache; + typedef std::pair IEdgeKey; + typedef DenseSet IEdgeCache; bool haveDisjointAllowedRegs(const PBQPRAGraph &G, PBQPRAGraph::NodeId NId, PBQPRAGraph::NodeId MId, @@ -277,6 +279,10 @@ public: // and uniquing them. IMatrixCache C; + // Finding an edge is expensive in the worst case (O(max_clique(G))). So + // cache locally edges we have already seen. + IEdgeCache EC; + // Cache known disjoint allowed registers pairs DisjointAllowedRegsCache D; @@ -329,14 +335,15 @@ public: continue; // Check that we haven't already added this edge - // FIXME: findEdge is expensive in the worst case (O(max_clique(G))). - // It might be better to replace this with a local bit-matrix. - if (G.findEdge(NId, MId) != PBQPRAGraph::invalidEdgeId()) + IEdgeKey EK(std::min(NId, MId), std::max(NId, MId)); + if (EC.count(EK)) continue; // This is a new edge - add it to the graph. if (!createInterferenceEdge(G, NId, MId, C)) setDisjointAllowedRegs(G, NId, MId, D); + else + EC.insert(EK); } // Finally, add Cur to the Active set.