OpenASIP  2.0
RegisterRenamer.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 RegisterRenamer.hh
26  *
27  * Declaration of RegisterRenamer class.
28  *
29  * @author Heikki Kultala 2009-2011 (hkultala-no.spam-cs.tut.fi)
30  * @note rating: red
31  */
32 
33 #ifndef TTA_REGISTER_RENAMER_HH
34 #define TTA_REGISTER_RENAMER_HH
35 
36 #include <climits>
37 
38 #include "TCEString.hh"
39 #include <set>
40 #include "MachinePart.hh"
41 #include "DataDependenceGraph.hh"
42 
43 namespace TTAMachine {
44  class Machine;
45  class RegisterFile;
46  class Bus;
47 }
48 
49 namespace TTAProgram {
50  class TerminalRegister;
51  class BasicBlock;
52 }
53 
54 struct LiveRange;
56 class MoveNode;
57 class MoveNodeSelector;
58 
60 public:
61  typedef std::set<const TTAMachine::RegisterFile*,
63 
66  unsigned int freeGPRCount() const { return freeGPRs_.size(); }
67 
69 
71  MoveNode& node, bool loopScheduling,
72  bool allowSameRf, bool differentRfOnlyDirectlyReachable,
73  int earliestCycle=-1);
74 
76  MoveNode& node, bool loopScheduling,
77  bool allowSameRf, bool differentRfOnlyDirectlyReachable,
78  int latestCycle = INT_MAX);
79 
80  void setSelector(MoveNodeSelector* selector);
81 
82  // typedef std::pair<DataDependenceGraph::NodeSet,
83  //DataDependenceGraph::NodeSet> LiveRange;
84 
85  bool renameLiveRange(
86  LiveRange& liveRange, const TCEString& newReg, bool usedBefore,
87  bool usedAfter, bool loopScheduling);
88 
89  std::set<TCEString> findPartiallyUsedRegistersAfterCycle(
90  int bitWidth, int latestCycle) const;
91 
92  std::set<TCEString> findFreeRegisters(int bitWidth) const;
93 
94  std::set<TCEString> findPartiallyUsedRegistersInRFAfterCycle(
95  const RegisterFileSet& rfs, int latestCycle) const;
96 
97  std::set<TCEString> findFreeRegistersInRF(
98  const RegisterFileSet& rfs) const;
99 
100  RegisterFileSet findConnectedRFs(LiveRange& lr, bool allowLimm);
101 
103 
104  void renamedToRegister(const TCEString& newReg);
105  void revertedRenameToRegister(const TCEString& reg);
106 private:
107 
108 
109  std::set<TCEString> registersOfRFs(const RegisterFileSet& rfs) const;
110 
112 
113  std::set<TCEString> findPartiallyUsedRegistersInRFBeforeCycle(
114  const RegisterFileSet& rfs, int earliestCycle,
115  const DataDependenceGraph::NodeSet& guardMoves) const;
116 
117  std::set<TCEString> findPartiallyUsedRegistersBeforeCycle(
118  int bitWidth, int earliestCycle,
119  const DataDependenceGraph::NodeSet& guardMoves) const;
120 
121  std::set<TCEString> findFreeGuardRegisters(
122  const DataDependenceGraph::NodeSet& guardUseNodes,
123  int bitWidth, const RegisterFileSet& rfs) const;
124 
125  std::set<TCEString> findGuardRegisters(
126  const DataDependenceGraph::NodeSet& guardMoves,
127  const RegisterFileSet& rfs) const;
128 
129  std::set<TCEString> findGuardRegisters(
130  const TTAMachine::Bus& bus,
131  const RegisterFileSet& rfs) const;
132 
134  LiveRange& liveRange,
135  const TCEString& newReg,
137  int loopDepth) const;
138 
139  void initialize();
140  std::set<TCEString> allNormalGPRs_;
141  std::set<TCEString> freeGPRs_;
142 
143  // already usd by the reg renamer, but can be reused of liveranges
144  // cannot overlap?
145  std::set<TCEString> usedGPRs_;
146 
147  // used partially by original code;
148  // used at beginning of bb, free at end.
149  std::set<TCEString> onlyBeginPartiallyUsedRegs_;
150  // used at end of bb, free at begin.
151  std::set<TCEString> onlyEndPartiallyUsedRegs_;
152  std::set<TCEString> onlyMidPartiallyUsedRegs_;
153 
154  static std::map<const TTAMachine::Machine*,
155  std::set <const TTAMachine::RegisterFile*,
158  std::set <const TTAMachine::RegisterFile*,
160 
164 
166 };
167 
168 #endif
RegisterRenamer::freeGPRs_
std::set< TCEString > freeGPRs_
Definition: RegisterRenamer.hh:141
TTAProgram
Definition: Estimator.hh:65
RegisterRenamer::onlyEndPartiallyUsedRegs_
std::set< TCEString > onlyEndPartiallyUsedRegs_
Definition: RegisterRenamer.hh:151
RegisterRenamer::RegisterFileSet
std::set< const TTAMachine::RegisterFile *, TTAMachine::MachinePart::Comparator > RegisterFileSet
Definition: RegisterRenamer.hh:62
RegisterRenamer::renamedToRegister
void renamedToRegister(const TCEString &newReg)
Definition: RegisterRenamer.cc:1094
RegisterRenamer::updateAntiEdgesFromLRTo
void updateAntiEdgesFromLRTo(LiveRange &liveRange, const TCEString &newReg, TTAProgram::BasicBlock &bb, int loopDepth) const
Definition: RegisterRenamer.cc:1139
machine
TTAMachine::Machine * machine
the architecture definition of the estimated processor
Definition: EstimatorCmdLineUI.cc:59
RegisterRenamer::allNormalGPRs_
std::set< TCEString > allNormalGPRs_
Definition: RegisterRenamer.hh:140
BoostGraph< MoveNode, DataDependenceEdge >::NodeSet
std::set< MoveNode *, typename MoveNode ::Comparator > NodeSet
Definition: BoostGraph.hh:86
TTAMachine::Bus
Definition: Bus.hh:53
RegisterRenamer::findConnectedRFs
RegisterFileSet findConnectedRFs(LiveRange &lr, bool allowLimm)
Definition: RegisterRenamer.cc:1206
RegisterRenamer::findPartiallyUsedRegistersAfterCycle
std::set< TCEString > findPartiallyUsedRegistersAfterCycle(int bitWidth, int latestCycle) const
Definition: RegisterRenamer.cc:394
RegisterRenamer::tempRegFiles_
std::set< const TTAMachine::RegisterFile *, TTAMachine::MachinePart::Comparator > tempRegFiles_
Definition: RegisterRenamer.hh:159
DataDependenceGraph.hh
MoveNode
Definition: MoveNode.hh:65
RegisterRenamer::usedGPRs_
std::set< TCEString > usedGPRs_
Definition: RegisterRenamer.hh:145
MachinePart.hh
TCEString.hh
RegisterRenamer::onlyBeginPartiallyUsedRegs_
std::set< TCEString > onlyBeginPartiallyUsedRegs_
Definition: RegisterRenamer.hh:149
RegisterRenamer::bb
TTAProgram::BasicBlock & bb()
Definition: RegisterRenamer.hh:102
RegisterRenamer::findFreeGuardRegisters
std::set< TCEString > findFreeGuardRegisters(const DataDependenceGraph::NodeSet &guardUseNodes, int bitWidth, const RegisterFileSet &rfs) const
Definition: RegisterRenamer.cc:437
RegisterRenamer::bb_
TTAProgram::BasicBlock & bb_
Definition: RegisterRenamer.hh:162
RegisterRenamer::findGuardRegisters
std::set< TCEString > findGuardRegisters(const DataDependenceGraph::NodeSet &guardMoves, const RegisterFileSet &rfs) const
Definition: RegisterRenamer.cc:1270
RegisterRenamer::initializeFreeRegisters
void initializeFreeRegisters()
Definition: RegisterRenamer.cc:114
RegisterRenamer::renameSourceRegister
bool renameSourceRegister(MoveNode &node, bool loopScheduling, bool allowSameRf, bool differentRfOnlyDirectlyReachable, int latestCycle=INT_MAX)
Definition: RegisterRenamer.cc:617
RegisterRenamer::tempRegFileCache_
static std::map< const TTAMachine::Machine *, std::set< const TTAMachine::RegisterFile *, TTAMachine::MachinePart::Comparator > > tempRegFileCache_
To avoid reanalysing machine every time hen new rr created.
Definition: RegisterRenamer.hh:157
MoveNodeSelector
Definition: MoveNodeSelector.hh:45
RegisterRenamer::findPartiallyUsedRegistersInRFBeforeCycle
std::set< TCEString > findPartiallyUsedRegistersInRFBeforeCycle(const RegisterFileSet &rfs, int earliestCycle, const DataDependenceGraph::NodeSet &guardMoves) const
Definition: RegisterRenamer.cc:260
RegisterRenamer::RegisterRenamer
RegisterRenamer(const TTAMachine::Machine &machine, TTAProgram::BasicBlock &bb)
Definition: RegisterRenamer.cc:74
TTAProgram::BasicBlock
Definition: BasicBlock.hh:85
RegisterRenamer::initialize
void initialize()
Definition: RegisterRenamer.cc:87
RegisterRenamer::renameDestinationRegister
bool renameDestinationRegister(MoveNode &node, bool loopScheduling, bool allowSameRf, bool differentRfOnlyDirectlyReachable, int earliestCycle=-1)
Definition: RegisterRenamer.cc:458
TCEString
Definition: TCEString.hh:53
DataDependenceGraph
Definition: DataDependenceGraph.hh:67
RegisterRenamer::setSelector
void setSelector(MoveNodeSelector *selector)
Definition: RegisterRenamer.cc:1126
RegisterRenamer::ddg_
DataDependenceGraph * ddg_
Definition: RegisterRenamer.hh:163
RegisterRenamer::renameLiveRange
bool renameLiveRange(LiveRange &liveRange, const TCEString &newReg, bool usedBefore, bool usedAfter, bool loopScheduling)
Definition: RegisterRenamer.cc:714
RegisterRenamer::findPartiallyUsedRegistersBeforeCycle
std::set< TCEString > findPartiallyUsedRegistersBeforeCycle(int bitWidth, int earliestCycle, const DataDependenceGraph::NodeSet &guardMoves) const
Definition: RegisterRenamer.cc:341
RegisterRenamer::findFreeRegistersInRF
std::set< TCEString > findFreeRegistersInRF(const RegisterFileSet &rfs) const
Definition: RegisterRenamer.cc:223
TTAMachine::RegisterFile
Definition: RegisterFile.hh:47
RegisterRenamer::machine_
const TTAMachine::Machine & machine_
Definition: RegisterRenamer.hh:161
RegisterRenamer::revertedRenameToRegister
void revertedRenameToRegister(const TCEString &reg)
Definition: RegisterRenamer.cc:1106
TTAMachine
Definition: Assembler.hh:48
TTAMachine::MachinePart::Comparator
Definition: MachinePart.hh:59
RegisterRenamer::onlyMidPartiallyUsedRegs_
std::set< TCEString > onlyMidPartiallyUsedRegs_
Definition: RegisterRenamer.hh:152
RegisterRenamer::freeGPRCount
unsigned int freeGPRCount() const
Definition: RegisterRenamer.hh:66
LiveRange
Definition: LiveRange.hh:38
RegisterRenamer
Definition: RegisterRenamer.hh:59
RegisterRenamer::findPartiallyUsedRegistersInRFAfterCycle
std::set< TCEString > findPartiallyUsedRegistersInRFAfterCycle(const RegisterFileSet &rfs, int latestCycle) const
Definition: RegisterRenamer.cc:310
RegisterRenamer::registersOfRFs
std::set< TCEString > registersOfRFs(const RegisterFileSet &rfs) const
Definition: RegisterRenamer.cc:233
RegisterRenamer::findFreeRegisters
std::set< TCEString > findFreeRegisters(int bitWidth) const
Definition: RegisterRenamer.cc:418
TTAMachine::Machine
Definition: Machine.hh:73
RegisterRenamer::selector_
MoveNodeSelector * selector_
Definition: RegisterRenamer.hh:165