OpenASIP  2.0
ProgramDependenceEdge.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2009 Tampere University.
3 
4  This file is part of TTA-Based Codesign Environment (TCE).
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23  */
24 /**
25  * @file ProgramDependenceEdge.cc
26  *
27  * Implementation of prototype of graph-based program representation:
28  * declaration of the program dependence edge.
29  *
30  * @author Vladimir Guzma 2006 (vladimir.guzma-no.spam-tut.fi)
31  * @note rating: red
32  */
33 
34 #include "ProgramDependenceEdge.hh"
35 #include "Exception.hh"
36 
37 /**
38  * Constructor, makes new Program Dependence Edge without reference
39  * to original Control Dependence Edge in CDG. It is artificial edge.
40  */
42  : cEdge_(NULL), dEdge_(NULL), type_(type), fixed_(false) {
43 }
44 
45 /**
46  * Constructor, makes new Program Dependence Edge with reference to
47  * original Control Dependence Edge in CDG.
48  * @param cEdge Control Dependence Edge
49  */
51  ControlDependenceEdge& cEdge)
52  : cEdge_(&cEdge), dEdge_(NULL), type_(PDG_EDGE_CONTROL), fixed_(false) {
53  if (cEdge.isLoopCloseEdge()) {
55  } else {
57  }
58 }
59 
60 /**
61  * Constructor, makes new Program Dependence Edge with reference to
62  * original Data Dependence Edge in DDG.
63  * @param dEdge Data Dependence Edge
64  */
66  DataDependenceEdge& dEdge)
67  : cEdge_(NULL), dEdge_(&dEdge), type_(PDG_EDGE_DATA), fixed_(false) {
68 }
69 
70 /**
71  * Empty destructor.
72  */
74 }
75 
76 /**
77  * Returns the edge description as a string.
78  * @return string describing the edge payload
79  */
83  return "PDG_ARTIFICIAL";
84  }
85  if (isLoopCloseEdge()) {
86  return "LoopClose";
87  }
88  if (isDataDependence()) {
89  return dEdge_->toString();
90  }
91  if (isControlDependence()) {
92  return cEdge_->toString();
93  }
94  return "Error!";
95 }
96 /**
97  * Returns the edge description as a string in .dot format.
98  * @return string describing the edge payload in .dot format
99  */
100 TCEString
103  return TCEString("label=\"") + toString() + "\",color=green";
104  }
105  if (isLoopCloseEdge()) {
106  return TCEString("label=\"") + toString() + "\",color=cyan";
107  }
108 
109  if (isControlDependence()) {
110  if (cEdge_->isTrueEdge()) {
111  return TCEString("label=\"") + toString() + "\",color=blue";
112  }
113  if (cEdge_->isFalseEdge()) {
114  return TCEString("label=\"") + toString() + "\",color=red";
115  }
116  return TCEString("label=\"") + toString() + "\"";
117  }
118  return TCEString("label=\"") + toString() + "\",style=dashed";
119 }
120 
121 /**
122  * Tests if edge is control dependence type.
123  * @return true if edge is control dependence
124  */
125 bool
128  return true;
129  }
130  return type_ == PDG_EDGE_CONTROL && cEdge_ != NULL ;
131 }
132 /**
133  * Tests if edge is data dependence type.
134  * @return true if edge is data dependence
135  */
136 bool
138  return type_ == PDG_EDGE_DATA && dEdge_ != NULL;
139 }
140 
141 /**
142  * Tests if edge is artificial control dependence type.
143  * Artificial edges are added during PDG synchronization.
144  * @return true if edge is artificial control dependence
145  */
146 bool
149 }
150 
151 /**
152  * Tests if edge is loop close edge from artificial close node to
153  * loop entry node
154  * @return true if edge is loop close edge
155  */
156 bool
158  return type_ == PDG_EDGE_LOOP_CLOSE;
159 }
160 
161 /**
162  * Returns reference to control dependence edge of CDG.
163  * @return control dependence edge of underlying CDG
164  */
167  if (cEdge_ != NULL) {
168  return *cEdge_;
169  } else {
170  throw InvalidData(__FILE__, __LINE__, __func__,
171  "Not a control dependence edge!");
172  }
173 }
174 /**
175  * Returns reference to data dependence edge of CDG.
176  * @return data dependence edge of underlying DDG
177  */
180  return *dEdge_;
181 }
ProgramDependenceEdge::ProgramDependenceEdge
ProgramDependenceEdge(ControlDependenceEdge &cEdge)
Definition: ProgramDependenceEdge.cc:50
ProgramDependenceEdge::PDG_EDGE_LOOP_CLOSE
@ PDG_EDGE_LOOP_CLOSE
Indicates Data Dependence Edge from DDG.
Definition: ProgramDependenceEdge.hh:46
Exception.hh
ProgramDependenceEdge::dotString
TCEString dotString() const
Definition: ProgramDependenceEdge.cc:101
ProgramDependenceEdge::EdgeType
EdgeType
Definition: ProgramDependenceEdge.hh:43
ProgramDependenceEdge::isDataDependence
bool isDataDependence() const
Definition: ProgramDependenceEdge.cc:137
ControlDependenceEdge::isTrueEdge
bool isTrueEdge() const
Definition: ControlDependenceEdge.hh:61
ProgramDependenceEdge::type_
EdgeType type_
Definition: ProgramDependenceEdge.hh:70
ProgramDependenceEdge::PDG_EDGE_CONTROL
@ PDG_EDGE_CONTROL
Definition: ProgramDependenceEdge.hh:44
ProgramDependenceEdge::isLoopCloseEdge
bool isLoopCloseEdge() const
Definition: ProgramDependenceEdge.cc:157
ProgramDependenceEdge::controlDependenceEdge
ControlDependenceEdge & controlDependenceEdge()
Definition: ProgramDependenceEdge.cc:166
ControlDependenceEdge
Definition: ControlDependenceEdge.hh:44
ControlDependenceEdge::toString
TCEString toString() const
Definition: ControlDependenceEdge.cc:44
ProgramDependenceEdge::isArtificialControlDependence
bool isArtificialControlDependence() const
Definition: ProgramDependenceEdge.cc:147
InvalidData
Definition: Exception.hh:149
ProgramDependenceEdge::~ProgramDependenceEdge
virtual ~ProgramDependenceEdge()
Definition: ProgramDependenceEdge.cc:73
ProgramDependenceEdge::PDG_EDGE_CONTROL_ARTIFICIAL
@ PDG_EDGE_CONTROL_ARTIFICIAL
Loop close edge from close node to loop entry.
Definition: ProgramDependenceEdge.hh:47
ProgramDependenceEdge::toString
TCEString toString() const
Definition: ProgramDependenceEdge.cc:81
__func__
#define __func__
Definition: Application.hh:67
ProgramDependenceEdge::dEdge_
DataDependenceEdge * dEdge_
Definition: ProgramDependenceEdge.hh:69
DataDependenceEdge::toString
TCEString toString() const
Definition: DataDependenceEdge.cc:201
ProgramDependenceEdge::isControlDependence
bool isControlDependence() const
Definition: ProgramDependenceEdge.cc:126
ControlDependenceEdge::isFalseEdge
bool isFalseEdge() const
Definition: ControlDependenceEdge.hh:62
ProgramDependenceEdge::cEdge_
ControlDependenceEdge * cEdge_
Definition: ProgramDependenceEdge.hh:68
ProgramDependenceEdge.hh
false
find Finds info of the inner loops in the false
Definition: InnerLoopFinder.cc:81
TCEString
Definition: TCEString.hh:53
DataDependenceEdge
Definition: DataDependenceEdge.hh:43
ProgramDependenceEdge::dataDependenceEdge
DataDependenceEdge & dataDependenceEdge()
Definition: ProgramDependenceEdge.cc:179
ProgramDependenceEdge::PDG_EDGE_DATA
@ PDG_EDGE_DATA
Indicates Control Dependence Edge from CDG.
Definition: ProgramDependenceEdge.hh:45
ControlDependenceEdge::isLoopCloseEdge
bool isLoopCloseEdge() const
Definition: ControlDependenceEdge.hh:63