OpenASIP  2.0
BasicBlockNode.hh
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 BasicBlockNode.hh
26  *
27  * Prototype control flow graph of TTA program representation: declaration
28  * of graph node (basic block).
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 #ifndef TTA_BASIC_BLOCK_NODE_HH
36 #define TTA_BASIC_BLOCK_NODE_HH
37 
38 #include <string>
39 
40 #include "GraphNode.hh"
41 #include "Address.hh"
42 
43 namespace TTAProgram {
44  class Program;
45  class Move;
46  class Instruction;
47  class CodeSnippet;
48  class BasicBlock;
49  class BasicBlockStatistics;
50 }
51 
52 
53 /**
54  * Node of the control flow graph. Each node represents one basic block.
55  *
56  * A basic block is defined as an ordered sequence of adjacent instructions
57  * in which only the first can be target of jump and only the last one (save
58  * jump delay slots) can contain jumps.
59  *
60  * @note Instructions that contain function calls are control flow barriers
61  * also. For now they split basic blocks into two, with special type of edge
62  * connecting them.
63  */
64 class BasicBlockNode : public GraphNode {
65 public:
69  bool entry = false,
70  bool exit = false);
71  explicit BasicBlockNode(
72  TTAProgram::BasicBlock& bb, bool scheduled = false,
73  bool refsUpdated = false,
74  int originalStartAddress = 0, bool loopScheduled = false);
75  virtual ~BasicBlockNode();
76 
77  bool isBasicBlockNode() const { return true; }
78  bool isNormalBB() const;
79  bool isEntryBB() const;
80  bool isExitBB() const;
81 
82  std::string toString() const;
83 
85  const TTAProgram::BasicBlock& basicBlock() const;
86 
87  bool hasOriginalAddress() const;
90 
92 
93  bool isScheduled() const { return scheduled_; }
94  void setScheduled(bool state=true) { scheduled_ = state;}
95 
96  std::pair<TTAProgram::Move*,TTAProgram::Move*> findJumps();
97  void updateHWloopLength(unsigned len);
98 
100 
101  bool isLoopScheduled() const { return loopScheduled_; }
102  void setLoopScheduled() { loopScheduled_ = true; }
103  void setBBOwnership(bool ownership = true) { bbOwned_ = ownership; }
104 
105  /// Set true if the bbn is known to be a loop body of a hwloop with
106  /// loop pattern- preheader BB -> loop body (single BB) -> tail BB.
107  /// Furthermore, preheader should use HWLOOP instruction for its
108  /// fallthrough jump to its loop body.
109  void
110  setHWLoop(bool hwloop = true) {
111  isHardwareLoop_ = hwloop;
112  }
113  bool
114  isHWLoop() const {
115  return isHardwareLoop_;
116  }
117 
118  // Ordering of basic blocks in a procedure.
119  // These are NULL if not set/decided.
120  const BasicBlockNode* successor() const { return successor_; }
121  const BasicBlockNode* predecessor() const { return predecessor_; }
124 
125  void link(BasicBlockNode* succ);
126 
127  int maximumSize() const;
128  void setMaximumSize(int sz) { maximumSize_ = sz; }
129 private:
130  /// start address of the original basic block, used for reconstructing
131  /// the original program after modifying the CFG and its nodes
133  /// end address of the original basic block, used for reconstructing
134  /// the original program after modifying the CFG and its nodes
136  /// not all basic blocks have original addresses (completely new
137  /// basic blocks, etc.), this flag is true in case it does
139  /// the actual payload data of the graph node (the basic block)
141  /// true if the BasicBlock is owned by the BasicBlockNode
142  bool bbOwned_;
143  /// true if this is an entry basic block (not real one)
144  bool entry_;
145  /// true if this is an exit basic block (not real one)
146  bool exit_;
147 
150  // if this bb was scheduled with loop scheduler
152  /// true if this bb is known to be a hwloop body
154 
157 
158  /// Maximum number of instructions this can consume when scheduled.
160 };
161 
162 #endif
TTAProgram
Definition: Estimator.hh:65
TTAProgram::Program
Definition: Program.hh:63
BasicBlockNode::isExitBB
bool isExitBB() const
Definition: BasicBlockNode.cc:257
InstructionAddress
UInt32 InstructionAddress
Definition: BaseType.hh:175
BasicBlockNode::loopScheduled_
bool loopScheduled_
Definition: BasicBlockNode.hh:151
BasicBlockNode::predecessor_
BasicBlockNode * predecessor_
Definition: BasicBlockNode.hh:156
BasicBlockNode::hasOriginalAddress_
bool hasOriginalAddress_
not all basic blocks have original addresses (completely new basic blocks, etc.), this flag is true i...
Definition: BasicBlockNode.hh:138
BasicBlockNode::predecessor
BasicBlockNode * predecessor()
Definition: BasicBlockNode.hh:123
BasicBlockNode::findJumps
std::pair< TTAProgram::Move *, TTAProgram::Move * > findJumps()
Definition: BasicBlockNode.cc:283
BasicBlockNode::isLoopScheduled
bool isLoopScheduled() const
Definition: BasicBlockNode.hh:101
BasicBlockNode::originalEndAddress
InstructionAddress originalEndAddress() const
Definition: BasicBlockNode.cc:174
BasicBlockNode::successor_
BasicBlockNode * successor_
Definition: BasicBlockNode.hh:155
BasicBlockNode::link
void link(BasicBlockNode *succ)
Definition: BasicBlockNode.cc:352
GraphNode.hh
BasicBlockNode::setLoopScheduled
void setLoopScheduled()
Definition: BasicBlockNode.hh:102
BasicBlockNode::originalEndAddress_
InstructionAddress originalEndAddress_
end address of the original basic block, used for reconstructing the original program after modifying...
Definition: BasicBlockNode.hh:135
BasicBlockNode::isBasicBlockNode
bool isBasicBlockNode() const
Definition: BasicBlockNode.hh:77
BasicBlockNode::isScheduled
bool isScheduled() const
Definition: BasicBlockNode.hh:93
BasicBlockNode::originalStartAddress_
InstructionAddress originalStartAddress_
start address of the original basic block, used for reconstructing the original program after modifyi...
Definition: BasicBlockNode.hh:132
BasicBlockNode::statistics
const TTAProgram::BasicBlockStatistics & statistics()
Definition: BasicBlockNode.cc:267
BasicBlockNode::basicBlock
TTAProgram::BasicBlock & basicBlock()
Definition: BasicBlockNode.cc:126
BasicBlockNode::setMaximumSize
void setMaximumSize(int sz)
Definition: BasicBlockNode.hh:128
TTAProgram::BasicBlockStatistics
Definition: BasicBlock.hh:55
BasicBlockNode::updateHWloopLength
void updateHWloopLength(unsigned len)
Definition: BasicBlockNode.cc:308
BasicBlockNode::maximumSize
int maximumSize() const
Definition: BasicBlockNode.cc:384
BasicBlockNode::successor
const BasicBlockNode * successor() const
Definition: BasicBlockNode.hh:120
BasicBlockNode::updateReferencesFromProcToCfg
void updateReferencesFromProcToCfg(TTAProgram::Program &prog)
Definition: BasicBlockNode.cc:331
BasicBlockNode
Definition: BasicBlockNode.hh:64
BasicBlockNode::isEntryBB
bool isEntryBB() const
Definition: BasicBlockNode.cc:248
BasicBlockNode::~BasicBlockNode
virtual ~BasicBlockNode()
Definition: BasicBlockNode.cc:107
BasicBlockNode::isNormalBB
bool isNormalBB() const
Definition: BasicBlockNode.cc:239
BasicBlockNode::isHWLoop
bool isHWLoop() const
Definition: BasicBlockNode.hh:114
BasicBlockNode::setBBOwnership
void setBBOwnership(bool ownership=true)
Definition: BasicBlockNode.hh:103
BasicBlockNode::refsUpdated_
bool refsUpdated_
Definition: BasicBlockNode.hh:149
BasicBlockNode::successor
BasicBlockNode * successor()
Definition: BasicBlockNode.hh:122
BasicBlockNode::BasicBlockNode
BasicBlockNode(InstructionAddress originalStartAddress, InstructionAddress originalEndAddress, bool entry=false, bool exit=false)
Definition: BasicBlockNode.cc:60
BasicBlockNode::bbOwned_
bool bbOwned_
true if the BasicBlock is owned by the BasicBlockNode
Definition: BasicBlockNode.hh:142
BasicBlockNode::basicBlock_
TTAProgram::BasicBlock * basicBlock_
the actual payload data of the graph node (the basic block)
Definition: BasicBlockNode.hh:140
BasicBlockNode::setScheduled
void setScheduled(bool state=true)
Definition: BasicBlockNode.hh:94
BasicBlockNode::scheduled_
bool scheduled_
Definition: BasicBlockNode.hh:148
TTAProgram::BasicBlock
Definition: BasicBlock.hh:85
BasicBlockNode::exit_
bool exit_
true if this is an exit basic block (not real one)
Definition: BasicBlockNode.hh:146
BasicBlockNode::predecessor
const BasicBlockNode * predecessor() const
Definition: BasicBlockNode.hh:121
Address.hh
BasicBlockNode::hasOriginalAddress
bool hasOriginalAddress() const
Definition: BasicBlockNode.cc:150
GraphNode
Definition: GraphNode.hh:42
BasicBlockNode::isHardwareLoop_
bool isHardwareLoop_
true if this bb is known to be a hwloop body
Definition: BasicBlockNode.hh:153
BasicBlockNode::maximumSize_
int maximumSize_
Maximum number of instructions this can consume when scheduled.
Definition: BasicBlockNode.hh:159
BasicBlockNode::setHWLoop
void setHWLoop(bool hwloop=true)
Set true if the bbn is known to be a loop body of a hwloop with loop pattern- preheader BB -> loop bo...
Definition: BasicBlockNode.hh:110
BasicBlockNode::entry_
bool entry_
true if this is an entry basic block (not real one)
Definition: BasicBlockNode.hh:144
BasicBlockNode::originalStartAddress
InstructionAddress originalStartAddress() const
Definition: BasicBlockNode.cc:162
BasicBlockNode::toString
std::string toString() const
Definition: BasicBlockNode.cc:185