+/*
+ * Copyright 2011 Christoph Bumiller
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
#ifndef __NV50_IR_GRAPH_H__
#define __NV50_IR_GRAPH_H__
public:
class Node;
- class GraphIterator : public Iterator
- {
- public:
- virtual ~GraphIterator() { };
- };
-
class Edge
{
public:
class EdgeIterator : public Iterator
{
public:
- EdgeIterator() : e(0), t(0), d(0) { }
- EdgeIterator(Graph::Edge *first, int dir) : e(first), t(first), d(dir) { }
+ EdgeIterator() : e(0), t(0), d(0), rev(false) { }
+ EdgeIterator(Graph::Edge *first, int dir, bool reverse)
+ : d(dir), rev(reverse)
+ {
+ t = e = ((rev && first) ? first->prev[d] : first);
+ }
- virtual void next() { e = (e->next[d] == t) ? 0 : e->next[d]; }
+ virtual void next()
+ {
+ Graph::Edge *n = (rev ? e->prev[d] : e->next[d]);
+ e = (n == t ? NULL : n);
+ }
virtual bool end() const { return !e; }
virtual void *get() const { return e; }
Graph::Edge *e;
Graph::Edge *t;
int d;
+ bool rev;
};
class Node
bool detach(Node *);
void cut();
- inline EdgeIterator outgoing() const;
- inline EdgeIterator incident() const;
+ inline EdgeIterator outgoing(bool reverse = false) const;
+ inline EdgeIterator incident(bool reverse = false) const;
inline Node *parent() const; // returns NULL if count(incident edges) != 1
void insert(Node *node); // attach to or set as root
- GraphIterator *iteratorDFS(bool preorder = true);
- GraphIterator *iteratorCFG();
+ IteratorRef iteratorDFS(bool preorder = true);
+ IteratorRef iteratorCFG();
// safe iterators are unaffected by changes to the *edges* of the graph
- GraphIterator *safeIteratorDFS(bool preorder = true);
- GraphIterator *safeIteratorCFG();
-
- inline void putIterator(Iterator *); // should be GraphIterator *
+ IteratorRef safeIteratorDFS(bool preorder = true);
+ IteratorRef safeIteratorCFG();
void classifyEdges();
return visited;
}
-void Graph::putIterator(Iterator *iter)
-{
- delete reinterpret_cast<GraphIterator *>(iter);
-}
-
-Graph::EdgeIterator Graph::Node::outgoing() const
+Graph::EdgeIterator Graph::Node::outgoing(bool reverse) const
{
- return EdgeIterator(out, 0);
+ return EdgeIterator(out, 0, reverse);
}
-Graph::EdgeIterator Graph::Node::incident() const
+Graph::EdgeIterator Graph::Node::incident(bool reverse) const
{
- return EdgeIterator(in, 1);
+ return EdgeIterator(in, 1, reverse);
}
int Graph::Node::incidentCountFwd() const