diff options
author | Lang Hames <lhames@gmail.com> | 2009-08-06 23:32:48 +0000 |
---|---|---|
committer | Lang Hames <lhames@gmail.com> | 2009-08-06 23:32:48 +0000 |
commit | 88fae6f9c966353ca94a66708fcb16bd0ab22b68 (patch) | |
tree | dc43bfa1a56bec5d2d110a7432a49795c4053751 /llvm/lib/CodeGen/PBQP/SimpleGraph.h | |
parent | 15a5fad94bb8924a1d7cb8a5c87cb8c98ef72f52 (diff) | |
download | bcm5719-llvm-88fae6f9c966353ca94a66708fcb16bd0ab22b68.tar.gz bcm5719-llvm-88fae6f9c966353ca94a66708fcb16bd0ab22b68.zip |
New C++ PBQP solver. Currently about as fast (read _slow_) as the old C based solver, but I'll be working to improve that. The PBQP allocator has been updated to use the new solver.
llvm-svn: 78354
Diffstat (limited to 'llvm/lib/CodeGen/PBQP/SimpleGraph.h')
-rw-r--r-- | llvm/lib/CodeGen/PBQP/SimpleGraph.h | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/PBQP/SimpleGraph.h b/llvm/lib/CodeGen/PBQP/SimpleGraph.h new file mode 100644 index 00000000000..595269c327e --- /dev/null +++ b/llvm/lib/CodeGen/PBQP/SimpleGraph.h @@ -0,0 +1,86 @@ +#ifndef LLVM_CODEGEN_PBQP_SIMPLEGRAPH_H +#define LLVM_CODEGEN_PBQP_SIMPLEGRAPH_H + +#include "GraphBase.h" + +namespace PBQP { + +class SimpleEdge; + +class SimpleNode : public NodeBase<SimpleNode, SimpleEdge> { +public: + SimpleNode(const Vector &costs) : + NodeBase<SimpleNode, SimpleEdge>(costs) {} +}; + +class SimpleEdge : public EdgeBase<SimpleNode, SimpleEdge> { +public: + SimpleEdge(const NodeIterator &node1Itr, const NodeIterator &node2Itr, + const Matrix &costs) : + EdgeBase<SimpleNode, SimpleEdge>(node1Itr, node2Itr, costs) {} +}; + +class SimpleGraph : public GraphBase<SimpleNode, SimpleEdge> { +private: + + typedef GraphBase<SimpleNode, SimpleEdge> PGraph; + + void copyFrom(const SimpleGraph &other) { + assert(other.areNodeIDsValid() && + "Cannot copy from another graph unless IDs have been assigned."); + + std::vector<NodeIterator> newNodeItrs(other.getNumNodes()); + + for (ConstNodeIterator nItr = other.nodesBegin(), nEnd = other.nodesEnd(); + nItr != nEnd; ++nItr) { + newNodeItrs[other.getNodeID(nItr)] = addNode(other.getNodeCosts(nItr)); + } + + for (ConstEdgeIterator eItr = other.edgesBegin(), eEnd = other.edgesEnd(); + eItr != eEnd; ++eItr) { + + unsigned node1ID = other.getNodeID(other.getEdgeNode1Itr(eItr)), + node2ID = other.getNodeID(other.getEdgeNode2Itr(eItr)); + + addEdge(newNodeItrs[node1ID], newNodeItrs[node2ID], + other.getEdgeCosts(eItr)); + } + } + + void copyFrom(SimpleGraph &other) { + if (!other.areNodeIDsValid()) { + other.assignNodeIDs(); + } + copyFrom(const_cast<const SimpleGraph&>(other)); + } + +public: + + SimpleGraph() {} + + + SimpleGraph(const SimpleGraph &other) : PGraph() { + copyFrom(other); + } + + SimpleGraph& operator=(const SimpleGraph &other) { + clear(); + copyFrom(other); + return *this; + } + + NodeIterator addNode(const Vector &costs) { + return PGraph::addConstructedNode(SimpleNode(costs)); + } + + EdgeIterator addEdge(const NodeIterator &node1Itr, + const NodeIterator &node2Itr, + const Matrix &costs) { + return PGraph::addConstructedEdge(SimpleEdge(node1Itr, node2Itr, costs)); + } + +}; + +} + +#endif // LLVM_CODEGEN_PBQP_SIMPLEGRAPH_H |