OpenASIP  2.0
CopyingDelaySlotFiller.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 CopyingDelaySlotFiller.hh
26  *
27  * Definition of CopyingDelaySlotFiller class.
28  *
29  * @author Heikki Kultala 2007-2009 (hkultala-no.spam-cs.tut.fi)
30  * @note rating: red
31  */
32 
33 #ifndef COPYING_DELAY_SLOT_FILLER_HH
34 #define COPYING_DELAY_SLOT_FILLER_HH
35 
36 #include <map>
37 #include <vector>
38 #include <list>
39 #include "Exception.hh"
40 #include "ProgramOperation.hh"
41 #include "ControlFlowGraph.hh"
42 #include "DataDependenceGraph.hh"
43 #include "ControlFlowEdge.hh"
44 
45 class BasicBlockNode;
46 class ControlFlowGraph;
47 class ControlFlowEdge;
49 class ResourceManager;
50 class UniversalMachine;
51 class InterPassData;
52 class MoveNode;
53 
54 namespace TTAMachine {
55  class Machine;
56  class RegisterFile;
57 }
58 
59 namespace TTAProgram {
60  class InstructionReferenceManager;
61  class Move;
62  class Immediate;
63  class MoveGuard;
64  class TerminalInstructionAddress;
65  class CodeGenerator;
66  class BasicBlock;
67  class TerminalImmediate;
68 }
69 
70 
72 public:
75 
76  void initialize(
79 
80  void fillDelaySlots(
84 
85  void bbnScheduled(BasicBlockNode& bbn);
86  void finalizeProcedure();
87 
88  static std::pair<int, TTAProgram::Move*> findJump(
90  ControlFlowEdge::CFGEdgePredicate* pred = nullptr);
91 
92  static std::pair<TTAProgram::Move*, std::shared_ptr<TTAProgram::Immediate> >
94  int jumpIndex, TTAProgram::Move& jumpMove,
96 
97  typedef std::map<TCEString,TTAProgram::TerminalImmediate*>
99 
100 protected:
101  bool fillDelaySlots(
102  BasicBlockNode& jumpingBB, int delaySlots, bool fillFallThru);
103 
104 private:
105  typedef std::vector <std::list<MoveNode*> > MoveNodeListVector;
106 
107 
108  bool areAllJumpPredsScheduled(BasicBlockNode& bbn) const;
109 
110  bool areAllJumpPredsFilled(BasicBlockNode& bbn) const;
111 
112  void bbFilled(BasicBlockNode& bbn);
113 
115 
116  bool writesRegister(
118  unsigned int registerIndex);
119 
120  bool tryToFillSlots(
121  BasicBlockNode& blockToFillNode, BasicBlockNode& nextBBNode,
122  bool fallThru, TTAProgram::Move* jumpMove, int slotsToFill,
123  int removeGuards, int grIndex, const TTAMachine::RegisterFile* grFile,
124  TTAProgram::Move*& skippedJump, int delaySlots);
125 
126  bool updateJumpsAndCfg(
127  BasicBlockNode& jumpBBN,
128  BasicBlockNode& fillingBBN,
129  ControlFlowEdge& fillEdge,
130  TTAProgram::Move* jumpAddressMove,
131  std::shared_ptr<TTAProgram::Immediate> jumpAddressImmediate,
132  TTAProgram::Move* jumpMove,
133  int slotsFilled,
134  TTAProgram::Move* skippedJump);
135 
136  bool updateFTBBAndCfg(
137  BasicBlockNode& jumpingBB, BasicBlockNode& nextBBN,
138  ControlFlowEdge& edge, int slotsFilled);
139 
140  void loseCopies(DataDependenceGraph::NodeSet* keptTempNodes);
141 
142  bool collectMoves(
143  BasicBlockNode& blockToFillNode, BasicBlockNode& nextBBN,
144  MoveNodeListVector& moves, int slotsToFill, bool fallThru,
145  int removeGuards, TTAProgram::Move* jumpMove, int grIndex,
146  const TTAMachine::RegisterFile* grFile, TTAProgram::Move*& skippedJump,
147  int delaySlots);
148 
149  bool checkImmediatesAfter(TTAProgram::BasicBlock& nextBB, int slotsToFill);
150 
151  bool checkIncomingDeps(
152  MoveNode& mnOld, BasicBlockNode& blockToFillNode, int cycleDiff);
153 
154  bool tryToAssignNodes(
155  MoveNodeListVector& moves, int slotsToFill, int firstCycleToFill,
156  ResourceManager& rm, int nextBBStart,
157  DataDependenceGraph::NodeSet& tempAssigns);
158 
160  MoveNode& mn, int firstCycleToFill, ResourceManager& rm,
161  int lastCycle, int nextBBStart, DataDependenceGraph::NodeSet& tempAssigns);
162 
164  ProgramOperation& po, int firstCycleToFill, ResourceManager& rm,
165  int lastCycle, int nextBBStart, DataDependenceGraph::NodeSet& tempAssigns);
166 
167  void unassignTempAssigns(
169 
171  MoveNode& old, BasicBlockNode& bbn, bool fillOverBackEdge);
173  ProgramOperationPtr old, BasicBlockNode& bbn, bool fillOverBackEdge);
174  std::shared_ptr<TTAProgram::Move> getMove(TTAProgram::Move& old);
175 
176  bool poMoved(
177  ProgramOperationPtr po, MoveNodeListVector& movesToCopy,
178  DataDependenceGraph::NodeSet& tempAssigns);
179 
180 
181  bool allowedToSpeculate(MoveNode& mn) const;
182 
183  void finishBB(BasicBlockNode& bbn, bool force = false);
184 
187 
188  std::map<TTAProgram::BasicBlock*,SimpleResourceManager*> resourceManagers_;
190 
191  // indexed by the original PO's
192  std::map<ProgramOperation*, ProgramOperationPtr, ProgramOperation::Comparator>
194  std::map<ProgramOperation*, ProgramOperationPtr, ProgramOperation::Comparator>
196  std::map<MoveNode*,MoveNode*,MoveNode::Comparator> moveNodes_;
197  std::map<MoveNode*,MoveNode*,MoveNode::Comparator> oldMoveNodes_;
198  std::map<TTAProgram::Move*, std::shared_ptr<TTAProgram::Move> > moves_;
199  std::map<MoveNode*, const TTAMachine::Bus*, MoveNode::Comparator> moveNodeBuses_;
200 
201  std::map<BasicBlockNode*, DataDependenceGraph::NodeSet> tempResultNodes_;
202  std::map<BasicBlockNode*, std::set<
204 
205  // garbage collection would be SOOOO nice!
206  std::map<MoveNode*,bool,MoveNode::Comparator> mnOwned_;
207 
208 
212  BBN_ALL_DONE = 31 };
213 
214  // can go from uninitialized to UNKNOWN
215  mutable std::map <BasicBlockNode*, BBNStates> bbnStatus_;
216 // mutable std::map <BasicBlockNode*, BBNStates> bbnIncomingStatus_;
218 
220 };
221 
222 #endif
CopyingDelaySlotFiller::addResourceManager
void addResourceManager(TTAProgram::BasicBlock &bbn, SimpleResourceManager &rm)
Definition: CopyingDelaySlotFiller.cc:691
CopyingDelaySlotFiller::moveNodeBuses_
std::map< MoveNode *, const TTAMachine::Bus *, MoveNode::Comparator > moveNodeBuses_
Definition: CopyingDelaySlotFiller.hh:199
CopyingDelaySlotFiller::oldProgramOperations_
std::map< ProgramOperation *, ProgramOperationPtr, ProgramOperation::Comparator > oldProgramOperations_
Definition: CopyingDelaySlotFiller.hh:195
CopyingDelaySlotFiller::killedBBs_
ControlFlowGraph::NodeSet killedBBs_
Definition: CopyingDelaySlotFiller.hh:219
TTAProgram
Definition: Estimator.hh:65
CopyingDelaySlotFiller::allowedToSpeculate
bool allowedToSpeculate(MoveNode &mn) const
Definition: CopyingDelaySlotFiller.cc:2013
CopyingDelaySlotFiller::writesRegister
bool writesRegister(TTAProgram::Move &move, const TTAMachine::RegisterFile *rf, unsigned int registerIndex)
Definition: CopyingDelaySlotFiller.cc:789
CopyingDelaySlotFiller::um_
UniversalMachine * um_
Definition: CopyingDelaySlotFiller.hh:189
machine
TTAMachine::Machine * machine
the architecture definition of the estimated processor
Definition: EstimatorCmdLineUI.cc:59
Exception.hh
CopyingDelaySlotFiller::bbnScheduled
void bbnScheduled(BasicBlockNode &bbn)
Definition: CopyingDelaySlotFiller.cc:640
BoostGraph< MoveNode, DataDependenceEdge >::NodeSet
std::set< MoveNode *, typename MoveNode ::Comparator > NodeSet
Definition: BoostGraph.hh:86
CopyingDelaySlotFiller::resourceManagers_
std::map< TTAProgram::BasicBlock *, SimpleResourceManager * > resourceManagers_
Definition: CopyingDelaySlotFiller.hh:188
CopyingDelaySlotFiller::findJump
static std::pair< int, TTAProgram::Move * > findJump(TTAProgram::BasicBlock &bb, ControlFlowEdge::CFGEdgePredicate *pred=nullptr)
Definition: CopyingDelaySlotFiller.cc:1751
CopyingDelaySlotFiller::updateJumpsAndCfg
bool updateJumpsAndCfg(BasicBlockNode &jumpBBN, BasicBlockNode &fillingBBN, ControlFlowEdge &fillEdge, TTAProgram::Move *jumpAddressMove, std::shared_ptr< TTAProgram::Immediate > jumpAddressImmediate, TTAProgram::Move *jumpMove, int slotsFilled, TTAProgram::Move *skippedJump)
Definition: CopyingDelaySlotFiller.cc:1796
CopyingDelaySlotFiller::getProgramOperationPtr
ProgramOperationPtr getProgramOperationPtr(ProgramOperationPtr old, BasicBlockNode &bbn, bool fillOverBackEdge)
Definition: CopyingDelaySlotFiller.cc:1542
CopyingDelaySlotFiller::getMove
std::shared_ptr< TTAProgram::Move > getMove(TTAProgram::Move &old)
Definition: CopyingDelaySlotFiller.cc:1578
ControlFlowEdge::CFGEdgePredicate
CFGEdgePredicate
Definition: ControlFlowEdge.hh:52
CopyingDelaySlotFiller::cfg_
ControlFlowGraph * cfg_
Definition: CopyingDelaySlotFiller.hh:186
DataDependenceGraph.hh
ProgramOperation
Definition: ProgramOperation.hh:70
MoveNode
Definition: MoveNode.hh:65
ProgramOperation::Comparator
Definition: ProgramOperation.hh:148
CopyingDelaySlotFiller::moves_
std::map< TTAProgram::Move *, std::shared_ptr< TTAProgram::Move > > moves_
Definition: CopyingDelaySlotFiller.hh:198
CopyingDelaySlotFiller::initialize
void initialize(ControlFlowGraph &cfg, DataDependenceGraph &ddg, const TTAMachine::Machine &machine)
Definition: CopyingDelaySlotFiller.cc:1937
CopyingDelaySlotFiller::checkIncomingDeps
bool checkIncomingDeps(MoveNode &mnOld, BasicBlockNode &blockToFillNode, int cycleDiff)
Definition: CopyingDelaySlotFiller.cc:1228
CopyingDelaySlotFiller::tryToAssignNodes
bool tryToAssignNodes(MoveNodeListVector &moves, int slotsToFill, int firstCycleToFill, ResourceManager &rm, int nextBBStart, DataDependenceGraph::NodeSet &tempAssigns)
Definition: CopyingDelaySlotFiller.cc:1283
CopyingDelaySlotFiller::BBN_ALL_DONE
@ BBN_ALL_DONE
Definition: CopyingDelaySlotFiller.hh:212
ControlFlowEdge
Definition: ControlFlowEdge.hh:50
ProgramOperationPtr
std::shared_ptr< ProgramOperation > ProgramOperationPtr
Definition: MoveNode.hh:52
CopyingDelaySlotFiller::checkImmediatesAfter
bool checkImmediatesAfter(TTAProgram::BasicBlock &nextBB, int slotsToFill)
Definition: CopyingDelaySlotFiller.cc:1146
CopyingDelaySlotFiller::bbFilled
void bbFilled(BasicBlockNode &bbn)
Definition: CopyingDelaySlotFiller.cc:524
CopyingDelaySlotFiller::fillDelaySlots
void fillDelaySlots(ControlFlowGraph &cfg, DataDependenceGraph &ddg, const TTAMachine::Machine &machine)
Definition: CopyingDelaySlotFiller.cc:405
CopyingDelaySlotFiller::oldMoveNodes_
std::map< MoveNode *, MoveNode *, MoveNode::Comparator > oldMoveNodes_
Definition: CopyingDelaySlotFiller.hh:197
CopyingDelaySlotFiller::moveNodes_
std::map< MoveNode *, MoveNode *, MoveNode::Comparator > moveNodes_
Definition: CopyingDelaySlotFiller.hh:196
ControlFlowGraph.hh
UniversalMachine
Definition: UniversalMachine.hh:56
CopyingDelaySlotFiller::tempResultNodes_
std::map< BasicBlockNode *, DataDependenceGraph::NodeSet > tempResultNodes_
Definition: CopyingDelaySlotFiller.hh:201
CopyingDelaySlotFiller::unassignTempAssigns
void unassignTempAssigns(DataDependenceGraph::NodeSet &tempAssigns, SimpleResourceManager &rm)
Definition: CopyingDelaySlotFiller.cc:2000
CopyingDelaySlotFiller::programOperations_
std::map< ProgramOperation *, ProgramOperationPtr, ProgramOperation::Comparator > programOperations_
Definition: CopyingDelaySlotFiller.hh:193
CopyingDelaySlotFiller::tryToFillSlots
bool tryToFillSlots(BasicBlockNode &blockToFillNode, BasicBlockNode &nextBBNode, bool fallThru, TTAProgram::Move *jumpMove, int slotsToFill, int removeGuards, int grIndex, const TTAMachine::RegisterFile *grFile, TTAProgram::Move *&skippedJump, int delaySlots)
Definition: CopyingDelaySlotFiller.cc:817
CopyingDelaySlotFiller::BBN_SCHEDULED
@ BBN_SCHEDULED
Definition: CopyingDelaySlotFiller.hh:209
ResourceManager
Definition: ResourceManager.hh:53
CopyingDelaySlotFiller
Definition: CopyingDelaySlotFiller.hh:71
CopyingDelaySlotFiller::finalizeProcedure
void finalizeProcedure()
Definition: CopyingDelaySlotFiller.cc:460
BasicBlockNode
Definition: BasicBlockNode.hh:64
CopyingDelaySlotFiller::CopyingDelaySlotFiller
CopyingDelaySlotFiller()
Definition: CopyingDelaySlotFiller.cc:394
InterPassData
Definition: InterPassData.hh:48
CopyingDelaySlotFiller::BBN_UNKNOWN
@ BBN_UNKNOWN
Definition: CopyingDelaySlotFiller.hh:209
CopyingDelaySlotFiller::collectMoves
bool collectMoves(BasicBlockNode &blockToFillNode, BasicBlockNode &nextBBN, MoveNodeListVector &moves, int slotsToFill, bool fallThru, int removeGuards, TTAProgram::Move *jumpMove, int grIndex, const TTAMachine::RegisterFile *grFile, TTAProgram::Move *&skippedJump, int delaySlots)
Definition: CopyingDelaySlotFiller.cc:890
TTAProgram::Move
Definition: Move.hh:55
CopyingDelaySlotFiller::BBNStates
BBNStates
Definition: CopyingDelaySlotFiller.hh:209
CopyingDelaySlotFiller::BBN_FALLTHRU_FILLED
@ BBN_FALLTHRU_FILLED
Definition: CopyingDelaySlotFiller.hh:210
CopyingDelaySlotFiller::findJumpImmediate
static std::pair< TTAProgram::Move *, std::shared_ptr< TTAProgram::Immediate > > findJumpImmediate(int jumpIndex, TTAProgram::Move &jumpMove, TTAProgram::InstructionReferenceManager &irm)
Definition: CopyingDelaySlotFiller.cc:705
CopyingDelaySlotFiller::BBN_TEMPS_CLEANED
@ BBN_TEMPS_CLEANED
Definition: CopyingDelaySlotFiller.hh:211
CopyingDelaySlotFiller::MoveNodeListVector
std::vector< std::list< MoveNode * > > MoveNodeListVector
Definition: CopyingDelaySlotFiller.hh:105
CopyingDelaySlotFiller::mightFillIncomingTo
bool mightFillIncomingTo(BasicBlockNode &bbn)
Definition: CopyingDelaySlotFiller.cc:537
CopyingDelaySlotFiller::bbnStatus_
std::map< BasicBlockNode *, BBNStates > bbnStatus_
Definition: CopyingDelaySlotFiller.hh:215
ProgramOperation.hh
TTAProgram::BasicBlock
Definition: BasicBlock.hh:85
CopyingDelaySlotFiller::BBN_BOTH_FILLED
@ BBN_BOTH_FILLED
Definition: CopyingDelaySlotFiller.hh:210
CopyingDelaySlotFiller::tryToAssignOtherMovesOfOp
bool tryToAssignOtherMovesOfOp(ProgramOperation &po, int firstCycleToFill, ResourceManager &rm, int lastCycle, int nextBBStart, DataDependenceGraph::NodeSet &tempAssigns)
Definition: CopyingDelaySlotFiller.cc:1418
TTAProgram::InstructionReferenceManager
Definition: InstructionReferenceManager.hh:82
CopyingDelaySlotFiller::PendingImmediateMap
std::map< TCEString, TTAProgram::TerminalImmediate * > PendingImmediateMap
Definition: CopyingDelaySlotFiller.hh:98
CopyingDelaySlotFiller::getMoveNode
MoveNode & getMoveNode(MoveNode &old, BasicBlockNode &bbn, bool fillOverBackEdge)
Definition: CopyingDelaySlotFiller.cc:1497
CopyingDelaySlotFiller::poMoved
bool poMoved(ProgramOperationPtr po, MoveNodeListVector &movesToCopy, DataDependenceGraph::NodeSet &tempAssigns)
Definition: CopyingDelaySlotFiller.cc:1716
DataDependenceGraph
Definition: DataDependenceGraph.hh:67
CopyingDelaySlotFiller::loseCopies
void loseCopies(DataDependenceGraph::NodeSet *keptTempNodes)
Definition: CopyingDelaySlotFiller.cc:1651
SimpleResourceManager
Definition: SimpleResourceManager.hh:58
CopyingDelaySlotFiller::tryToAssignOtherMovesOfDestOps
bool tryToAssignOtherMovesOfDestOps(MoveNode &mn, int firstCycleToFill, ResourceManager &rm, int lastCycle, int nextBBStart, DataDependenceGraph::NodeSet &tempAssigns)
Definition: CopyingDelaySlotFiller.cc:1404
CopyingDelaySlotFiller::areAllJumpPredsFilled
bool areAllJumpPredsFilled(BasicBlockNode &bbn) const
Definition: CopyingDelaySlotFiller.cc:470
TTAMachine::RegisterFile
Definition: RegisterFile.hh:47
TTAMachine
Definition: Assembler.hh:48
CopyingDelaySlotFiller::areAllJumpPredsScheduled
bool areAllJumpPredsScheduled(BasicBlockNode &bbn) const
Definition: CopyingDelaySlotFiller.cc:498
CopyingDelaySlotFiller::delaySlots_
int delaySlots_
Definition: CopyingDelaySlotFiller.hh:217
ControlFlowEdge.hh
CopyingDelaySlotFiller::updateFTBBAndCfg
bool updateFTBBAndCfg(BasicBlockNode &jumpingBB, BasicBlockNode &nextBBN, ControlFlowEdge &edge, int slotsFilled)
Definition: CopyingDelaySlotFiller.cc:333
CopyingDelaySlotFiller::~CopyingDelaySlotFiller
~CopyingDelaySlotFiller()
Definition: CopyingDelaySlotFiller.cc:1692
ControlFlowGraph
Definition: ControlFlowGraph.hh:100
CopyingDelaySlotFiller::finishBB
void finishBB(BasicBlockNode &bbn, bool force=false)
Definition: CopyingDelaySlotFiller.cc:1949
TTAMachine::Machine
Definition: Machine.hh:73
CopyingDelaySlotFiller::ddg_
DataDependenceGraph * ddg_
Definition: CopyingDelaySlotFiller.hh:185
CopyingDelaySlotFiller::tempPOs_
std::map< BasicBlockNode *, std::set< ProgramOperationPtr, ProgramOperation::Comparator > > tempPOs_
Definition: CopyingDelaySlotFiller.hh:203
CopyingDelaySlotFiller::BBN_JUMP_FILLED
@ BBN_JUMP_FILLED
Definition: CopyingDelaySlotFiller.hh:209
CopyingDelaySlotFiller::mnOwned_
std::map< MoveNode *, bool, MoveNode::Comparator > mnOwned_
Definition: CopyingDelaySlotFiller.hh:206