[llvm-commits] CVS: poolalloc/lib/PoolAllocate/EquivClassGraphs.cpp Heuristic.cpp Heuristic.h PoolAllocate.cpp PoolAllocate.h TransformFunctionBody.cpp
Chris Lattner
lattner at cs.uiuc.edu
Sun Jan 30 15:51:35 PST 2005
Changes in directory poolalloc/lib/PoolAllocate:
EquivClassGraphs.cpp updated: 1.18 -> 1.19
Heuristic.cpp updated: 1.4 -> 1.5
Heuristic.h updated: 1.2 -> 1.3
PoolAllocate.cpp updated: 1.97 -> 1.98
PoolAllocate.h updated: 1.33 -> 1.34
TransformFunctionBody.cpp updated: 1.34 -> 1.35
---
Log message:
Make things more const-correct, adjust to changes in DSA interfaces.
---
Diffs of the changes: (+70 -62)
Index: poolalloc/lib/PoolAllocate/EquivClassGraphs.cpp
diff -u poolalloc/lib/PoolAllocate/EquivClassGraphs.cpp:1.18 poolalloc/lib/PoolAllocate/EquivClassGraphs.cpp:1.19
--- poolalloc/lib/PoolAllocate/EquivClassGraphs.cpp:1.18 Thu Nov 11 16:11:17 2004
+++ poolalloc/lib/PoolAllocate/EquivClassGraphs.cpp Sun Jan 30 17:51:25 2005
@@ -292,8 +292,8 @@
Stack.push_back(&FG);
// The edges out of the current node are the call site targets...
- for (unsigned i = 0, e = FG.getFunctionCalls().size(); i != e; ++i) {
- Instruction *Call = FG.getFunctionCalls()[i].getCallSite().getInstruction();
+ for (DSGraph::fc_iterator CI = FG.fc_begin(), E = FG.fc_end(); CI != E; ++CI){
+ Instruction *Call = CI->getCallSite().getInstruction();
// Loop over all of the actually called functions...
ActualCalleesTy::const_iterator I, E;
@@ -355,8 +355,10 @@
// Else we need to inline some callee graph. Visit all call sites.
// The edges out of the current node are the call site targets...
- for (unsigned i=0, e = G.getFunctionCalls().size(); i != e; ++i) {
- const DSCallSite &CS = G.getFunctionCalls()[i];
+ unsigned i = 0;
+ for (DSGraph::fc_iterator CI = G.fc_begin(), E = G.fc_end(); CI != E;
+ ++CI, ++i) {
+ const DSCallSite &CS = *CI;
Instruction *TheCall = CS.getCallSite().getInstruction();
assert(calls.insert(TheCall).second &&
@@ -392,7 +394,8 @@
DSGraph::KeepModRefBits | DSGraph::StripAllocaBit |
DSGraph::DontCloneCallNodes |
DSGraph::DontCloneAuxCallNodes);
- DEBUG(std::cerr << " Inlining graph [" << i << "/" << e-1
+ DEBUG(std::cerr << " Inlining graph [" << i << "/"
+ << G.getFunctionCalls().size()-1
<< ":" << TNum << "/" << Num-1 << "] for "
<< CalleeFunc->getName() << "["
<< CalleeGraph->getGraphSize() << "+"
Index: poolalloc/lib/PoolAllocate/Heuristic.cpp
diff -u poolalloc/lib/PoolAllocate/Heuristic.cpp:1.4 poolalloc/lib/PoolAllocate/Heuristic.cpp:1.5
--- poolalloc/lib/PoolAllocate/Heuristic.cpp:1.4 Wed Nov 10 15:13:47 2004
+++ poolalloc/lib/PoolAllocate/Heuristic.cpp Sun Jan 30 17:51:25 2005
@@ -49,7 +49,7 @@
Heuristic::~Heuristic() {}
-unsigned Heuristic::getRecommendedSize(DSNode *N) {
+unsigned Heuristic::getRecommendedSize(const DSNode *N) {
unsigned PoolSize = 0;
if (!N->isArray() && N->getType()->isSized()) {
PoolSize = N->getParentGraph()->getTargetData().getTypeSize(N->getType());
@@ -87,7 +87,7 @@
/// getRecommendedAlignment - Return the recommended object alignment for this
/// DSNode.
///
-unsigned Heuristic::getRecommendedAlignment(DSNode *N) {
+unsigned Heuristic::getRecommendedAlignment(const DSNode *N) {
if (N->getType() == Type::VoidTy) // Is this void or collapsed?
return 0; // No known alignment, let runtime decide.
@@ -105,7 +105,7 @@
//
struct AllNodesHeuristic : public Heuristic {
- void AssignToPools(const std::vector<DSNode*> &NodesToPA,
+ void AssignToPools(const std::vector<const DSNode*> &NodesToPA,
Function *F, DSGraph &G,
std::vector<OnePool> &ResultPools) {
for (unsigned i = 0, e = NodesToPA.size(); i != e; ++i)
@@ -123,7 +123,7 @@
//
struct AllButUnreachableFromMemoryHeuristic : public Heuristic {
- void AssignToPools(const std::vector<DSNode*> &NodesToPA,
+ void AssignToPools(const std::vector<const DSNode*> &NodesToPA,
Function *F, DSGraph &G,
std::vector<OnePool> &ResultPools) {
// Build a set of all nodes that are reachable from another node in the
@@ -161,19 +161,20 @@
//
struct CyclicNodesHeuristic : public Heuristic {
- void AssignToPools(const std::vector<DSNode*> &NodesToPA,
+ void AssignToPools(const std::vector<const DSNode*> &NodesToPA,
Function *F, DSGraph &G,
std::vector<OnePool> &ResultPools);
};
-static bool NodeExistsInCycle(DSNode *N) {
- for (DSNode::iterator I = N->begin(), E = N->end(); I != E; ++I)
+static bool NodeExistsInCycle(const DSNode *N) {
+ for (DSNode::const_iterator I = N->begin(), E = N->end(); I != E; ++I)
if (*I && std::find(df_begin(*I), df_end(*I), N) != df_end(*I))
return true;
return false;
}
-void CyclicNodesHeuristic::AssignToPools(const std::vector<DSNode*> &NodesToPA,
+void CyclicNodesHeuristic::AssignToPools(const std::vector<const
+ DSNode*> &NodesToPA,
Function *F, DSGraph &G,
std::vector<OnePool> &ResultPools) {
for (unsigned i = 0, e = NodesToPA.size(); i != e; ++i)
@@ -189,14 +190,14 @@
//
struct SmartCoallesceNodesHeuristic : public Heuristic {
- void AssignToPools(const std::vector<DSNode*> &NodesToPA,
+ void AssignToPools(const std::vector<const DSNode*> &NodesToPA,
Function *F, DSGraph &G,
std::vector<OnePool> &ResultPools) {
// For globals, do not pool allocate unless the node is cyclic and not an
// array (unless it's collapsed).
if (F == 0) {
for (unsigned i = 0, e = NodesToPA.size(); i != e; ++i) {
- DSNode *Node = NodesToPA[i];
+ const DSNode *Node = NodesToPA[i];
if ((Node->isNodeCompletelyFolded() || !Node->isArray()) &&
NodeExistsInCycle(Node))
ResultPools.push_back(OnePool(Node));
@@ -374,7 +375,7 @@
virtual bool IsRealHeuristic() { return false; }
- void AssignToPools(const std::vector<DSNode*> &NodesToPA,
+ void AssignToPools(const std::vector<const DSNode*> &NodesToPA,
Function *F, DSGraph &G,
std::vector<OnePool> &ResultPools) {
if (TheGlobalPD == 0)
@@ -398,7 +399,7 @@
struct OnlyOverheadHeuristic : public Heuristic {
virtual bool IsRealHeuristic() { return false; }
- void AssignToPools(const std::vector<DSNode*> &NodesToPA,
+ void AssignToPools(const std::vector<const DSNode*> &NodesToPA,
Function *F, DSGraph &G,
std::vector<OnePool> &ResultPools) {
// For this heuristic, we assign everything possible to its own pool.
@@ -461,7 +462,7 @@
struct NoNodesHeuristic : public Heuristic {
virtual bool IsRealHeuristic() { return false; }
- void AssignToPools(const std::vector<DSNode*> &NodesToPA,
+ void AssignToPools(const std::vector<const DSNode*> &NodesToPA,
Function *F, DSGraph &G,
std::vector<OnePool> &ResultPools) {
// Nothing to pool allocate here.
Index: poolalloc/lib/PoolAllocate/Heuristic.h
diff -u poolalloc/lib/PoolAllocate/Heuristic.h:1.2 poolalloc/lib/PoolAllocate/Heuristic.h:1.3
--- poolalloc/lib/PoolAllocate/Heuristic.h:1.2 Wed Nov 10 15:13:47 2004
+++ poolalloc/lib/PoolAllocate/Heuristic.h Sun Jan 30 17:51:25 2005
@@ -48,7 +48,7 @@
struct OnePool {
// NodesInPool - The DS nodes to be allocated to this pool. There may be
// multiple here if they are being coallesced into the same pool.
- std::vector<DSNode*> NodesInPool;
+ std::vector<const DSNode*> NodesInPool;
// PoolDesc - If the heuristic wants the nodes allocated to a specific
// pool descriptor, it can specify it here, otherwise a new pool is
@@ -62,12 +62,12 @@
OnePool() : PoolDesc(0), PoolSize(0), PoolAlignment(0) {}
- OnePool(DSNode *N) : PoolDesc(0), PoolSize(getRecommendedSize(N)),
- PoolAlignment(getRecommendedAlignment(N)) {
+ OnePool(const DSNode *N) : PoolDesc(0), PoolSize(getRecommendedSize(N)),
+ PoolAlignment(getRecommendedAlignment(N)) {
NodesInPool.push_back(N);
}
- OnePool(DSNode *N, Value *PD) : PoolDesc(PD), PoolSize(0),
- PoolAlignment(0) {
+ OnePool(const DSNode *N, Value *PD) : PoolDesc(PD), PoolSize(0),
+ PoolAlignment(0) {
NodesInPool.push_back(N);
}
};
@@ -75,21 +75,22 @@
/// AssignToPools - Partition NodesToPA into a set of disjoint pools,
/// returning the result in ResultPools. If this is a function being pool
/// allocated, F will not be null.
- virtual void AssignToPools(const std::vector<DSNode*> &NodesToPA,
+ virtual void AssignToPools(const std::vector<const DSNode*> &NodesToPA,
Function *F, DSGraph &G,
std::vector<OnePool> &ResultPools) = 0;
// Hacks for the OnlyOverhead heuristic.
- virtual void HackFunctionBody(Function &F, std::map<DSNode*, Value*> &PDs){}
+ virtual void HackFunctionBody(Function &F,
+ std::map<const DSNode*, Value*> &PDs) {}
/// getRecommendedSize - Return the recommended pool size for this DSNode.
///
- static unsigned getRecommendedSize(DSNode *N);
+ static unsigned getRecommendedSize(const DSNode *N);
/// getRecommendedAlignment - Return the recommended object alignment for
/// this DSNode.
///
- static unsigned getRecommendedAlignment(DSNode *N);
+ static unsigned getRecommendedAlignment(const DSNode *N);
/// create - This static ctor creates the heuristic, based on the command
/// line argument to choose the heuristic.
Index: poolalloc/lib/PoolAllocate/PoolAllocate.cpp
diff -u poolalloc/lib/PoolAllocate/PoolAllocate.cpp:1.97 poolalloc/lib/PoolAllocate/PoolAllocate.cpp:1.98
--- poolalloc/lib/PoolAllocate/PoolAllocate.cpp:1.97 Thu Jan 20 13:12:14 2005
+++ poolalloc/lib/PoolAllocate/PoolAllocate.cpp Sun Jan 30 17:51:25 2005
@@ -224,13 +224,13 @@
static void GetNodesReachableFromGlobals(DSGraph &G,
- hash_set<DSNode*> &NodesFromGlobals) {
+ hash_set<const DSNode*> &NodesFromGlobals) {
for (DSScalarMap::global_iterator I = G.getScalarMap().global_begin(),
E = G.getScalarMap().global_end(); I != E; ++I)
G.getNodeForValue(*I).getNode()->markReachableNodes(NodesFromGlobals);
}
-static void MarkNodesWhichMustBePassedIn(hash_set<DSNode*> &MarkedNodes,
+static void MarkNodesWhichMustBePassedIn(hash_set<const DSNode*> &MarkedNodes,
Function &F, DSGraph &G) {
// Mark globals and incomplete nodes as live... (this handles arguments)
if (F.getName() != "main") {
@@ -250,16 +250,16 @@
// Calculate which DSNodes are reachable from globals. If a node is reachable
// from a global, we will create a global pool for it, so no argument passage
// is required.
- hash_set<DSNode*> NodesFromGlobals;
+ hash_set<const DSNode*> NodesFromGlobals;
GetNodesReachableFromGlobals(G, NodesFromGlobals);
// Remove any nodes reachable from a global. These nodes will be put into
// global pools, which do not require arguments to be passed in. Also, erase
// any marked node that is not a heap node. Since no allocations or frees
// will be done with it, it needs no argument.
- for (hash_set<DSNode*>::iterator I = MarkedNodes.begin(),
+ for (hash_set<const DSNode*>::iterator I = MarkedNodes.begin(),
E = MarkedNodes.end(); I != E; ) {
- DSNode *N = *I++;
+ const DSNode *N = *I++;
if ((!N->isHeapNode() && !PASS_ALL_ARGUMENTS) || NodesFromGlobals.count(N))
MarkedNodes.erase(N);
}
@@ -270,7 +270,7 @@
DSGraph &G = ECGraphs->getDSGraph(F);
FuncInfo &FI = FunctionInfo[&F]; // Create a new entry for F
- hash_set<DSNode*> &MarkedNodes = FI.MarkedNodes;
+ hash_set<const DSNode*> &MarkedNodes = FI.MarkedNodes;
if (G.node_begin() == G.node_end())
return; // No memory activity, nothing is required
@@ -316,7 +316,7 @@
// Set the rest of the new arguments names to be PDa<n> and add entries to the
// pool descriptors map
- std::map<DSNode*, Value*> &PoolDescriptors = FI.PoolDescriptors;
+ std::map<const DSNode*, Value*> &PoolDescriptors = FI.PoolDescriptors;
Function::aiterator NI = New->abegin();
for (unsigned i = 0, e = FI.ArgNodes.size(); i != e; ++i, ++NI) {
@@ -367,13 +367,13 @@
DSGraph &GG = ECGraphs->getGlobalsGraph();
// Get all of the nodes reachable from globals.
- hash_set<DSNode*> GlobalHeapNodes;
+ hash_set<const DSNode*> GlobalHeapNodes;
GetNodesReachableFromGlobals(GG, GlobalHeapNodes);
// Filter out all nodes which have no heap allocations merged into them.
- for (hash_set<DSNode*>::iterator I = GlobalHeapNodes.begin(),
+ for (hash_set<const DSNode*>::iterator I = GlobalHeapNodes.begin(),
E = GlobalHeapNodes.end(); I != E; ) {
- hash_set<DSNode*>::iterator Last = I++;
+ hash_set<const DSNode*>::iterator Last = I++;
if (!(*Last)->isHeapNode())
GlobalHeapNodes.erase(Last);
}
@@ -390,7 +390,8 @@
<< " global nodes!\n";
- std::vector<DSNode*> NodesToPA(GlobalHeapNodes.begin(),GlobalHeapNodes.end());
+ std::vector<const DSNode*> NodesToPA(GlobalHeapNodes.begin(),
+ GlobalHeapNodes.end());
std::vector<Heuristic::OnePool> ResultPools;
CurHeuristic->AssignToPools(NodesToPA, 0, GG, ResultPools);
@@ -415,7 +416,7 @@
}
// Any unallocated DSNodes get null pool descriptor pointers.
- for (hash_set<DSNode*>::iterator I = GlobalHeapNodes.begin(),
+ for (hash_set<const DSNode*>::iterator I = GlobalHeapNodes.begin(),
E = GlobalHeapNodes.end(); I != E; ++I) {
GlobalNodes[*I] = Constant::getNullValue(PointerType::get(PoolDescType));
++NumNonprofit;
@@ -456,15 +457,16 @@
// PoolDescriptors map for each DSNode.
//
void PoolAllocate::CreatePools(Function &F,
- const std::vector<DSNode*> &NodesToPA,
- std::map<DSNode*, Value*> &PoolDescriptors) {
+ const std::vector<const DSNode*> &NodesToPA,
+ std::map<const DSNode*,
+ Value*> &PoolDescriptors) {
if (NodesToPA.empty()) return;
std::vector<Heuristic::OnePool> ResultPools;
CurHeuristic->AssignToPools(NodesToPA, &F, *NodesToPA[0]->getParentGraph(),
ResultPools);
- std::set<DSNode*> UnallocatedNodes(NodesToPA.begin(), NodesToPA.end());
+ std::set<const DSNode*> UnallocatedNodes(NodesToPA.begin(), NodesToPA.end());
BasicBlock::iterator InsertPoint = F.front().begin();
while (isa<AllocaInst>(InsertPoint)) ++InsertPoint;
@@ -497,7 +499,7 @@
}
// Any unallocated DSNodes get null pool descriptor pointers.
- for (std::set<DSNode*>::iterator I = UnallocatedNodes.begin(),
+ for (std::set<const DSNode*>::iterator I = UnallocatedNodes.begin(),
E = UnallocatedNodes.end(); I != E; ++I) {
PoolDescriptors[*I] =Constant::getNullValue(PointerType::get(PoolDescType));
++NumNonprofit;
@@ -513,7 +515,7 @@
if (G.node_begin() == G.node_end()) return; // Quick exit if nothing to do.
FuncInfo &FI = FunctionInfo[&F]; // Get FuncInfo for F
- hash_set<DSNode*> &MarkedNodes = FI.MarkedNodes;
+ hash_set<const DSNode*> &MarkedNodes = FI.MarkedNodes;
// Calculate which DSNodes are reachable from globals. If a node is reachable
// from a global, we will create a global pool for it, so no argument passage
@@ -531,7 +533,7 @@
// Loop over all of the nodes which are non-escaping, adding pool-allocatable
// ones to the NodesToPA vector.
- std::vector<DSNode*> NodesToPA;
+ std::vector<const DSNode*> NodesToPA;
for (DSGraph::node_iterator I = G.node_begin(), E = G.node_end(); I != E;++I){
// We only need to make a pool if there is a heap object in it...
DSNode *N = *I;
@@ -616,8 +618,8 @@
/// InitializeAndDestroyPools- This inserts calls to poolinit and pooldestroy
/// into the function to initialize and destroy one pool.
///
-void PoolAllocate::InitializeAndDestroyPool(Function &F, DSNode *Node,
- std::map<DSNode*, Value*> &PoolDescriptors,
+void PoolAllocate::InitializeAndDestroyPool(Function &F, const DSNode *Node,
+ std::map<const DSNode*, Value*> &PoolDescriptors,
std::multimap<AllocaInst*, Instruction*> &PoolUses,
std::multimap<AllocaInst*, CallInst*> &PoolFrees) {
AllocaInst *PD = cast<AllocaInst>(PoolDescriptors[Node]);
@@ -812,15 +814,15 @@
/// into the function to initialize and destroy the pools in the NodesToPA list.
///
void PoolAllocate::InitializeAndDestroyPools(Function &F,
- const std::vector<DSNode*> &NodesToPA,
- std::map<DSNode*, Value*> &PoolDescriptors,
+ const std::vector<const DSNode*> &NodesToPA,
+ std::map<const DSNode*, Value*> &PoolDescriptors,
std::multimap<AllocaInst*, Instruction*> &PoolUses,
std::multimap<AllocaInst*, CallInst*> &PoolFrees) {
std::set<AllocaInst*> AllocasHandled;
// Insert all of the poolinit/destroy calls into the function.
for (unsigned i = 0, e = NodesToPA.size(); i != e; ++i) {
- DSNode *Node = NodesToPA[i];
+ const DSNode *Node = NodesToPA[i];
if (isa<GlobalVariable>(PoolDescriptors[Node]) ||
isa<ConstantPointerNull>(PoolDescriptors[Node]))
Index: poolalloc/lib/PoolAllocate/PoolAllocate.h
diff -u poolalloc/lib/PoolAllocate/PoolAllocate.h:1.33 poolalloc/lib/PoolAllocate/PoolAllocate.h:1.34
--- poolalloc/lib/PoolAllocate/PoolAllocate.h:1.33 Tue Dec 14 14:16:24 2004
+++ poolalloc/lib/PoolAllocate/PoolAllocate.h Sun Jan 30 17:51:25 2005
@@ -49,14 +49,14 @@
/// MarkedNodes - The set of nodes which are not locally pool allocatable in
/// the current function.
///
- hash_set<DSNode*> MarkedNodes;
+ hash_set<const DSNode*> MarkedNodes;
/// Clone - The cloned version of the function, if applicable.
Function *Clone;
/// ArgNodes - The list of DSNodes which have pools passed in as arguments.
///
- std::vector<DSNode*> ArgNodes;
+ std::vector<const DSNode*> ArgNodes;
/// PoolDescriptors - The Value* (either an argument or an alloca) which
/// defines the pool descriptor for this DSNode. Pools are mapped one to
@@ -68,7 +68,7 @@
/// not.
/// Note: Does not include pool arguments that are passed in because of
/// indirect function calls that are not used in the function.
- std::map<DSNode*, Value*> PoolDescriptors;
+ std::map<const DSNode*, Value*> PoolDescriptors;
//This is a map from Old to New Value Map reverse of the one above
//Useful in SAFECode for check insertion
@@ -104,7 +104,7 @@
/// GlobalNodes - For each node (with an H marker) in the globals graph, this
/// map contains the global variable that holds the pool descriptor for the
/// node.
- std::map<DSNode*, Value*> GlobalNodes;
+ std::map<const DSNode*, Value*> GlobalNodes;
public:
bool runOnModule(Module &M);
@@ -183,8 +183,8 @@
/// pools specified in the NodesToPA list. This adds an entry to the
/// PoolDescriptors map for each DSNode.
///
- void CreatePools(Function &F, const std::vector<DSNode*> &NodesToPA,
- std::map<DSNode*, Value*> &PoolDescriptors);
+ void CreatePools(Function &F, const std::vector<const DSNode*> &NodesToPA,
+ std::map<const DSNode*, Value*> &PoolDescriptors);
void TransformBody(DSGraph &g, PA::FuncInfo &fi,
std::multimap<AllocaInst*, Instruction*> &poolUses,
@@ -195,13 +195,13 @@
/// into the function to initialize and destroy the pools in the NodesToPA
/// list.
void InitializeAndDestroyPools(Function &F,
- const std::vector<DSNode*> &NodesToPA,
- std::map<DSNode*, Value*> &PoolDescriptors,
+ const std::vector<const DSNode*> &NodesToPA,
+ std::map<const DSNode*, Value*> &PoolDescriptors,
std::multimap<AllocaInst*, Instruction*> &PoolUses,
std::multimap<AllocaInst*, CallInst*> &PoolFrees);
- void InitializeAndDestroyPool(Function &F, DSNode *Pool,
- std::map<DSNode*, Value*> &PoolDescriptors,
+ void InitializeAndDestroyPool(Function &F, const DSNode *Pool,
+ std::map<const DSNode*, Value*> &PoolDescriptors,
std::multimap<AllocaInst*, Instruction*> &PoolUses,
std::multimap<AllocaInst*, CallInst*> &PoolFrees);
Index: poolalloc/lib/PoolAllocate/TransformFunctionBody.cpp
diff -u poolalloc/lib/PoolAllocate/TransformFunctionBody.cpp:1.34 poolalloc/lib/PoolAllocate/TransformFunctionBody.cpp:1.35
--- poolalloc/lib/PoolAllocate/TransformFunctionBody.cpp:1.34 Tue Dec 14 14:16:24 2004
+++ poolalloc/lib/PoolAllocate/TransformFunctionBody.cpp Sun Jan 30 17:51:25 2005
@@ -102,7 +102,8 @@
Value *getPoolHandle(Value *V) {
DSNode *Node = getDSNodeHFor(V).getNode();
// Get the pool handle for this DSNode...
- std::map<DSNode*, Value*>::iterator I = FI.PoolDescriptors.find(Node);
+ std::map<const DSNode*, Value*>::iterator I =
+ FI.PoolDescriptors.find(Node);
return I != FI.PoolDescriptors.end() ? I->second : 0;
}
@@ -422,7 +423,7 @@
DSGraph::NodeMapTy NodeMapping;
Instruction *NewCall;
Value *NewCallee;
- std::vector<DSNode*> ArgNodes;
+ std::vector<const DSNode*> ArgNodes;
DSGraph *CalleeGraph; // The callee graph
// For indirect callees find any callee since all DS graphs have been merged.
More information about the llvm-commits
mailing list