[llvm-commits] [poolalloc] r97715 - in /poolalloc/trunk: include/dsa/ include/poolalloc/ include/poolalloc/ADT/ lib/AssistDS/ lib/DSA/ lib/PoolAllocate/
alenhar2 at llvm.org
alenhar2 at llvm.org
Wed Mar 3 18:28:42 PST 2010
Author: alenhar2
Date: Wed Mar 3 20:28:41 2010
New Revision: 97715
URL: http://llvm.org/viewvc/llvm-project?rev=97715&view=rev
Log:
Drop hash_ usage, move to std for now, will move to llvm hash soon. update to 2.7 api (breaks poolalloc). Support multiple entry points
Removed:
poolalloc/trunk/include/poolalloc/ADT/HashExtras.h
Modified:
poolalloc/trunk/include/dsa/DSGraph.h
poolalloc/trunk/include/dsa/DSNode.h
poolalloc/trunk/include/dsa/DSSupport.h
poolalloc/trunk/include/dsa/DataStructure.h
poolalloc/trunk/include/poolalloc/PoolAllocate.h
poolalloc/trunk/lib/AssistDS/FuncSpec.cpp
poolalloc/trunk/lib/DSA/BottomUpClosure.cpp
poolalloc/trunk/lib/DSA/CompleteBottomUp.cpp
poolalloc/trunk/lib/DSA/DataStructure.cpp
poolalloc/trunk/lib/DSA/DataStructureStats.cpp
poolalloc/trunk/lib/DSA/GraphChecker.cpp
poolalloc/trunk/lib/DSA/Local.cpp
poolalloc/trunk/lib/DSA/Printer.cpp
poolalloc/trunk/lib/DSA/Steensgaard.cpp
poolalloc/trunk/lib/DSA/TopDownClosure.cpp
poolalloc/trunk/lib/PoolAllocate/AccessTrace.cpp
poolalloc/trunk/lib/PoolAllocate/Heuristic.cpp
poolalloc/trunk/lib/PoolAllocate/PAMultipleGlobalPool.cpp
poolalloc/trunk/lib/PoolAllocate/PASimple.cpp
poolalloc/trunk/lib/PoolAllocate/PoolAllocate.cpp
poolalloc/trunk/lib/PoolAllocate/PoolOptimize.cpp
poolalloc/trunk/lib/PoolAllocate/RunTimeAssociate.cpp
poolalloc/trunk/lib/PoolAllocate/TransformFunctionBody.cpp
Modified: poolalloc/trunk/include/dsa/DSGraph.h
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/include/dsa/DSGraph.h?rev=97715&r1=97714&r2=97715&view=diff
==============================================================================
--- poolalloc/trunk/include/dsa/DSGraph.h (original)
+++ poolalloc/trunk/include/dsa/DSGraph.h Wed Mar 3 20:28:41 2010
@@ -17,13 +17,10 @@
#include "dsa/DSNode.h"
#include "llvm/ADT/EquivalenceClasses.h"
-#include "poolalloc/ADT/HashExtras.h"
-#include <ext/hash_map>
-#include <ext/hash_set>
#include <list>
#include <map>
-#include <iostream>
+#include <set>
namespace llvm {
@@ -42,10 +39,10 @@
/// globals or unique node handles active in the function.
///
class DSScalarMap {
- typedef hash_map<const Value*, DSNodeHandle> ValueMapTy;
+ typedef std::map<const Value*, DSNodeHandle> ValueMapTy;
ValueMapTy ValueMap;
- typedef hash_set<const GlobalValue*> GlobalSetTy;
+ typedef std::set<const GlobalValue*> GlobalSetTy;
GlobalSetTy GlobalSet;
EquivalenceClasses<const GlobalValue*> &GlobalECs;
@@ -193,17 +190,17 @@
public:
// Public data-type declarations...
typedef DSScalarMap ScalarMapTy;
- typedef hash_map<const Function*, DSNodeHandle> ReturnNodesTy;
+ typedef std::map<const Function*, DSNodeHandle> ReturnNodesTy;
typedef ilist<DSNode> NodeListTy;
/// NodeMapTy - This data type is used when cloning one graph into another to
/// keep track of the correspondence between the nodes in the old and new
/// graphs.
- typedef hash_map<const DSNode*, DSNodeHandle> NodeMapTy;
+ typedef std::map<const DSNode*, DSNodeHandle> NodeMapTy;
// InvNodeMapTy - This data type is used to represent the inverse of a node
// map.
- typedef hash_multimap<DSNodeHandle, const DSNode*> InvNodeMapTy;
+ typedef std::multimap<DSNodeHandle, const DSNode*> InvNodeMapTy;
private:
DSGraph *GlobalsGraph; // Pointer to the common graph of global objects
bool PrintAuxCalls; // Should this graph print the Aux calls vector?
@@ -417,10 +414,7 @@
/// print - Print a dot graph to the specified ostream...
///
- void print(OStream &O) const {
- if (O.stream()) print(*O.stream());
- }
- void print(std::ostream &O) const;
+ void print(llvm::raw_ostream &O) const;
/// dump - call print(cerr), for use from the debugger...
///
@@ -431,7 +425,7 @@
///
void viewGraph() const;
- void writeGraphToFile(std::ostream &O, const std::string &GraphName) const;
+ void writeGraphToFile(llvm::raw_ostream &O, const std::string &GraphName) const;
/// maskNodeTypes - Apply a mask to all of the node types in the graph. This
/// is useful for clearing out markers like Incomplete.
@@ -583,12 +577,15 @@
unsigned BitsToKeep;
unsigned CloneFlags;
+ bool createDest;
+
// NodeMap - A mapping from nodes in the source graph to the nodes that
// represent them in the destination graph.
DSGraph::NodeMapTy NodeMap;
public:
- ReachabilityCloner(DSGraph* dest, const DSGraph* src, unsigned cloneFlags)
- : Dest(dest), Src(src), CloneFlags(cloneFlags) {
+ ReachabilityCloner(DSGraph* dest, const DSGraph* src, unsigned cloneFlags,
+ bool _createDest = true)
+ : Dest(dest), Src(src), CloneFlags(cloneFlags), createDest(_createDest) {
assert(Dest != Src && "Cannot clone from graph to same graph!");
BitsToKeep = ~DSNode::DeadNode;
if (CloneFlags & DSGraph::StripAllocaBit)
Modified: poolalloc/trunk/include/dsa/DSNode.h
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/include/dsa/DSNode.h?rev=97715&r1=97714&r2=97715&view=diff
==============================================================================
--- poolalloc/trunk/include/dsa/DSNode.h (original)
+++ poolalloc/trunk/include/dsa/DSNode.h Wed Mar 3 20:28:41 2010
@@ -16,8 +16,9 @@
#include "dsa/DSSupport.h"
#include "llvm/ADT/ilist_node.h"
-#include "llvm/Support/Streams.h"
-#include "poolalloc/ADT/HashExtras.h"
+
+#include <map>
+#include <set>
namespace llvm {
@@ -91,20 +92,21 @@
HeapNode = 1 << 1, // This node was allocated with malloc
GlobalNode = 1 << 2, // This node was allocated by a global var decl
ExternFuncNode = 1 << 3, // This node contains external functions
- UnknownNode = 1 << 4, // This node points to unknown allocated memory
- IncompleteNode = 1 << 5, // This node may not be complete
-
- ModifiedNode = 1 << 6, // This node is modified in this context
- ReadNode = 1 << 7, // This node is read in this context
-
- ArrayNode = 1 << 8, // This node is treated like an array
- ExternalNode = 1 << 9, // This node comes from an external source
- IntToPtrNode = 1 << 10, // This node comes from an int cast
- PtrToIntNode = 1 << 11, // This node excapes to an int cast
- VAStartNode = 1 << 12, // This node excapes to an int cast
+ ExternGlobalNode = 1 << 4, // This node contains external globals
+ UnknownNode = 1 << 5, // This node points to unknown allocated memory
+ IncompleteNode = 1 << 6, // This node may not be complete
+
+ ModifiedNode = 1 << 7, // This node is modified in this context
+ ReadNode = 1 << 8, // This node is read in this context
+
+ ArrayNode = 1 << 9, // This node is treated like an array
+ ExternalNode = 1 << 10, // This node comes from an external source
+ IntToPtrNode = 1 << 11, // This node comes from an int cast
+ PtrToIntNode = 1 << 12, // This node excapes to an int cast
+ VAStartNode = 1 << 13, // This node excapes to an int cast
//#ifndef NDEBUG
- DeadNode = 1 << 13, // This node is dead and should not be pointed to
+ DeadNode = 1 << 14, // This node is dead and should not be pointed to
//#endif
Composition = AllocaNode | HeapNode | GlobalNode | UnknownNode
@@ -351,6 +353,7 @@
DSNode* setHeapMarker() { NodeType |= HeapNode; return this; }
DSNode* setGlobalMarker() { NodeType |= GlobalNode; return this; }
DSNode* setExternFuncMarker() { NodeType |= ExternFuncNode; return this; }
+ DSNode* setExternGlobalMarker() { NodeType |= ExternGlobalNode; return this; }
DSNode* setUnknownMarker() { NodeType |= UnknownNode; return this; }
DSNode* setModifiedMarker() { NodeType |= ModifiedNode; return this; }
DSNode* setReadMarker() { NodeType |= ReadNode; return this; }
@@ -372,10 +375,7 @@
///
void forwardNode(DSNode *To, unsigned Offset);
- void print(OStream &O, const DSGraph *G) const {
- if (O.stream()) print(*O.stream(), G);
- }
- void print(std::ostream &O, const DSGraph *G) const;
+ void print(llvm::raw_ostream &O, const DSGraph *G) const;
void dump() const;
void assertOK() const;
@@ -389,13 +389,13 @@
/// remapLinks - Change all of the Links in the current node according to the
/// specified mapping.
///
- void remapLinks(hash_map<const DSNode*, DSNodeHandle> &OldNodeMap);
+ void remapLinks(std::map<const DSNode*, DSNodeHandle> &OldNodeMap);
/// markReachableNodes - This method recursively traverses the specified
/// DSNodes, marking any nodes which are reachable. All reachable nodes it
/// adds to the set, which allows it to only traverse visited nodes once.
///
- void markReachableNodes(hash_set<const DSNode*> &ReachableNodes) const;
+ void markReachableNodes(std::set<const DSNode*> &ReachableNodes) const;
private:
friend class DSNodeHandle;
Modified: poolalloc/trunk/include/dsa/DSSupport.h
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/include/dsa/DSSupport.h?rev=97715&r1=97714&r2=97715&view=diff
==============================================================================
--- poolalloc/trunk/include/dsa/DSSupport.h (original)
+++ poolalloc/trunk/include/dsa/DSSupport.h Wed Mar 3 20:28:41 2010
@@ -15,8 +15,11 @@
#define LLVM_ANALYSIS_DSSUPPORT_H
#include <functional>
+#include <vector>
+#include <map>
+#include <set>
+
#include "llvm/Support/CallSite.h"
-#include "poolalloc/ADT/HashExtras.h"
namespace llvm {
@@ -139,15 +142,6 @@
inline void swap<llvm::DSNodeHandle>(llvm::DSNodeHandle &NH1, llvm::DSNodeHandle &NH2) { NH1.swap(NH2); }
}
-namespace __gnu_cxx {
- // Provide a hash function for arbitrary pointers...
- template <> struct hash<llvm::DSNodeHandle> {
- inline size_t operator()(const llvm::DSNodeHandle &Val) const {
- return hash<void*>()(Val.getNode()) ^ Val.getOffset();
- }
- };
-}
-
namespace llvm {
//===----------------------------------------------------------------------===//
@@ -163,18 +157,18 @@
std::vector<DSNodeHandle> CallArgs; // The pointer arguments
static void InitNH(DSNodeHandle &NH, const DSNodeHandle &Src,
- const hash_map<const DSNode*, DSNode*> &NodeMap) {
+ const std::map<const DSNode*, DSNode*> &NodeMap) {
if (DSNode *N = Src.getNode()) {
- hash_map<const DSNode*, DSNode*>::const_iterator I = NodeMap.find(N);
+ std::map<const DSNode*, DSNode*>::const_iterator I = NodeMap.find(N);
assert(I != NodeMap.end() && "Node not in mapping!");
NH.setTo(I->second, Src.getOffset());
}
}
static void InitNH(DSNodeHandle &NH, const DSNodeHandle &Src,
- const hash_map<const DSNode*, DSNodeHandle> &NodeMap) {
+ const std::map<const DSNode*, DSNodeHandle> &NodeMap) {
if (DSNode *N = Src.getNode()) {
- hash_map<const DSNode*, DSNodeHandle>::const_iterator I = NodeMap.find(N);
+ std::map<const DSNode*, DSNodeHandle>::const_iterator I = NodeMap.find(N);
assert(I != NodeMap.end() && "Node not in mapping!");
DSNode *NN = I->second.getNode(); // Call getNode before getOffset()
@@ -298,7 +292,7 @@
/// DSNodes, marking any nodes which are reachable. All reachable nodes it
/// adds to the set, which allows it to only traverse visited nodes once.
///
- void markReachableNodes(hash_set<const DSNode*> &Nodes) const;
+ void markReachableNodes(std::set<const DSNode*> &Nodes) const;
bool operator<(const DSCallSite &CS) const {
if (isDirectCall()) { // This must sort by callee first!
Modified: poolalloc/trunk/include/dsa/DataStructure.h
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/include/dsa/DataStructure.h?rev=97715&r1=97714&r2=97715&view=diff
==============================================================================
--- poolalloc/trunk/include/dsa/DataStructure.h (original)
+++ poolalloc/trunk/include/dsa/DataStructure.h Wed Mar 3 20:28:41 2010
@@ -19,7 +19,7 @@
#include "llvm/Support/CallSite.h"
#include "llvm/ADT/EquivalenceClasses.h"
-#include "poolalloc/ADT/HashExtras.h"
+#include "dsa/EntryPointAnalysis.h"
#include <map>
@@ -37,10 +37,10 @@
FunctionPass *createDataStructureGraphCheckerPass();
class DataStructures : public ModulePass {
- typedef hash_map<const Instruction*, hash_set<const Function*> > ActualCalleesTy;
- typedef hash_map<const Function*, DSGraph*> DSInfoTy;
+ typedef std::map<const Instruction*, std::set<const Function*> > ActualCalleesTy;
+ typedef std::map<const Function*, DSGraph*> DSInfoTy;
public:
- typedef hash_set<const Function*>::const_iterator callee_iterator;
+ typedef std::set<const Function*>::const_iterator callee_iterator;
private:
/// TargetData, comes in handy
@@ -91,6 +91,14 @@
ActualCallees[I].insert(F);
}
+ template<class Iterator>
+ void callee_add_many(const Instruction* I, Iterator _begin, Iterator _end) {
+ ActualCallees[I].insert(_begin,_end);
+// typename ActualCalleesTy::mapped_type& S = ActualCallees[I];
+// for (; _begin != _end; ++_begin)
+// S.insert(*_begin);
+ }
+
DataStructures(intptr_t id, const char* name)
: ModulePass(id), TD(0), GraphSource(0), printname(name), GlobalsGraph(0) {
//a dummy node for empty call sites
@@ -103,7 +111,7 @@
public:
/// print - Print out the analysis results...
///
- void print(std::ostream &O, const Module *M) const;
+ void print(llvm::raw_ostream &O, const Module *M) const;
void dumpCallGraph() const;
callee_iterator callee_begin(const Instruction *I) const {
@@ -135,7 +143,8 @@
void callee_get_keys(std::vector<const Instruction*>& keys) {
for (ActualCalleesTy::const_iterator ii = ActualCallees.begin(),
ee = ActualCallees.end(); ii != ee; ++ii)
- keys.push_back(ii->first);
+ if (ii->first)
+ keys.push_back(ii->first);
}
virtual void releaseMemory();
@@ -147,7 +156,7 @@
/// getDSGraph - Return the data structure graph for the specified function.
///
virtual DSGraph *getDSGraph(const Function &F) const {
- hash_map<const Function*, DSGraph*>::const_iterator I = DSInfo.find(&F);
+ std::map<const Function*, DSGraph*>::const_iterator I = DSInfo.find(&F);
assert(I != DSInfo.end() && "Function not in module!");
return I->second;
}
@@ -226,7 +235,7 @@
///
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired<LocalDataStructures>();
- AU.addPreserved<TargetData>();
+ AU.addPreserved<EntryPointAnalysis>();
AU.setPreservesCFG();
}
};
@@ -245,6 +254,8 @@
const char* debugname;
bool useCallGraph;
+ EntryPointAnalysis* EP;
+
public:
static char ID;
//Child constructor (CBU)
@@ -260,7 +271,8 @@
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired<StdLibDataStructures>();
- AU.addPreserved<TargetData>();
+ AU.addRequired<EntryPointAnalysis>();
+ AU.addPreserved<EntryPointAnalysis>();
AU.setPreservesCFG();
}
@@ -270,15 +282,15 @@
private:
void calculateGraph(DSGraph* G);
- void inlineUnresolved(DSGraph* G);
-
unsigned calculateGraphs(const Function *F,
std::vector<const Function*> &Stack,
unsigned &NextID,
- hash_map<const Function*, unsigned> &ValMap);
+ std::map<const Function*, unsigned> &ValMap);
void CloneAuxIntoGlobal(DSGraph* G);
+ void cloneGlobalsInto(DSGraph* G);
+ void cloneIntoGlobals(DSGraph* G);
void finalizeGlobals(void);
};
@@ -302,7 +314,8 @@
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired<BUDataStructures>();
- AU.addPreserved<TargetData>();
+ AU.addRequired<EntryPointAnalysis > ();
+ AU.addPreserved<EntryPointAnalysis>();
AU.setPreservesCFG();
}
@@ -325,7 +338,6 @@
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired<CompleteBUDataStructures>();
- AU.addPreserved<TargetData>();
AU.setPreservesCFG();
}
@@ -336,7 +348,7 @@
/// by the bottom-up pass.
///
class TDDataStructures : public DataStructures {
- hash_set<const Function*> ArgsRemainIncomplete;
+ std::set<const Function*> ArgsRemainIncomplete;
/// CallerCallEdges - For a particular graph, we keep a list of these records
/// which indicates which graphs call this function and from where.
@@ -370,7 +382,7 @@
static char ID;
TDDataStructures(intptr_t CID = (intptr_t)&ID, const char* printname = "td.", bool useEQ = false)
: DataStructures(CID, printname), useEQBU(useEQ) {}
- ~TDDataStructures() { releaseMemory(); }
+ ~TDDataStructures();
virtual bool runOnModule(Module &M);
@@ -383,16 +395,15 @@
AU.addRequired<BUDataStructures>();
AU.addPreserved<BUDataStructures>();
}
- AU.addPreserved<TargetData>();
AU.setPreservesCFG();
}
private:
void markReachableFunctionsExternallyAccessible(DSNode *N,
- hash_set<DSNode*> &Visited);
+ std::set<DSNode*> &Visited);
void InlineCallersIntoGraph(DSGraph* G);
- void ComputePostOrder(const Function &F, hash_set<DSGraph*> &Visited,
+ void ComputePostOrder(const Function &F, std::set<DSGraph*> &Visited,
std::vector<DSGraph*> &PostOrder);
};
@@ -406,6 +417,7 @@
EQTDDataStructures()
:TDDataStructures((intptr_t)&ID, "eqtd.", false)
{}
+ ~EQTDDataStructures();
};
/// SteensgaardsDataStructures - Analysis that computes a context-insensitive
@@ -449,8 +461,7 @@
return ResultGraph;
}
- void print(OStream O, const Module *M) const;
- void print(std::ostream &O, const Module *M) const;
+ void print(llvm::raw_ostream &O, const Module *M) const;
};
Removed: poolalloc/trunk/include/poolalloc/ADT/HashExtras.h
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/include/poolalloc/ADT/HashExtras.h?rev=97714&view=auto
==============================================================================
--- poolalloc/trunk/include/poolalloc/ADT/HashExtras.h (original)
+++ poolalloc/trunk/include/poolalloc/ADT/HashExtras.h (removed)
@@ -1,49 +0,0 @@
-//===-- poolalloc/ADT/HashExtras.h - STL hashing for LLVM -------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file contains some templates that are useful if you are working with the
-// STL Hashed containers.
-//
-// No library is required when using these functions.
-//
-// This header files is a modification of HashExtras.h from LLVM. It is GNU
-// C++ specific.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef POOLALLOC_ADT_HASHEXTRAS_H
-#define POOLALLOC_ADT_HASHEXTRAS_H
-
-#include <functional>
-#include <ext/hash_map>
-#include <ext/hash_set>
-#include <string>
-
-// Cannot specialize hash template from outside of the std namespace.
-namespace __gnu_cxx {
-
-// Provide a hash function for arbitrary pointers...
-template <class T> struct hash<T *> {
- inline size_t operator()(const T *Val) const {
- return reinterpret_cast<size_t>(Val);
- }
-};
-
-template <> struct hash<std::string> {
- size_t operator()(std::string const &str) const {
- return hash<char const *>()(str.c_str());
- }
-};
-
-} // End namespace std
-
-// Use the namespace so that we don't need to state it explictly.
-using namespace __gnu_cxx;
-
-#endif
Modified: poolalloc/trunk/include/poolalloc/PoolAllocate.h
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/include/poolalloc/PoolAllocate.h?rev=97715&r1=97714&r2=97715&view=diff
==============================================================================
--- poolalloc/trunk/include/poolalloc/PoolAllocate.h (original)
+++ poolalloc/trunk/include/poolalloc/PoolAllocate.h Wed Mar 3 20:28:41 2010
@@ -29,7 +29,6 @@
#include "llvm/Support/CommandLine.h"
#include "dsa/DataStructure.h"
-#include "poolalloc/ADT/HashExtras.h"
#include "poolalloc/Config/config.h"
#include <set>
@@ -60,7 +59,7 @@
/// MarkedNodes - The set of nodes which are not locally pool allocatable in
/// the current function.
///
- hash_set<const DSNode*> MarkedNodes;
+ std::set<const DSNode*> MarkedNodes;
/// F - The function this FuncInfo corresponds to.
///
@@ -131,7 +130,7 @@
virtual PA::FuncInfo *getFuncInfoOrClone(const Function &F) {return 0;}
virtual Function *getOrigFunctionFromClone(const Function *F) const {return 0;}
- virtual const Type * getPoolType() {return 0;}
+ virtual const Type * getPoolType(LLVMContext*) {return 0;}
virtual bool hasDSGraph (const Function & F) const {
return Graphs->hasDSGraph (F);
@@ -273,8 +272,8 @@
Instruction *IPHint = 0);
/// getPoolType - Return the type of a pool descriptor
- const Type * getPoolType() {
- const IntegerType * IT = IntegerType::getInt8Ty(getGlobalContext());
+ const Type * getPoolType(LLVMContext* C) {
+ const IntegerType * IT = IntegerType::getInt8Ty(*C);
Type * VoidPtrType = PointerType::getUnqual(IT);
if (SAFECodeEnabled)
return ArrayType::get(VoidPtrType, 92);
@@ -336,14 +335,15 @@
// In short, we need to filter out the case where we find a pool handle,
// but it's only accessible from a clone and not the original function.
//
+ //FIXME: handle allocators
assert ((isa<GlobalVariable>(Pool) ||
- isa<AllocationInst>(Pool) ||
+ isa<AllocaInst>(Pool) ||
isa<Argument>(Pool) ||
isa<Constant>(Pool)) &&
"Pool of unknown type!\n");
if ((isa<GlobalVariable>(Pool)) || (isa<Constant>(Pool))) {
return Pool;
- } else if (AllocationInst * AI = dyn_cast<AllocationInst>(Pool)) {
+ } else if (AllocaInst * AI = dyn_cast<AllocaInst>(Pool)) {
if (AI->getParent()->getParent() == &F)
return Pool;
} else if (Argument * Arg = dyn_cast<Argument>(Pool)) {
@@ -532,7 +532,7 @@
virtual Value * getGlobalPool (const DSNode * Node);
virtual Value * getPool (const DSNode * N, Function & F);
- virtual void print(std::ostream &OS, const Module * M) const;
+ virtual void print(llvm::raw_ostream &OS, const Module * M) const;
virtual void dump() const;
};
Modified: poolalloc/trunk/lib/AssistDS/FuncSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/AssistDS/FuncSpec.cpp?rev=97715&r1=97714&r2=97715&view=diff
==============================================================================
--- poolalloc/trunk/lib/AssistDS/FuncSpec.cpp (original)
+++ poolalloc/trunk/lib/AssistDS/FuncSpec.cpp Wed Mar 3 20:28:41 2010
@@ -14,6 +14,8 @@
#include "llvm/Pass.h"
#include "llvm/Transforms/Utils/Cloning.h"
#include "llvm/ADT/Statistic.h"
+#include "llvm/Support/FormattedStream.h"
+
#include <set>
#include <map>
#include <vector>
@@ -40,11 +42,11 @@
if (const PointerType* Ty = dyn_cast<PointerType>(ii->getType())) {
if (isa<FunctionType>(Ty->getElementType())) {
FPArgs.push_back(ii->getArgNo());
- cerr << "Eligable: " << I->getNameStr() << "\n";
+ errs() << "Eligable: " << I->getNameStr() << "\n";
}
} else if (isa<FunctionType>(ii->getType())) {
FPArgs.push_back(ii->getArgNo());
- cerr << "Eligable: " << I->getNameStr() << "\n";
+ errs() << "Eligable: " << I->getNameStr() << "\n";
}
for(Value::use_iterator ui = I->use_begin(), ue = I->use_end();
ui != ue; ++ui)
Modified: poolalloc/trunk/lib/DSA/BottomUpClosure.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/BottomUpClosure.cpp?rev=97715&r1=97714&r2=97715&view=diff
==============================================================================
--- poolalloc/trunk/lib/DSA/BottomUpClosure.cpp (original)
+++ poolalloc/trunk/lib/DSA/BottomUpClosure.cpp Wed Mar 3 20:28:41 2010
@@ -40,30 +40,41 @@
//
bool BUDataStructures::runOnModule(Module &M) {
init(&getAnalysis<StdLibDataStructures>(), false, true, false, false );
+ EP = &getAnalysis<EntryPointAnalysis>();
return runOnModuleInternal(M);
}
bool BUDataStructures::runOnModuleInternal(Module& M) {
std::vector<const Function*> Stack;
- hash_map<const Function*, unsigned> ValMap;
+ std::map<const Function*, unsigned> ValMap;
unsigned NextID = 1;
- Function *MainFunc = M.getFunction("main");
- if (MainFunc && !MainFunc->isDeclaration()) {
- calculateGraphs(MainFunc, Stack, NextID, ValMap);
- CloneAuxIntoGlobal(getDSGraph(*MainFunc));
- } else {
- DEBUG(errs() << debugname << ": No 'main' function found!\n");
+ std::vector<const Function*> EntryPoints;
+ EP = &getAnalysis<EntryPointAnalysis>();
+ EP->findEntryPoints(M, EntryPoints);
+
+ for (std::vector<const Function*>::iterator ii = EntryPoints.begin(),
+ ee = EntryPoints.end(); ii != ee; ++ii)
+ if (!hasDSGraph(**ii))
+ calculateGraphs(*ii, Stack, NextID, ValMap);
+
+ for (std::vector<const Function*>::iterator ii = EntryPoints.begin(),
+ ee = EntryPoints.end(); ii != ee; ++ii) {
+ cloneGlobalsInto(getDSGraph(**ii));
+ calculateGraph(getDSGraph(**ii));
+ CloneAuxIntoGlobal(getDSGraph(**ii));
}
// Calculate the graphs for any functions that are unreachable from main...
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
if (!I->isDeclaration() && !hasDSGraph(*I)) {
- if (MainFunc)
- DEBUG(errs() << debugname << ": Function unreachable from main: "
- << I->getName() << "\n");
- calculateGraphs(I, Stack, NextID, ValMap); // Calculate all graphs.
+ DEBUG(
+ if (EntryPoints.size())
+ errs() << debugname << ": Function unreachable from main: "
+ << I->getName() << "\n";
+ );
+ calculateGraphs(I, Stack, NextID, ValMap); // Calculate all graphs.
CloneAuxIntoGlobal(getDSGraph(*I));
}
@@ -83,7 +94,7 @@
// incomplete in the globals graph.
//
- finalizeGlobals();
+ //finalizeGlobals();
GlobalsGraph->removeTriviallyDeadNodes(true);
GlobalsGraph->maskIncompleteMarkers();
@@ -96,18 +107,10 @@
// Merge the globals variables (not the calls) from the globals graph back
// into the main function's graph so that the main function contains all of
// the information about global pools and GV usage in the program.
- if (MainFunc && !MainFunc->isDeclaration()) {
- DSGraph* MainGraph = getOrCreateGraph(MainFunc);
- const DSGraph* GG = MainGraph->getGlobalsGraph();
- ReachabilityCloner RC(MainGraph, GG,
- DSGraph::DontCloneCallNodes |
- DSGraph::DontCloneAuxCallNodes);
-
- // Clone the global nodes into this graph.
- for (DSScalarMap::global_iterator I = GG->getScalarMap().global_begin(),
- E = GG->getScalarMap().global_end(); I != E; ++I)
- if (isa<GlobalVariable>(*I))
- RC.getClonedNH(GG->getNodeForValue(*I));
+ for (std::vector<const Function*>::iterator ii = EntryPoints.begin(),
+ ee = EntryPoints.end(); ii != ee; ++ii) {
+ DSGraph* MainGraph = getOrCreateGraph(*ii);
+ cloneGlobalsInto(MainGraph);
MainGraph->maskIncompleteMarkers();
MainGraph->markIncompleteNodes(DSGraph::MarkFormalArgs |
@@ -130,7 +133,7 @@
BadCalls.insert(*ii);
else
GoodCalls.insert(*ii);
- hash_set<const DSNode*> reachable;
+ std::set<const DSNode*> reachable;
for (std::set<DSCallSite>::iterator ii = BadCalls.begin(),
ee = BadCalls.end(); ii != ee; ++ii) {
ii->getRetVal().getNode()->markReachableNodes(reachable);
@@ -189,7 +192,7 @@
unsigned BUDataStructures::calculateGraphs(const Function *F,
std::vector<const Function*> &Stack,
unsigned &NextID,
- hash_map<const Function*, unsigned> &ValMap) {
+ std::map<const Function*, unsigned> &ValMap) {
assert(!ValMap.count(F) && "Shouldn't revisit functions!");
unsigned Min = NextID++, MyID = Min;
ValMap[F] = Min;
@@ -216,7 +219,7 @@
const Function *Callee = CalleeFunctions[i];
unsigned M;
// Have we visited the destination function yet?
- hash_map<const Function*, unsigned>::iterator It = ValMap.find(Callee);
+ std::map<const Function*, unsigned>::iterator It = ValMap.find(Callee);
if (It == ValMap.end()) // No, visit it now.
M = calculateGraphs(Callee, Stack, NextID, ValMap);
else // Yes, get it's number.
@@ -338,35 +341,6 @@
void BUDataStructures::calculateGraph(DSGraph* Graph) {
DEBUG(Graph->AssertGraphOK(); Graph->getGlobalsGraph()->AssertGraphOK());
- // If this graph contains the main function, clone the globals graph into this
- // graph before we inline callees and other fun stuff.
- bool ContainsMain = false;
- DSGraph::ReturnNodesTy &ReturnNodes = Graph->getReturnNodes();
-
- for (DSGraph::ReturnNodesTy::iterator I = ReturnNodes.begin(),
- E = ReturnNodes.end(); I != E; ++I)
- if (I->first->hasExternalLinkage() && I->first->getName() == "main") {
- ContainsMain = true;
- break;
- }
-
- // If this graph contains main, copy the contents of the globals graph over.
- // Note that this is *required* for correctness. If a callee contains a use
- // of a global, we have to make sure to link up nodes due to global-argument
- // bindings.
- if (ContainsMain) {
- const DSGraph* GG = Graph->getGlobalsGraph();
- ReachabilityCloner RC(Graph, GG,
- DSGraph::DontCloneCallNodes |
- DSGraph::DontCloneAuxCallNodes);
-
- // Clone the global nodes into this graph.
- for (DSScalarMap::global_iterator I = GG->getScalarMap().global_begin(),
- E = GG->getScalarMap().global_end(); I != E; ++I)
- if (isa<GlobalVariable>(*I))
- RC.getClonedNH(GG->getNodeForValue(*I));
- }
-
// Move our call site list into TempFCs so that inline call sites go into the
// new call site list and doesn't invalidate our iterators!
std::list<DSCallSite> TempFCs;
@@ -385,6 +359,10 @@
// Fast path for noop calls. Note that we don't care about merging globals
// in the callee with nodes in the caller here.
if (CS.getRetVal().isNull() && CS.getNumPtrArgs() == 0) {
+ if (!CS.isDirectCall()) {
+ GetAnyCallees(CS, CalledFuncs);
+ callee_add_many(TheCall, CalledFuncs.begin(), CalledFuncs.end());
+ }
TempFCs.erase(TempFCs.begin());
continue;
}
@@ -392,6 +370,11 @@
GetAllCallees(CS, CalledFuncs);
if (CalledFuncs.empty()) {
+ //Get any callees we do have for the callgraph
+ if (!CS.isDirectCall()) {
+ GetAnyCallees(CS, CalledFuncs);
+ callee_add_many(TheCall, CalledFuncs.begin(), CalledFuncs.end());
+ }
// Remember that we could not resolve this yet!
AuxCallsList.splice(AuxCallsList.end(), TempFCs, TempFCs.begin());
continue;
@@ -508,150 +491,30 @@
// reach live nodes as live.
Graph->removeDeadNodes(DSGraph::KeepUnreachableGlobals);
- // When this graph is finalized, clone the globals in the graph into the
- // globals graph to make sure it has everything, from all graphs.
- DSScalarMap &MainSM = Graph->getScalarMap();
- ReachabilityCloner RC(GlobalsGraph, Graph, DSGraph::StripAllocaBit);
-
- // Clone everything reachable from globals in the function graph into the
- // globals graph.
- for (DSScalarMap::global_iterator I = MainSM.global_begin(),
- E = MainSM.global_end(); I != E; ++I)
- RC.getClonedNH(MainSM[*I]);
-
+ cloneIntoGlobals(Graph);
//Graph.writeGraphToFile(cerr, "bu_" + F.getName());
}
-void BUDataStructures::inlineUnresolved(DSGraph* Graph) {
-
- // Move our call site list into TempFCs so that inline call sites go into the
- // new call site list and doesn't invalidate our iterators!
- std::list<DSCallSite> TempFCs = Graph->getAuxFunctionCalls();
-
- for (DSGraph::afc_iterator aii = TempFCs.begin(), aee = TempFCs.end();
- aii != aee; ++aii) {
- std::vector<const Function*> CalledFuncs;
- DSCallSite CS = *aii;
- GetAnyCallees(CS, CalledFuncs);
- if (CalledFuncs.empty())
- continue;
-
- DSGraph *GI;
- Instruction *TheCall = CS.getCallSite().getInstruction();
-
- for (std::vector<const Function*>::iterator ii = CalledFuncs.begin(), ee = CalledFuncs.end();
- ii != ee; ++ii)
- callee_add(TheCall, *ii);
-
- if (CalledFuncs.size() == 1 && hasDSGraph(*CalledFuncs[0])) {
- const Function *Callee = CalledFuncs[0];
-
- // Get the data structure graph for the called function.
- GI = getDSGraph(*Callee); // Graph to inline
- if (GI == Graph) continue;
- DEBUG(errs() << " Inlining graph for " << Callee->getName()
- << "[" << GI->getGraphSize() << "+"
- << GI->getAuxFunctionCalls().size() << "] into '"
- << Graph->getFunctionNames() << "' [" << Graph->getGraphSize() <<"+"
- << Graph->getAuxFunctionCalls().size() << "]\n");
- Graph->mergeInGraph(CS, *Callee, *GI,
- DSGraph::StripAllocaBit|DSGraph::DontCloneCallNodes |
- DSGraph::DontCloneAuxCallNodes);
- ++NumInlines;
- } else {
- DEBUG(errs() << "In Fns: " << Graph->getFunctionNames() << "\n");
- DEBUG(std::cerr << " calls " << CalledFuncs.size()
- << " fns from site: " << CS.getCallSite().getInstruction()
- << " " << *CS.getCallSite().getInstruction());
- DEBUG(errs() << " Fns =");
- unsigned NumPrinted = 0;
-
- for (std::vector<const Function*>::iterator I = CalledFuncs.begin(),
- E = CalledFuncs.end(); I != E; ++I)
- if (NumPrinted++ < 8) {
- DEBUG(errs() << " " << (*I)->getName());
- }
- DEBUG(errs() << "\n");
-
- for (unsigned x = 0; x < CalledFuncs.size(); )
- if (!hasDSGraph(*CalledFuncs[x]))
- CalledFuncs.erase(CalledFuncs.begin() + x);
- else
- ++x;
- if (!CalledFuncs.size())
- continue;
-
- // See if we already computed a graph for this set of callees.
- std::sort(CalledFuncs.begin(), CalledFuncs.end());
- std::pair<DSGraph*, std::vector<DSNodeHandle> > &IndCallGraph =
- IndCallGraphMap[CalledFuncs];
-
- if (IndCallGraph.first == Graph) continue;
-
- if (IndCallGraph.first == 0) {
- std::vector<const Function*>::iterator I = CalledFuncs.begin(),
- E = CalledFuncs.end();
-
- // Start with a copy of the first graph.
- GI = IndCallGraph.first = new DSGraph(getDSGraph(**I), GlobalECs);
- GI->setGlobalsGraph(Graph->getGlobalsGraph());
- std::vector<DSNodeHandle> &Args = IndCallGraph.second;
-
- // Get the argument nodes for the first callee. The return value is
- // the 0th index in the vector.
- GI->getFunctionArgumentsForCall(*I, Args);
-
- // Merge all of the other callees into this graph.
- for (++I; I != E; ++I) {
- // If the graph already contains the nodes for the function, don't
- // bother merging it in again.
- if (!GI->containsFunction(*I)) {
- GI->cloneInto(getDSGraph(**I));
- ++NumInlines;
- }
-
- std::vector<DSNodeHandle> NextArgs;
- GI->getFunctionArgumentsForCall(*I, NextArgs);
- unsigned i = 0, e = Args.size();
- for (; i != e; ++i) {
- if (i == NextArgs.size()) break;
- Args[i].mergeWith(NextArgs[i]);
- }
- for (e = NextArgs.size(); i != e; ++i)
- Args.push_back(NextArgs[i]);
- }
-
- // Clean up the final graph!
- GI->removeDeadNodes(DSGraph::KeepUnreachableGlobals);
- } else {
- DEBUG(errs() << "***\n*** RECYCLED GRAPH ***\n***\n");
- }
-
- GI = IndCallGraph.first;
-
- // Merge the unified graph into this graph now.
- DEBUG(errs() << " Inlining multi callee graph "
- << "[" << GI->getGraphSize() << "+"
- << GI->getAuxFunctionCalls().size() << "] into '"
- << Graph->getFunctionNames() << "' [" << Graph->getGraphSize() <<"+"
- << Graph->getAuxFunctionCalls().size() << "]\n" );
-
- Graph->mergeInGraph(CS, IndCallGraph.second, *GI,
- DSGraph::StripAllocaBit |
- DSGraph::DontCloneCallNodes |
- DSGraph::DontCloneAuxCallNodes);
- ++NumInlines;
- }
- }
-
- // Recompute the Incomplete markers
- Graph->maskIncompleteMarkers();
- Graph->markIncompleteNodes(DSGraph::MarkFormalArgs);
-
- // Delete dead nodes. Treat globals that are unreachable but that can
- // reach live nodes as live.
- Graph->removeDeadNodes(DSGraph::KeepUnreachableGlobals);
+//For Entry Points
+void BUDataStructures::cloneGlobalsInto(DSGraph* Graph) {
+ // If this graph contains main, copy the contents of the globals graph over.
+ // Note that this is *required* for correctness. If a callee contains a use
+ // of a global, we have to make sure to link up nodes due to global-argument
+ // bindings.
+ const DSGraph* GG = Graph->getGlobalsGraph();
+ ReachabilityCloner RC(Graph, GG,
+ DSGraph::DontCloneCallNodes |
+ DSGraph::DontCloneAuxCallNodes);
+
+ // Clone the global nodes into this graph.
+ for (DSScalarMap::global_iterator I = Graph->getScalarMap().global_begin(),
+ E = Graph->getScalarMap().global_end(); I != E; ++I)
+ if (isa<GlobalVariable > (*I))
+ RC.getClonedNH(GG->getNodeForValue(*I));
+}
+//For all graphs
+void BUDataStructures::cloneIntoGlobals(DSGraph* Graph) {
// When this graph is finalized, clone the globals in the graph into the
// globals graph to make sure it has everything, from all graphs.
DSScalarMap &MainSM = Graph->getScalarMap();
@@ -662,6 +525,5 @@
for (DSScalarMap::global_iterator I = MainSM.global_begin(),
E = MainSM.global_end(); I != E; ++I)
RC.getClonedNH(MainSM[*I]);
-
- //Graph.writeGraphToFile(cerr, "bu_" + F.getName());
}
+
Modified: poolalloc/trunk/lib/DSA/CompleteBottomUp.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/CompleteBottomUp.cpp?rev=97715&r1=97714&r2=97715&view=diff
==============================================================================
--- poolalloc/trunk/lib/DSA/CompleteBottomUp.cpp (original)
+++ poolalloc/trunk/lib/DSA/CompleteBottomUp.cpp Wed Mar 3 20:28:41 2010
@@ -47,18 +47,18 @@
std::vector<const Instruction*> keys;
callee_get_keys(keys);
+ DSGraph* G = getGlobalsGraph();
+ DSGraph::ScalarMapTy& SM = G->getScalarMap();
+
//mege nodes in the global graph for these functions
for (std::vector<const Instruction*>::iterator ii = keys.begin(), ee = keys.end();
ii != ee; ++ii) {
- if (*ii) {
- callee_iterator csi = callee_begin(*ii), cse = callee_end(*ii);
- if (csi != cse) ++csi;
- DSGraph* G = getOrCreateGraph((*ii)->getParent()->getParent());
- for ( ; csi != cse; ++csi) {
- G->getNodeForValue(*csi).mergeWith(G->getNodeForValue((*ii)->getOperand(0)));
- G->getNodeForValue((*ii)->getOperand(0)).getNode()->setGlobalMarker();
- G->getNodeForValue((*ii)->getOperand(0)).getNode()->addGlobal(*csi);
- }
+ callee_iterator csi = callee_begin(*ii), cse = callee_end(*ii);
+ if (csi != cse && SM.find(*csi) != SM.end()) {
+ DSNodeHandle& SrcNH = SM.find(*csi)->second;
+ ++csi;
+ for (; csi != cse; ++csi)
+ SrcNH.mergeWith(SM.find(*csi)->second);
}
}
}
Modified: poolalloc/trunk/lib/DSA/DataStructure.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/DataStructure.cpp?rev=97715&r1=97714&r2=97715&view=diff
==============================================================================
--- poolalloc/trunk/lib/DSA/DataStructure.cpp (original)
+++ poolalloc/trunk/lib/DSA/DataStructure.cpp Wed Mar 3 20:28:41 2010
@@ -30,7 +30,6 @@
#include "llvm/ADT/Statistic.h"
#include "llvm/Support/Timer.h"
#include "llvm/Support/raw_ostream.h"
-#include "poolalloc/ADT/HashExtras.h"
#include <iostream>
#include <algorithm>
@@ -42,8 +41,8 @@
STATISTIC (NumCallNodesMerged, "Number of call nodes merged");
STATISTIC (NumNodeAllocated , "Number of nodes allocated");
STATISTIC (NumDNE , "Number of nodes removed by reachability");
- STATISTIC (NumTrivialDNE , "Number of nodes trivially removed");
- STATISTIC (NumTrivialGlobalDNE, "Number of globals trivially removed");
+// STATISTIC (NumTrivialDNE , "Number of nodes trivially removed");
+// STATISTIC (NumTrivialGlobalDNE, "Number of globals trivially removed");
#ifdef LLVA_KERNEL
STATISTIC (LostPools , "Number of pools lost to DSNode Merge");
#endif
@@ -800,8 +799,8 @@
// Check to see if we have a pointer & integer mismatch going on here,
// loading a pointer as a long, for example.
//
- if ((SubType->isInteger() && isa<PointerType>(NewTy)) ||
- (NewTy->isInteger() && isa<PointerType>(SubType)))
+ if ((SubType->isIntegerTy() && NewTy->isPointerTy()) ||
+ (NewTy->isIntegerTy() && SubType->isPointerTy()))
return false;
} else if (NewTySize > SubTypeSize && NewTySize <= PadSize) {
// We are accessing the field, plus some structure padding. Ignore the
@@ -1098,6 +1097,8 @@
}
}
+ if (!createDest) return DSNodeHandle(0,0);
+
DSNode *DN = new DSNode(*SN, Dest, true /* Null out all links */);
DN->maskNodeTypes(BitsToKeep);
NH = DN;
@@ -1494,7 +1495,7 @@
}
// dump - Allow inspection of graph in a debugger.
-void DSGraph::dump() const { print(cerr); }
+void DSGraph::dump() const { print(errs()); }
/// remapLinks - Change all of the Links in the current node according to the
@@ -1540,8 +1541,8 @@
if (GlobalValue *GV = dyn_cast<GlobalValue>(Ptr)) {
N->addGlobal(GV);
- } else if (isa<MallocInst>(Ptr)) {
- N->setHeapMarker();
+// } else if (isa<MallocInst>(Ptr)) {
+// N->setHeapMarker();
} else if (isa<AllocaInst>(Ptr)) {
N->setAllocaMarker();
} else {
@@ -2200,6 +2201,7 @@
// we don't have to perform any non-trivial analysis here.
//
void DSGraph::removeTriviallyDeadNodes(bool updateForwarders) {
+#if 0
if (updateForwarders) {
/// NOTE: This code is disabled. This slows down DSA on 177.mesa
/// substantially!
@@ -2258,8 +2260,9 @@
// Make sure NumReferrers still agrees, if so, the node is truly dead.
if (Node.getNumReferrers() == Node.numGlobals()) {
for (DSNode::globals_iterator j = Node.globals_begin(), e = Node.globals_end();
- j != e; ++j)
- ScalarMap.erase(*j);
+ j != e; ++j)
+ if (ScalarMap.find(*j) != ScalarMap.end())
+ ScalarMap.erase(*j);
Node.makeNodeDead();
++NumTrivialGlobalDNE;
}
@@ -2275,7 +2278,7 @@
++NI;
}
}
-
+#endif
removeIdenticalCalls(FunctionCalls);
removeIdenticalCalls(AuxFunctionCalls);
}
@@ -2285,7 +2288,7 @@
/// DSNodes, marking any nodes which are reachable. All reachable nodes it adds
/// to the set, which allows it to only traverse visited nodes once.
///
-void DSNode::markReachableNodes(hash_set<const DSNode*> &ReachableNodes) const {
+void DSNode::markReachableNodes(std::set<const DSNode*> &ReachableNodes) const {
if (this == 0) return;
assert(getForwardNode() == 0 && "Cannot mark a forwarded node!");
if (ReachableNodes.insert(this).second) // Is newly reachable?
@@ -2294,7 +2297,7 @@
I->getNode()->markReachableNodes(ReachableNodes);
}
-void DSCallSite::markReachableNodes(hash_set<const DSNode*> &Nodes) const {
+void DSCallSite::markReachableNodes(std::set<const DSNode*> &Nodes) const {
getRetVal().getNode()->markReachableNodes(Nodes);
if (isIndirectCall()) getCalleeNode()->markReachableNodes(Nodes);
@@ -2307,8 +2310,8 @@
// true, otherwise return false. If an alive node is reachable, this node is
// marked as alive...
//
-static bool CanReachAliveNodes(DSNode *N, hash_set<const DSNode*> &Alive,
- hash_set<const DSNode*> &Visited,
+static bool CanReachAliveNodes(DSNode *N, std::set<const DSNode*> &Alive,
+ std::set<const DSNode*> &Visited,
bool IgnoreGlobals) {
if (N == 0) return false;
assert(N->getForwardNode() == 0 && "Cannot mark a forwarded node!");
@@ -2337,8 +2340,8 @@
// alive nodes.
//
static bool CallSiteUsesAliveArgs(const DSCallSite &CS,
- hash_set<const DSNode*> &Alive,
- hash_set<const DSNode*> &Visited,
+ std::set<const DSNode*> &Alive,
+ std::set<const DSNode*> &Visited,
bool IgnoreGlobals) {
if (CanReachAliveNodes(CS.getRetVal().getNode(), Alive, Visited,
IgnoreGlobals))
@@ -2369,7 +2372,7 @@
// FIXME: Merge non-trivially identical call nodes...
// Alive - a set that holds all nodes found to be reachable/alive.
- hash_set<const DSNode*> Alive;
+ std::set<const DSNode*> Alive;
std::vector<std::pair<const Value*, DSNode*> > GlobalNodes;
// Copy and merge all information about globals to the GlobalsGraph if this is
@@ -2417,8 +2420,8 @@
// value (which makes them live in turn), and continue till no more are found.
//
bool Iterate;
- hash_set<const DSNode*> Visited;
- hash_set<const DSCallSite*> AuxFCallsAlive;
+ std::set<const DSNode*> Visited;
+ std::set<const DSCallSite*> AuxFCallsAlive;
do {
Visited.clear();
// If any global node points to a non-global that is "alive", the global is
@@ -2748,8 +2751,8 @@
return;
}
- cerr << *From;
- cerr << *To;
+ errs() << *From;
+ errs() << *To;
assert(0 && "Do not know how to copy this yet!");
abort();
}
@@ -2913,12 +2916,12 @@
//
if (DSGraphsStolen) return;
- hash_set<DSGraph*> toDelete;
+ std::set<DSGraph*> toDelete;
for (DSInfoTy::iterator I = DSInfo.begin(), E = DSInfo.end(); I != E; ++I) {
I->second->getReturnNodes().clear();
toDelete.insert(I->second);
}
- for (hash_set<DSGraph*>::iterator I = toDelete.begin(), E = toDelete.end(); I != E; ++I)
+ for (std::set<DSGraph*>::iterator I = toDelete.begin(), E = toDelete.end(); I != E; ++I)
delete *I;
// Empty map so next time memory is released, data structures are not
Modified: poolalloc/trunk/lib/DSA/DataStructureStats.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/DataStructureStats.cpp?rev=97715&r1=97714&r2=97715&view=diff
==============================================================================
--- poolalloc/trunk/lib/DSA/DataStructureStats.cpp (original)
+++ poolalloc/trunk/lib/DSA/DataStructureStats.cpp Wed Mar 3 20:28:41 2010
@@ -17,7 +17,6 @@
#include "llvm/Instructions.h"
#include "llvm/Pass.h"
#include "llvm/Support/InstVisitor.h"
-#include "llvm/Support/Streams.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/FormattedStream.h"
@@ -61,7 +60,7 @@
void visitStore(StoreInst &SI);
/// Debugging support methods
- void print(std::ostream &O, const Module* = 0) const { }
+ void print(llvm::raw_ostream &O, const Module* = 0) const { }
};
static RegisterPass<DSGraphStats> Z("dsstats", "DS Graph Statistics");
Modified: poolalloc/trunk/lib/DSA/GraphChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/GraphChecker.cpp?rev=97715&r1=97714&r2=97715&view=diff
==============================================================================
--- poolalloc/trunk/lib/DSA/GraphChecker.cpp (original)
+++ poolalloc/trunk/lib/DSA/GraphChecker.cpp Wed Mar 3 20:28:41 2010
@@ -26,7 +26,7 @@
#include "dsa/DataStructure.h"
#include "dsa/DSGraph.h"
#include "llvm/Support/CommandLine.h"
-#include "llvm/Support/Streams.h"
+#include "llvm/Support/FormattedStream.h"
#include "llvm/Value.h"
#include <set>
using namespace llvm;
@@ -68,7 +68,7 @@
}
AU.setPreservesAll();
}
- void print(std::ostream &O, const Module *M) const {}
+ void print(llvm::raw_ostream &O, const Module *M) const {}
private:
void verify(const DSGraph* G);
@@ -87,8 +87,8 @@
DSGC::DSGC() : FunctionPass((intptr_t)&ID) {
if (!AbortIfAnyCollapsed && AbortIfCollapsed.empty() &&
CheckFlags.empty() && AbortIfMerged.empty()) {
- cerr << "The -datastructure-gc is useless if you don't specify any"
- << " -dsgc-* options. See the -help-hidden output for a list.\n";
+ errs() << "The -datastructure-gc is useless if you don't specify any"
+ << " -dsgc-* options. See the -help-hidden output for a list.\n";
abort();
}
}
@@ -126,8 +126,8 @@
for (DSGraph::node_const_iterator I = G->node_begin(), E = G->node_end();
I != E; ++I)
if (I->isNodeCompletelyFolded()) {
- cerr << "Node is collapsed: ";
- I->print(cerr, G);
+ errs() << "Node is collapsed: ";
+ I->print(errs(), G);
abort();
}
}
@@ -145,8 +145,8 @@
E = CheckFlags.end(); I != E; ++I) {
std::string::size_type ColonPos = I->rfind(':');
if (ColonPos == std::string::npos) {
- cerr << "Error: '" << *I
- << "' is an invalid value for the --dsgc-check-flags option!\n";
+ errs() << "Error: '" << *I
+ << "' is an invalid value for the --dsgc-check-flags option!\n";
abort();
}
@@ -161,7 +161,7 @@
case 'M': Flags |= DSNode::ModifiedNode; break;
case 'R': Flags |= DSNode::ReadNode; break;
case 'A': Flags |= DSNode::ArrayNode; break;
- default: cerr << "Invalid DSNode flag!\n"; abort();
+ default: errs() << "Invalid DSNode flag!\n"; abort();
}
CheckFlagsM[std::string(I->begin(), I->begin()+ColonPos)] = Flags;
}
@@ -179,25 +179,25 @@
// Verify it is not collapsed if it is not supposed to be...
if (N->isNodeCompletelyFolded() && AbortIfCollapsedS.count(Name)) {
- cerr << "Node for value '%" << Name << "' is collapsed: ";
- N->print(cerr, G);
+ errs() << "Node for value '%" << Name << "' is collapsed: ";
+ N->print(errs(), G);
abort();
}
if (CheckFlagsM.count(Name) && CheckFlagsM[Name] != N->getNodeFlags()) {
- cerr << "Node flags are not as expected for node: " << Name
- << " (" << CheckFlagsM[Name] << ":" <<N->getNodeFlags()
- << ")\n";
- N->print(cerr, G);
+ errs() << "Node flags are not as expected for node: " << Name
+ << " (" << CheckFlagsM[Name] << ":" <<N->getNodeFlags()
+ << ")\n";
+ N->print(errs(), G);
abort();
}
// Verify that it is not merged if it is not supposed to be...
if (AbortIfMergedS.count(Name)) {
if (AbortIfMergedNodes.count(N)) {
- cerr << "Nodes for values '%" << Name << "' and '%"
- << AbortIfMergedNodes[N] << "' is merged: ";
- N->print(cerr, G);
+ errs() << "Nodes for values '%" << Name << "' and '%"
+ << AbortIfMergedNodes[N] << "' is merged: ";
+ N->print(errs(), G);
abort();
}
AbortIfMergedNodes[N] = Name;
Modified: poolalloc/trunk/lib/DSA/Local.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/Local.cpp?rev=97715&r1=97714&r2=97715&view=diff
==============================================================================
--- poolalloc/trunk/lib/DSA/Local.cpp (original)
+++ poolalloc/trunk/lib/DSA/Local.cpp Wed Mar 3 20:28:41 2010
@@ -29,6 +29,7 @@
#include "llvm/ADT/DenseSet.h"
#include <iostream>
+#include <fstream>
// FIXME: This should eventually be a FunctionPass that is automatically
// aggregated into a Pass.
@@ -40,6 +41,9 @@
static RegisterPass<LocalDataStructures>
X("dsa-local", "Local Data Structure Analysis");
+static cl::opt<std::string> hasMagicSections("dsa-magic-sections",
+ cl::desc("File with section to global mapping")); //, cl::ReallyHidden);
+
namespace {
//===--------------------------------------------------------------------===//
// GraphBuilder Class
@@ -88,16 +92,18 @@
// Visitor functions, used to handle each instruction type we encounter...
friend class InstVisitor<GraphBuilder>;
- void visitMallocInst(MallocInst &MI)
- { setDestTo(MI, createNode()->setHeapMarker()); }
+ //FIXME: implement in stdlib pass
+// void visitMallocInst(MallocInst &MI)
+// { setDestTo(MI, createNode()->setHeapMarker()); }
void visitAllocaInst(AllocaInst &AI)
{ setDestTo(AI, createNode()->setAllocaMarker()); }
- void visitFreeInst(FreeInst &FI)
- { if (DSNode *N = getValueDest(FI.getOperand(0)).getNode())
- N->setHeapMarker();
- }
+ //FIXME: implement in stdlib pass
+ //void visitFreeInst(FreeInst &FI)
+ //{ if (DSNode *N = getValueDest(FI.getOperand(0)).getNode())
+// N->setHeapMarker();
+// }
//the simple ones
void visitPHINode(PHINode &PN);
@@ -145,16 +151,19 @@
// If there are any constant globals referenced in this function, merge
// their initializers into the local graph from the globals graph.
- if (g.getScalarMap().global_begin() != g.getScalarMap().global_end()) {
+ // This resolves indirect calls in some common cases
+ // Only merge info for nodes that already exist in the local pass
+ // otherwise leaf functions could contain less collapsing than the globals
+ // graph
+ if (g.getScalarMap().global_begin() != g.getScalarMap().global_end()) {
ReachabilityCloner RC(&g, g.getGlobalsGraph(), 0);
-
for (DSScalarMap::global_iterator I = g.getScalarMap().global_begin();
I != g.getScalarMap().global_end(); ++I)
- if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(*I))
- if (!GV->isDeclaration() && GV->isConstant())
+ if (const GlobalVariable * GV = dyn_cast<GlobalVariable > (*I))
+ //if (GV->isConstant())
RC.merge(g.getNodeForValue(GV), g.getGlobalsGraph()->getNodeForValue(GV));
}
-
+
g.markIncompleteNodes(DSGraph::MarkFormalArgs);
// Remove any nodes made dead due to merging...
@@ -167,6 +176,7 @@
{}
void mergeInGlobalInitializer(GlobalVariable *GV);
+ void mergeExternalGlobal(GlobalVariable* GV);
void mergeFunction(Function* F) { getValueDest(F); }
};
@@ -216,6 +226,8 @@
// Create a new global node for this global variable.
N = createNode(GV->getType()->getElementType());
N->addGlobal(GV);
+ if (GV->isDeclaration())
+ N->setExternGlobalMarker();
} else if (Function* GV = dyn_cast<Function>(V)) {
// Create a new global node for this function.
N = createNode();
@@ -642,11 +654,7 @@
->foldNodeCompletely();
return true;
case Intrinsic::vaend:
- case Intrinsic::dbg_func_start:
- case Intrinsic::dbg_region_end:
- case Intrinsic::dbg_stoppoint:
- case Intrinsic::dbg_region_start:
- case Intrinsic::dbg_declare:
+ case Intrinsic::memory_barrier:
return true; // noop
case Intrinsic::memcpy:
case Intrinsic::memmove: {
@@ -703,10 +711,6 @@
- case Intrinsic::eh_selector_i32:
- case Intrinsic::eh_selector_i64:
- case Intrinsic::eh_typeid_for_i32:
- case Intrinsic::eh_typeid_for_i64:
case Intrinsic::prefetch:
return true;
@@ -746,9 +750,8 @@
// Special case handling of certain libc allocation functions here.
if (Function *F = dyn_cast<Function>(Callee))
- if (F->isDeclaration())
- if (F->isIntrinsic() && visitIntrinsic(CS, F))
- return;
+ if (F->isIntrinsic() && visitIntrinsic(CS, F))
+ return;
// Set up the return value...
DSNodeHandle RetVal;
@@ -821,7 +824,7 @@
return;
}
- if (Ty->isIntOrIntVector() || Ty->isFPOrFPVector()) return;
+ if (Ty->isIntOrIntVectorTy() || Ty->isFPOrFPVectorTy()) return;
const TargetData &TD = NH.getNode()->getTargetData();
@@ -858,6 +861,57 @@
MergeConstantInitIntoNode(NH, GV->getType()->getElementType(), GV->getInitializer());
}
+void GraphBuilder::mergeExternalGlobal(GlobalVariable *GV) {
+ // Get a node handle to the global node and merge the initializer into it.
+ DSNodeHandle NH = getValueDest(GV);
+}
+
+// some evil programs use sections as linker generated arrays
+// read a description of this behavior in and apply it
+// format: numglobals section globals...
+// terminates when numglobals == 0
+void handleMagicSections(DSGraph* GlobalsGraph, Module& M) {
+ std::ifstream msf(hasMagicSections.c_str(), std::ifstream::in);
+ if (msf.good()) {
+ //no checking happens here
+ unsigned count = 0;
+ msf >> count;
+ while (count) {
+ std::string section;
+ msf >> section;
+ std::set<Value*> inSection;
+ for (Module::iterator MI = M.begin(), ME = M.end();
+ MI != ME; ++MI)
+ if (MI->hasSection() && MI->getSection() == section)
+ inSection.insert(MI);
+ for (Module::global_iterator MI = M.global_begin(), ME = M.global_end();
+ MI != ME; ++MI)
+ if (MI->hasSection() && MI->getSection() == section)
+ inSection.insert(MI);
+
+ for (unsigned x = 0; x < count; ++x) {
+ std::string global;
+ msf >> global;
+ Value* V = M.getNamedValue(global);
+ if (V) {
+ DSNodeHandle& DHV = GlobalsGraph->getNodeForValue(V);
+ for (std::set<Value*>::iterator SI = inSection.begin(),
+ SE = inSection.end(); SI != SE; ++SI) {
+ DEBUG(errs() << "Merging " << V->getNameStr() << " with "
+ << (*SI)->getNameStr() << "\n");
+ GlobalsGraph->getNodeForValue(*SI).mergeWith(DHV);
+ }
+ //DHV.getNode()->dump();
+ }
+ }
+ msf >> count;
+ }
+ } else {
+ errs() << "Failed to open magic sections file:" << hasMagicSections <<
+ "\n";
+ }
+}
+
char LocalDataStructures::ID;
bool LocalDataStructures::runOnModule(Module &M) {
@@ -870,13 +924,18 @@
// Add initializers for all of the globals to the globals graph.
for (Module::global_iterator I = M.global_begin(), E = M.global_end();
I != E; ++I)
- if (!I->isDeclaration())
+ if (I->isDeclaration())
+ GGB.mergeExternalGlobal(I);
+ else
GGB.mergeInGlobalInitializer(I);
// Add Functions to the globals graph.
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
- if (!I->isDeclaration() && I->hasAddressTaken())
+ if (I->hasAddressTaken())
GGB.mergeFunction(I);
}
+
+ if (hasMagicSections.size())
+ handleMagicSections(GlobalsGraph, M);
// Next step, iterate through the nodes in the globals graph, unioning
// together the globals into equivalence classes.
@@ -892,6 +951,8 @@
propagateUnknownFlag(G);
}
+
+
GlobalsGraph->removeTriviallyDeadNodes();
GlobalsGraph->markIncompleteNodes(DSGraph::MarkFormalArgs);
Modified: poolalloc/trunk/lib/DSA/Printer.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/Printer.cpp?rev=97715&r1=97714&r2=97715&view=diff
==============================================================================
--- poolalloc/trunk/lib/DSA/Printer.cpp (original)
+++ poolalloc/trunk/lib/DSA/Printer.cpp Wed Mar 3 20:28:41 2010
@@ -21,12 +21,9 @@
#include "llvm/Assembly/Writer.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/GraphWriter.h"
-#include "llvm/Support/Streams.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Config/config.h"
#include "llvm/Support/FormattedStream.h"
-#include <ostream>
-#include <fstream>
#include <sstream>
using namespace llvm;
@@ -34,14 +31,14 @@
// printing of only the graph for "main".
//
namespace {
- cl::opt<bool> OnlyPrintMain("only-print-main-ds", cl::ReallyHidden);
+ cl::list<std::string> OnlyPrint("dsa-only-print", cl::ReallyHidden);
cl::opt<bool> DontPrintAnything("dont-print-ds", cl::ReallyHidden);
cl::opt<bool> LimitPrint("dsa-limit-print", cl::Hidden);
STATISTIC (MaxGraphSize , "Maximum graph size");
STATISTIC (NumFoldedNodes , "Number of folded nodes (in final graph)");
}
-void DSNode::dump() const { print(cerr, 0); }
+void DSNode::dump() const { print(errs(), 0); }
static std::string getCaption(const DSNode *N, const DSGraph *G) {
std::string empty;
@@ -115,6 +112,8 @@
namespace llvm {
template<>
struct DOTGraphTraits<const DSGraph*> : public DefaultDOTGraphTraits {
+ DOTGraphTraits(bool& b) {}
+ DOTGraphTraits() {}
static std::string getGraphName(const DSGraph *G) {
switch (G->getReturnNodes().size()) {
case 0: return G->getFunctionNames();
@@ -124,7 +123,7 @@
}
static std::string
- getNodeLabel(const DSNode *Node, const DSGraph *Graph, bool ShortNames) {
+ getNodeLabel(const DSNode* Node, const DSGraph *Graph) {
return getCaption(Node, Graph);
}
@@ -169,9 +168,11 @@
if (!LimitPrint) {
// Add scalar nodes to the graph...
const DSGraph::ScalarMapTy &VM = G->getScalarMap();
- for (DSGraph::ScalarMapTy::const_iterator I = VM.begin(); I != VM.end();++I)
+ for (DSGraph::ScalarMapTy::const_iterator I = VM.begin();
+ I != VM.end(); ++I)
if (!isa<GlobalValue>(I->first)) {
- std::stringstream OS;
+ std::string OS_str;
+ llvm::raw_string_ostream OS(OS_str);
WriteAsOperand(OS, I->first, false, CurMod);
GW.emitSimpleNode(I->first, "", OS.str());
@@ -246,28 +247,29 @@
};
} // end namespace llvm
-void DSNode::print(std::ostream &O, const DSGraph *G) const {
+void DSNode::print(llvm::raw_ostream &O, const DSGraph *G) const {
GraphWriter<const DSGraph *> W(O, G, false);
W.writeNode(this);
}
-void DSGraph::print(std::ostream &O) const {
+void DSGraph::print(llvm::raw_ostream &O) const {
WriteGraph(O, this, "DataStructures");
}
-void DSGraph::writeGraphToFile(std::ostream &O,
+void DSGraph::writeGraphToFile(llvm::raw_ostream &O,
const std::string &GraphName) const {
std::string Filename = GraphName + ".dot";
O << "Writing '" << Filename << "'...";
- std::ofstream F(Filename.c_str());
+ std::string Error;
+ llvm::raw_fd_ostream F(Filename.c_str(), Error);
- if (F.good()) {
+ if (!Error.size()) {
print(F);
unsigned NumCalls = shouldPrintAuxCalls() ?
getAuxFunctionCalls().size() : getFunctionCalls().size();
O << " [" << getGraphSize() << "+" << NumCalls << "]\n";
} else {
- O << " error opening file for writing!\n";
+ O << " error opening file for writing! " << Error << "\n";
}
}
@@ -280,7 +282,7 @@
template <typename Collection>
-static void printCollection(const Collection &C, std::ostream &O,
+static void printCollection(const Collection &C, llvm::raw_ostream &O,
const Module *M, const std::string &Prefix) {
if (M == 0) {
O << "Null Module pointer, cannot continue!\n";
@@ -295,7 +297,14 @@
Gr->getAuxFunctionCalls().size() : Gr->getFunctionCalls().size();
bool IsDuplicateGraph = false;
- if (I->getName() == "main" || !OnlyPrintMain) {
+ //if no only print options, print everything
+ bool doPrint = OnlyPrint.begin() == OnlyPrint.end();
+ //otherwise check the name
+ if (!doPrint)
+ doPrint = OnlyPrint.end() !=
+ std::find(OnlyPrint.begin(), OnlyPrint.end(), I->getNameStr());
+
+ if (doPrint) {
const Function *SCCFn = Gr->retnodes_begin()->first;
if (&*I == SCCFn) {
Gr->writeGraphToFile(O, Prefix+I->getNameStr());
@@ -308,8 +317,8 @@
} else {
const Function *SCCFn = Gr->retnodes_begin()->first;
if (&*I == SCCFn) {
- O << "Skipped Writing '" << Prefix+I->getNameStr() << ".dot'... ["
- << Gr->getGraphSize() << "+" << NumCalls << "]\n";
+// O << "Skipped Writing '" << Prefix+I->getNameStr() << ".dot'... ["
+// << Gr->getGraphSize() << "+" << NumCalls << "]\n";
} else {
IsDuplicateGraph = true; // Don't double count node/call nodes.
}
@@ -331,15 +340,10 @@
DSGraph* GG = C.getGlobalsGraph();
TotalNumNodes += GG->getGraphSize();
TotalCallNodes += GG->getFunctionCalls().size();
- if (!OnlyPrintMain) {
- GG->writeGraphToFile(O, Prefix+"GlobalsGraph");
- } else {
- O << "Skipped Writing '" << Prefix << "GlobalsGraph.dot'... ["
- << GG->getGraphSize() << "+" << GG->getFunctionCalls().size() << "]\n";
- }
+ GG->writeGraphToFile(O, Prefix + "GlobalsGraph");
O << "\nGraphs contain [" << TotalNumNodes << "+" << TotalCallNodes
- << "] nodes total" << std::endl;
+ << "] nodes total\n";
}
@@ -358,8 +362,8 @@
}
// print - Print out the analysis results...
-void DataStructures::print(std::ostream &O, const Module *M) const {
+void DataStructures::print(llvm::raw_ostream &O, const Module *M) const {
if (DontPrintAnything) return;
printCollection(*this, O, M, printname);
- dumpCallGraph();
+ //dumpCallGraph();
}
Modified: poolalloc/trunk/lib/DSA/Steensgaard.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/Steensgaard.cpp?rev=97715&r1=97714&r2=97715&view=diff
==============================================================================
--- poolalloc/trunk/lib/DSA/Steensgaard.cpp (original)
+++ poolalloc/trunk/lib/DSA/Steensgaard.cpp Wed Mar 3 20:28:41 2010
@@ -19,6 +19,7 @@
#include "llvm/Analysis/Passes.h"
#include "llvm/Module.h"
#include "llvm/Support/Debug.h"
+#include "llvm/Support/FormattedStream.h"
#include <ostream>
using namespace llvm;
@@ -33,12 +34,7 @@
// print - Implement the Pass::print method...
void
-SteensgaardDataStructures::print(OStream O, const Module *M) const {
- if (O.stream()) print(*O.stream(), M);
-}
-
-void
-SteensgaardDataStructures::print(std::ostream &O, const Module *M) const {
+SteensgaardDataStructures::print(llvm::raw_ostream &O, const Module *M) const {
assert(ResultGraph && "Result graph has not yet been computed!");
ResultGraph->writeGraphToFile(O, "steensgaards");
}
@@ -154,7 +150,7 @@
RC.getClonedNH(GlobalsGraph->getNodeForValue(*I));
- print(DOUT, &M);
+ print(errs(), &M);
return false;
}
Modified: poolalloc/trunk/lib/DSA/TopDownClosure.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/TopDownClosure.cpp?rev=97715&r1=97714&r2=97715&view=diff
==============================================================================
--- poolalloc/trunk/lib/DSA/TopDownClosure.cpp (original)
+++ poolalloc/trunk/lib/DSA/TopDownClosure.cpp Wed Mar 3 20:28:41 2010
@@ -45,8 +45,16 @@
char TDDataStructures::ID;
char EQTDDataStructures::ID;
+TDDataStructures::~TDDataStructures() {
+ releaseMemory();
+}
+
+EQTDDataStructures::~EQTDDataStructures() {
+ releaseMemory();
+}
+
void TDDataStructures::markReachableFunctionsExternallyAccessible(DSNode *N,
- hash_set<DSNode*> &Visited) {
+ std::set<DSNode*> &Visited) {
if (!N || Visited.count(N)) return;
Visited.insert(N);
@@ -76,7 +84,7 @@
// arguments are functions which are reachable by global variables in the
// globals graph.
const DSScalarMap &GGSM = GlobalsGraph->getScalarMap();
- hash_set<DSNode*> Visited;
+ std::set<DSNode*> Visited;
for (DSScalarMap::global_iterator I=GGSM.global_begin(), E=GGSM.global_end();
I != E; ++I) {
DSNode *N = GGSM.find(*I)->second.getNode();
@@ -105,7 +113,7 @@
// We want to traverse the call graph in reverse post-order. To do this, we
// calculate a post-order traversal, then reverse it.
- hash_set<DSGraph*> VisitedGraph;
+ std::set<DSGraph*> VisitedGraph;
std::vector<DSGraph*> PostOrder;
{TIME_REGION(XXX, "td:Compute postorder");
@@ -147,7 +155,7 @@
void TDDataStructures::ComputePostOrder(const Function &F,
- hash_set<DSGraph*> &Visited,
+ std::set<DSGraph*> &Visited,
std::vector<DSGraph*> &PostOrder) {
if (F.isDeclaration()) return;
DSGraph* G = getOrCreateGraph(&F);
Modified: poolalloc/trunk/lib/PoolAllocate/AccessTrace.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/PoolAllocate/AccessTrace.cpp?rev=97715&r1=97714&r2=97715&view=diff
==============================================================================
--- poolalloc/trunk/lib/PoolAllocate/AccessTrace.cpp (original)
+++ poolalloc/trunk/lib/PoolAllocate/AccessTrace.cpp Wed Mar 3 20:28:41 2010
@@ -63,8 +63,8 @@
}
void PoolAccessTrace::InitializeLibraryFunctions(Module &M) {
- const IntegerType * IT = IntegerType::getInt8Ty(getGlobalContext());
- const Type * VoidType = Type::getVoidTy(getGlobalContext());
+ const IntegerType * IT = IntegerType::getInt8Ty(M.getContext());
+ const Type * VoidType = Type::getVoidTy(M.getContext());
VoidPtrTy = PointerType::getUnqual(IT);
AccessTraceInitFn = M.getOrInsertFunction("poolaccesstraceinit",
Modified: poolalloc/trunk/lib/PoolAllocate/Heuristic.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/PoolAllocate/Heuristic.cpp?rev=97715&r1=97714&r2=97715&view=diff
==============================================================================
--- poolalloc/trunk/lib/PoolAllocate/Heuristic.cpp (original)
+++ poolalloc/trunk/lib/PoolAllocate/Heuristic.cpp Wed Mar 3 20:28:41 2010
@@ -19,6 +19,7 @@
#include "llvm/Module.h"
#include "llvm/ADT/DepthFirstIterator.h"
#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/FormattedStream.h"
#include "llvm/Target/TargetData.h"
#include <iostream>
using namespace llvm;
@@ -80,7 +81,7 @@
// Doubles always want to be 8-byte aligned.
if (Ty == Type::DoubleTy) return true;
#else
- if (Ty->isFloatingPoint()) return true;
+ if (Ty->isFloatingPointTy()) return true;
#endif
// If we are on a 64-bit system, we want to align 8-byte integers and
@@ -102,7 +103,7 @@
} else if (const SequentialType *STy = dyn_cast<SequentialType>(Ty)) {
return Wants8ByteAlignment(STy->getElementType(), Offs, TD);
} else {
- std::cerr << *Ty << "\n";
+ errs() << *Ty << "\n";
assert(0 && "Unknown type!");
}
return false;
@@ -110,8 +111,7 @@
unsigned Heuristic::getRecommendedAlignment(const Type *Ty,
const TargetData &TD) {
- const Type * VoidType = Type::getVoidTy(getGlobalContext());
- if (Ty == VoidType) // Is this void or collapsed?
+ if (!Ty || Ty->isVoidTy()) // Is this void or collapsed?
return 0; // No known alignment, let runtime decide.
return Wants8ByteAlignment(Ty, 0, TD) ? 8 : 4;
@@ -121,8 +121,7 @@
/// DSNode.
///
unsigned Heuristic::getRecommendedAlignment(const DSNode *N) {
- const Type * VoidType = Type::getVoidTy(getGlobalContext());
- if (N->getType() == VoidType) // Is this void or collapsed?
+ if (!N->getType() || N->getType()->isVoidTy()) // Is this void or collapsed?
return 0; // No known alignment, let runtime decide.
const TargetData &TD = N->getParentGraph()->getTargetData();
Modified: poolalloc/trunk/lib/PoolAllocate/PAMultipleGlobalPool.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/PoolAllocate/PAMultipleGlobalPool.cpp?rev=97715&r1=97714&r2=97715&view=diff
==============================================================================
--- poolalloc/trunk/lib/PoolAllocate/PAMultipleGlobalPool.cpp (original)
+++ poolalloc/trunk/lib/PoolAllocate/PAMultipleGlobalPool.cpp Wed Mar 3 20:28:41 2010
@@ -34,6 +34,7 @@
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
+#include "llvm/Support/FormattedStream.h"
#include "llvm/Support/Timer.h"
#include <iostream>
@@ -135,7 +136,9 @@
for (Function::iterator i = F.begin(), e = F.end(); i != e; ++i)
for (BasicBlock::iterator ii = i->begin(), ee = i->end(); ii != ee; ++ii) {
- if (MallocInst * MI = dyn_cast<MallocInst>(ii)) {
+//FIXME: Handle malloc here
+ if (false) { //MallocInst * MI = dyn_cast<MallocInst>(ii)) {
+#if 0
// Associate the global pool decriptor with the DSNode
DSNode * Node = ECG->getNodeForValue(MI).getNode();
GlobalVariable * Pool = PoolMap[Node];
@@ -170,7 +173,7 @@
DSNodeHandle NH = SM[ii];
SM.erase(ii);
SM[casted] = SM[x] = NH;
-
+ #endif
} else if (CallInst * CI = dyn_cast<CallInst>(ii)) {
CallSite CS(CI);
Function *CF = CS.getCalledFunction();
@@ -308,7 +311,9 @@
SM.erase(CI);
SM[Casted] = SM[V] = NH;
}
- } else if (FreeInst * FI = dyn_cast<FreeInst>(ii)) {
+ //FIXME: handle Frees
+#if 0
+ } else if (FreeInst * FI = dyn_cast<FreeInst > (ii)) {
Type * VoidPtrTy = PointerType::getUnqual(Int8Type);
Value * FreedNode = castTo (FI->getPointerOperand(), VoidPtrTy, "cast", ii);
DSNode * Node = ECG->getNodeForValue(FI->getPointerOperand()).getNode();
@@ -321,6 +326,7 @@
DSNodeHandle NH = SM[ii];
SM.erase(ii);
SM[CI] = NH;
+ #endif
} else if (isa<ReturnInst>(ii)) {
Returns.push_back(cast<ReturnInst>(ii));
}
@@ -357,7 +363,7 @@
BasicBlock * BB = BasicBlock::Create(getGlobalContext(), "entry", InitFunc);
- SteensgaardDataStructures * DS = dynamic_cast<SteensgaardDataStructures*>(Graphs);
+ SteensgaardDataStructures * DS = (SteensgaardDataStructures*)Graphs;
assert (DS && "PoolAllocateMultipleGlobalPools requires Steensgaard Data Structure!");
@@ -398,8 +404,8 @@
GlobalVariable *GV =
new GlobalVariable
(M,
- getPoolType(), false, GlobalValue::ExternalLinkage,
- ConstantAggregateZero::get(getPoolType()), "__poolalloc_GlobalPool");
+ getPoolType(&M.getContext()), false, GlobalValue::ExternalLinkage,
+ ConstantAggregateZero::get(getPoolType(&M.getContext())), "__poolalloc_GlobalPool");
Value *ElSize = ConstantInt::get(Int32Type, RecSize);
Value *AlignV = ConstantInt::get(Int32Type, Align);
@@ -424,15 +430,15 @@
}
void
-PoolAllocateMultipleGlobalPool::print(std::ostream &OS, const Module * M) const {
+PoolAllocateMultipleGlobalPool::print(llvm::raw_ostream &OS, const Module * M) const {
for (PoolMapTy::const_iterator I = PoolMap.begin(), E = PoolMap.end(); I != E; ++I) {
- OS << I->first << " -> " << I->second->getNameStr() << "\n";
- }
+ OS << I->first << " -> " << I->second->getName() << "\n";
+ }
}
void
PoolAllocateMultipleGlobalPool::dump() const {
- print (std::cerr, currentModule);
+ print (errs(), currentModule);
}
PoolAllocateMultipleGlobalPool::~PoolAllocateMultipleGlobalPool() {}
Modified: poolalloc/trunk/lib/PoolAllocate/PASimple.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/PoolAllocate/PASimple.cpp?rev=97715&r1=97714&r2=97715&view=diff
==============================================================================
--- poolalloc/trunk/lib/PoolAllocate/PASimple.cpp (original)
+++ poolalloc/trunk/lib/PoolAllocate/PASimple.cpp Wed Mar 3 20:28:41 2010
@@ -107,9 +107,9 @@
//
// Get pointers to 8 and 32 bit LLVM integer types.
//
- VoidType = Type::getVoidTy(getGlobalContext());
- Int8Type = IntegerType::getInt8Ty(getGlobalContext());
- Int32Type = IntegerType::getInt32Ty(getGlobalContext());
+ VoidType = Type::getVoidTy(M.getContext());
+ Int8Type = IntegerType::getInt8Ty(M.getContext());
+ Int32Type = IntegerType::getInt32Ty(M.getContext());
// Get the Target Data information and the Graphs
if (CompleteDSA) {
@@ -173,7 +173,10 @@
for (Function::iterator i = F.begin(), e = F.end(); i != e; ++i)
for (BasicBlock::iterator ii = i->begin(), ee = i->end(); ii != ee; ++ii) {
- if (MallocInst * MI = dyn_cast<MallocInst>(ii)) {
+ if (false) {
+ //FIXME: malloc
+#if 0
+ if (MallocInst * MI = dyn_cast<MallocInst>(ii)) {
// Associate the global pool decriptor with the DSNode
DSNode * Node = ECG->getNodeForValue(MI).getNode();
FInfo.PoolDescriptors.insert(std::make_pair(Node,TheGlobalPool));
@@ -201,6 +204,7 @@
Value* args[] = {TheGlobalPool, AllocSize};
Instruction* x = CallInst::Create(PoolAlloc, &args[0], &args[2], MI->getName(), ii);
ii->replaceAllUsesWith(CastInst::CreatePointerCast(x, ii->getType(), "", ii));
+ #endif
} else if (CallInst * CI = dyn_cast<CallInst>(ii)) {
CallSite CS(CI);
Function *CF = CS.getCalledFunction();
@@ -325,12 +329,15 @@
// Update def-use info
CI->replaceAllUsesWith(Casted);
}
+ //FIXME: free
+ #if 0
} else if (FreeInst * FI = dyn_cast<FreeInst>(ii)) {
Type * VoidPtrTy = PointerType::getUnqual(Int8Type);
Value * FreedNode = castTo (FI->getPointerOperand(), VoidPtrTy, "cast", ii);
toDelete.push_back(ii);
Value* args[] = {TheGlobalPool, FreedNode};
CallInst::Create(PoolFree, &args[0], &args[2], "", ii);
+ #endif
} else if (isa<ReturnInst>(ii)) {
Returns.push_back(cast<ReturnInst>(ii));
}
@@ -361,20 +368,20 @@
Module& M) {
GlobalVariable *GV =
new GlobalVariable(M,
- getPoolType(), false, GlobalValue::ExternalLinkage,
- ConstantAggregateZero::get(getPoolType()),
+ getPoolType(&M.getContext()), false, GlobalValue::ExternalLinkage,
+ ConstantAggregateZero::get(getPoolType(&M.getContext())),
"__poolalloc_GlobalPool");
Function *InitFunc = Function::Create
(FunctionType::get(VoidType, std::vector<const Type*>(), false),
GlobalValue::ExternalLinkage, "__poolalloc_init", &M);
- BasicBlock * BB = BasicBlock::Create(getGlobalContext(), "entry", InitFunc);
+ BasicBlock * BB = BasicBlock::Create(M.getContext(), "entry", InitFunc);
Value *ElSize = ConstantInt::get(Int32Type, RecSize);
Value *AlignV = ConstantInt::get(Int32Type, Align);
Value* Opts[3] = {GV, ElSize, AlignV};
CallInst::Create(PoolInit, Opts, Opts + 3, "", BB);
- ReturnInst::Create(getGlobalContext(), BB);
+ ReturnInst::Create(M.getContext(), BB);
return GV;
}
Modified: poolalloc/trunk/lib/PoolAllocate/PoolAllocate.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/PoolAllocate/PoolAllocate.cpp?rev=97715&r1=97714&r2=97715&view=diff
==============================================================================
--- poolalloc/trunk/lib/PoolAllocate/PoolAllocate.cpp (original)
+++ poolalloc/trunk/lib/PoolAllocate/PoolAllocate.cpp Wed Mar 3 20:28:41 2010
@@ -33,10 +33,9 @@
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
+#include "llvm/Support/FormattedStream.h"
#include "llvm/Support/Timer.h"
-#include <iostream>
-
using namespace llvm;
using namespace PA;
@@ -106,9 +105,9 @@
//
// Get pointers to 8 and 32 bit LLVM integer types.
//
- VoidType = Type::getVoidTy(getGlobalContext());
- Int8Type = IntegerType::getInt8Ty(getGlobalContext());
- Int32Type = IntegerType::getInt32Ty(getGlobalContext());
+ VoidType = Type::getVoidTy(M.getContext());
+ Int8Type = IntegerType::getInt8Ty(M.getContext());
+ Int32Type = IntegerType::getInt32Ty(M.getContext());
//
// Get references to the DSA information. For SAFECode, we need Top-Down
@@ -222,7 +221,7 @@
if (VoidPtrTy == 0) {
// NOTE: If these are changed, make sure to update PoolOptimize.cpp as well!
VoidPtrTy = PointerType::getUnqual(Int8Type);
- PoolDescType = getPoolType();
+ PoolDescType = getPoolType(&M->getContext());
PoolDescPtrTy = PointerType::getUnqual(PoolDescType);
}
@@ -303,7 +302,7 @@
if (isa<Constant>(User->getOperand(1)) &&
cast<Constant>(User->getOperand(1))->isNullValue()) {
bool CondIsTrue = ICI->getPredicate() == ICmpInst::ICMP_NE;
- const Type * Int1Type = IntegerType::getInt1Ty(getGlobalContext());
+ const Type * Int1Type = IntegerType::getInt1Ty(*Context);
User->replaceAllUsesWith(ConstantInt::get(Int1Type, CondIsTrue));
}
} else if ((User->getOpcode() == Instruction::Trunc) ||
@@ -339,7 +338,7 @@
CallInst *CI = Calls[i];
// poolalloc never returns null. Loop over all uses of the call looking for
// set(eq|ne) X, null.
- OptimizePointerNotNull(CI, &getGlobalContext());
+ OptimizePointerNotNull(CI, &CI->getContext());
}
// TODO: poolfree accepts a null pointer, so remove any check above it, like
@@ -350,13 +349,13 @@
static void GetNodesReachableFromGlobals(DSGraph* G,
- hash_set<const DSNode*> &NodesFromGlobals) {
+ std::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<const DSNode*> &MarkedNodes,
+static void MarkNodesWhichMustBePassedIn(std::set<const DSNode*> &MarkedNodes,
Function &F, DSGraph* G,
bool PassAllArguments) {
// Mark globals and incomplete nodes as live... (this handles arguments)
@@ -378,14 +377,14 @@
// 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<const DSNode*> NodesFromGlobals;
+ std::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<const DSNode*>::iterator I = MarkedNodes.begin(),
+ for (std::set<const DSNode*>::iterator I = MarkedNodes.begin(),
E = MarkedNodes.end(); I != E; ) {
const DSNode *N = *I++;
if ((!(1 || N->isHeapNode()) && !PassAllArguments) || NodesFromGlobals.count(N))
@@ -403,7 +402,7 @@
// Create a new entry for F.
FuncInfo &FI =
FunctionInfo.insert(std::make_pair(&F, FuncInfo(F))).first->second;
- hash_set<const DSNode*> &MarkedNodes = FI.MarkedNodes;
+ std::set<const DSNode*> &MarkedNodes = FI.MarkedNodes;
if (G->node_begin() == G->node_end())
return; // No memory activity, nothing is required
@@ -476,7 +475,7 @@
}
// Perform the cloning.
- std::vector<ReturnInst*> Returns;
+ SmallVector<ReturnInst*,100> Returns;
CloneFunctionInto(New, &F, ValueMap, Returns);
//
@@ -528,13 +527,13 @@
DSGraph* GG = Graphs->getGlobalsGraph();
// Get all of the nodes reachable from globals.
- hash_set<const DSNode*> GlobalHeapNodes;
+ std::set<const DSNode*> GlobalHeapNodes;
GetNodesReachableFromGlobals(GG, GlobalHeapNodes);
// Filter out all nodes which have no heap allocations merged into them.
- for (hash_set<const DSNode*>::iterator I = GlobalHeapNodes.begin(),
+ for (std::set<const DSNode*>::iterator I = GlobalHeapNodes.begin(),
E = GlobalHeapNodes.end(); I != E; ) {
- hash_set<const DSNode*>::iterator Last = I++;
+ std::set<const DSNode*>::iterator Last = I++;
#if 0
//
@@ -549,7 +548,7 @@
#endif
const DSNode *tmp = *Last;
- // std::cerr << "test \n";
+ // errs() << "test \n";
if (!(tmp->isHeapNode() || tmp->isArray()))
GlobalHeapNodes.erase(Last);
}
@@ -557,12 +556,12 @@
// Otherwise get the main function to insert the poolinit calls.
Function *MainFunc = M.getFunction("main");
if (MainFunc == 0 || MainFunc->isDeclaration()) {
- std::cerr << "Cannot pool allocate this program: it has global "
+ errs() << "Cannot pool allocate this program: it has global "
<< "pools but no 'main' function yet!\n";
return true;
}
- std::cerr << "Pool allocating " << GlobalHeapNodes.size()
+ errs() << "Pool allocating " << GlobalHeapNodes.size()
<< " global nodes!\n";
@@ -591,7 +590,7 @@
}
// Any unallocated DSNodes get null pool descriptor pointers.
- for (hash_set<const DSNode*>::iterator I = GlobalHeapNodes.begin(),
+ for (std::set<const DSNode*>::iterator I = GlobalHeapNodes.begin(),
E = GlobalHeapNodes.end(); I != E; ++I) {
GlobalNodes[*I] = ConstantPointerNull::get(PointerType::getUnqual(PoolDescType));
++NumNonprofit;
@@ -705,7 +704,7 @@
if (G->node_begin() == G->node_end()) return; // Quick exit if nothing to do.
FuncInfo &FI = *getFuncInfo(F);
- hash_set<const DSNode*> &MarkedNodes = FI.MarkedNodes;
+ std::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
@@ -738,11 +737,11 @@
}
if (!FI.NodesToPA.empty()) {
- std::cerr << "[" << F.getNameStr() << "] " << FI.NodesToPA.size()
+ errs() << "[" << F.getNameStr() << "] " << FI.NodesToPA.size()
<< " nodes pool allocatable\n";
CreatePools(NewF, G, FI.NodesToPA, FI.PoolDescriptors);
} else {
- DEBUG(std::cerr << "[" << F.getNameStr() << "] transforming body.\n");
+ DEBUG(errs() << "[" << F.getNameStr() << "] transforming body.\n");
}
// Transform the body of the function now... collecting information about uses
@@ -844,12 +843,12 @@
InitializedBefore.clear();
DestroyedAfter.clear();
- DEBUG(std::cerr << "POOL: " << PD->getNameStr() << " information:\n");
- DEBUG(std::cerr << " Live in blocks: ");
+ DEBUG(errs() << "POOL: " << PD->getNameStr() << " information:\n");
+ DEBUG(errs() << " Live in blocks: ");
DEBUG(for (std::set<BasicBlock*>::iterator I = LiveBlocks.begin(),
E = LiveBlocks.end(); I != E; ++I)
- std::cerr << (*I)->getNameStr() << " ");
- DEBUG(std::cerr << "\n");
+ errs() << (*I)->getNameStr() << " ");
+ DEBUG(errs() << "\n");
std::vector<Instruction*> PoolInitPoints;
@@ -951,7 +950,7 @@
}
}
- DEBUG(std::cerr << " Init in blocks: ");
+ DEBUG(errs() << " Init in blocks: ");
// Insert the calls to initialize the pool.
unsigned ElSizeV = Heuristic::getRecommendedSize(Node);
@@ -962,18 +961,18 @@
for (unsigned i = 0, e = PoolInitPoints.size(); i != e; ++i) {
Value* Opts[3] = {PD, ElSize, Align};
CallInst::Create(PoolInit, Opts, Opts + 3, "", PoolInitPoints[i]);
- DEBUG(std::cerr << PoolInitPoints[i]->getParent()->getNameStr() << " ");
+ DEBUG(errs() << PoolInitPoints[i]->getParent()->getNameStr() << " ");
}
- DEBUG(std::cerr << "\n Destroy in blocks: ");
+ DEBUG(errs() << "\n Destroy in blocks: ");
// Loop over all of the places to insert pooldestroy's...
for (unsigned i = 0, e = PoolDestroyPoints.size(); i != e; ++i) {
// Insert the pooldestroy call for this pool.
CallInst::Create(PoolDestroy, PD, "", PoolDestroyPoints[i]);
- DEBUG(std::cerr << PoolDestroyPoints[i]->getParent()->getNameStr()<<" ");
+ DEBUG(errs() << PoolDestroyPoints[i]->getParent()->getNameStr()<<" ");
}
- DEBUG(std::cerr << "\n\n");
+ DEBUG(errs() << "\n\n");
// We are allowed to delete any poolfree's which occur between the last
// call to poolalloc, and the call to pooldestroy. Figure out which
Modified: poolalloc/trunk/lib/PoolAllocate/PoolOptimize.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/PoolAllocate/PoolOptimize.cpp?rev=97715&r1=97714&r2=97715&view=diff
==============================================================================
--- poolalloc/trunk/lib/PoolAllocate/PoolOptimize.cpp (original)
+++ poolalloc/trunk/lib/PoolAllocate/PoolOptimize.cpp Wed Mar 3 20:28:41 2010
@@ -62,9 +62,9 @@
//
// Get pointers to 8 and 32 bit LLVM integer types.
//
- VoidType = Type::getVoidTy(getGlobalContext());
- Int8Type = IntegerType::getInt8Ty(getGlobalContext());
- Int32Type = IntegerType::getInt32Ty(getGlobalContext());
+ VoidType = Type::getVoidTy(M.getContext());
+ Int8Type = IntegerType::getInt8Ty(M.getContext());
+ Int32Type = IntegerType::getInt32Ty(M.getContext());
//
// Create LLVM types used by the pool allocation passes.
@@ -165,10 +165,13 @@
// poolalloc(null, X) -> malloc(X)
if (isa<Constant>(CI->getOperand(1)) &&
cast<Constant>(CI->getOperand(1))->isNullValue()) {
+//FIXME: handle malloc
+ #if 0
Value *New = new MallocInst(Int8Type, CI->getOperand(2),
CI->getName(), CI);
CI->replaceAllUsesWith(New);
CI->eraseFromParent();
+ #endif
}
}
@@ -194,8 +197,9 @@
CI->eraseFromParent();
else if (isa<ConstantPointerNull>(CI->getOperand(1))) {
// poolfree(null, Ptr) -> free(Ptr)
- new FreeInst(CI->getOperand(2), CI);
- CI->eraseFromParent();
+ //FIXME: Handle free
+ //new FreeInst(CI->getOperand(2), CI);
+ //CI->eraseFromParent();
}
}
Modified: poolalloc/trunk/lib/PoolAllocate/RunTimeAssociate.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/PoolAllocate/RunTimeAssociate.cpp?rev=97715&r1=97714&r2=97715&view=diff
==============================================================================
--- poolalloc/trunk/lib/PoolAllocate/RunTimeAssociate.cpp (original)
+++ poolalloc/trunk/lib/PoolAllocate/RunTimeAssociate.cpp Wed Mar 3 20:28:41 2010
@@ -32,10 +32,9 @@
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
+#include "llvm/Support/FormattedStream.h"
-#include "EntryPointAnalysis.h"
-
-#include <iostream>
+#include "dsa/EntryPointAnalysis.h"
using namespace llvm;
using namespace rPA;
@@ -57,13 +56,13 @@
////////////////////////////////////////////////////////////////////////////////
static void GetNodesReachableFromGlobals(DSGraph* G,
- hash_set<const DSNode*> &NodesFromGlobals) {
+ std::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<const DSNode*> &MarkedNodes,
+static void MarkNodesWhichMustBePassedIn(std::set<const DSNode*> &MarkedNodes,
Function &F, DSGraph* G,
EntryPointAnalysis* EPA) {
// All DSNodes reachable from arguments must be passed in...
@@ -85,13 +84,13 @@
// 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<const DSNode*> NodesFromGlobals;
+ std::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.
- for (hash_set<const DSNode*>::iterator I = NodesFromGlobals.begin(),
+ for (std::set<const DSNode*>::iterator I = NodesFromGlobals.begin(),
E = NodesFromGlobals.end(); I != E; ++I)
MarkedNodes.erase(*I);
}
@@ -102,7 +101,7 @@
/// map and recording this info in the ArgNodes set.
static void FindFunctionPoolArgs(Function &F, FuncInfo& FI,
EntryPointAnalysis* EPA) {
- hash_set<const DSNode*> MarkedNodes;
+ std::set<const DSNode*> MarkedNodes;
if (FI.G->node_begin() == FI.G->node_end())
return; // No memory activity, nothing is required
@@ -172,7 +171,7 @@
}
// Perform the cloning.
- std::vector<ReturnInst*> Returns;
+ SmallVector<ReturnInst*,100> Returns;
CloneFunctionInto(New, &F, ValueMap, Returns);
//
@@ -210,7 +209,7 @@
: ModulePass((intptr_t) & ID) { }
void RTAssociate::getAnalysisUsage(AnalysisUsage &AU) const {
- AU.addRequiredTransitive<EquivBUDataStructures > ();
+ AU.addRequiredTransitive<CompleteBUDataStructures > ();
AU.addRequired<EntryPointAnalysis> ();
}
@@ -222,7 +221,7 @@
// DSA. For Automatic Pool Allocation only, we need Bottom-Up DSA. In all
// cases, we need to use the Equivalence-Class version of DSA.
//
- DataStructures* Graphs = &getAnalysis<EquivBUDataStructures > ();
+ DataStructures* Graphs = &getAnalysis<CompleteBUDataStructures > ();
EntryPointAnalysis* EPA = &getAnalysis<EntryPointAnalysis > ();
// PoolDescType = OpaqueType::get(M.getContext());
@@ -287,10 +286,10 @@
// DSGraph* GG = Graphs->getGlobalsGraph();
// Get all of the nodes reachable from globals.
- hash_set<const DSNode*> GlobalHeapNodes;
+ std::set<const DSNode*> GlobalHeapNodes;
GetNodesReachableFromGlobals(GG, GlobalHeapNodes);
- std::cerr << "Pool allocating " << GlobalHeapNodes.size()
+ errs() << "Pool allocating " << GlobalHeapNodes.size()
<< " global nodes!\n";
FuncInfo& FI = makeFuncInfo(0, GG);
@@ -356,6 +355,7 @@
// 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.
+
G->getGlobalsGraph();
// Map all node reachable from this global to the corresponding nodes in
@@ -414,13 +414,13 @@
CF = cast<Function>(CE->getOperand(0));
if (isa<InlineAsm>(TheCall->getOperand(0))) {
- std::cerr << "INLINE ASM: ignoring. Hoping that's safe.\n";
+ errs() << "INLINE ASM: ignoring. Hoping that's safe.\n";
return;
}
// Ignore calls to NULL pointers.
if (isa<ConstantPointerNull>(CS.getCalledValue())) {
- std::cerr << "WARNING: Ignoring call using NULL function pointer.\n";
+ errs() << "WARNING: Ignoring call using NULL function pointer.\n";
return;
}
// We need to figure out which local pool descriptors correspond to the pool
@@ -438,7 +438,7 @@
// For indirect callees, find any callee since all DS graphs have been
// merged.
if (CF) { // Direct calls are nice and simple.
- DEBUG(std::cerr << " Handling direct call: " << *TheCall);
+ DEBUG(errs() << " Handling direct call: " << *TheCall);
FuncInfo *CFI = getFuncInfo(CF);
if (CFI == 0 || CFI->Clone == 0) // Nothing to transform...
return;
@@ -449,7 +449,7 @@
assert ((DS->hasDSGraph (*CF)) && "Function has no ECGraph!\n");
CalleeGraph = DS->getDSGraph(*CF);
} else {
- DEBUG(std::cerr << " Handling indirect call: " << *TheCall);
+ DEBUG(errs() << " Handling indirect call: " << *TheCall);
// Here we fill in CF with one of the possible called functions. Because we
// merged together all of the arguments to all of the functions in the
@@ -478,7 +478,7 @@
for(std::vector<const Function*>::const_iterator ii = g.begin(), ee = g.end();
!CF && ii != ee; ++ii) {
for (EquivalenceClasses<const GlobalValue *>::member_iterator MI = EC.findLeader(*ii);
- MI != EC.member_end(); ++MI) // Loop over members in this set.
+ MI != EC.member_end(); ++MI) // Loop over members in this set.
if ((CF = dyn_cast<Function>(*MI))) {
break;
}
@@ -490,6 +490,13 @@
// Do an assert unless we're bugpointing something.
//
// if ((UsingBugpoint) && (!CF)) return;
+ if (!CF)
+ errs() << "No Graph for CallSite in "
+ << TheCall->getParent()->getParent()->getNameStr()
+ << " originally "
+ << OrigInst->getParent()->getParent()->getNameStr()
+ << "\n";
+
assert (CF && "No call graph info");
// Get the common graph for the set of functions this call may invoke.
@@ -551,7 +558,7 @@
if (FI.PoolDescriptors.count(LocalNode))
ArgVal = FI.PoolDescriptors.find(LocalNode)->second;
if (isa<Constant > (ArgVal) && cast<Constant > (ArgVal)->isNullValue())
- std::cerr << "WARNING: NULL POOL ARGUMENTS ARE PASSED IN!\n";
+ errs() << "WARNING: NULL POOL ARGUMENTS ARE PASSED IN!\n";
Args.push_back(ArgVal);
}
@@ -587,7 +594,7 @@
}
TheCall->replaceAllUsesWith(NewCall);
- DEBUG(std::cerr << " Result Call: " << *NewCall);
+ DEBUG(errs() << " Result Call: " << *NewCall);
if (TheCall->getType()->getTypeID() != Type::VoidTyID) {
// If we are modifying the original function, update the DSGraph...
Modified: poolalloc/trunk/lib/PoolAllocate/TransformFunctionBody.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/PoolAllocate/TransformFunctionBody.cpp?rev=97715&r1=97714&r2=97715&view=diff
==============================================================================
--- poolalloc/trunk/lib/PoolAllocate/TransformFunctionBody.cpp (original)
+++ poolalloc/trunk/lib/PoolAllocate/TransformFunctionBody.cpp Wed Mar 3 20:28:41 2010
@@ -23,6 +23,7 @@
#include "llvm/Instructions.h"
#include "llvm/Target/TargetData.h"
#include "llvm/Support/InstVisitor.h"
+#include "llvm/Support/FormattedStream.h"
#include "llvm/Support/Debug.h"
#include "llvm/ADT/VectorExtras.h"
#include <iostream>
@@ -38,14 +39,6 @@
//
static bool UsingBugpoint = false;
-//
-// Variables for referencing LLVM basic types.
-//
-static const Type * VoidType = 0;
-static const Type * Int8Type = 0;
-static const Type * Int32Type = 0;
-static const Type * Int64Type = 0;
-
namespace {
/// FuncTransform - This class implements transformation required of pool
/// allocated functions.
@@ -69,13 +62,6 @@
std::multimap<AllocaInst*, CallInst*> &poolFrees)
: PAInfo(P), G(g), FI(fi),
PoolUses(poolUses), PoolFrees(poolFrees) {
- //
- // Get pointers to 8 and 32 bit LLVM integer types.
- //
- VoidType = Type::getVoidTy(getGlobalContext());
- Int8Type = IntegerType::getInt8Ty(getGlobalContext());
- Int32Type = IntegerType::getInt32Ty(getGlobalContext());
- Int64Type = IntegerType::getInt64Ty(getGlobalContext());
}
template <typename InstType, typename SetType>
@@ -85,13 +71,13 @@
}
void visitInstruction(Instruction &I);
- void visitMallocInst(MallocInst &MI);
+ //void visitMallocInst(MallocInst &MI);
void visitAllocaInst(AllocaInst &MI);
void visitCallocCall(CallSite CS);
void visitReallocCall(CallSite CS);
void visitMemAlignCall(CallSite CS);
void visitStrdupCall(CallSite CS);
- void visitFreeInst(FreeInst &FI);
+ //void visitFreeInst(FreeInst &FI);
void visitCallSite(CallSite &CS);
void visitCallInst(CallInst &CI) {
CallSite CS(&CI);
@@ -178,8 +164,8 @@
Value *Size) {
std::string Name = I->getName(); I->setName("");
- if (Size->getType() != Int32Type)
- Size = CastInst::CreateIntegerCast(Size, Int32Type, false, Size->getName(), I);
+ if (!Size->getType()->isIntegerTy(32))
+ Size = CastInst::CreateIntegerCast(Size, Type::getInt32Ty(Size->getType()->getContext()), false, Size->getName(), I);
// Insert a call to poolalloc
Value *PH = getPoolHandle(I);
@@ -222,7 +208,7 @@
return Casted;
}
-
+#if 0
void FuncTransform::visitMallocInst(MallocInst &MI) {
// Get the pool handle for the node that this contributes to...
Value *PH = getPoolHandle(&MI);
@@ -277,6 +263,7 @@
TransformAllocationInstr(&MI, AllocSize);
}
}
+#endif
void FuncTransform::visitAllocaInst(AllocaInst &MI) {
// Don't do anything if bounds checking will not be done by SAFECode later.
@@ -288,7 +275,7 @@
Value *PH = getPoolHandle(&MI);
if (PH == 0 || isa<ConstantPointerNull>(PH)) return;
TargetData &TD = PAInfo.getAnalysis<TargetData>();
- Value *AllocSize = ConstantInt::get(Int32Type, TD.getTypeAllocSize(MI.getAllocatedType()));
+ Value *AllocSize = ConstantInt::get(Type::getInt32Ty(MI.getContext()), TD.getTypeAllocSize(MI.getAllocatedType()));
if (MI.isArrayAllocation())
AllocSize = BinaryOperator::Create(Instruction::Mul, AllocSize,
@@ -297,7 +284,7 @@
// TransformAllocationInstr(&MI, AllocSize);
BasicBlock::iterator InsertPt(MI);
++InsertPt;
- Instruction *Casted = CastInst::CreatePointerCast(&MI, PointerType::getUnqual(Int8Type),
+ Instruction *Casted = CastInst::CreatePointerCast(&MI, PointerType::getUnqual(Type::getInt8Ty(MI.getContext())),
MI.getName()+".casted", InsertPt);
std::vector<Value *> args;
args.push_back (PH);
@@ -316,8 +303,8 @@
// Insert a cast and a call to poolfree...
Value *Casted = Arg;
- if (Arg->getType() != PointerType::getUnqual(Int8Type)) {
- Casted = CastInst::CreatePointerCast(Arg, PointerType::getUnqual(Int8Type),
+ if (Arg->getType() != PointerType::getUnqual(Type::getInt8Ty(Arg->getContext()))) {
+ Casted = CastInst::CreatePointerCast(Arg, PointerType::getUnqual(Type::getInt8Ty(Arg->getContext())),
Arg->getName()+".casted", Where);
G->getScalarMap()[Casted] = G->getScalarMap()[Arg];
}
@@ -328,7 +315,7 @@
return FreeI;
}
-
+#if 0
void FuncTransform::visitFreeInst(FreeInst &FrI) {
if (Instruction *I = InsertPoolFreeInstr(FrI.getOperand(0), &FrI)) {
// Delete the now obsolete free instruction...
@@ -345,10 +332,14 @@
}
}
}
-
+#endif
void FuncTransform::visitCallocCall(CallSite CS) {
TargetData& TD = PAInfo.getAnalysis<TargetData>();
+ const Type* Int8Type = Type::getInt8Ty(CS.getInstruction()->getContext());
+ const Type* Int32Type = Type::getInt32Ty(CS.getInstruction()->getContext());
+ const Type* Int64Type = Type::getInt64Ty(CS.getInstruction()->getContext());
+
bool useLong = TD.getTypeAllocSize(PointerType::getUnqual(Int8Type)) != 4;
Module *M = CS.getInstruction()->getParent()->getParent()->getParent();
@@ -372,7 +363,7 @@
// We just turned the call of 'calloc' into the equivalent of malloc. To
// finish calloc, we need to zero out the memory.
Constant *MemSet = M->getOrInsertFunction((useLong ? "llvm.memset.i64" : "llvm.memset.i32"),
- VoidType,
+ Type::getVoidTy(M->getContext()),
PointerType::getUnqual(Int8Type),
Int8Type, (useLong ? Int64Type : Int32Type),
Int32Type, NULL);
@@ -398,10 +389,10 @@
// Don't poolallocate if we have no pool handle
if (PH == 0 || isa<ConstantPointerNull>(PH)) return;
- if (Size->getType() != Int32Type)
- Size = CastInst::CreateIntegerCast(Size, Int32Type, false, Size->getName(), I);
+ if (Size->getType() != Type::getInt32Ty(CS.getInstruction()->getContext()))
+ Size = CastInst::CreateIntegerCast(Size, Type::getInt32Ty(CS.getInstruction()->getContext()), false, Size->getName(), I);
- static Type *VoidPtrTy = PointerType::getUnqual(Int8Type);
+ static Type *VoidPtrTy = PointerType::getUnqual(Type::getInt8Ty(CS.getInstruction()->getContext()));
if (OldPtr->getType() != VoidPtrTy)
OldPtr = CastInst::CreatePointerCast(OldPtr, VoidPtrTy, OldPtr->getName(), I);
@@ -445,6 +436,10 @@
Value *Size = 0;
Value *PH;
+ const Type* Int8Type = Type::getInt8Ty(CS.getInstruction()->getContext());
+ const Type* Int32Type = Type::getInt32Ty(CS.getInstruction()->getContext());
+
+
if (CS.getCalledFunction()->getName() == "memalign") {
Align = CS.getArgument(0);
Size = CS.getArgument(1);
@@ -470,9 +465,9 @@
ResultDest = CastInst::CreatePointerCast(ResultDest, PtrPtr, ResultDest->getName(), I);
}
- if (Align->getType() != Int32Type)
+ if (!Align->getType()->isIntegerTy(32))
Align = CastInst::CreateIntegerCast(Align, Int32Type, false, Align->getName(), I);
- if (Size->getType() != Int32Type)
+ if (!Size->getType()->isIntegerTy(32))
Size = CastInst::CreateIntegerCast(Size, Int32Type, false, Size->getName(), I);
std::string Name = I->getName(); I->setName("");
@@ -516,11 +511,15 @@
DSNode *Node = getDSNodeHFor(I).getNode();
assert (Node && "strdup has NULL DSNode!\n");
Value *PH = getPoolHandle(I);
+
+ const Type* Int8Type = Type::getInt8Ty(CS.getInstruction()->getContext());
+
+
#if 0
assert (PH && "PH for strdup is null!\n");
#else
if (!PH) {
- std::cerr << "strdup: NoPH" << std::endl;
+ errs() << "strdup: NoPH\n";
return;
}
#endif
@@ -565,6 +564,9 @@
const Function *CF = CS.getCalledFunction();
Instruction *TheCall = CS.getInstruction();
+ const Type* Int32Type = Type::getInt32Ty(CS.getInstruction()->getContext());
+
+
// If the called function is casted from one function type to another, peer
// into the cast instruction and pull out the actual function being called.
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(CS.getCalledValue()))
@@ -573,13 +575,13 @@
CF = cast<Function>(CE->getOperand(0));
if (isa<InlineAsm>(TheCall->getOperand(0))) {
- std::cerr << "INLINE ASM: ignoring. Hoping that's safe.\n";
+ errs() << "INLINE ASM: ignoring. Hoping that's safe.\n";
return;
}
// Ignore calls to NULL pointers.
if (isa<ConstantPointerNull>(CS.getCalledValue())) {
- std::cerr << "WARNING: Ignoring call using NULL function pointer.\n";
+ errs() << "WARNING: Ignoring call using NULL function pointer.\n";
return;
}
@@ -600,7 +602,7 @@
visitStrdupCall(CS);
return;
} else if (CF->getName() == "valloc") {
- std::cerr << "VALLOC USED BUT NOT HANDLED!\n";
+ errs() << "VALLOC USED BUT NOT HANDLED!\n";
abort();
}
}
@@ -621,7 +623,7 @@
// For indirect callees, find any callee since all DS graphs have been
// merged.
if (CF) { // Direct calls are nice and simple.
- DEBUG(std::cerr << " Handling direct call: " << *TheCall);
+ DEBUG(errs() << " Handling direct call: " << *TheCall);
FuncInfo *CFI = PAInfo.getFuncInfo(*CF);
if (CFI == 0 || CFI->Clone == 0) { // Nothing to transform...
visitInstruction(*TheCall);
@@ -633,7 +635,7 @@
assert ((Graphs.hasDSGraph (*CF)) && "Function has no ECGraph!\n");
CalleeGraph = Graphs.getDSGraph(*CF);
} else {
- DEBUG(std::cerr << " Handling indirect call: " << *TheCall);
+ DEBUG(errs() << " Handling indirect call: " << *TheCall);
// Here we fill in CF with one of the possible called functions. Because we
// merged together all of the arguments to all of the functions in the
@@ -754,7 +756,7 @@
// Dinakar: We need pooldescriptors for allocas in the callee if it
// escapes
BasicBlock::iterator InsertPt = TheCall->getParent()->getParent()->front().begin();
- ArgVal = new AllocaInst(PAInfo.getPoolType(),
+ ArgVal = new AllocaInst(PAInfo.getPoolType(&TheCall->getContext()),
0,
"PD",
InsertPt);
@@ -767,7 +769,7 @@
}
//probably need to update DSG
- // std::cerr << "WARNING: NULL POOL ARGUMENTS ARE PASSED IN!\n";
+ // errs() << "WARNING: NULL POOL ARGUMENTS ARE PASSED IN!\n";
}
}
Args.push_back(ArgVal);
@@ -809,9 +811,9 @@
AddPoolUse(*NewCall, Args[i], PoolUses);
TheCall->replaceAllUsesWith(NewCall);
- DEBUG(std::cerr << " Result Call: " << *NewCall);
+ DEBUG(errs() << " Result Call: " << *NewCall);
- if (TheCall->getType() != VoidType) {
+ if (!TheCall->getType()->isVoidTy()) {
// If we are modifying the original function, update the DSGraph...
DSGraph::ScalarMapTy &SM = G->getScalarMap();
DSGraph::ScalarMapTy::iterator CII = SM.find(TheCall);
More information about the llvm-commits
mailing list