33 namespace VirtualCFG {
47 enum EdgeConditionKind
56 eckForallIndicesInRange,
57 eckForallIndicesNotInRange,
58 eckComputedGotoCaseLabel,
61 eckArithmeticIfGreater,
83 std::string toString()
const;
85 std::string toStringForDebugging()
const;
87 std::string id()
const;
93 std::vector<CFGEdge> outEdges()
const;
95 std::vector<CFGEdge> inEdges()
const;
100 bool isInteresting()
const;
106 bool operator<(
const CFGNode& o)
const {
return node < o.node || (node == o.node && index < o.index);}
121 std::string toString()
const;
123 std::string toStringForDebugging()
const;
125 std::string id()
const;
131 EdgeConditionKind condition()
const;
135 unsigned int computedGotoCaseIndex()
const;
139 std::vector<SgInitializedName*> scopesBeingExited()
const;
141 std::vector<SgInitializedName*> scopesBeingEntered()
const;
148 bool operator<(
const CFGEdge& o)
const {
return src < o.src || (src == o.src && tgt < o.tgt);}
158 std::vector<CFGEdge> edges;
165 assert (!a.edges.empty());
166 assert (!b.edges.empty());
167 assert (a.edges.back().target() == b.edges.front().source());
168 edges.insert(edges.end(),b.edges.begin(),b.edges.end());
176 std::string toString()
const;
177 std::string toStringForDebugging()
const;
178 std::string id()
const;
180 CFGNode source()
const {assert (!edges.empty());
return edges.front().source();}
182 CFGNode target()
const {assert (!edges.empty());
return edges.back().target();}
184 EdgeConditionKind condition()
const {
185 for (
unsigned int i = 0; i < edges.size(); ++i) {
186 EdgeConditionKind kind = edges[i].condition();
187 if (kind != eckUnconditional)
return kind;
189 return eckUnconditional;
193 for (
unsigned int i = 0; i < edges.size(); ++i) {
195 if (label != NULL)
return label;
200 for (
unsigned int i = 0; i < edges.size(); ++i) {
202 if (base != NULL)
return base;
206 std::vector<SgInitializedName*> scopesBeingExited()
const {
207 std::vector<SgInitializedName*> result;
208 for (
unsigned int i = 0; i < edges.size(); ++i) {
209 std::vector<SgInitializedName*> s_i = edges[i].scopesBeingExited();
210 result.insert(result.end(), s_i.begin(), s_i.end());
214 std::vector<SgInitializedName*> scopesBeingEntered()
const {
215 std::vector<SgInitializedName*> result;
216 for (
unsigned int i = 0; i < edges.size(); ++i) {
217 std::vector<SgInitializedName*> s_i = edges[i].scopesBeingEntered();
218 result.insert(result.end(), s_i.begin(), s_i.end());
222 bool operator==(
const CFGPath& o)
const {
return edges == o.edges;}
223 bool operator!=(
const CFGPath& o)
const {
return edges != o.edges;}
227 if (edges.size() != o.edges.size()) {
228 return edges.size() < o.edges.size();
230 for (
unsigned int i = 0; i < edges.size(); ++i) {
231 if (edges[i] != o.edges[i]) {
232 return edges[i] < o.edges[i];
246 inline CFGPath mergePaths(
const CFGPath& hd,
const CFGPath& tl) {
248 return CFGPath(hd, tl);
252 inline CFGPath mergePathsReversed(
const CFGPath& tl,
const CFGPath& hd) {
253 return mergePaths(hd, tl);
258 inline CFGNode cfgBeginningOfConstruct(
SgNode* c) {
259 return CFGNode(c, 0);
264 unsigned int cfgIndexForEndWrapper(
SgNode* n);
269 inline CFGNode cfgEndOfConstruct(
SgNode* c) {
270 return CFGNode(c, cfgIndexForEndWrapper(c));
274 inline CFGNode makeCfg(
SgNode* start) {
275 return cfgBeginningOfConstruct(start);
279 class InterestingEdge;
286 std::string toString()
const {
return n.
toString();}
288 std::string id()
const {
return n.
id();}
290 const CFGNode& toNode()
const {
return n; }
291 unsigned int getIndex()
const {
return n.
getIndex();}
292 std::vector<InterestingEdge> outEdges()
const;
293 std::vector<InterestingEdge> inEdges()
const;
294 bool isInteresting()
const {
return true;}
296 bool operator!=(
const InterestingNode& o)
const {
return !(*
this == o);}
305 std::string toString()
const {
return p.toString();}
306 std::string toStringForDebugging()
const {
return p.toStringForDebugging();}
307 std::string id()
const {
return p.id();}
310 EdgeConditionKind condition()
const {
return p.condition();}
312 SgExpression* conditionBasedOn()
const {
return p.conditionBasedOn();}
313 std::vector<SgInitializedName*> scopesBeingExited()
const {
return p.scopesBeingExited();}
314 std::vector<SgInitializedName*> scopesBeingEntered()
const {
return p.scopesBeingEntered();}
326 CFGNode getCFGTargetOfFortranLabelSymbol(
SgLabelSymbol* sym);
331 template <
class Node1T,
class Node2T,
class EdgeT>
332 void makeEdge(Node1T from, Node2T to, std::vector<EdgeT>& result);
336 #define SGFUNCTIONCALLEXP_INTERPROCEDURAL_INDEX 2
337 #define SGCONSTRUCTORINITIALIZER_INTERPROCEDURAL_INDEX 1
338 #define SGFUNCTIONDEFINITION_INTERPROCEDURAL_INDEX 2
340 #define SGFUNCTIONCALLEXP_INTERPROCEDURAL_INDEX 2
341 #define SGCONSTRUCTORINITIALIZER_INTERPROCEDURAL_INDEX 1
342 #define SGFUNCTIONDEFINITION_INTERPROCEDURAL_INDEX 2
345 template <
class NodeT1,
class NodeT2,
class EdgeT>
346 void makeEdge(NodeT1 from, NodeT2 to, std::vector<EdgeT>& result);
348 #endif // VIRTUAL_CFG_H