OpenASIP  2.0
ControlFlowEdge.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 ControlFlowEdge.cc
26  *
27  * Prototype of graph-based program representation: implementation of graph
28  * edge.
29  *
30  * @author Andrea Cilio 2005 (cilio-no.spam-cs.tut.fi)
31  * @author Vladimir Guzma 2006 (vladimir.guzma-no.spam-tut.fi)
32  * @note rating: red
33  */
34 
35 #include "ControlFlowEdge.hh"
36 #include "Move.hh"
37 #include "MoveGuard.hh"
38 #include "Operation.hh"
39 #include "Terminal.hh"
40 
41 /**
42  * Constructor creates Control Flow Edge of given type
43  *
44  * @param edgePredicate The truth value of edge (or normal)
45  * @param edgeType Define if edge represents jump, if false the it is call
46  */
48  CFGEdgePredicate edgePredicate,
49  CFGEdgeType edgeType) :
50  edgePredicate_(edgePredicate), edgeType_(edgeType), backEdge_(false) {
51 }
52 
53 /**
54  * Destructor
55  */
57 
58 /**
59  * Returns type as a string. Helper for graph output to dot file.
60  *
61  * @return String representing type of edge.
62  */
65  TCEString result = "";
66  if (isJumpEdge()) {
67  result += "Jump_";
68  }
69  if (isFallThroughEdge()) {
70  result += "FallThrough_";
71  }
72  if (isCallPassEdge()) {
73  result += "CallPass_";
74  }
75  if (isBackEdge()) {
76  result += "BackEdge_";
77  }
78  if (isNormalEdge()) {
79  result += "normal";
80  }
81  if (isTrueEdge()) {
82  result += "true";
83  }
84  if (isFalseEdge()) {
85  result += "false";
86  }
87  if (isLoopBreakEdge()) {
88  result += "break";
89  }
90  return result;
91 }
92 
93 /**
94  * Returns true if object represents ControlFlowEdge.
95  *
96  * @return True if object is control flow edge
97  */
98 bool
100  return true;
101 }
102 /**
103  * Returns true if the edge is representing unconditional jump
104  *
105  * @return True if jump is not guarded
106  */
107 bool
110 }
111 
112 /**
113  * Returns true if edge represents conditional control flow that is
114  * taken if condition evaluates to true.
115  *
116  * @return True if edge represents True path
117  */
118 bool
121 }
122 /**
123  * Returns true if edge represents conditional control flow that is
124  * taken if condition evaluates to false.
125  *
126  * @return True if edge represents False path
127  */
128 bool
131 }
132 /**
133  * Returns true if edge represents control flow over the call in code.
134  *
135  * @return True if edge is split in basic block when call happened.
136  */
137 bool
139  return edgeType_ == CFLOW_EDGE_CALL;
140 }
141 
142 /**
143  * Returns true if the edge is representing jump.
144  *
145  * @return True if the edge represents jump.
146  */
147 bool
149  return edgeType_ == CFLOW_EDGE_JUMP;
150 }
151 
152 /**
153  * Returns true if the edge is representing fall through.
154  *
155  * @return True if the edge represents fall through.
156  */
157 bool
160 }
161 
162 /**
163  * Returns true if edge was added to break infinite
164  * loop for control dependence computation.
165  *
166  * @return True if edge was added to break infinite loop
167  */
168 bool
171 }
172 
173 /**
174  * Returns true if edge is loop back edge
175  *
176  * @return True if edge is loop back edge
177  */
178 bool
180  return backEdge_;
181 }
182 
183 /**
184  * Creates an edge predicate based on the guard of a move
185  */
188  if (move.isUnconditional()) {
189  if (move.isTriggering()) {
190  Operation& o = move.destination().operation();
191  if (o.name() == "BNZ" || o.name() == "IRFJUMPNZ" ||
192  o.name() == "BNZ1" || o.name() == "IRFJUMPNZ1") {
194  }
195  if (o.name() == "BZ" || o.name() == "IRFJUMPZ" ||
196  o.name() == "BZ1" || o.name() == "IRFJUMPZ1") {
198  }
199  } else {
200  Operation& o = move.destination().hintOperation();
201  if (&o != &NullOperation::instance()) {
202  if (o.name() == "BNZ" || o.name() == "IRFJUMPNZ" ||
203  o.name() == "BNZ1" || o.name() == "IRFJUMPNZ1") {
205  }
206  if (o.name() == "BZ" || o.name() == "IRFJUMPZ" ||
207  o.name() == "BZ1" || o.name() == "IRFJUMPZ1") {
209  }
210  }
211  }
213  }
214  TTAProgram::MoveGuard& mg = move.guard();
215  return mg.isInverted() ?
218 }
ControlFlowEdge::CFLOW_EDGE_LOOP_BREAK
@ CFLOW_EDGE_LOOP_BREAK
Definition: ControlFlowEdge.hh:56
TTAProgram::Move::isTriggering
bool isTriggering() const
Definition: Move.cc:284
ControlFlowEdge::isJumpEdge
bool isJumpEdge() const
Definition: ControlFlowEdge.cc:148
TTAProgram::MoveGuard::isInverted
bool isInverted() const
Definition: MoveGuard.cc:76
TTAProgram::Move::isUnconditional
bool isUnconditional() const
Definition: Move.cc:154
ControlFlowEdge::toString
TCEString toString() const
Definition: ControlFlowEdge.cc:64
ControlFlowEdge::edgePredicateFromMove
static ControlFlowEdge::CFGEdgePredicate edgePredicateFromMove(const TTAProgram::Move &move)
Definition: ControlFlowEdge.cc:187
TTAProgram::Move::destination
Terminal & destination() const
Definition: Move.cc:323
TTAProgram::Terminal::hintOperation
virtual Operation & hintOperation() const
Definition: Terminal.cc:341
ControlFlowEdge::CFGEdgePredicate
CFGEdgePredicate
Definition: ControlFlowEdge.hh:52
ControlFlowEdge::isBackEdge
bool isBackEdge() const
Definition: ControlFlowEdge.cc:179
Terminal.hh
ControlFlowEdge::isControlFlowEdge
bool isControlFlowEdge() const
Definition: ControlFlowEdge.cc:99
NullOperation::instance
static NullOperation & instance()
Operation::name
virtual TCEString name() const
Definition: Operation.cc:93
ControlFlowEdge::isNormalEdge
bool isNormalEdge() const
Definition: ControlFlowEdge.cc:108
ControlFlowEdge::isTrueEdge
bool isTrueEdge() const
Definition: ControlFlowEdge.cc:119
ControlFlowEdge::CFLOW_EDGE_NORMAL
@ CFLOW_EDGE_NORMAL
Definition: ControlFlowEdge.hh:53
ControlFlowEdge::ControlFlowEdge
ControlFlowEdge(CFGEdgePredicate edgePredicate=CFLOW_EDGE_NORMAL, CFGEdgeType edgeType=CFLOW_EDGE_JUMP)
Definition: ControlFlowEdge.cc:47
ControlFlowEdge::~ControlFlowEdge
virtual ~ControlFlowEdge()
Definition: ControlFlowEdge.cc:56
TTAProgram::Terminal::operation
virtual Operation & operation() const
Definition: Terminal.cc:319
ControlFlowEdge::isLoopBreakEdge
bool isLoopBreakEdge() const
Definition: ControlFlowEdge.cc:169
TTAProgram::Move::guard
MoveGuard & guard() const
Definition: Move.cc:345
ControlFlowEdge::backEdge_
bool backEdge_
Definition: ControlFlowEdge.hh:96
Operation.hh
ControlFlowEdge::CFGEdgeType
CFGEdgeType
Definition: ControlFlowEdge.hh:59
TTAProgram::Move
Definition: Move.hh:55
ControlFlowEdge::isFallThroughEdge
bool isFallThroughEdge() const
Definition: ControlFlowEdge.cc:158
Operation
Definition: Operation.hh:59
ControlFlowEdge::isCallPassEdge
bool isCallPassEdge() const
Definition: ControlFlowEdge.cc:138
false
find Finds info of the inner loops in the false
Definition: InnerLoopFinder.cc:81
TCEString
Definition: TCEString.hh:53
ControlFlowEdge::CFLOW_EDGE_FALSE
@ CFLOW_EDGE_FALSE
Definition: ControlFlowEdge.hh:55
Move.hh
ControlFlowEdge::edgePredicate_
CFGEdgePredicate edgePredicate_
Definition: ControlFlowEdge.hh:94
TTAProgram::MoveGuard
Definition: MoveGuard.hh:47
ControlFlowEdge.hh
ControlFlowEdge::CFLOW_EDGE_FALLTHROUGH
@ CFLOW_EDGE_FALLTHROUGH
Definition: ControlFlowEdge.hh:62
ControlFlowEdge::CFLOW_EDGE_TRUE
@ CFLOW_EDGE_TRUE
Definition: ControlFlowEdge.hh:54
ControlFlowEdge::CFLOW_EDGE_CALL
@ CFLOW_EDGE_CALL
Definition: ControlFlowEdge.hh:61
ControlFlowEdge::isFalseEdge
bool isFalseEdge() const
Definition: ControlFlowEdge.cc:129
ControlFlowEdge::CFLOW_EDGE_JUMP
@ CFLOW_EDGE_JUMP
Definition: ControlFlowEdge.hh:60
ControlFlowEdge::edgeType_
CFGEdgeType edgeType_
Definition: ControlFlowEdge.hh:95
MoveGuard.hh