OpenADFortTk (including Open64 and OpenAnalysis references)
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
RIFG.cpp
Go to the documentation of this file.
1
23
//************************** System Include Files ***************************
24
25
#ifdef NO_STD_CHEADERS
26
# include <assert.h>
27
# include <limits.h>
28
#else
29
# include <cassert>
30
# include <climits>
31
#endif
32
33
#include <inttypes.h>
34
35
//*************************** User Include Files ****************************
36
37
#include <
OpenAnalysis/Utils/RIFG.hpp
>
38
#include <
OpenAnalysis/CFG/CFGInterface.hpp
>
39
40
//*************************** Forward Declarations **************************
41
42
//***************************************************************************
43
44
//***************************************************************************
45
// Representation Independent Flowgraph
46
//***************************************************************************
47
48
namespace
OA {
49
50
unsigned
int
RIFG::NIL
= 0;
51
52
RIFG::RIFG
(
OA_ptr<DGraph::DGraphInterface>
graph_,
53
OA_ptr<DGraph::NodeInterface>
source,
54
OA_ptr<DGraph::NodeInterface>
sink)
55
: graph(graph_), mSource(source), mSink(sink)
56
{
57
// Sanity check
58
assert(
graph
->
getNumNodes
() <= UINT_MAX);
59
assert(
graph
->
getNumEdges
() <= UINT_MAX);
60
61
// Initialize the node-id to node map: ids are 1...num_nodes
62
highWaterMarkNodeId
=
graph
->
getNumNodes
();
63
OA::OA_ptr<OA::DGraph::NodesIteratorInterface>
it1 =
64
graph
->
getNodesIterator
();
65
for
(
NodeId
i = 1; it1->
isValid
(); ++(*it1), ++i) {
66
OA::OA_ptr<OA::DGraph::NodeInterface>
node = it1->
current
();
67
node_to_id_map
[node] = i;
68
id_to_node_map
[i] = node;
69
}
70
71
// Initialize the edge-id to edge map: ids are 1...num_edges
72
highWaterMarkEdgeId
=
graph
->
getNumEdges
();
73
OA::OA_ptr<OA::DGraph::EdgesIteratorInterface>
it2 =
74
graph
->
getEdgesIterator
();
75
for
(
NodeId
i = 1; it2->
isValid
(); ++(*it2), ++i) {
76
OA::OA_ptr<OA::DGraph::EdgeInterface>
edge = it2->
current
();
77
edge_to_id_map
[edge] = i;
78
id_to_edge_map
[i] = edge;
79
}
80
}
81
82
83
RIFG::~RIFG
()
84
{
85
node_to_id_map
.clear();
86
id_to_node_map
.clear();
87
edge_to_id_map
.clear();
88
id_to_edge_map
.clear();
89
}
90
91
92
bool
93
RIFG::isValid
(
RIFG::NodeId
nid)
const
94
{
95
return
true
;
96
}
97
98
99
RIFG::NodeId
100
RIFG::getSource
()
const
101
{
102
return
(
getNodeId
(
mSource
));
103
}
104
105
106
RIFG::NodeId
107
RIFG::getSink
()
const
108
{
109
return
(
getNodeId
(
mSink
));
110
}
111
112
RIFG::NodeId
113
RIFG::getEdgeSrc
(
RIFG::EdgeId
eid)
const
114
{
115
OA::OA_ptr<OA::DGraph::EdgeInterface>
e =
getEdge
(eid);
116
OA::OA_ptr<OA::DGraph::NodeInterface>
n
= e->
getSource
();
117
return
(
getNodeId
(n));
118
}
119
120
121
RIFG::NodeId
122
RIFG::getEdgeSink
(
RIFG::EdgeId
eid)
const
123
{
124
OA::OA_ptr<OA::DGraph::EdgeInterface>
e =
getEdge
(eid);
125
OA::OA_ptr<OA::DGraph::NodeInterface>
n
= e->
getSink
();
126
return
(
getNodeId
(n));
127
}
128
129
130
OA_ptr<RIFG::NodesIterator>
131
RIFG::getNodesIterator
()
const
132
{
133
OA_ptr<RIFG::NodesIterator>
it;
134
it =
new
NodesIterator
(*
this
);
135
return
it;
136
}
137
138
139
OA_ptr<RIFG::IncomingEdgesIterator>
140
RIFG::getIncomingEdgesIterator
(
NodeId
nid)
const
141
{
142
OA_ptr<RIFG::IncomingEdgesIterator>
it;
143
it =
new
IncomingEdgesIterator
(*
this
, nid);
144
return
it;
145
}
146
147
148
OA_ptr<RIFG::OutgoingEdgesIterator>
149
RIFG::getOutgoingEdgesIterator
(
NodeId
nid)
const
150
{
151
OA_ptr<RIFG::OutgoingEdgesIterator>
it;
152
it =
new
OutgoingEdgesIterator
(*
this
, nid);
153
return
it;
154
}
155
156
157
void
158
RIFG::dumpNode
(std::ostream& os,
RIFG::NodeId
nid)
159
{
160
// getNode(nid)->dump(os);
161
}
162
163
164
//***************************************************************************
165
//
166
//***************************************************************************
167
168
OA_ptr<DGraph::NodeInterface>
169
RIFG::getSourceNode
(
OA_ptr<DGraph::DGraphInterface>
graph)
170
{
171
if
(graph.
isa
<
OA::CFG::CFGInterface
>()) {
172
OA_ptr<OA::CFG::CFGInterface>
g = graph.
convert
<
OA::CFG::CFGInterface
>();
173
OA_ptr<OA::CFG::NodeInterface>
n
= g->
getEntry
();
174
return
n
;
175
}
176
else
{
177
OA_ptr<DGraph::NodesIteratorInterface>
it =
178
graph->
getEntryNodesIterator
();
179
assert(it->isValid());
180
OA_ptr<DGraph::NodeInterface>
n
= it->current();
181
return
n
;
182
}
183
}
184
185
OA_ptr<DGraph::NodeInterface>
186
RIFG::getSinkNode
(
OA_ptr<DGraph::DGraphInterface>
graph)
187
{
188
if
(graph.
isa
<
OA::CFG::CFGInterface
>()) {
189
OA_ptr<OA::CFG::CFGInterface>
g = graph.
convert
<
OA::CFG::CFGInterface
>();
190
OA_ptr<OA::CFG::NodeInterface>
n
= g->
getExit
();
191
return
n
;
192
}
193
else
{
194
OA_ptr<DGraph::NodesIteratorInterface>
it =
195
graph->
getExitNodesIterator
();
196
assert(it->isValid());
197
OA_ptr<DGraph::NodeInterface>
n
= it->current();
198
return
n
;
199
}
200
}
201
202
}
// end of namespace OA
203
OpenAnalysis
src
OpenAnalysis
Utils
RIFG.cpp
Generated on Fri Mar 14 2014 04:23:14 for OpenADFortTk (including Open64 and OpenAnalysis references) by
1.8.4