It turns out most of the thumb2 instructions are not allowed to touch SP. The semanti...
[llvm/avr.git] / lib / CodeGen / PBQP / AnnotatedGraph.h
blob904061ca4fbc02544e8c5e16b07aa46094d1ea52
1 //===-- AnnotatedGraph.h - Annotated 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 // Annotated PBQP Graph class. This class is used internally by the PBQP solver
11 // to cache information to speed up reduction.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CODEGEN_PBQP_ANNOTATEDGRAPH_H
16 #define LLVM_CODEGEN_PBQP_ANNOTATEDGRAPH_H
18 #include "GraphBase.h"
20 namespace PBQP {
23 template <typename NodeData, typename EdgeData> class AnnotatedEdge;
25 template <typename NodeData, typename EdgeData>
26 class AnnotatedNode : public NodeBase<AnnotatedNode<NodeData, EdgeData>,
27 AnnotatedEdge<NodeData, EdgeData> > {
28 private:
30 NodeData nodeData;
32 public:
34 AnnotatedNode(const Vector &costs, const NodeData &nodeData) :
35 NodeBase<AnnotatedNode<NodeData, EdgeData>,
36 AnnotatedEdge<NodeData, EdgeData> >(costs),
37 nodeData(nodeData) {}
39 NodeData& getNodeData() { return nodeData; }
40 const NodeData& getNodeData() const { return nodeData; }
44 template <typename NodeData, typename EdgeData>
45 class AnnotatedEdge : public EdgeBase<AnnotatedNode<NodeData, EdgeData>,
46 AnnotatedEdge<NodeData, EdgeData> > {
47 private:
49 typedef typename GraphBase<AnnotatedNode<NodeData, EdgeData>,
50 AnnotatedEdge<NodeData, EdgeData> >::NodeIterator
51 NodeIterator;
53 EdgeData edgeData;
55 public:
58 AnnotatedEdge(const NodeIterator &node1Itr, const NodeIterator &node2Itr,
59 const Matrix &costs, const EdgeData &edgeData) :
60 EdgeBase<AnnotatedNode<NodeData, EdgeData>,
61 AnnotatedEdge<NodeData, EdgeData> >(node1Itr, node2Itr, costs),
62 edgeData(edgeData) {}
64 EdgeData& getEdgeData() { return edgeData; }
65 const EdgeData& getEdgeData() const { return edgeData; }
69 template <typename NodeData, typename EdgeData>
70 class AnnotatedGraph : public GraphBase<AnnotatedNode<NodeData, EdgeData>,
71 AnnotatedEdge<NodeData, EdgeData> > {
72 private:
74 typedef GraphBase<AnnotatedNode<NodeData, EdgeData>,
75 AnnotatedEdge<NodeData, EdgeData> > PGraph;
77 typedef AnnotatedNode<NodeData, EdgeData> NodeEntry;
78 typedef AnnotatedEdge<NodeData, EdgeData> EdgeEntry;
81 void copyFrom(const AnnotatedGraph &other) {
82 if (!other.areNodeIDsValid()) {
83 other.assignNodeIDs();
85 std::vector<NodeIterator> newNodeItrs(other.getNumNodes());
87 for (ConstNodeIterator nItr = other.nodesBegin(), nEnd = other.nodesEnd();
88 nItr != nEnd; ++nItr) {
89 newNodeItrs[other.getNodeID(nItr)] = addNode(other.getNodeCosts(nItr));
92 for (ConstEdgeIterator eItr = other.edgesBegin(), eEnd = other.edgesEnd();
93 eItr != eEnd; ++eItr) {
95 unsigned node1ID = other.getNodeID(other.getEdgeNode1(eItr)),
96 node2ID = other.getNodeID(other.getEdgeNode2(eItr));
98 addEdge(newNodeItrs[node1ID], newNodeItrs[node2ID],
99 other.getEdgeCosts(eItr), other.getEdgeData(eItr));
104 public:
106 typedef typename PGraph::NodeIterator NodeIterator;
107 typedef typename PGraph::ConstNodeIterator ConstNodeIterator;
108 typedef typename PGraph::EdgeIterator EdgeIterator;
109 typedef typename PGraph::ConstEdgeIterator ConstEdgeIterator;
111 AnnotatedGraph() {}
113 AnnotatedGraph(const AnnotatedGraph &other) {
114 copyFrom(other);
117 AnnotatedGraph& operator=(const AnnotatedGraph &other) {
118 PGraph::clear();
119 copyFrom(other);
120 return *this;
123 NodeIterator addNode(const Vector &costs, const NodeData &data) {
124 return PGraph::addConstructedNode(NodeEntry(costs, data));
127 EdgeIterator addEdge(const NodeIterator &node1Itr,
128 const NodeIterator &node2Itr,
129 const Matrix &costs, const EdgeData &data) {
130 return PGraph::addConstructedEdge(EdgeEntry(node1Itr, node2Itr,
131 costs, data));
134 NodeData& getNodeData(const NodeIterator &nodeItr) {
135 return getNodeEntry(nodeItr).getNodeData();
138 const NodeData& getNodeData(const NodeIterator &nodeItr) const {
139 return getNodeEntry(nodeItr).getNodeData();
142 EdgeData& getEdgeData(const EdgeIterator &edgeItr) {
143 return getEdgeEntry(edgeItr).getEdgeData();
146 const EdgeEntry& getEdgeData(const EdgeIterator &edgeItr) const {
147 return getEdgeEntry(edgeItr).getEdgeData();
150 SimpleGraph toSimpleGraph() const {
151 SimpleGraph g;
153 if (!PGraph::areNodeIDsValid()) {
154 PGraph::assignNodeIDs();
156 std::vector<SimpleGraph::NodeIterator> newNodeItrs(PGraph::getNumNodes());
158 for (ConstNodeIterator nItr = PGraph::nodesBegin(),
159 nEnd = PGraph::nodesEnd();
160 nItr != nEnd; ++nItr) {
162 newNodeItrs[getNodeID(nItr)] = g.addNode(getNodeCosts(nItr));
165 for (ConstEdgeIterator
166 eItr = PGraph::edgesBegin(), eEnd = PGraph::edgesEnd();
167 eItr != eEnd; ++eItr) {
169 unsigned node1ID = getNodeID(getEdgeNode1(eItr)),
170 node2ID = getNodeID(getEdgeNode2(eItr));
172 g.addEdge(newNodeItrs[node1ID], newNodeItrs[node2ID],
173 getEdgeCosts(eItr));
176 return g;
184 #endif // LLVM_CODEGEN_PBQP_ANNOTATEDGRAPH_H