gem5  v20.1.0.0
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:
172  static constexpr uint32_t NVecElems = TheISA::NumVecElemPerVecReg;
175 
178 
181 
184 
187 
190 
193 
194  using VecMode = Enums::VecRegRenameMode;
196 
202 
203  public:
204 
206 
208  UnifiedRenameMap() : regFile(nullptr) {};
209 
212 
214  void init(PhysRegFile *_regFile,
215  RegIndex _intZeroReg,
216  RegIndex _floatZeroReg,
217  UnifiedFreeList *freeList,
218  VecMode _mode);
219 
228  RenameInfo rename(const RegId& arch_reg)
229  {
230  switch (arch_reg.classValue()) {
231  case IntRegClass:
232  return intMap.rename(arch_reg);
233  case FloatRegClass:
234  return floatMap.rename(arch_reg);
235  case VecRegClass:
236  assert(vecMode == Enums::Full);
237  return vecMap.rename(arch_reg);
238  case VecElemClass:
239  assert(vecMode == Enums::Elem);
240  return vecElemMap.rename(arch_reg);
241  case VecPredRegClass:
242  return predMap.rename(arch_reg);
243  case CCRegClass:
244  return ccMap.rename(arch_reg);
245  case MiscRegClass:
246  {
247  // misc regs aren't really renamed, just remapped
248  PhysRegIdPtr phys_reg = lookup(arch_reg);
249  // Set the new register to the previous one to keep the same
250  // mapping throughout the execution.
251  return RenameInfo(phys_reg, phys_reg);
252  }
253 
254  default:
255  panic("rename rename(): unknown reg class %s\n",
256  arch_reg.className());
257  }
258  }
259 
268  lookup(const RegId& arch_reg) const
269  {
270  switch (arch_reg.classValue()) {
271  case IntRegClass:
272  return intMap.lookup(arch_reg);
273 
274  case FloatRegClass:
275  return floatMap.lookup(arch_reg);
276 
277  case VecRegClass:
278  assert(vecMode == Enums::Full);
279  return vecMap.lookup(arch_reg);
280 
281  case VecElemClass:
282  assert(vecMode == Enums::Elem);
283  return vecElemMap.lookup(arch_reg);
284 
285  case VecPredRegClass:
286  return predMap.lookup(arch_reg);
287 
288  case CCRegClass:
289  return ccMap.lookup(arch_reg);
290 
291  case MiscRegClass:
292  // misc regs aren't really renamed, they keep the same
293  // mapping throughout the execution.
294  return regFile->getMiscRegId(arch_reg.flatIndex());
295 
296  default:
297  panic("rename lookup(): unknown reg class %s\n",
298  arch_reg.className());
299  }
300  }
301 
310  void
311  setEntry(const RegId& arch_reg, PhysRegIdPtr phys_reg)
312  {
313  switch (arch_reg.classValue()) {
314  case IntRegClass:
315  assert(phys_reg->isIntPhysReg());
316  return intMap.setEntry(arch_reg, phys_reg);
317 
318  case FloatRegClass:
319  assert(phys_reg->isFloatPhysReg());
320  return floatMap.setEntry(arch_reg, phys_reg);
321 
322  case VecRegClass:
323  assert(phys_reg->isVectorPhysReg());
324  assert(vecMode == Enums::Full);
325  return vecMap.setEntry(arch_reg, phys_reg);
326 
327  case VecElemClass:
328  assert(phys_reg->isVectorPhysElem());
329  assert(vecMode == Enums::Elem);
330  return vecElemMap.setEntry(arch_reg, phys_reg);
331 
332  case VecPredRegClass:
333  assert(phys_reg->isVecPredPhysReg());
334  return predMap.setEntry(arch_reg, phys_reg);
335 
336  case CCRegClass:
337  assert(phys_reg->isCCPhysReg());
338  return ccMap.setEntry(arch_reg, phys_reg);
339 
340  case MiscRegClass:
341  // Misc registers do not actually rename, so don't change
342  // their mappings. We end up here when a commit or squash
343  // tries to update or undo a hardwired misc reg nmapping,
344  // which should always be setting it to what it already is.
345  assert(phys_reg == lookup(arch_reg));
346  return;
347 
348  default:
349  panic("rename setEntry(): unknown reg class %s\n",
350  arch_reg.className());
351  }
352  }
353 
360  unsigned
362  {
363  return std::min({intMap.numFreeEntries(),
365  vecMode == Enums::Full ? vecMap.numFreeEntries() :
368  }
369 
370  unsigned numFreeIntEntries() const { return intMap.numFreeEntries(); }
371  unsigned numFreeFloatEntries() const { return floatMap.numFreeEntries(); }
372  unsigned
374  {
375  return vecMode == Enums::Full
378  }
379  unsigned numFreePredEntries() const { return predMap.numFreeEntries(); }
380  unsigned numFreeCCEntries() const { return ccMap.numFreeEntries(); }
381 
385  bool
386  canRename(uint32_t intRegs, uint32_t floatRegs, uint32_t vectorRegs,
387  uint32_t vecElemRegs, uint32_t vecPredRegs,
388  uint32_t ccRegs) const
389  {
390  return intRegs <= intMap.numFreeEntries() &&
391  floatRegs <= floatMap.numFreeEntries() &&
392  vectorRegs <= vecMap.numFreeEntries() &&
393  vecElemRegs <= vecElemMap.numFreeEntries() &&
394  vecPredRegs <= predMap.numFreeEntries() &&
395  ccRegs <= ccMap.numFreeEntries();
396  }
403  void switchMode(VecMode newVecMode);
404 
409  void switchFreeList(UnifiedFreeList* freeList);
410 
411 };
412 
413 #endif //__CPU_O3_RENAME_MAP_HH__
PhysRegId::isFloatPhysReg
bool isFloatPhysReg() const
Definition: reg_class.hh:278
ArmISA::VecReg
::VecRegT< VecElem, NumVecElemPerVecReg, false > VecReg
Definition: registers.hh:69
UnifiedRenameMap::numFreeIntEntries
unsigned numFreeIntEntries() const
Definition: rename_map.hh:370
UnifiedRenameMap::numFreeVecEntries
unsigned numFreeVecEntries() const
Definition: rename_map.hh:373
PhysRegId::isVectorPhysElem
bool isVectorPhysElem() const
@Return true if it is a vector element physical register.
Definition: reg_class.hh:287
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:228
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:202
UnifiedRenameMap::UnifiedRenameMap
UnifiedRenameMap()
Default constructor.
Definition: rename_map.hh:208
UnifiedRenameMap::intMap
SimpleRenameMap intMap
The integer register rename map.
Definition: rename_map.hh:177
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:135
PhysRegId::isVectorPhysReg
bool isVectorPhysReg() const
@Return true if it is a vector physical register.
Definition: reg_class.hh:284
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:201
UnifiedRenameMap::~UnifiedRenameMap
~UnifiedRenameMap()
Destructor.
Definition: rename_map.hh:211
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:173
UnifiedRenameMap::setEntry
void setEntry(const RegId &arch_reg, PhysRegIdPtr phys_reg)
Update rename map with a specific mapping.
Definition: rename_map.hh:311
UnifiedRenameMap::VecReg
TheISA::VecReg VecReg
Definition: rename_map.hh:173
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:60
UnifiedRenameMap::vecMap
SimpleRenameMap vecMap
The vector register rename map.
Definition: rename_map.hh:186
PhysRegFile::getMiscRegId
PhysRegIdPtr getMiscRegId(RegIndex reg_idx)
Gets a misc register PhysRegIdPtr.
Definition: regfile.hh:175
UnifiedRenameMap::numFreeEntries
unsigned numFreeEntries() const
Return the minimum number of free entries across all of the register classes.
Definition: rename_map.hh:361
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:189
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:268
UnifiedRenameMap::init
void init(PhysRegFile *_regFile, RegIndex _intZeroReg, RegIndex _floatZeroReg, UnifiedFreeList *freeList, VecMode _mode)
Initializes rename map with given parameters.
Definition: rename_map.cc:110
SimpleFreeList::numFreeRegs
unsigned numFreeRegs() const
Return the number of free registers on the list.
Definition: free_list.hh:95
SimpleRenameMap::end
const_iterator end() const
Definition: rename_map.hh:157
ArmISA::NumVecElemPerVecReg
constexpr unsigned NumVecElemPerVecReg
Definition: registers.hh:66
UnifiedFreeList
FreeList class that simply holds the list of free integer and floating point registers.
Definition: free_list.hh:115
UnifiedRenameMap::ccMap
SimpleRenameMap ccMap
The condition-code register rename map.
Definition: rename_map.hh:183
UnifiedRenameMap::RenameInfo
SimpleRenameMap::RenameInfo RenameInfo
Definition: rename_map.hh:205
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:281
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:180
ArmISA::VecPredReg
::VecPredRegT< VecElem, NumVecElemPerVecReg, VecPredRegHasPackedRepr, false > VecPredReg
Definition: registers.hh:74
regfile.hh
UnifiedRenameMap::predMap
SimpleRenameMap predMap
The predicate register rename map.
Definition: rename_map.hh:192
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:275
IntRegClass
@ IntRegClass
Integer register.
Definition: reg_class.hh:53
UnifiedRenameMap::VecMode
Enums::VecRegRenameMode VecMode
Definition: rename_map.hh:194
CCRegClass
@ CCRegClass
Condition-code register.
Definition: reg_class.hh:60
UnifiedRenameMap::vecMode
VecMode vecMode
Definition: rename_map.hh:195
UnifiedRenameMap::numFreeCCEntries
unsigned numFreeCCEntries() const
Definition: rename_map.hh:380
UnifiedRenameMap::numFreeFloatEntries
unsigned numFreeFloatEntries() const
Definition: rename_map.hh:371
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:72
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:386
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
UnifiedRenameMap::VecPredReg
TheISA::VecPredReg VecPredReg
Definition: rename_map.hh:174
SimpleRenameMap::map
Arch2PhysMap map
The acutal arch-to-phys register map.
Definition: rename_map.hh:68
SimpleRenameMap::SimpleRenameMap
SimpleRenameMap()
Definition: rename_map.cc:53
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:379
PhysRegId
Physical register ID.
Definition: reg_class.hh:223
RegId::flatIndex
RegIndex flatIndex() const
Index flattening.
Definition: reg_class.hh:179
SimpleRenameMap::begin
iterator begin()
Forward begin/cbegin to the map.
Definition: rename_map.hh:149
PhysRegId::isVecPredPhysReg
bool isVecPredPhysReg() const
Definition: reg_class.hh:290
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:200
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:62
UnifiedRenameMap::NVecElems
static constexpr uint32_t NVecElems
Definition: rename_map.hh:172
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:171

Generated on Wed Sep 30 2020 14:02:09 for gem5 by doxygen 1.8.17