Skip to content

Commit

Permalink
Merge pull request #18 from mbarbar/optimise
Browse files Browse the repository at this point in the history
Optimise node retrieval in CHG.
  • Loading branch information
yuleisui authored Nov 29, 2018
2 parents 1143333 + d0ce61f commit eb7ff9b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
1 change: 1 addition & 0 deletions include/MemoryModel/CHA.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ class CHGraph: public GenericCHGraphTy {
u32_t classNum;
s32_t vfID;
double buildingCHGTime;
std::map<const std::string, CHNode *> classNameToNodeMap;
NameToCHNodesMap classNameToDescendantsMap;
NameToCHNodesMap classNameToAncestorsMap;
NameToCHNodesMap classNameToInstAndDescsMap;
Expand Down
11 changes: 4 additions & 7 deletions lib/MemoryModel/CHA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit eb7ff9b

Please sign in to comment.