It turns out most of the thumb2 instructions are not allowed to touch SP. The semanti...
[llvm/avr.git] / lib / CodeGen / PBQP / SimpleGraph.h
blob1ca9caee3467fe254c3886b7477bd60f1dd8ed69
1 //===-- SimpleGraph.h - Simple PBQP Graph ----------------------*- C++ --*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Simple PBQP graph class representing a PBQP problem. Graphs of this type
11 // can be passed to a PBQPSolver instance to solve the PBQP problem.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CODEGEN_PBQP_SIMPLEGRAPH_H
16 #define LLVM_CODEGEN_PBQP_SIMPLEGRAPH_H
18 #include "GraphBase.h"
20 namespace PBQP {
22 class SimpleEdge;
24 class SimpleNode : public NodeBase<SimpleNode, SimpleEdge> {
25 public:
26 SimpleNode(const Vector &costs) :
27 NodeBase<SimpleNode, SimpleEdge>(costs) {}
30 class SimpleEdge : public EdgeBase<SimpleNode, SimpleEdge> {
31 public:
32 SimpleEdge(const NodeIterator &node1Itr, const NodeIterator &node2Itr,
33 const Matrix &costs) :
34 EdgeBase<SimpleNode, SimpleEdge>(node1Itr, node2Itr, costs) {}
37 class SimpleGraph : public GraphBase<SimpleNode, SimpleEdge> {
38 private:
40 typedef GraphBase<SimpleNode, SimpleEdge> PGraph;
42 void copyFrom(const SimpleGraph &other) {
43 assert(other.areNodeIDsValid() &&
44 "Cannot copy from another graph unless IDs have been assigned.");
46 std::vector<NodeIterator> newNodeItrs(other.getNumNodes());
48 for (ConstNodeIterator nItr = other.nodesBegin(), nEnd = other.nodesEnd();
49 nItr != nEnd; ++nItr) {
50 newNodeItrs[other.getNodeID(nItr)] = addNode(other.getNodeCosts(nItr));
53 for (ConstEdgeIterator eItr = other.edgesBegin(), eEnd = other.edgesEnd();
54 eItr != eEnd; ++eItr) {
56 unsigned node1ID = other.getNodeID(other.getEdgeNode1Itr(eItr)),
57 node2ID = other.getNodeID(other.getEdgeNode2Itr(eItr));
59 addEdge(newNodeItrs[node1ID], newNodeItrs[node2ID],
60 other.getEdgeCosts(eItr));
64 void copyFrom(SimpleGraph &other) {
65 if (!other.areNodeIDsValid()) {
66 other.assignNodeIDs();
68 copyFrom(const_cast<const SimpleGraph&>(other));
71 public:
73 SimpleGraph() {}
76 SimpleGraph(const SimpleGraph &other) : PGraph() {
77 copyFrom(other);
80 SimpleGraph& operator=(const SimpleGraph &other) {
81 clear();
82 copyFrom(other);
83 return *this;
86 NodeIterator addNode(const Vector &costs) {
87 return PGraph::addConstructedNode(SimpleNode(costs));
90 EdgeIterator addEdge(const NodeIterator &node1Itr,
91 const NodeIterator &node2Itr,
92 const Matrix &costs) {
93 return PGraph::addConstructedEdge(SimpleEdge(node1Itr, node2Itr, costs));
100 #endif // LLVM_CODEGEN_PBQP_SIMPLEGRAPH_H