[llvm-commits] [poolalloc] r57681 - in /poolalloc/trunk: include/dsa/DataStructure.h lib/DSA/EquivClassGraphs.cpp lib/DSA/TopDownClosure.cpp lib/PoolAllocate/PoolAllocate.cpp
Andrew Lenharth
alenhar2 at cs.uiuc.edu
Fri Oct 17 08:51:40 PDT 2008
Author: alenhar2
Date: Fri Oct 17 10:51:39 2008
New Revision: 57681
URL: http://llvm.org/viewvc/llvm-project?rev=57681&view=rev
Log:
The return of EQClassGraph, and by popular demand, EQTD
Added:
poolalloc/trunk/lib/DSA/EquivClassGraphs.cpp
Modified:
poolalloc/trunk/include/dsa/DataStructure.h
poolalloc/trunk/lib/DSA/TopDownClosure.cpp
poolalloc/trunk/lib/PoolAllocate/PoolAllocate.cpp
Modified: poolalloc/trunk/include/dsa/DataStructure.h
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/include/dsa/DataStructure.h?rev=57681&r1=57680&r2=57681&view=diff
==============================================================================
--- poolalloc/trunk/include/dsa/DataStructure.h (original)
+++ poolalloc/trunk/include/dsa/DataStructure.h Fri Oct 17 10:51:39 2008
@@ -52,7 +52,6 @@
/// Do we clone Graphs or steal them?
bool Clone;
-
/// do we reset the aux list to the func list?
bool resetAuxCalls;
@@ -203,6 +202,8 @@
///
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired<LocalDataStructures>();
+ AU.addPreserved<TargetData>();
+ AU.setPreservesCFG();
}
};
@@ -237,6 +238,8 @@
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired<StdLibDataStructures>();
+ AU.addPreserved<TargetData>();
+ AU.setPreservesCFG();
}
protected:
@@ -257,6 +260,54 @@
void finalizeGlobals(void);
};
+/// CompleteBUDataStructures - This is the exact same as the bottom-up graphs,
+/// but we use take a completed call graph and inline all indirect callees into
+/// their callers graphs, making the result more useful for things like pool
+/// allocation.
+///
+class CompleteBUDataStructures : public BUDataStructures {
+protected:
+ void buildIndirectFunctionSets(Module &M);
+public:
+ static char ID;
+ CompleteBUDataStructures(intptr_t CID = (intptr_t)&ID,
+ const char* name = "dsa-cbu",
+ const char* printname = "cbu.")
+ : BUDataStructures(CID, name, printname) {}
+ ~CompleteBUDataStructures() { releaseMemory(); }
+
+ virtual bool runOnModule(Module &M);
+
+ virtual void getAnalysisUsage(AnalysisUsage &AU) const {
+ AU.addRequired<BUDataStructures>();
+ AU.addPreserved<TargetData>();
+ AU.setPreservesCFG();
+ }
+
+};
+
+/// EquivBUDataStructures - This is the same as the complete bottom-up graphs, but
+/// with functions partitioned into equivalence classes and a single merged
+/// DS graph for all functions in an equivalence class. After this merging,
+/// graphs are inlined bottom-up on the SCCs of the final (CBU) call graph.
+///
+class EquivBUDataStructures : public CompleteBUDataStructures {
+ void mergeGraphsByGlobalECs();
+public:
+ static char ID;
+ EquivBUDataStructures()
+ : CompleteBUDataStructures((intptr_t)&ID, "dsa-eq", "eq.") {}
+ ~EquivBUDataStructures() { releaseMemory(); }
+
+ virtual bool runOnModule(Module &M);
+
+ virtual void getAnalysisUsage(AnalysisUsage &AU) const {
+ AU.addRequired<CompleteBUDataStructures>();
+ AU.addPreserved<TargetData>();
+ AU.setPreservesCFG();
+ }
+
+};
/// TDDataStructures - Analysis that computes new data structure graphs
/// for each function using the closed graphs for the callers computed
@@ -291,9 +342,12 @@
// the arguments for each function.
std::map<std::vector<const Function*>, DSGraph*> IndCallMap;
+ bool useEQBU;
+
public:
static char ID;
- TDDataStructures() : DataStructures((intptr_t)&ID, "td.") {}
+ TDDataStructures(intptr_t CID = (intptr_t)&ID, const char* printname = "td.", bool useEQ = false)
+ : DataStructures(CID, "td."), useEQBU(useEQ) {}
~TDDataStructures() { releaseMemory(); }
virtual bool runOnModule(Module &M);
@@ -301,8 +355,12 @@
/// getAnalysisUsage - This obviously provides a data structure graph.
///
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
- AU.addRequired<BUDataStructures>();
- AU.setPreservesAll();
+ if (useEQBU)
+ AU.addRequired<EquivBUDataStructures>();
+ else
+ AU.addRequired<BUDataStructures>();
+ AU.addPreserved<TargetData>();
+ AU.setPreservesCFG();
}
private:
@@ -314,27 +372,19 @@
std::vector<DSGraph*> &PostOrder);
};
-
-/// CompleteBUDataStructures - This is the exact same as the bottom-up graphs,
-/// but we use take a completed call graph and inline all indirect callees into
-/// their callers graphs, making the result more useful for things like pool
-/// allocation.
+/// EQTDDataStructures - Analysis that computes new data structure graphs
+/// for each function using the closed graphs for the callers computed
+/// by the EQ bottom-up pass.
///
-class CompleteBUDataStructures : public BUDataStructures {
- void buildIndirectFunctionSets(Module &M);
+class EQTDDataStructures : public TDDataStructures {
public:
static char ID;
- CompleteBUDataStructures()
- : BUDataStructures((intptr_t)&ID, "dsa-cbu", "cbu.") {}
- ~CompleteBUDataStructures() { releaseMemory(); }
-
- virtual bool runOnModule(Module &M);
+ EQTDDataStructures()
+ :TDDataStructures((intptr_t)&ID, "td.", false)
+ {}
+};
- virtual void getAnalysisUsage(AnalysisUsage &AU) const {
- AU.addRequired<BUDataStructures>();
- }
-};
} // End llvm namespace
Added: poolalloc/trunk/lib/DSA/EquivClassGraphs.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/EquivClassGraphs.cpp?rev=57681&view=auto
==============================================================================
--- poolalloc/trunk/lib/DSA/EquivClassGraphs.cpp (added)
+++ poolalloc/trunk/lib/DSA/EquivClassGraphs.cpp Fri Oct 17 10:51:39 2008
@@ -0,0 +1,89 @@
+//===- EquivClassGraphs.cpp - Merge equiv-class graphs & inline bottom-up -===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file was developed by the LLVM research group and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This pass is the same as the complete bottom-up graphs, but
+// with functions partitioned into equivalence classes and a single merged
+// DS graph for all functions in an equivalence class. After this merging,
+// graphs are inlined bottom-up on the SCCs of the final (CBU) call graph.
+//
+//===----------------------------------------------------------------------===//
+
+#define DEBUG_TYPE "ECGraphs"
+#include "dsa/DataStructure.h"
+#include "llvm/DerivedTypes.h"
+#include "llvm/Module.h"
+#include "llvm/Pass.h"
+#include "dsa/DSGraph.h"
+#include "llvm/Support/CallSite.h"
+#include "llvm/Support/Debug.h"
+#include "llvm/ADT/SCCIterator.h"
+#include "llvm/ADT/Statistic.h"
+#include "llvm/ADT/EquivalenceClasses.h"
+#include "llvm/ADT/STLExtras.h"
+using namespace llvm;
+
+namespace {
+ RegisterPass<EquivBUDataStructures> X("dsa-eq",
+ "Equivalence-class Bottom-up Data Structure Analysis");
+}
+
+char EquivBUDataStructures::ID = 0;
+
+// runOnModule - Calculate the bottom up data structure graphs for each function
+// in the program.
+//
+bool EquivBUDataStructures::runOnModule(Module &M) {
+ init(&getAnalysis<CompleteBUDataStructures>(), false, true, false, true);
+
+ //update the EQ class from indirect calls
+ buildIndirectFunctionSets(M);
+
+ mergeGraphsByGlobalECs();
+
+ return runOnModuleInternal(M);
+}
+
+
+// Merge all graphs that are in the same equivalence class
+// the ensures things like poolalloc only deal with one graph for a
+// call site
+void EquivBUDataStructures::mergeGraphsByGlobalECs() {
+ // Merge the graphs for each equivalence class.
+ //
+ for (EquivalenceClasses<const GlobalValue*>::iterator EQSI = GlobalECs.begin(),
+ EQSE = GlobalECs.end(); EQSI != EQSE; ++EQSI) {
+ if (!EQSI->isLeader()) continue;
+ DSGraph* BaseGraph = 0;
+ std::vector<DSNodeHandle> Args;
+ for (EquivalenceClasses<const GlobalValue*>::member_iterator MI = GlobalECs.member_begin(EQSI);
+ MI != GlobalECs.member_end(); ++MI) {
+ if (const Function* F = dyn_cast<Function>(*MI)) {
+ if (!BaseGraph) {
+ BaseGraph = &getOrCreateGraph(F);
+ BaseGraph->getFunctionArgumentsForCall(F, Args);
+ } else if (BaseGraph->containsFunction(F)) {
+ //already merged
+ } else {
+ std::vector<DSNodeHandle> NextArgs;
+ BaseGraph->cloneInto(getOrCreateGraph(F));
+ BaseGraph->getFunctionArgumentsForCall(F, 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]);
+ setDSGraph(*F, BaseGraph);
+ }
+ }
+ }
+ }
+}
+
Modified: poolalloc/trunk/lib/DSA/TopDownClosure.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/TopDownClosure.cpp?rev=57681&r1=57680&r2=57681&view=diff
==============================================================================
--- poolalloc/trunk/lib/DSA/TopDownClosure.cpp (original)
+++ poolalloc/trunk/lib/DSA/TopDownClosure.cpp Fri Oct 17 10:51:39 2008
@@ -35,10 +35,14 @@
RegisterPass<TDDataStructures> // Register the pass
Y("dsa-td", "Top-down Data Structure Analysis");
+ RegisterPass<EQTDDataStructures> // Register the pass
+ Z("dsa-eqtd", "EQ Top-down Data Structure Analysis");
+
STATISTIC (NumTDInlines, "Number of graphs inlined");
}
char TDDataStructures::ID;
+char EQTDDataStructures::ID;
void TDDataStructures::markReachableFunctionsExternallyAccessible(DSNode *N,
hash_set<DSNode*> &Visited) {
@@ -61,7 +65,10 @@
// program.
//
bool TDDataStructures::runOnModule(Module &M) {
- init(&getAnalysis<BUDataStructures>(), true, true, true, false);
+
+ init(useEQBU ? &getAnalysis<EquivBUDataStructures>()
+ : &getAnalysis<BUDataStructures>(),
+ true, true, true, false);
// Figure out which functions must not mark their arguments complete because
// they are accessible outside this compilation unit. Currently, these
Modified: poolalloc/trunk/lib/PoolAllocate/PoolAllocate.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/PoolAllocate/PoolAllocate.cpp?rev=57681&r1=57680&r2=57681&view=diff
==============================================================================
--- poolalloc/trunk/lib/PoolAllocate/PoolAllocate.cpp (original)
+++ poolalloc/trunk/lib/PoolAllocate/PoolAllocate.cpp Fri Oct 17 10:51:39 2008
@@ -87,8 +87,8 @@
}
void PoolAllocate::getAnalysisUsage(AnalysisUsage &AU) const {
- AU.addRequiredTransitive<CompleteBUDataStructures>();
- AU.addPreserved<CompleteBUDataStructures>();
+ AU.addRequired<EquivBUDataStructures>();
+ AU.addPreserved<EquivBUDataStructures>();
// Preserve the pool information across passes
if (SAFECodeEnabled)
@@ -100,7 +100,7 @@
bool PoolAllocate::runOnModule(Module &M) {
if (M.begin() == M.end()) return false;
CurModule = &M;
- Graphs = &getAnalysis<CompleteBUDataStructures>(); // folded inlined CBU graphs
+ Graphs = &getAnalysis<EquivBUDataStructures>(); // folded inlined CBU graphs
CurHeuristic = Heuristic::create();
CurHeuristic->Initialize(M, Graphs->getGlobalsGraph(), *this);
More information about the llvm-commits
mailing list