From d0ce61fbb3b09524b5523adfbc39df3c0ecaffab Mon Sep 17 00:00:00 2001 From: Mohamad Barbar Date: Fri, 30 Nov 2018 09:52:22 +1100 Subject: [PATCH] Optimise node retrieval in CHG. --- include/MemoryModel/CHA.h | 1 + lib/MemoryModel/CHA.cpp | 11 ++++------- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/include/MemoryModel/CHA.h b/include/MemoryModel/CHA.h index dcab57c2c..5b69fa027 100644 --- a/include/MemoryModel/CHA.h +++ b/include/MemoryModel/CHA.h @@ -248,6 +248,7 @@ class CHGraph: public GenericCHGraphTy { u32_t classNum; s32_t vfID; double buildingCHGTime; + std::map classNameToNodeMap; NameToCHNodesMap classNameToDescendantsMap; NameToCHNodesMap classNameToAncestorsMap; NameToCHNodesMap classNameToInstAndDescsMap; diff --git a/lib/MemoryModel/CHA.cpp b/lib/MemoryModel/CHA.cpp index e6d6a7d42..9ddd8d93f 100644 --- a/lib/MemoryModel/CHA.cpp +++ b/lib/MemoryModel/CHA.cpp @@ -236,19 +236,16 @@ void CHGraph::addEdge(const string className, const string baseClassName, } CHNode *CHGraph::getNode(const string name) const { - for (CHGraph::const_iterator it = this->begin(), eit = this->end(); - it != eit; ++it) { - CHNode *node = it->second; - if (node->getName() == name) - return node; - } - return NULL; + auto chNode = classNameToNodeMap.find(name); + if (chNode != classNameToNodeMap.end()) return chNode->second; + else return NULL; } CHNode *CHGraph::createNode(const std::string className) { assert(!getNode(className) && "this node should never be created before!"); CHNode * node = new CHNode(className, classNum++); + classNameToNodeMap[className] = node; addGNode(node->getId(), node); if (className.size() > 0 && className[className.size() - 1] == '>') { string templateName = getBeforeBrackets(className);