[llvm-commits] [poolalloc] r159066 - in /poolalloc/trunk: include/dsa/stl_util.h lib/DSA/DSGraph.cpp
Will Dietz
wdietz2 at illinois.edu
Fri Jun 22 19:57:00 PDT 2012
Author: wdietz2
Date: Fri Jun 22 21:57:00 2012
New Revision: 159066
URL: http://llvm.org/viewvc/llvm-project?rev=159066&view=rev
Log:
Introduce 'stl_util.h' to abstract common operations on stl containers.
This abstraction is really to make changing the underlying datastructure
easy (but code still uses appropriately efficient implementations).
Added:
poolalloc/trunk/include/dsa/stl_util.h
Modified:
poolalloc/trunk/lib/DSA/DSGraph.cpp
Added: poolalloc/trunk/include/dsa/stl_util.h
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/include/dsa/stl_util.h?rev=159066&view=auto
==============================================================================
--- poolalloc/trunk/include/dsa/stl_util.h (added)
+++ poolalloc/trunk/include/dsa/stl_util.h Fri Jun 22 21:57:00 2012
@@ -0,0 +1,54 @@
+#ifndef _DSA_STL_UTIL_H_
+#define _DSA_STL_UTIL_H_
+
+#include "llvm/ADT/ilist.h"
+#include <list>
+#include <map>
+#include <vector>
+
+namespace llvm {
+
+// Splicing one container into another as efficiently as we can
+template <typename T>
+inline void splice(std::list<T>& Dst, std::list<T>& Src) {
+ Dst.splice(Dst.end(), Src);
+}
+template <typename T>
+inline void splice(ilist<T>& Dst, ilist<T>& Src) {
+ Dst.splice(Dst.end(), Src);
+}
+
+template <typename T>
+static void splice(std::vector<T>& Dst, std::vector<T>& Src) {
+ if (Dst.empty())
+ Dst.swap(Src);
+ else {
+ Dst.insert(Dst.end(), Src.begin(), Src.end());
+ Src.clear();
+ }
+}
+
+template <typename T, typename U>
+inline void splice(std::map<T, U>& Dst, std::map<T, U>& Src) {
+ if (Dst.empty())
+ Dst.swap(Src);
+ else {
+ Dst.insert(Src.begin(), Src.end());
+ Src.clear();
+ }
+}
+
+// Efficient sort
+template <typename T>
+inline void sort(std::vector<T>& L) {
+ std::sort(L.begin(), L.end());
+}
+
+template <typename T>
+inline void sort(std::list<T>& L) {
+ L.sort();
+}
+
+} // end namespace llvm
+#endif // _DSA_STL_UTIL_H_
+
Modified: poolalloc/trunk/lib/DSA/DSGraph.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/DSGraph.cpp?rev=159066&r1=159065&r2=159066&view=diff
==============================================================================
--- poolalloc/trunk/lib/DSA/DSGraph.cpp (original)
+++ poolalloc/trunk/lib/DSA/DSGraph.cpp Fri Jun 22 21:57:00 2012
@@ -16,6 +16,7 @@
#include "dsa/DSGraph.h"
#include "dsa/DSSupport.h"
#include "dsa/DSNode.h"
+#include "dsa/stl_util.h"
#include "llvm/Constants.h"
#include "llvm/Function.h"
#include "llvm/GlobalVariable.h"
@@ -270,29 +271,19 @@
I != E; ++I)
I->setParentGraph(this);
// Take all of the nodes.
- Nodes.splice(Nodes.end(), RHS->Nodes);
+ splice(Nodes, RHS->Nodes);
// Take all of the calls.
- FunctionCalls.splice(FunctionCalls.end(), RHS->FunctionCalls);
- AuxFunctionCalls.splice(AuxFunctionCalls.end(), RHS->AuxFunctionCalls);
+ splice(FunctionCalls, RHS->FunctionCalls);
+ splice(AuxFunctionCalls, RHS->AuxFunctionCalls);
// Take all of the return nodes.
- if (ReturnNodes.empty()) {
- ReturnNodes.swap(RHS->ReturnNodes);
- } else {
- ReturnNodes.insert(RHS->ReturnNodes.begin(), RHS->ReturnNodes.end());
- RHS->ReturnNodes.clear();
- }
+ splice(ReturnNodes, RHS->ReturnNodes);
// Same for the VA nodes
- if (VANodes.empty()) {
- VANodes.swap(RHS->VANodes);
- } else {
- VANodes.insert(RHS->VANodes.begin(), RHS->VANodes.end());
- RHS->VANodes.clear();
- }
+ splice(VANodes, RHS->VANodes);
- // Merge the scalar map in.
+ // Merge the scalar map in.
ScalarMap.spliceFrom(RHS->ScalarMap);
}
@@ -854,7 +845,7 @@
static void removeIdenticalCalls(DSGraph::FunctionListTy &Calls) {
// Remove trivially identical function calls
- Calls.sort(); // Sort by callee as primary key!
+ sort(Calls);
// Scan the call list cleaning it up as necessary...
DSNodeHandle LastCalleeNode;
@@ -980,7 +971,7 @@
}
// Resort now that we simplified things.
- Calls.sort();
+ sort(Calls);
// Now that we are in sorted order, eliminate duplicates.
DSGraph::FunctionListTy::iterator CI = Calls.begin(), CE = Calls.end();
More information about the llvm-commits
mailing list