gem5  v21.0.1.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
rename_map.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2017 ARM Limited
3  * All rights reserved.
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Copyright (c) 2004-2005 The Regents of The University of Michigan
15  * Copyright (c) 2013 Advanced Micro Devices, Inc.
16  * All rights reserved.
17  *
18  * Redistribution and use in source and binary forms, with or without
19  * modification, are permitted provided that the following conditions are
20  * met: redistributions of source code must retain the above copyright
21  * notice, this list of conditions and the following disclaimer;
22  * redistributions in binary form must reproduce the above copyright
23  * notice, this list of conditions and the following disclaimer in the
24  * documentation and/or other materials provided with the distribution;
25  * neither the name of the copyright holders nor the names of its
26  * contributors may be used to endorse or promote products derived from
27  * this software without specific prior written permission.
28  *
29  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40  */
41 
42 #ifndef __CPU_O3_RENAME_MAP_HH__
43 #define __CPU_O3_RENAME_MAP_HH__
44 
45 #include <iostream>
46 #include <utility>
47 #include <vector>
48 
49 #include "arch/types.hh"
50 #include "config/the_isa.hh"
51 #include "cpu/o3/free_list.hh"
52 #include "cpu/o3/regfile.hh"
53 #include "cpu/reg_class.hh"
54 #include "enums/VecRegRenameMode.hh"
55 
64 {
65  private:
69  public:
70  using iterator = Arch2PhysMap::iterator;
71  using const_iterator = Arch2PhysMap::const_iterator;
72  private:
73 
79 
88 
89  public:
90 
92 
94 
100  void init(unsigned size, SimpleFreeList *_freeList, RegIndex _zeroReg);
101 
109 
117  RenameInfo rename(const RegId& arch_reg);
118 
125  lookup(const RegId& arch_reg) const
126  {
127  assert(arch_reg.flatIndex() <= map.size());
128  return map[arch_reg.flatIndex()];
129  }
130 
137  void
138  setEntry(const RegId& arch_reg, PhysRegIdPtr phys_reg)
139  {
140  assert(arch_reg.flatIndex() <= map.size());
141  map[arch_reg.flatIndex()] = phys_reg;
142  }
143 
145  unsigned numFreeEntries() const { return freeList->numFreeRegs(); }
146 
149  iterator begin() { return map.begin(); }
150  const_iterator begin() const { return map.begin(); }
151  const_iterator cbegin() const { return map.cbegin(); }
156  iterator end() { return map.end(); }
157  const_iterator end() const { return map.end(); }
158  const_iterator cend() const { return map.cend(); }
160 };
161 
170 {
171  private:
174 
177 
180 
183 
186 
189 
190  using VecMode = Enums::VecRegRenameMode;
192 
198 
199  public:
200 
202 
204  UnifiedRenameMap() : regFile(nullptr) {};
205 
208 
210  void init(PhysRegFile *_regFile,
211  RegIndex _intZeroReg,
212  RegIndex _floatZeroReg,
213  UnifiedFreeList *freeList,
214  VecMode _mode);
215 
224  RenameInfo rename(const RegId& arch_reg)
225  {
226  switch (arch_reg.classValue()) {
227  case IntRegClass:
228  return intMap.rename(arch_reg);
229  case FloatRegClass:
230  return floatMap.rename(arch_reg);
231  case VecRegClass:
232  assert(vecMode == Enums::Full);
233  return vecMap.rename(arch_reg);
234  case VecElemClass:
235  assert(vecMode == Enums::Elem);
236  return vecElemMap.rename(arch_reg);
237  case VecPredRegClass:
238  return predMap.rename(arch_reg);
239  case CCRegClass:
240  return ccMap.rename(arch_reg);
241  case MiscRegClass:
242  {
243  // misc regs aren't really renamed, just remapped
244  PhysRegIdPtr phys_reg = lookup(arch_reg);
245  // Set the new register to the previous one to keep the same
246  // mapping throughout the execution.
247  return RenameInfo(phys_reg, phys_reg);
248  }
249 
250  default:
251  panic("rename rename(): unknown reg class %s\n",
252  arch_reg.className());
253  }
254  }
255 
264  lookup(const RegId& arch_reg) const
265  {
266  switch (arch_reg.classValue()) {
267  case IntRegClass:
268  return intMap.lookup(arch_reg);
269 
270  case FloatRegClass:
271  return floatMap.lookup(arch_reg);
272 
273  case VecRegClass:
274  assert(vecMode == Enums::Full);
275  return vecMap.lookup(arch_reg);
276 
277  case VecElemClass:
278  assert(vecMode == Enums::Elem);
279  return vecElemMap.lookup(arch_reg);
280 
281  case VecPredRegClass:
282  return predMap.lookup(arch_reg);
283 
284  case CCRegClass:
285  return ccMap.lookup(arch_reg);
286 
287  case MiscRegClass:
288  // misc regs aren't really renamed, they keep the same
289  // mapping throughout the execution.
290  return regFile->getMiscRegId(arch_reg.flatIndex());
291 
292  default:
293  panic("rename lookup(): unknown reg class %s\n",
294  arch_reg.className());
295  }
296  }
297 
306  void
307  setEntry(const RegId& arch_reg, PhysRegIdPtr phys_reg)
308  {
309  switch (arch_reg.classValue()) {
310  case IntRegClass:
311  assert(phys_reg->isIntPhysReg());
312  return intMap.setEntry(arch_reg, phys_reg);
313 
314  case FloatRegClass:
315  assert(phys_reg->isFloatPhysReg());
316  return floatMap.setEntry(arch_reg, phys_reg);
317 
318  case VecRegClass:
319  assert(phys_reg->isVectorPhysReg());
320  assert(vecMode == Enums::Full);
321  return vecMap.setEntry(arch_reg, phys_reg);
322 
323  case VecElemClass:
324  assert(phys_reg->isVectorPhysElem());
325  assert(vecMode == Enums::Elem);
326  return vecElemMap.setEntry(arch_reg, phys_reg);
327 
328  case VecPredRegClass:
329  assert(phys_reg->isVecPredPhysReg());
330  return predMap.setEntry(arch_reg, phys_reg);
331 
332  case CCRegClass:
333  assert(phys_reg->isCCPhysReg());
334  return ccMap.setEntry(arch_reg, phys_reg);
335 
336  case MiscRegClass:
337  // Misc registers do not actually rename, so don't change
338  // their mappings. We end up here when a commit or squash
339  // tries to update or undo a hardwired misc reg nmapping,
340  // which should always be setting it to what it already is.
341  assert(phys_reg == lookup(arch_reg));
342  return;
343 
344  default:
345  panic("rename setEntry(): unknown reg class %s\n",
346  arch_reg.className());
347  }
348  }
349 
356  unsigned
358  {
359  return std::min({intMap.numFreeEntries(),
361  vecMode == Enums::Full ? vecMap.numFreeEntries() :
364  }
365 
366  unsigned numFreeIntEntries() const { return intMap.numFreeEntries(); }
367  unsigned numFreeFloatEntries() const { return floatMap.numFreeEntries(); }
368  unsigned
370  {
371  return vecMode == Enums::Full
374  }
375  unsigned numFreePredEntries() const { return predMap.numFreeEntries(); }
376  unsigned numFreeCCEntries() const { return ccMap.numFreeEntries(); }
377 
381  bool
382  canRename(uint32_t intRegs, uint32_t floatRegs, uint32_t vectorRegs,
383  uint32_t vecElemRegs, uint32_t vecPredRegs,
384  uint32_t ccRegs) const
385  {
386  return intRegs <= intMap.numFreeEntries() &&
387  floatRegs <= floatMap.numFreeEntries() &&
388  vectorRegs <= vecMap.numFreeEntries() &&
389  vecElemRegs <= vecElemMap.numFreeEntries() &&
390  vecPredRegs <= predMap.numFreeEntries() &&
391  ccRegs <= ccMap.numFreeEntries();
392  }
399  void switchMode(VecMode newVecMode);
400 
405  void switchFreeList(UnifiedFreeList* freeList);
406 
407 };
408 
409 #endif //__CPU_O3_RENAME_MAP_HH__
PhysRegId::isFloatPhysReg
bool isFloatPhysReg() const
Definition: reg_class.hh:285
UnifiedRenameMap::numFreeIntEntries
unsigned numFreeIntEntries() const
Definition: rename_map.hh:366
UnifiedRenameMap::numFreeVecEntries
unsigned numFreeVecEntries() const
Definition: rename_map.hh:369
PhysRegId::isVectorPhysElem
bool isVectorPhysElem() const
@Return true if it is a vector element physical register.
Definition: reg_class.hh:294
UnifiedRenameMap
Unified register rename map for all classes of registers.
Definition: rename_map.hh:169
SimpleRenameMap::freeList
SimpleFreeList * freeList
Pointer to the free list from which new physical registers should be allocated in rename()
Definition: rename_map.hh:78
UnifiedRenameMap::rename
RenameInfo rename(const RegId &arch_reg)
Tell rename map to get a new free physical register to remap the specified architectural register.
Definition: rename_map.hh:224
VecElemClass
@ VecElemClass
Vector Register Native Elem lane.
Definition: reg_class.hh:58
RegId::className
const char * className() const
Return a const char* with the register class name.
Definition: reg_class.hh:201
UnifiedRenameMap::UnifiedRenameMap
UnifiedRenameMap()
Default constructor.
Definition: rename_map.hh:204
UnifiedRenameMap::intMap
SimpleRenameMap intMap
The integer register rename map.
Definition: rename_map.hh:173
SimpleRenameMap::iterator
Arch2PhysMap::iterator iterator
Definition: rename_map.hh:70
SimpleRenameMap::~SimpleRenameMap
~SimpleRenameMap()
Definition: rename_map.hh:93
UnifiedRenameMap::switchFreeList
void switchFreeList(UnifiedFreeList *freeList)
Switch freeList of registers from Full to Elem or vicevers depending on vecMode (vector renaming mode...
Definition: rename_map.cc:133
PhysRegId::isVectorPhysReg
bool isVectorPhysReg() const
@Return true if it is a vector physical register.
Definition: reg_class.hh:291
UnifiedRenameMap::regFile
PhysRegFile * regFile
The register file object is used only to get PhysRegIdPtr on MiscRegs, as they are stored in it.
Definition: rename_map.hh:197
UnifiedRenameMap::~UnifiedRenameMap
~UnifiedRenameMap()
Destructor.
Definition: rename_map.hh:207
PhysRegFile
Simple physical register file class.
Definition: regfile.hh:59
std::vector< PhysRegIdPtr >
UnifiedRenameMap::switchMode
void switchMode(VecMode newVecMode)
Set vector mode to Full or Elem.
Definition: rename_map.cc:171
UnifiedRenameMap::setEntry
void setEntry(const RegId &arch_reg, PhysRegIdPtr phys_reg)
Update rename map with a specific mapping.
Definition: rename_map.hh:307
RegId
Register ID: describe an architectural register with its class and index.
Definition: reg_class.hh:75
SimpleRenameMap::init
void init(unsigned size, SimpleFreeList *_freeList, RegIndex _zeroReg)
Because we have an array of rename maps (one per thread) in the CPU, it's awkward to initialize this ...
Definition: rename_map.cc:58
UnifiedRenameMap::vecMap
SimpleRenameMap vecMap
The vector register rename map.
Definition: rename_map.hh:182
PhysRegFile::getMiscRegId
PhysRegIdPtr getMiscRegId(RegIndex reg_idx)
Gets a misc register PhysRegIdPtr.
Definition: regfile.hh:170
UnifiedRenameMap::numFreeEntries
unsigned numFreeEntries() const
Return the minimum number of free entries across all of the register classes.
Definition: rename_map.hh:357
FloatRegClass
@ FloatRegClass
Floating-point register.
Definition: reg_class.hh:54
SimpleRenameMap::begin
const_iterator begin() const
Definition: rename_map.hh:150
UnifiedRenameMap::vecElemMap
SimpleRenameMap vecElemMap
The vector element register rename map.
Definition: rename_map.hh:185
SimpleRenameMap::end
iterator end()
Forward end/cend to the map.
Definition: rename_map.hh:156
UnifiedRenameMap::lookup
PhysRegIdPtr lookup(const RegId &arch_reg) const
Look up the physical register mapped to an architectural register.
Definition: rename_map.hh:264
UnifiedRenameMap::init
void init(PhysRegFile *_regFile, RegIndex _intZeroReg, RegIndex _floatZeroReg, UnifiedFreeList *freeList, VecMode _mode)
Initializes rename map with given parameters.
Definition: rename_map.cc:108
SimpleFreeList::numFreeRegs
unsigned numFreeRegs() const
Return the number of free registers on the list.
Definition: free_list.hh:94
SimpleRenameMap::end
const_iterator end() const
Definition: rename_map.hh:157
UnifiedFreeList
FreeList class that simply holds the list of free integer and floating point registers.
Definition: free_list.hh:114
UnifiedRenameMap::ccMap
SimpleRenameMap ccMap
The condition-code register rename map.
Definition: rename_map.hh:179
UnifiedRenameMap::RenameInfo
SimpleRenameMap::RenameInfo RenameInfo
Definition: rename_map.hh:201
SimpleRenameMap::lookup
PhysRegIdPtr lookup(const RegId &arch_reg) const
Look up the physical register mapped to an architectural register.
Definition: rename_map.hh:125
SimpleRenameMap::RenameInfo
std::pair< PhysRegIdPtr, PhysRegIdPtr > RenameInfo
Pair of a physical register and a physical register.
Definition: rename_map.hh:108
PhysRegId::isCCPhysReg
bool isCCPhysReg() const
@Return true if it is a condition-code physical register.
Definition: reg_class.hh:288
std::pair
STL pair class.
Definition: stl.hh:58
VecPredRegClass
@ VecPredRegClass
Definition: reg_class.hh:59
UnifiedRenameMap::floatMap
SimpleRenameMap floatMap
The floating-point register rename map.
Definition: rename_map.hh:176
regfile.hh
UnifiedRenameMap::predMap
SimpleRenameMap predMap
The predicate register rename map.
Definition: rename_map.hh:188
SimpleRenameMap::numFreeEntries
unsigned numFreeEntries() const
Return the number of free entries on the associated free list.
Definition: rename_map.hh:145
PhysRegId::isIntPhysReg
bool isIntPhysReg() const
Definition: reg_class.hh:282
IntRegClass
@ IntRegClass
Integer register.
Definition: reg_class.hh:53
UnifiedRenameMap::VecMode
Enums::VecRegRenameMode VecMode
Definition: rename_map.hh:190
CCRegClass
@ CCRegClass
Condition-code register.
Definition: reg_class.hh:60
UnifiedRenameMap::vecMode
VecMode vecMode
Definition: rename_map.hh:191
UnifiedRenameMap::numFreeCCEntries
unsigned numFreeCCEntries() const
Definition: rename_map.hh:376
UnifiedRenameMap::numFreeFloatEntries
unsigned numFreeFloatEntries() const
Definition: rename_map.hh:367
MiscRegClass
@ MiscRegClass
Control (misc) register.
Definition: reg_class.hh:61
VecRegClass
@ VecRegClass
Vector Register.
Definition: reg_class.hh:56
SimpleRenameMap::rename
RenameInfo rename(const RegId &arch_reg)
Tell rename map to get a new free physical register to remap the specified architectural register.
Definition: rename_map.cc:70
UnifiedRenameMap::canRename
bool canRename(uint32_t intRegs, uint32_t floatRegs, uint32_t vectorRegs, uint32_t vecElemRegs, uint32_t vecPredRegs, uint32_t ccRegs) const
Return whether there are enough registers to serve the request.
Definition: rename_map.hh:382
SimpleRenameMap::setEntry
void setEntry(const RegId &arch_reg, PhysRegIdPtr phys_reg)
Update rename map with a specific mapping.
Definition: rename_map.hh:138
RegIndex
uint16_t RegIndex
Definition: types.hh:52
SimpleRenameMap::map
Arch2PhysMap map
The acutal arch-to-phys register map.
Definition: rename_map.hh:68
SimpleRenameMap::SimpleRenameMap
SimpleRenameMap()
Definition: rename_map.cc:51
reg_class.hh
SimpleRenameMap::cbegin
const_iterator cbegin() const
Definition: rename_map.hh:151
SimpleRenameMap::cend
const_iterator cend() const
Definition: rename_map.hh:158
free_list.hh
UnifiedRenameMap::numFreePredEntries
unsigned numFreePredEntries() const
Definition: rename_map.hh:375
PhysRegId
Physical register ID.
Definition: reg_class.hh:223
RegId::flatIndex
RegIndex flatIndex() const
Index flattening.
Definition: reg_class.hh:178
SimpleRenameMap::begin
iterator begin()
Forward begin/cbegin to the map.
Definition: rename_map.hh:149
PhysRegId::isVecPredPhysReg
bool isVecPredPhysReg() const
Definition: reg_class.hh:297
SimpleRenameMap::const_iterator
Arch2PhysMap::const_iterator const_iterator
Definition: rename_map.hh:71
RegId::classValue
const RegClass & classValue() const
Class accessor.
Definition: reg_class.hh:199
SimpleRenameMap::zeroReg
RegId zeroReg
The architectural index of the zero register.
Definition: rename_map.hh:87
SimpleRenameMap
Register rename map for a single class of registers (e.g., integer or floating point).
Definition: rename_map.hh:63
SimpleFreeList
Free list for a single class of registers (e.g., integer or floating point).
Definition: free_list.hh:61
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:171

Generated on Tue Jun 22 2021 15:28:26 for gem5 by doxygen 1.8.17