TCE  1.20
BypassingBUBasicBlockScheduler.hh
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2011 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 BypassingBUBasicBlockScheduler.cc
26  *
27  * Declaration of BypassingBUBasicBlockScheduler class.
28  *
29  * This scheduler first schedules result reads of an operation, then
30  * it tries to bypass the operands, and recursively schedule the
31  * operations which produce the result, bypassing the operands while
32  * bypassing the results of the other operation. If it cannot schedule the
33  * operation producing the value of the operand, it reverts the bypass,
34  * and schedules operands from registers.
35  *
36  * @author Heikki Kultala 2011 (hkultala-no.spam-tut.fi)
37  * @note rating: red
38  */
39 
40 #ifndef TTA_BYPASSING_BU_BB_SCHEDULER_HH
41 #define TTA_BYPASSING_BU_BB_SCHEDULER_HH
42 
43 #include "BUMoveNodeSelector.hh"
44 #include "DDGPass.hh"
45 #include "BasicBlockPass.hh"
46 #include "BasicBlockScheduler.hh"
47 #include "MachinePart.hh"
48 
49 class BasicBlockNode;
51 class SoftwareBypasser;
55 class RegisterRenamer;
56 class MoveNode;
57 class MoveNodeGroup;
59 
60 namespace TTAMachine {
61  class Unit;
62  class Port;
63  class RegisterFile;
64 }
65 
66 /**
67  * A class that implements the functionality of a bottom up basic block
68  * scheduler.
69  *
70  * Schedules the program one basic block at a time. Does not fill delay slots
71  * if they couldn't be filled with the basic block's contents itself (no
72  * instruction importing).
73  */
75  public BasicBlockScheduler {
76 public:
77 
81  TempRegAfter };
82 
84  InterPassData& data, SoftwareBypasser* bypasser=NULL,
85  CopyingDelaySlotFiller* delaySlotFiller=NULL,
86  RegisterRenamer* registerRenamer = NULL);
88 
89  virtual void handleDDG(
91  const TTAMachine::Machine& targetMachine);
92 
93  virtual std::string shortDescription() const;
94  virtual std::string longDescription() const;
95 
98  return new BUMoveNodeSelector(bb, machine);
99  }
100 
102 
103  void scheduleOperation(MoveNodeGroup& mng, MoveNodeSelector& selector);
104 
105 private:
106 
107  bool renameSourceIfNotConnected(
108  MoveNode& moveNode, int latestCycle);
109 
110  void finalizeOperation(MoveNodeSelector& selector);
111 
112  bool scheduleOperation(
113  ProgramOperation& po, int& latestCycle, bool allowTempRegCopies);
114 
115 
116  bool scheduleResults(
117  ProgramOperation& po, int latestCycle, bool allowTempRegCopies);
118 
119 
120 
121  bool scheduleMoveUB(MoveNode& mn, int earlistCycle, int latestCycle);
122 
123  bool scheduleMoveBU(
124  MoveNode& mn, int earlistCycle, int latestCycle,
126 
127  int bypassNode(MoveNode& node, int maxHopCount);
128 
129  std::pair<MoveNode*, int> findBypassSource(
130  MoveNode& node, int maxHopCount);
131 
132  bool bypassAndScheduleNode(
133  MoveNode& node, MoveNode* trigger, int latestCycle,
134  bool allowRegCopies);
135 
136  bool bypassAndScheduleOperands(
137  ProgramOperation& po, MoveNode* trigger, int latestCycle,
138  bool allowRegCopies);
139 
140  bool scheduleOperandOrTrigger(
141  MoveNode& operand, MoveNode* trigger, int latestCycle,
142  bool allowRegCopies);
143 
144  void unscheduleResults(ProgramOperation& po);
145 
146  void unscheduleOperands(ProgramOperation& po);
147 
148  void unschedule(MoveNode& mn);
149 
150  void undoBypass(MoveNode& mn);
151 
152  void undoBypassAndUnschedule(MoveNode& mn);
153 
154  void unscheduleOperation(ProgramOperation& po);
155 
156  std::pair<int,int> operandCycleLimits(MoveNode& mn, MoveNode* trigger);
157 
158  int lastOperandCycle(const ProgramOperation& po);
159 
160  MoveNode* createTempRegCopy(MoveNode& mn, bool after);
161 
162  void createAntidepsFromUnscheduledRegCopies(
163  MoveNode& copyNode, MoveNode& mn,
164  TTAProgram::Terminal& terminalRegister);
165 
166  std::set<TTAMachine::RegisterFile*, TTAMachine::MachinePart::Comparator>
167  possibleTempRegRFs(const MoveNode& mn, bool tempRegAfter);
168 
169  void clearCaches();
170 
171  std::map<MoveNode*, MoveNode*, MoveNode::Comparator> bypassSources_;
172  std::map<MoveNode*, MoveNode*, MoveNode::Comparator> removedBypassSources_;
173 
174  std::set<MoveNode*, MoveNode::Comparator> removedNodes_;
175  std::set<MoveNode*, MoveNode::Comparator> pendingBypassSources_;
176  std::set<MoveNode*, MoveNode::Comparator> scheduledMoves_;
177 
178  std::map<MoveNode*, MoveNode*, MoveNode::Comparator> regCopiesBefore_;
179  std::map<MoveNode*, MoveNode*, MoveNode::Comparator> regCopiesAfter_;
180 
181 
185 };
186 
187 #endif
TTAMachine::Machine * machine
the architecture definition of the estimated processor
virtual MoveNodeSelector * createSelector(TTAProgram::BasicBlock &bb, const TTAMachine::Machine &machine)
std::set< MoveNode *, MoveNode::Comparator > removedNodes_
virtual DataDependenceGraphBuilder & ddgBuilder()
std::map< MoveNode *, MoveNode *, MoveNode::Comparator > removedBypassSources_
std::map< MoveNode *, MoveNode *, MoveNode::Comparator > bypassSources_
std::map< MoveNode *, MoveNode *, MoveNode::Comparator > regCopiesAfter_
std::set< MoveNode *, MoveNode::Comparator > scheduledMoves_
std::map< MoveNode *, MoveNode *, MoveNode::Comparator > regCopiesBefore_
std::set< MoveNode *, MoveNode::Comparator > pendingBypassSources_