Change DSGraph stuff to use hash_(set|map) instead of std::(set|map)

This change provides a small (3%) but consistent speedup

llvm-svn: 5460
This commit is contained in:
Chris Lattner 2003-02-01 04:52:08 +00:00
parent 6c4005ccfe
commit c44c04af44
13 changed files with 93 additions and 93 deletions

View File

@ -19,7 +19,7 @@ class DSGraph {
DSNodeHandle RetNode; // The node that gets returned... DSNodeHandle RetNode; // The node that gets returned...
std::vector<DSNode*> Nodes; std::vector<DSNode*> Nodes;
std::map<Value*, DSNodeHandle> ScalarMap; hash_map<Value*, DSNodeHandle> ScalarMap;
// FunctionCalls - This vector maintains a single entry for each call // FunctionCalls - This vector maintains a single entry for each call
// instruction in the current graph. The first entry in the vector is the // instruction in the current graph. The first entry in the vector is the
@ -49,7 +49,7 @@ public:
// method. // method.
// //
DSGraph(const DSGraph &DSG); DSGraph(const DSGraph &DSG);
DSGraph(const DSGraph &DSG, std::map<const DSNode*, DSNodeHandle> &NodeMap); DSGraph(const DSGraph &DSG, hash_map<const DSNode*, DSNodeHandle> &NodeMap);
~DSGraph(); ~DSGraph();
bool hasFunction() const { return Func != 0; } bool hasFunction() const { return Func != 0; }
@ -76,8 +76,8 @@ public:
/// getScalarMap - Get a map that describes what the nodes the scalars in this /// getScalarMap - Get a map that describes what the nodes the scalars in this
/// function point to... /// function point to...
/// ///
std::map<Value*, DSNodeHandle> &getScalarMap() { return ScalarMap; } hash_map<Value*, DSNodeHandle> &getScalarMap() { return ScalarMap; }
const std::map<Value*, DSNodeHandle> &getScalarMap() const {return ScalarMap;} const hash_map<Value*, DSNodeHandle> &getScalarMap() const {return ScalarMap;}
/// getFunctionCalls - Return the list of call sites in the original local /// getFunctionCalls - Return the list of call sites in the original local
/// graph... /// graph...
@ -102,7 +102,7 @@ public:
DSNodeHandle &getNodeForValue(Value *V) { return ScalarMap[V]; } DSNodeHandle &getNodeForValue(Value *V) { return ScalarMap[V]; }
const DSNodeHandle &getNodeForValue(Value *V) const { const DSNodeHandle &getNodeForValue(Value *V) const {
std::map<Value*, DSNodeHandle>::const_iterator I = ScalarMap.find(V); hash_map<Value*, DSNodeHandle>::const_iterator I = ScalarMap.find(V);
assert(I != ScalarMap.end() && assert(I != ScalarMap.end() &&
"Use non-const lookup function if node may not be in the map"); "Use non-const lookup function if node may not be in the map");
return I->second; return I->second;
@ -168,8 +168,8 @@ public:
// being cloned. // being cloned.
// //
DSNodeHandle cloneInto(const DSGraph &G, DSNodeHandle cloneInto(const DSGraph &G,
std::map<Value*, DSNodeHandle> &OldValMap, hash_map<Value*, DSNodeHandle> &OldValMap,
std::map<const DSNode*, DSNodeHandle> &OldNodeMap, hash_map<const DSNode*, DSNodeHandle> &OldNodeMap,
unsigned CloneFlags = 0); unsigned CloneFlags = 0);
/// mergeInGraph - The method is used for merging graphs together. If the /// mergeInGraph - The method is used for merging graphs together. If the

View File

@ -218,13 +218,13 @@ public:
/// remapLinks - Change all of the Links in the current node according to the /// remapLinks - Change all of the Links in the current node according to the
/// specified mapping. /// specified mapping.
void remapLinks(std::map<const DSNode*, DSNodeHandle> &OldNodeMap); void remapLinks(hash_map<const DSNode*, DSNodeHandle> &OldNodeMap);
/// markReachableNodes - This method recursively traverses the specified /// markReachableNodes - This method recursively traverses the specified
/// DSNodes, marking any nodes which are reachable. All reachable nodes it /// DSNodes, marking any nodes which are reachable. All reachable nodes it
/// adds to the set, which allows it to only traverse visited nodes once. /// adds to the set, which allows it to only traverse visited nodes once.
/// ///
void markReachableNodes(std::set<DSNode*> &ReachableNodes); void markReachableNodes(hash_set<DSNode*> &ReachableNodes);
private: private:
friend class DSNodeHandle; friend class DSNodeHandle;

View File

@ -8,10 +8,10 @@
#define LLVM_ANALYSIS_DSSUPPORT_H #define LLVM_ANALYSIS_DSSUPPORT_H
#include <vector> #include <vector>
#include <map>
#include <set>
#include <functional> #include <functional>
#include <string> #include <string>
#include "Support/HashExtras.h"
#include "Support/hash_set"
class Function; class Function;
class CallInst; class CallInst;
@ -118,9 +118,9 @@ class DSCallSite {
Function *ResolvingCaller; // See comments above Function *ResolvingCaller; // See comments above
static void InitNH(DSNodeHandle &NH, const DSNodeHandle &Src, static void InitNH(DSNodeHandle &NH, const DSNodeHandle &Src,
const std::map<const DSNode*, DSNode*> &NodeMap) { const hash_map<const DSNode*, DSNode*> &NodeMap) {
if (DSNode *N = Src.getNode()) { if (DSNode *N = Src.getNode()) {
std::map<const DSNode*, DSNode*>::const_iterator I = NodeMap.find(N); hash_map<const DSNode*, DSNode*>::const_iterator I = NodeMap.find(N);
assert(I != NodeMap.end() && "Not not in mapping!"); assert(I != NodeMap.end() && "Not not in mapping!");
NH.setOffset(Src.getOffset()); NH.setOffset(Src.getOffset());
@ -129,9 +129,9 @@ class DSCallSite {
} }
static void InitNH(DSNodeHandle &NH, const DSNodeHandle &Src, static void InitNH(DSNodeHandle &NH, const DSNodeHandle &Src,
const std::map<const DSNode*, DSNodeHandle> &NodeMap) { const hash_map<const DSNode*, DSNodeHandle> &NodeMap) {
if (DSNode *N = Src.getNode()) { if (DSNode *N = Src.getNode()) {
std::map<const DSNode*, DSNodeHandle>::const_iterator I = NodeMap.find(N); hash_map<const DSNode*, DSNodeHandle>::const_iterator I = NodeMap.find(N);
assert(I != NodeMap.end() && "Not not in mapping!"); assert(I != NodeMap.end() && "Not not in mapping!");
NH.setOffset(Src.getOffset()+I->second.getOffset()); NH.setOffset(Src.getOffset()+I->second.getOffset());
@ -219,7 +219,7 @@ public:
/// DSNodes, marking any nodes which are reachable. All reachable nodes it /// DSNodes, marking any nodes which are reachable. All reachable nodes it
/// adds to the set, which allows it to only traverse visited nodes once. /// adds to the set, which allows it to only traverse visited nodes once.
/// ///
void markReachableNodes(std::set<DSNode*> &Nodes); void markReachableNodes(hash_set<DSNode*> &Nodes);
bool operator<(const DSCallSite &CS) const { bool operator<(const DSCallSite &CS) const {
if (Callee < CS.Callee) return true; // This must sort by callee first! if (Callee < CS.Callee) return true; // This must sort by callee first!

View File

@ -8,7 +8,8 @@
#define LLVM_ANALYSIS_DATA_STRUCTURE_H #define LLVM_ANALYSIS_DATA_STRUCTURE_H
#include "llvm/Pass.h" #include "llvm/Pass.h"
#include <set> #include "Support/HashExtras.h"
#include "Support/hash_set"
class Type; class Type;
class DSGraph; class DSGraph;
@ -32,7 +33,7 @@ namespace DataStructureAnalysis {
// //
class LocalDataStructures : public Pass { class LocalDataStructures : public Pass {
// DSInfo, one graph for each function // DSInfo, one graph for each function
std::map<const Function*, DSGraph*> DSInfo; hash_map<const Function*, DSGraph*> DSInfo;
DSGraph *GlobalsGraph; DSGraph *GlobalsGraph;
public: public:
~LocalDataStructures() { releaseMemory(); } ~LocalDataStructures() { releaseMemory(); }
@ -45,7 +46,7 @@ public:
// getDSGraph - Return the data structure graph for the specified function. // getDSGraph - Return the data structure graph for the specified function.
DSGraph &getDSGraph(const Function &F) const { DSGraph &getDSGraph(const Function &F) const {
std::map<const Function*, DSGraph*>::const_iterator I = DSInfo.find(&F); hash_map<const Function*, DSGraph*>::const_iterator I = DSInfo.find(&F);
assert(I != DSInfo.end() && "Function not in module!"); assert(I != DSInfo.end() && "Function not in module!");
return *I->second; return *I->second;
} }
@ -71,7 +72,7 @@ public:
// //
class BUDataStructures : public Pass { class BUDataStructures : public Pass {
// DSInfo, one graph for each function // DSInfo, one graph for each function
std::map<const Function*, DSGraph*> DSInfo; hash_map<const Function*, DSGraph*> DSInfo;
DSGraph *GlobalsGraph; DSGraph *GlobalsGraph;
public: public:
~BUDataStructures() { releaseMemory(); } ~BUDataStructures() { releaseMemory(); }
@ -84,7 +85,7 @@ public:
// getDSGraph - Return the data structure graph for the specified function. // getDSGraph - Return the data structure graph for the specified function.
DSGraph &getDSGraph(const Function &F) const { DSGraph &getDSGraph(const Function &F) const {
std::map<const Function*, DSGraph*>::const_iterator I = DSInfo.find(&F); hash_map<const Function*, DSGraph*>::const_iterator I = DSInfo.find(&F);
assert(I != DSInfo.end() && "Function not in module!"); assert(I != DSInfo.end() && "Function not in module!");
return *I->second; return *I->second;
} }
@ -110,10 +111,10 @@ private:
// functions IN the SCC at all. // functions IN the SCC at all.
// //
DSGraph &inlineNonSCCGraphs(Function &F, DSGraph &inlineNonSCCGraphs(Function &F,
std::set<Function*> &SCCFunctions); hash_set<Function*> &SCCFunctions);
DSGraph &calculateSCCGraph(Function &F, DSGraph &calculateSCCGraph(Function &F,
std::set<Function*> &InlinedSCCFunctions); hash_set<Function*> &InlinedSCCFunctions);
void calculateReachableGraphs(Function *F); void calculateReachableGraphs(Function *F);
@ -121,7 +122,7 @@ private:
unsigned calculateGraphs(Function *F, std::vector<Function*> &Stack, unsigned calculateGraphs(Function *F, std::vector<Function*> &Stack,
unsigned &NextID, unsigned &NextID,
std::map<Function*, unsigned> &ValMap); hash_map<Function*, unsigned> &ValMap);
}; };
@ -131,8 +132,8 @@ private:
// //
class TDDataStructures : public Pass { class TDDataStructures : public Pass {
// DSInfo, one graph for each function // DSInfo, one graph for each function
std::map<const Function*, DSGraph*> DSInfo; hash_map<const Function*, DSGraph*> DSInfo;
std::set<const Function*> GraphDone; hash_set<const Function*> GraphDone;
DSGraph *GlobalsGraph; DSGraph *GlobalsGraph;
public: public:
~TDDataStructures() { releaseMemory(); } ~TDDataStructures() { releaseMemory(); }
@ -145,7 +146,7 @@ public:
// getDSGraph - Return the data structure graph for the specified function. // getDSGraph - Return the data structure graph for the specified function.
DSGraph &getDSGraph(const Function &F) const { DSGraph &getDSGraph(const Function &F) const {
std::map<const Function*, DSGraph*>::const_iterator I = DSInfo.find(&F); hash_map<const Function*, DSGraph*>::const_iterator I = DSInfo.find(&F);
assert(I != DSInfo.end() && "Function not in module!"); assert(I != DSInfo.end() && "Function not in module!");
return *I->second; return *I->second;
} }

View File

@ -41,6 +41,7 @@
#include "llvm/Pass.h" #include "llvm/Pass.h"
#include "Support/BitSetVector.h" #include "Support/BitSetVector.h"
#include "Support/hash_map"
class Module; class Module;
class Function; class Function;
@ -125,7 +126,7 @@ class FunctionModRefInfo {
void computeModRef (const Function &func); void computeModRef (const Function &func);
void computeModRef (const CallInst& callInst); void computeModRef (const CallInst& callInst);
DSGraph *ResolveCallSiteModRefInfo(CallInst &CI, DSGraph *ResolveCallSiteModRefInfo(CallInst &CI,
std::map<const DSNode*, DSNodeHandle> &NodeMap); hash_map<const DSNode*, DSNodeHandle> &NodeMap);
public: public:
/* ctor */ FunctionModRefInfo (const Function& func, /* ctor */ FunctionModRefInfo (const Function& func,

View File

@ -11,6 +11,7 @@
#include "llvm/Analysis/DSGraph.h" #include "llvm/Analysis/DSGraph.h"
#include "llvm/Module.h" #include "llvm/Module.h"
#include "Support/Statistic.h" #include "Support/Statistic.h"
#include "Support/hash_map"
namespace { namespace {
Statistic<> MaxSCC("budatastructure", "Maximum SCC Size in Call Graph"); Statistic<> MaxSCC("budatastructure", "Maximum SCC Size in Call Graph");
@ -128,7 +129,7 @@ bool BUDataStructures::run(Module &M) {
void BUDataStructures::calculateReachableGraphs(Function *F) { void BUDataStructures::calculateReachableGraphs(Function *F) {
std::vector<Function*> Stack; std::vector<Function*> Stack;
std::map<Function*, unsigned> ValMap; hash_map<Function*, unsigned> ValMap;
unsigned NextID = 1; unsigned NextID = 1;
calculateGraphs(F, Stack, NextID, ValMap); calculateGraphs(F, Stack, NextID, ValMap);
} }
@ -152,7 +153,7 @@ DSGraph &BUDataStructures::getOrCreateGraph(Function *F) {
unsigned BUDataStructures::calculateGraphs(Function *F, unsigned BUDataStructures::calculateGraphs(Function *F,
std::vector<Function*> &Stack, std::vector<Function*> &Stack,
unsigned &NextID, unsigned &NextID,
std::map<Function*, unsigned> &ValMap) { hash_map<Function*, unsigned> &ValMap) {
assert(ValMap.find(F) == ValMap.end() && "Shouldn't revisit functions!"); assert(ValMap.find(F) == ValMap.end() && "Shouldn't revisit functions!");
unsigned Min = NextID++, MyID = Min; unsigned Min = NextID++, MyID = Min;
ValMap[F] = Min; ValMap[F] = Min;
@ -173,7 +174,7 @@ unsigned BUDataStructures::calculateGraphs(Function *F,
Function *Callee = *I; Function *Callee = *I;
unsigned M; unsigned M;
// Have we visited the destination function yet? // Have we visited the destination function yet?
std::map<Function*, unsigned>::iterator It = ValMap.find(Callee); hash_map<Function*, unsigned>::iterator It = ValMap.find(Callee);
if (It == ValMap.end()) // No, visit it now. if (It == ValMap.end()) // No, visit it now.
M = calculateGraphs(Callee, Stack, NextID, ValMap); M = calculateGraphs(Callee, Stack, NextID, ValMap);
else // Yes, get it's number. else // Yes, get it's number.
@ -206,7 +207,7 @@ unsigned BUDataStructures::calculateGraphs(Function *F,
} else { } else {
// SCCFunctions - Keep track of the functions in the current SCC // SCCFunctions - Keep track of the functions in the current SCC
// //
std::set<Function*> SCCFunctions; hash_set<Function*> SCCFunctions;
Function *NF; Function *NF;
std::vector<Function*>::iterator FirstInSCC = Stack.end(); std::vector<Function*>::iterator FirstInSCC = Stack.end();
@ -283,7 +284,7 @@ unsigned BUDataStructures::calculateGraphs(Function *F,
// our memory... here... // our memory... here...
// //
void BUDataStructures::releaseMemory() { void BUDataStructures::releaseMemory() {
for (std::map<const Function*, DSGraph*>::iterator I = DSInfo.begin(), for (hash_map<const Function*, DSGraph*>::iterator I = DSInfo.begin(),
E = DSInfo.end(); I != E; ++I) E = DSInfo.end(); I != E; ++I)
delete I->second; delete I->second;
@ -383,7 +384,7 @@ DSGraph &BUDataStructures::calculateGraph(Function &F) {
// IN the SCC at all. // IN the SCC at all.
// //
DSGraph &BUDataStructures::inlineNonSCCGraphs(Function &F, DSGraph &BUDataStructures::inlineNonSCCGraphs(Function &F,
std::set<Function*> &SCCFunctions){ hash_set<Function*> &SCCFunctions){
DSGraph &Graph = getDSGraph(F); DSGraph &Graph = getDSGraph(F);
DEBUG(std::cerr << " [BU] Inlining Non-SCC graphs for: " DEBUG(std::cerr << " [BU] Inlining Non-SCC graphs for: "
<< F.getName() << "\n"); << F.getName() << "\n");
@ -452,12 +453,12 @@ DSGraph &BUDataStructures::inlineNonSCCGraphs(Function &F,
DSGraph &BUDataStructures::calculateSCCGraph(Function &F, DSGraph &BUDataStructures::calculateSCCGraph(Function &F,
std::set<Function*> &SCCFunctions){ hash_set<Function*> &SCCFunctions){
DSGraph &Graph = getDSGraph(F); DSGraph &Graph = getDSGraph(F);
DEBUG(std::cerr << " [BU] Calculating SCC graph for: " << F.getName()<<"\n"); DEBUG(std::cerr << " [BU] Calculating SCC graph for: " << F.getName()<<"\n");
std::vector<DSCallSite> UnresolvableCalls; std::vector<DSCallSite> UnresolvableCalls;
std::map<Function*, DSCallSite> SCCCallSiteMap; hash_map<Function*, DSCallSite> SCCCallSiteMap;
std::vector<DSCallSite> &AuxCallsList = Graph.getAuxFunctionCalls(); std::vector<DSCallSite> &AuxCallsList = Graph.getAuxFunctionCalls();
while (1) { // Loop until we run out of resolvable call sites! while (1) { // Loop until we run out of resolvable call sites!

View File

@ -540,12 +540,12 @@ Function &DSCallSite::getCaller() const {
DSGraph::DSGraph(const DSGraph &G) : Func(G.Func), GlobalsGraph(0) { DSGraph::DSGraph(const DSGraph &G) : Func(G.Func), GlobalsGraph(0) {
PrintAuxCalls = false; PrintAuxCalls = false;
std::map<const DSNode*, DSNodeHandle> NodeMap; hash_map<const DSNode*, DSNodeHandle> NodeMap;
RetNode = cloneInto(G, ScalarMap, NodeMap); RetNode = cloneInto(G, ScalarMap, NodeMap);
} }
DSGraph::DSGraph(const DSGraph &G, DSGraph::DSGraph(const DSGraph &G,
std::map<const DSNode*, DSNodeHandle> &NodeMap) hash_map<const DSNode*, DSNodeHandle> &NodeMap)
: Func(G.Func), GlobalsGraph(0) { : Func(G.Func), GlobalsGraph(0) {
PrintAuxCalls = false; PrintAuxCalls = false;
RetNode = cloneInto(G, ScalarMap, NodeMap); RetNode = cloneInto(G, ScalarMap, NodeMap);
@ -572,7 +572,7 @@ void DSGraph::dump() const { print(std::cerr); }
/// remapLinks - Change all of the Links in the current node according to the /// remapLinks - Change all of the Links in the current node according to the
/// specified mapping. /// specified mapping.
/// ///
void DSNode::remapLinks(std::map<const DSNode*, DSNodeHandle> &OldNodeMap) { void DSNode::remapLinks(hash_map<const DSNode*, DSNodeHandle> &OldNodeMap) {
for (unsigned i = 0, e = Links.size(); i != e; ++i) { for (unsigned i = 0, e = Links.size(); i != e; ++i) {
DSNodeHandle &H = OldNodeMap[Links[i].getNode()]; DSNodeHandle &H = OldNodeMap[Links[i].getNode()];
Links[i].setNode(H.getNode()); Links[i].setNode(H.getNode());
@ -588,8 +588,8 @@ void DSNode::remapLinks(std::map<const DSNode*, DSNodeHandle> &OldNodeMap) {
// calling function's graph. // calling function's graph.
// //
DSNodeHandle DSGraph::cloneInto(const DSGraph &G, DSNodeHandle DSGraph::cloneInto(const DSGraph &G,
std::map<Value*, DSNodeHandle> &OldValMap, hash_map<Value*, DSNodeHandle> &OldValMap,
std::map<const DSNode*, DSNodeHandle> &OldNodeMap, hash_map<const DSNode*, DSNodeHandle> &OldNodeMap,
unsigned CloneFlags) { unsigned CloneFlags) {
assert(OldNodeMap.empty() && "Returned OldNodeMap should be empty!"); assert(OldNodeMap.empty() && "Returned OldNodeMap should be empty!");
assert(&G != this && "Cannot clone graph into itself!"); assert(&G != this && "Cannot clone graph into itself!");
@ -625,7 +625,7 @@ DSNodeHandle DSGraph::cloneInto(const DSGraph &G,
} }
// Copy the value map... and merge all of the global nodes... // Copy the value map... and merge all of the global nodes...
for (std::map<Value*, DSNodeHandle>::const_iterator I = G.ScalarMap.begin(), for (hash_map<Value*, DSNodeHandle>::const_iterator I = G.ScalarMap.begin(),
E = G.ScalarMap.end(); I != E; ++I) { E = G.ScalarMap.end(); I != E; ++I) {
DSNodeHandle &H = OldValMap[I->first]; DSNodeHandle &H = OldValMap[I->first];
DSNodeHandle &MappedNode = OldNodeMap[I->second.getNode()]; DSNodeHandle &MappedNode = OldNodeMap[I->second.getNode()];
@ -633,7 +633,7 @@ DSNodeHandle DSGraph::cloneInto(const DSGraph &G,
H.setOffset(I->second.getOffset()+MappedNode.getOffset()); H.setOffset(I->second.getOffset()+MappedNode.getOffset());
if (isa<GlobalValue>(I->first)) { // Is this a global? if (isa<GlobalValue>(I->first)) { // Is this a global?
std::map<Value*, DSNodeHandle>::iterator GVI = ScalarMap.find(I->first); hash_map<Value*, DSNodeHandle>::iterator GVI = ScalarMap.find(I->first);
if (GVI != ScalarMap.end()) { // Is the global value in this fn already? if (GVI != ScalarMap.end()) { // Is the global value in this fn already?
GVI->second.mergeWith(H); GVI->second.mergeWith(H);
} else { } else {
@ -671,16 +671,16 @@ DSNodeHandle DSGraph::cloneInto(const DSGraph &G,
/// ///
void DSGraph::mergeInGraph(DSCallSite &CS, const DSGraph &Graph, void DSGraph::mergeInGraph(DSCallSite &CS, const DSGraph &Graph,
unsigned CloneFlags) { unsigned CloneFlags) {
std::map<Value*, DSNodeHandle> OldValMap; hash_map<Value*, DSNodeHandle> OldValMap;
DSNodeHandle RetVal; DSNodeHandle RetVal;
std::map<Value*, DSNodeHandle> *ScalarMap = &OldValMap; hash_map<Value*, DSNodeHandle> *ScalarMap = &OldValMap;
// If this is not a recursive call, clone the graph into this graph... // If this is not a recursive call, clone the graph into this graph...
if (&Graph != this) { if (&Graph != this) {
// Clone the callee's graph into the current graph, keeping // Clone the callee's graph into the current graph, keeping
// track of where scalars in the old graph _used_ to point, // track of where scalars in the old graph _used_ to point,
// and of the new nodes matching nodes of the old graph. // and of the new nodes matching nodes of the old graph.
std::map<const DSNode*, DSNodeHandle> OldNodeMap; hash_map<const DSNode*, DSNodeHandle> OldNodeMap;
// The clone call may invalidate any of the vectors in the data // The clone call may invalidate any of the vectors in the data
// structure graph. Strip locals and don't copy the list of callers // structure graph. Strip locals and don't copy the list of callers
@ -811,7 +811,7 @@ void DSGraph::markIncompleteNodes(unsigned Flags) {
// removeRefsToGlobal - Helper function that removes globals from the // removeRefsToGlobal - Helper function that removes globals from the
// ScalarMap so that the referrer count will go down to zero. // ScalarMap so that the referrer count will go down to zero.
static void removeRefsToGlobal(DSNode* N, static void removeRefsToGlobal(DSNode* N,
std::map<Value*, DSNodeHandle> &ScalarMap) { hash_map<Value*, DSNodeHandle> &ScalarMap) {
while (!N->getGlobals().empty()) { while (!N->getGlobals().empty()) {
GlobalValue *GV = N->getGlobals().back(); GlobalValue *GV = N->getGlobals().back();
N->getGlobals().pop_back(); N->getGlobals().pop_back();
@ -939,18 +939,16 @@ void DSGraph::removeTriviallyDeadNodes() {
/// DSNodes, marking any nodes which are reachable. All reachable nodes it adds /// DSNodes, marking any nodes which are reachable. All reachable nodes it adds
/// to the set, which allows it to only traverse visited nodes once. /// to the set, which allows it to only traverse visited nodes once.
/// ///
void DSNode::markReachableNodes(std::set<DSNode*> &ReachableNodes) { void DSNode::markReachableNodes(hash_set<DSNode*> &ReachableNodes) {
if (this == 0) return; if (this == 0) return;
std::set<DSNode*>::iterator I = ReachableNodes.lower_bound(this); if (ReachableNodes.count(this)) return; // Already marked reachable
if (I != ReachableNodes.end() && *I == this) ReachableNodes.insert(this); // Is reachable now
return; // Already marked reachable
ReachableNodes.insert(I, this); // Is reachable now
for (unsigned i = 0, e = getSize(); i < e; i += DS::PointerSize) for (unsigned i = 0, e = getSize(); i < e; i += DS::PointerSize)
getLink(i).getNode()->markReachableNodes(ReachableNodes); getLink(i).getNode()->markReachableNodes(ReachableNodes);
} }
void DSCallSite::markReachableNodes(std::set<DSNode*> &Nodes) { void DSCallSite::markReachableNodes(hash_set<DSNode*> &Nodes) {
getRetVal().getNode()->markReachableNodes(Nodes); getRetVal().getNode()->markReachableNodes(Nodes);
getCallee().getNode()->markReachableNodes(Nodes); getCallee().getNode()->markReachableNodes(Nodes);
@ -965,8 +963,8 @@ void DSCallSite::markReachableNodes(std::set<DSNode*> &Nodes) {
// //
// This function returns true if the specified node is alive. // This function returns true if the specified node is alive.
// //
static bool markAliveIfCanReachAlive(DSNode *N, std::set<DSNode*> &Alive, static bool markAliveIfCanReachAlive(DSNode *N, hash_set<DSNode*> &Alive,
std::set<DSNode*> &Visited) { hash_set<DSNode*> &Visited) {
if (N == 0) return false; if (N == 0) return false;
// If we know that this node is alive, return so! // If we know that this node is alive, return so!
@ -974,10 +972,9 @@ static bool markAliveIfCanReachAlive(DSNode *N, std::set<DSNode*> &Alive,
// Otherwise, we don't think the node is alive yet, check for infinite // Otherwise, we don't think the node is alive yet, check for infinite
// recursion. // recursion.
std::set<DSNode*>::iterator VI = Visited.lower_bound(N); if (Visited.count(N)) return false; // Found a cycle
if (VI != Visited.end() && *VI == N) return false; // Found a cycle
// No recursion, insert into Visited... // No recursion, insert into Visited...
Visited.insert(VI, N); Visited.insert(N);
if (N->NodeType & DSNode::GlobalNode) if (N->NodeType & DSNode::GlobalNode)
return false; // Global nodes will be marked on their own return false; // Global nodes will be marked on their own
@ -992,8 +989,8 @@ static bool markAliveIfCanReachAlive(DSNode *N, std::set<DSNode*> &Alive,
return ChildrenAreAlive; return ChildrenAreAlive;
} }
static bool CallSiteUsesAliveArgs(DSCallSite &CS, std::set<DSNode*> &Alive, static bool CallSiteUsesAliveArgs(DSCallSite &CS, hash_set<DSNode*> &Alive,
std::set<DSNode*> &Visited) { hash_set<DSNode*> &Visited) {
if (markAliveIfCanReachAlive(CS.getRetVal().getNode(), Alive, Visited) || if (markAliveIfCanReachAlive(CS.getRetVal().getNode(), Alive, Visited) ||
markAliveIfCanReachAlive(CS.getCallee().getNode(), Alive, Visited)) markAliveIfCanReachAlive(CS.getCallee().getNode(), Alive, Visited))
return true; return true;
@ -1034,11 +1031,11 @@ void DSGraph::removeDeadNodes(unsigned Flags) {
// FIXME: Merge nontrivially identical call nodes... // FIXME: Merge nontrivially identical call nodes...
// Alive - a set that holds all nodes found to be reachable/alive. // Alive - a set that holds all nodes found to be reachable/alive.
std::set<DSNode*> Alive; hash_set<DSNode*> Alive;
std::vector<std::pair<Value*, DSNode*> > GlobalNodes; std::vector<std::pair<Value*, DSNode*> > GlobalNodes;
// Mark all nodes reachable by (non-global) scalar nodes as alive... // Mark all nodes reachable by (non-global) scalar nodes as alive...
for (std::map<Value*, DSNodeHandle>::iterator I = ScalarMap.begin(), for (hash_map<Value*, DSNodeHandle>::iterator I = ScalarMap.begin(),
E = ScalarMap.end(); I != E; ++I) E = ScalarMap.end(); I != E; ++I)
if (!isa<GlobalValue>(I->first) || if (!isa<GlobalValue>(I->first) ||
GlobalIsAlivenessRoot(I->second.getNode(), Flags)) GlobalIsAlivenessRoot(I->second.getNode(), Flags))
@ -1052,7 +1049,7 @@ void DSGraph::removeDeadNodes(unsigned Flags) {
// If any global nodes points to a non-global that is "alive", the global is // If any global nodes points to a non-global that is "alive", the global is
// "alive" as well... // "alive" as well...
// //
std::set<DSNode*> Visited; hash_set<DSNode*> Visited;
for (unsigned i = 0, e = GlobalNodes.size(); i != e; ++i) for (unsigned i = 0, e = GlobalNodes.size(); i != e; ++i)
markAliveIfCanReachAlive(GlobalNodes[i].second, Alive, Visited); markAliveIfCanReachAlive(GlobalNodes[i].second, Alive, Visited);
@ -1129,7 +1126,7 @@ static const char ExternalTypeBits = DSNode::GlobalNode | DSNode::HeapNode;
// This is a helper function for cloneGlobals and cloneCalls. // This is a helper function for cloneGlobals and cloneCalls.
// //
DSNode* GlobalDSGraph::cloneNodeInto(DSNode *OldNode, DSNode* GlobalDSGraph::cloneNodeInto(DSNode *OldNode,
std::map<const DSNode*, DSNode*> &NodeCache, hash_map<const DSNode*, DSNode*> &NodeCache,
bool GlobalsAreFinal) { bool GlobalsAreFinal) {
if (OldNode == 0) return 0; if (OldNode == 0) return 0;
@ -1208,7 +1205,7 @@ DSNode* GlobalDSGraph::cloneNodeInto(DSNode *OldNode,
// links (and recursively their such links) into this graph. // links (and recursively their such links) into this graph.
// //
void GlobalDSGraph::cloneCalls(DSGraph& Graph) { void GlobalDSGraph::cloneCalls(DSGraph& Graph) {
std::map<const DSNode*, DSNode*> NodeCache; hash_map<const DSNode*, DSNode*> NodeCache;
std::vector<DSCallSite >& FromCalls =Graph.FunctionCalls; std::vector<DSCallSite >& FromCalls =Graph.FunctionCalls;
FunctionCalls.reserve(FunctionCalls.size() + FromCalls.size()); FunctionCalls.reserve(FunctionCalls.size() + FromCalls.size());

View File

@ -56,12 +56,12 @@ namespace {
DSGraph &G; DSGraph &G;
std::vector<DSNode*> &Nodes; std::vector<DSNode*> &Nodes;
DSNodeHandle &RetNode; // Node that gets returned... DSNodeHandle &RetNode; // Node that gets returned...
std::map<Value*, DSNodeHandle> &ScalarMap; hash_map<Value*, DSNodeHandle> &ScalarMap;
std::vector<DSCallSite> &FunctionCalls; std::vector<DSCallSite> &FunctionCalls;
public: public:
GraphBuilder(DSGraph &g, std::vector<DSNode*> &nodes, DSNodeHandle &retNode, GraphBuilder(DSGraph &g, std::vector<DSNode*> &nodes, DSNodeHandle &retNode,
std::map<Value*, DSNodeHandle> &SM, hash_map<Value*, DSNodeHandle> &SM,
std::vector<DSCallSite> &fc) std::vector<DSCallSite> &fc)
: G(g), Nodes(nodes), RetNode(retNode), ScalarMap(SM), FunctionCalls(fc) { : G(g), Nodes(nodes), RetNode(retNode), ScalarMap(SM), FunctionCalls(fc) {
@ -166,7 +166,7 @@ DSNodeHandle GraphBuilder::getValueDest(Value &Val) {
return NH = getValueDest(*CE->getOperand(0)); return NH = getValueDest(*CE->getOperand(0));
if (CE->getOpcode() == Instruction::GetElementPtr) { if (CE->getOpcode() == Instruction::GetElementPtr) {
visitGetElementPtrInst(*CE); visitGetElementPtrInst(*CE);
std::map<Value*, DSNodeHandle>::iterator I = ScalarMap.find(CE); hash_map<Value*, DSNodeHandle>::iterator I = ScalarMap.find(CE);
assert(I != ScalarMap.end() && "GEP didn't get processed right?"); assert(I != ScalarMap.end() && "GEP didn't get processed right?");
return NH = I->second; return NH = I->second;
} }
@ -431,7 +431,7 @@ bool LocalDataStructures::run(Module &M) {
// our memory... here... // our memory... here...
// //
void LocalDataStructures::releaseMemory() { void LocalDataStructures::releaseMemory() {
for (std::map<const Function*, DSGraph*>::iterator I = DSInfo.begin(), for (hash_map<const Function*, DSGraph*>::iterator I = DSInfo.begin(),
E = DSInfo.end(); I != E; ++I) E = DSInfo.end(); I != E; ++I)
delete I->second; delete I->second;

View File

@ -87,8 +87,8 @@ struct DOTGraphTraits<const DSGraph*> : public DefaultDOTGraphTraits {
static void addCustomGraphFeatures(const DSGraph *G, static void addCustomGraphFeatures(const DSGraph *G,
GraphWriter<const DSGraph*> &GW) { GraphWriter<const DSGraph*> &GW) {
// Add scalar nodes to the graph... // Add scalar nodes to the graph...
const std::map<Value*, DSNodeHandle> &VM = G->getScalarMap(); const hash_map<Value*, DSNodeHandle> &VM = G->getScalarMap();
for (std::map<Value*, DSNodeHandle>::const_iterator I = VM.begin(); for (hash_map<Value*, DSNodeHandle>::const_iterator I = VM.begin();
I != VM.end(); ++I) I != VM.end(); ++I)
if (!isa<GlobalValue>(I->first)) { if (!isa<GlobalValue>(I->first)) {
std::stringstream OS; std::stringstream OS;

View File

@ -89,7 +89,7 @@ void Steens::ResolveFunctionCall(Function *F,
const DSCallSite &Call, const DSCallSite &Call,
DSNodeHandle &RetVal) { DSNodeHandle &RetVal) {
assert(ResultGraph != 0 && "Result graph not allocated!"); assert(ResultGraph != 0 && "Result graph not allocated!");
std::map<Value*, DSNodeHandle> &ValMap = ResultGraph->getScalarMap(); hash_map<Value*, DSNodeHandle> &ValMap = ResultGraph->getScalarMap();
// Handle the return value of the function... // Handle the return value of the function...
if (Call.getRetVal().getNode() && RetVal.getNode()) if (Call.getRetVal().getNode() && RetVal.getNode())
@ -98,7 +98,7 @@ void Steens::ResolveFunctionCall(Function *F,
// Loop over all pointer arguments, resolving them to their provided pointers // Loop over all pointer arguments, resolving them to their provided pointers
unsigned PtrArgIdx = 0; unsigned PtrArgIdx = 0;
for (Function::aiterator AI = F->abegin(), AE = F->aend(); AI != AE; ++AI) { for (Function::aiterator AI = F->abegin(), AE = F->aend(); AI != AE; ++AI) {
std::map<Value*, DSNodeHandle>::iterator I = ValMap.find(AI); hash_map<Value*, DSNodeHandle>::iterator I = ValMap.find(AI);
if (I != ValMap.end()) // If its a pointer argument... if (I != ValMap.end()) // If its a pointer argument...
I->second.addEdgeTo(Call.getPtrArg(PtrArgIdx++)); I->second.addEdgeTo(Call.getPtrArg(PtrArgIdx++));
} }
@ -120,16 +120,16 @@ bool Steens::run(Module &M) {
// RetValMap - Keep track of the return values for all functions that return // RetValMap - Keep track of the return values for all functions that return
// valid pointers. // valid pointers.
// //
std::map<Function*, DSNodeHandle> RetValMap; hash_map<Function*, DSNodeHandle> RetValMap;
// Loop over the rest of the module, merging graphs for non-external functions // Loop over the rest of the module, merging graphs for non-external functions
// into this graph. // into this graph.
// //
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
if (!I->isExternal()) { if (!I->isExternal()) {
std::map<Value*, DSNodeHandle> ValMap; hash_map<Value*, DSNodeHandle> ValMap;
{ // Scope to free NodeMap memory ASAP { // Scope to free NodeMap memory ASAP
std::map<const DSNode*, DSNodeHandle> NodeMap; hash_map<const DSNode*, DSNodeHandle> NodeMap;
const DSGraph &FDSG = LDS.getDSGraph(*I); const DSGraph &FDSG = LDS.getDSGraph(*I);
DSNodeHandle RetNode = ResultGraph->cloneInto(FDSG, ValMap, NodeMap); DSNodeHandle RetNode = ResultGraph->cloneInto(FDSG, ValMap, NodeMap);
@ -142,11 +142,11 @@ bool Steens::run(Module &M) {
// Incorporate the inlined Function's ScalarMap into the global // Incorporate the inlined Function's ScalarMap into the global
// ScalarMap... // ScalarMap...
std::map<Value*, DSNodeHandle> &GVM = ResultGraph->getScalarMap(); hash_map<Value*, DSNodeHandle> &GVM = ResultGraph->getScalarMap();
while (!ValMap.empty()) { // Loop over value map, moving entries over... while (!ValMap.empty()) { // Loop over value map, moving entries over...
const std::pair<Value*, DSNodeHandle> &DSN = *ValMap.begin(); const std::pair<Value*, DSNodeHandle> &DSN = *ValMap.begin();
std::map<Value*, DSNodeHandle>::iterator I = GVM.find(DSN.first); hash_map<Value*, DSNodeHandle>::iterator I = GVM.find(DSN.first);
if (I == GVM.end()) if (I == GVM.end())
GVM[DSN.first] = DSN.second; GVM[DSN.first] = DSN.second;
else else
@ -209,12 +209,12 @@ bool Steens::run(Module &M) {
AliasAnalysis::Result Steens::alias(const Value *V1, const Value *V2) { AliasAnalysis::Result Steens::alias(const Value *V1, const Value *V2) {
assert(ResultGraph && "Result graph has not been computed yet!"); assert(ResultGraph && "Result graph has not been computed yet!");
std::map<Value*, DSNodeHandle> &GVM = ResultGraph->getScalarMap(); hash_map<Value*, DSNodeHandle> &GVM = ResultGraph->getScalarMap();
std::map<Value*, DSNodeHandle>::iterator I = GVM.find(const_cast<Value*>(V1)); hash_map<Value*, DSNodeHandle>::iterator I = GVM.find(const_cast<Value*>(V1));
if (I != GVM.end() && I->second.getNode()) { if (I != GVM.end() && I->second.getNode()) {
DSNodeHandle &V1H = I->second; DSNodeHandle &V1H = I->second;
std::map<Value*, DSNodeHandle>::iterator J=GVM.find(const_cast<Value*>(V2)); hash_map<Value*, DSNodeHandle>::iterator J=GVM.find(const_cast<Value*>(V2));
if (J != GVM.end() && J->second.getNode()) { if (J != GVM.end() && J->second.getNode()) {
DSNodeHandle &V2H = J->second; DSNodeHandle &V2H = J->second;
// If the two pointers point to different data structure graph nodes, they // If the two pointers point to different data structure graph nodes, they

View File

@ -40,7 +40,7 @@ bool TDDataStructures::run(Module &M) {
// our memory... here... // our memory... here...
// //
void TDDataStructures::releaseMemory() { void TDDataStructures::releaseMemory() {
for (std::map<const Function*, DSGraph*>::iterator I = DSInfo.begin(), for (hash_map<const Function*, DSGraph*>::iterator I = DSInfo.begin(),
E = DSInfo.end(); I != E; ++I) E = DSInfo.end(); I != E; ++I)
delete I->second; delete I->second;
@ -140,8 +140,8 @@ void TDDataStructures::calculateGraph(Function &F) {
<< "'\n"); << "'\n");
// Clone our current graph into the callee... // Clone our current graph into the callee...
std::map<Value*, DSNodeHandle> OldValMap; hash_map<Value*, DSNodeHandle> OldValMap;
std::map<const DSNode*, DSNodeHandle> OldNodeMap; hash_map<const DSNode*, DSNodeHandle> OldNodeMap;
CG.cloneInto(Graph, OldValMap, OldNodeMap, CG.cloneInto(Graph, OldValMap, OldNodeMap,
DSGraph::StripModRefBits | DSGraph::StripModRefBits |
DSGraph::KeepAllocaBit | DSGraph::DontCloneCallNodes); DSGraph::KeepAllocaBit | DSGraph::DontCloneCallNodes);

View File

@ -118,7 +118,7 @@ void FunctionModRefInfo::computeModRef(const Function &func)
// function or we cannot determine the complete set of functions invoked). // function or we cannot determine the complete set of functions invoked).
// //
DSGraph* FunctionModRefInfo::ResolveCallSiteModRefInfo(CallInst &CI, DSGraph* FunctionModRefInfo::ResolveCallSiteModRefInfo(CallInst &CI,
std::map<const DSNode*, DSNodeHandle> &NodeMap) hash_map<const DSNode*, DSNodeHandle> &NodeMap)
{ {
// Step #0: Quick check if we are going to fail anyway: avoid // Step #0: Quick check if we are going to fail anyway: avoid
// all the graph cloning and map copying in steps #1 and #2. // all the graph cloning and map copying in steps #1 and #2.
@ -194,7 +194,7 @@ FunctionModRefInfo::computeModRef(const CallInst& callInst)
callSiteModRefInfo[&callInst] = callModRefInfo; callSiteModRefInfo[&callInst] = callModRefInfo;
// Get a copy of the graph for the callee with the callee inlined // Get a copy of the graph for the callee with the callee inlined
std::map<const DSNode*, DSNodeHandle> NodeMap; hash_map<const DSNode*, DSNodeHandle> NodeMap;
DSGraph* csgp = ResolveCallSiteModRefInfo(const_cast<CallInst&>(callInst), DSGraph* csgp = ResolveCallSiteModRefInfo(const_cast<CallInst&>(callInst),
NodeMap); NodeMap);
if (!csgp) if (!csgp)
@ -238,7 +238,7 @@ public:
knownValues.resize(tdGraph.getGraphSize()); knownValues.resize(tdGraph.getGraphSize());
// For every identifiable value, save Value pointer in knownValues[i] // For every identifiable value, save Value pointer in knownValues[i]
for (std::map<Value*, DSNodeHandle>::const_iterator for (hash_map<Value*, DSNodeHandle>::const_iterator
I = tdGraph.getScalarMap().begin(), I = tdGraph.getScalarMap().begin(),
E = tdGraph.getScalarMap().end(); I != E; ++I) E = tdGraph.getScalarMap().end(); I != E; ++I)
if (isa<GlobalValue>(I->first) || if (isa<GlobalValue>(I->first) ||

View File

@ -43,7 +43,7 @@ namespace {
/// MarkedNodes - The set of nodes which are not locally pool allocatable in /// MarkedNodes - The set of nodes which are not locally pool allocatable in
/// the current function. /// the current function.
/// ///
std::set<DSNode*> MarkedNodes; hash_set<DSNode*> MarkedNodes;
/// Clone - The cloned version of the function, if applicable. /// Clone - The cloned version of the function, if applicable.
Function *Clone; Function *Clone;
@ -204,7 +204,7 @@ Function *PA::MakeFunctionClone(Function &F) {
// Find DataStructure nodes which are allocated in pools non-local to the // Find DataStructure nodes which are allocated in pools non-local to the
// current function. This set will contain all of the DSNodes which require // current function. This set will contain all of the DSNodes which require
// pools to be passed in from outside of the function. // pools to be passed in from outside of the function.
std::set<DSNode*> &MarkedNodes = FI.MarkedNodes; hash_set<DSNode*> &MarkedNodes = FI.MarkedNodes;
// Mark globals and incomplete nodes as live... (this handles arguments) // Mark globals and incomplete nodes as live... (this handles arguments)
if (F.getName() != "main") if (F.getName() != "main")
@ -225,7 +225,7 @@ Function *PA::MakeFunctionClone(Function &F) {
ArgTys.reserve(OldFuncTy->getParamTypes().size() + MarkedNodes.size()); ArgTys.reserve(OldFuncTy->getParamTypes().size() + MarkedNodes.size());
FI.ArgNodes.reserve(MarkedNodes.size()); FI.ArgNodes.reserve(MarkedNodes.size());
for (std::set<DSNode*>::iterator I = MarkedNodes.begin(), for (hash_set<DSNode*>::iterator I = MarkedNodes.begin(),
E = MarkedNodes.end(); I != E; ++I) E = MarkedNodes.end(); I != E; ++I)
if ((*I)->NodeType & DSNode::Incomplete) { if ((*I)->NodeType & DSNode::Incomplete) {
ArgTys.push_back(PoolDescPtr); // Add the appropriate # of pool descs ArgTys.push_back(PoolDescPtr); // Add the appropriate # of pool descs
@ -289,7 +289,7 @@ void PA::ProcessFunctionBody(Function &F, Function &NewF) {
if (Nodes.empty()) return; // Quick exit if nothing to do... if (Nodes.empty()) return; // Quick exit if nothing to do...
FuncInfo &FI = FunctionInfo[&F]; // Get FuncInfo for F FuncInfo &FI = FunctionInfo[&F]; // Get FuncInfo for F
std::set<DSNode*> &MarkedNodes = FI.MarkedNodes; hash_set<DSNode*> &MarkedNodes = FI.MarkedNodes;
DEBUG(std::cerr << "[" << F.getName() << "] Pool Allocate: "); DEBUG(std::cerr << "[" << F.getName() << "] Pool Allocate: ");
@ -414,8 +414,8 @@ void FuncTransform::visitMallocInst(MallocInst &MI) {
// Remove old malloc instruction // Remove old malloc instruction
MI.getParent()->getInstList().erase(&MI); MI.getParent()->getInstList().erase(&MI);
std::map<Value*, DSNodeHandle> &SM = G.getScalarMap(); hash_map<Value*, DSNodeHandle> &SM = G.getScalarMap();
std::map<Value*, DSNodeHandle>::iterator MII = SM.find(&MI); hash_map<Value*, DSNodeHandle>::iterator MII = SM.find(&MI);
// If we are modifying the original function, update the DSGraph... // If we are modifying the original function, update the DSGraph...
if (MII != SM.end()) { if (MII != SM.end()) {