OpenASIP 2.2
Loading...
Searching...
No Matches
BF2Scheduler.hh
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2014 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/**
26 * @file BF2Scheduler.hh
27 *
28 * Declaration of BF2Scheduler class.
29 *
30 * Bypassing Bottom-up Breadth-First-Search Instruction Scheduler
31 * (BubblefishScheduler)
32 *
33 * @author Heikki Kultala 2014-2020(heikki.kultala-no.spam-tuni.fi)
34 * @note rating: red
35 */
36
37#ifndef TTA_BF2_SCHEDULER_HH
38#define TTA_BF2_SCHEDULER_HH
39
40#include "DDGPass.hh"
41
42#include <map>
43
45#include "MachinePart.hh"
46
47#include "LiveRangeData.hh"
48#include "LoopAnalyzer.hh"
49
50class ResourceManager;
54class RegisterRenamer;
55class BFOptimization;
58class BFScheduleLoopBufferInit;
59
60namespace TTAMachine {
61 class Unit;
62 class RegisterFile;
63 class Port;
64 class Bus;
65 class FUPort;
66 class HWOperation;
67}
68
69namespace TTAProgram {
70 class Terminal;
71 class MoveGuard;
72}
73
74class BF2Scheduler : public DDGPass {
75
76public:
80
82
83 virtual int handleDDG(
85 const TTAMachine::Machine& targetMachine, int minCycle = 0,
86 bool testOnly = false);
87
88 void scheduleDDG(
92
93 virtual std::string shortDescription() const override;
94
95 virtual int handleLoopDDG(
98 SimpleResourceManager*, bool testOnly) override;
99
101 const DataDependenceGraph& ddg() const { return *ddg_; }
107 assert(duplicator_!=NULL);
108 return *duplicator_;
109 }
110 bool killDeadResults() const { return killDeadResults_; }
111
114
115 std::set<const TTAMachine::RegisterFile*,
117 possibleTempRegRFs(const MoveNode& mn, bool tempRegAfter,
118 const TTAMachine::RegisterFile* forbiddenRF = nullptr);
119
120 static bool isSourceUniversalReg(const MoveNode& mn);
122
123 void nodeKilled(MoveNode& mn);
124 void nodeResurrected(MoveNode& mn);
125 void nodeAndCopyKilled(MoveNode& mn);
126
128
129 // This is not yet used, but will be used soon.
131 // Old version
133 };
134
141
142 /** Struct for return values */
155
162
163 bool isDeadResult(MoveNode& mn) const;
165
173
174 static bool isDestinationUniversalReg(const MoveNode& mn);
175
176 typedef std::map<MoveNode*, MoveNode*, MoveNode::Comparator>
178
180 bool isTrigger(const TTAMachine::Unit& unit, MoveNode& mn);
181
182 bool hasUnscheduledSuccessors(MoveNode& mn) const;
183
184 int tripCount() { return tripCount_; }
185
186 int maximumAllowedCycle() const { return latestCycle_; }
187
189
193
195 return llResult_ == 0 ? NULL : llResult_->counterValueNode;
196 }
197
201
203 llResult_ = llResult;
204 }
205
206 bool mustBeTrigger(const MoveNode& mn, const ProgramOperation& po);
207
208 // just to allow prolog to be longer than loop body.
209 static const int PROLOG_CYCLE_BIAS = 1000;
210
211 std::list<ProgramOperation*> loopBufOps();
212
213 void deletingNode(MoveNode* deletedNode);
214
215 void finalizeSchedule();
216
217 void unschedule();
218
220
222protected:
223
224 int handleLoopDDG(BUMoveNodeSelector& selector, bool allowPreLoopOpshare);
225
226private:
227
228 bool findJump();
229
232
233 std::vector<BFOptimization*> scheduledStack_;
234
235 // kill copy also for these
237 // do not kill copy for these
239
242
243 /// Nodes that may become ready due bypass removing antideps
245
247
249
250
252
254
255 static void writeDotWithNameAndNodeID(
257 const TCEString& namePrefix, const MoveNode& mn);
258
261
262 bool pushAntidepDestsDown(MoveNode& mn, int oldLC, int maxLC);
263 void undoPushAntideps(MoveNode& aDepSource);
264
267 const TCEString& reg, MoveNode* mn);
268
269 int swapToUntrigger(
270 ProgramOperationPtr po, const Operation& op,
271 int operandIndex, MoveNode& trig);
272
273 void revertTopOpt();
274
279
281 ProgramOperationPtr po, const Operation& op,
282 const TTAMachine::HWOperation& hwop, bool onlySharedWithAnother);
283
284
286 ProgramOperationPtr po, const Operation& op, int operandIndex,
287 const TTAMachine::HWOperation& hwop, bool onlySharedWithAnother);
288
290 ProgramOperationPtr po, const Operation& op,
291 bool onlySharedWithAnother);
292
294
295 void releasePortForOp(const Operation& op);
296
301
303
308
314
316
317 std::multimap<TCEString, MoveNode*> invariants_;
318 std::multimap<int, TCEString> invariantsOfCount_;
319
320 // NULL as movenode means no operand share, FU used mutliple times
321 std::multimap<TTAMachine::FUPort*, MoveNode*> preSharedOperandPorts_;
322
323 // NULL as movenode means no operand share, FU used multiple times
324 std::map<MoveNode*, TTAMachine::FUPort*, MoveNode::Comparator>
326
327 std::list<ProgramOperation*> loopBufOps_;
328};
329
330#endif
#define assert(condition)
std::shared_ptr< ProgramOperation > ProgramOperationPtr
Definition MoveNode.hh:53
bool mustBeTrigger(const MoveNode &mn, const ProgramOperation &po)
void revertBBLiveRangeBookkeepingForDestination(MoveNode *mn)
LoopAnalyzer::LoopAnalysisResult * getLoopAnalysis()
SimpleResourceManager & rm()
std::list< ProgramOperation * > loopBufOps()
void nodeResurrected(MoveNode &mn)
MoveNode * jumpNode()
int maximumAllowedCycle() const
DataDependenceGraph & ddg()
void initializeQueues()
virtual int handleLoopDDG(DataDependenceGraph &, SimpleResourceManager &, const TTAMachine::Machine &, int tripCount, SimpleResourceManager *, bool testOnly) override
PreLoopShareInfo preAllocateFunctionUnitsInner(ProgramOperationPtr po, const Operation &op, bool onlySharedWithAnother)
bool isRegCopyBefore(MoveNode &mn)
bool killDeadResults() const
static void writeDotWithNameAndNodeID(DataDependenceGraph &ddg, const TCEString &namePrefix, const MoveNode &mn)
std::multimap< TCEString, MoveNode * > invariants_
std::set< const TTAMachine::RegisterFile *, TTAMachine::MachinePart::Comparator > possibleTempRegRFs(const MoveNode &mn, bool tempRegAfter, const TTAMachine::RegisterFile *forbiddenRF=nullptr)
bool isDeadResult(MoveNode &mn) const
SimpleResourceManager * prologRM_
static bool isSourceUniversalReg(const MoveNode &mn)
void reservePreallocatedFUs()
static bool isDestinationUniversalReg(const MoveNode &mn)
const DataDependenceGraph & ddg() const
void undoPushAntideps(MoveNode &aDepSource)
std::multimap< TTAMachine::FUPort *, MoveNode * > preSharedOperandPorts_
TTAProgram::MoveGuard * jumpGuard()
void releasePortForOp(const Operation &op)
virtual int handleDDG(DataDependenceGraph &ddg, SimpleResourceManager &rm, const TTAMachine::Machine &targetMachine, int minCycle=0, bool testOnly=false)
bool isTrigger(const TTAMachine::Unit &unit, MoveNode &mn)
void unreservePreallocatedFUs()
SimpleResourceManager * rm_
void countLoopInvariantValueUsages()
MoveNodeMap sharedOperands_
void setLoopLimits(LoopAnalyzer::LoopAnalysisResult *llResult)
RegisterRenamer * renamer_
std::multimap< int, TCEString > invariantsOfCount_
BUMoveNodeSelector & selector()
LLVMTCECmdLineOptions * options_
DataDependenceGraph * prologDDG_
MoveNodeMap bypassNodes()
LoopAnalyzer::LoopAnalysisResult * llResult_
BF2ScheduleFront * currentFront_
TTAMachine::FUPort * isPreLoopSharedOperand(MoveNode &mn) const
bool hasUnscheduledSuccessors(MoveNode &mn) const
void preAllocateFunctionUnits(ProgramOperationPtr po)
MoveNodeDuplicator & duplicator()
DataDependenceGraph::NodeSet removedMoves_
const TTAMachine::Machine * targetMachine_
DataDependenceGraph::NodeSet pendingMoves_
TTAMachine::Unit * getDstUnit(MoveNode &mn)
void nodeKilled(MoveNode &mn)
std::list< ProgramOperation * > loopBufOps_
void revertBBLiveRangeBookkeepingForSource(MoveNode *mn)
void scheduleDDG(DataDependenceGraph &ddg, SimpleResourceManager &rm, const TTAMachine::Machine &targetMachine)
DataDependenceGraph::NodeSet dreRemovedMoves_
static const int PROLOG_CYCLE_BIAS
std::map< MoveNode *, TTAMachine::FUPort *, MoveNode::Comparator > preLoopSharedOperands_
std::map< MoveNode *, MoveNode *, MoveNode::Comparator > MoveNodeMap
void finalizeSchedule()
bool pushAntidepDestsDown(MoveNode &mn, int oldLC, int maxLC)
const TTAMachine::Machine & targetMachine() const
DataDependenceGraph * prologDDG()
DataDependenceGraph::NodeSet bypassPredecessors_
Nodes that may become ready due bypass removing antideps.
DataDependenceEdge * findBypassEdge(const MoveNode &mn)
void allocateFunctionUnits()
MoveNodeMap operandShareRemovedMoves_
void eraseFromMoveNodeUseSet(LiveRangeData::MoveNodeUseMapSet &mnuMap, const TCEString &reg, MoveNode *mn)
MoveNode * jumpGuardWrite_
void nodeAndCopyKilled(MoveNode &mn)
MoveNodeSet findSiblings(MoveNode &mn)
bool isRegCopyAfter(MoveNode &mn)
MoveNode * guardWriteNode()
MoveNode * jumpNode_
SimpleResourceManager * prologRM()
RegisterRenamer * renamer()
int scheduleFrontFromMove(MoveNode &mn)
BF2ScheduleFront * currentFront()
virtual std::string shortDescription() const override
MoveNodeDuplicator * duplicator_
std::vector< BFOptimization * > scheduledStack_
BUMoveNodeSelector * selector_
int swapToUntrigger(ProgramOperationPtr po, const Operation &op, int operandIndex, MoveNode &trig)
DataDependenceGraph * ddg_
void deletingNode(MoveNode *deletedNode)
MoveNode * loopLimitNode()
MoveNode * selectMoveToSchedule()
std::set< GraphNode *, typename GraphNode::Comparator > NodeSet
Definition Graph.hh:53
PreLoopShareInfo(PreLoopOperandEnum state)
TTAMachine::FUPort * sharedPort_
PreLoopShareInfo(MoveNode &mn, TTAMachine::FUPort &port)
SchedulingDirection direction
std::map< TCEString, MoveNodeUseSet > MoveNodeUseMapSet