gem5  v20.0.0.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 
124  PhysRegIdPtr lookup(const RegId& arch_reg) const
125  {
126  assert(arch_reg.flatIndex() <= map.size());
127  return map[arch_reg.flatIndex()];
128  }
129 
136  void setEntry(const RegId& arch_reg, PhysRegIdPtr phys_reg)
137  {
138  assert(arch_reg.flatIndex() <= map.size());
139  map[arch_reg.flatIndex()] = phys_reg;
140  }
141 
143  unsigned numFreeEntries() const { return freeList->numFreeRegs(); }
144 
147  iterator begin() { return map.begin(); }
148  const_iterator begin() const { return map.begin(); }
149  const_iterator cbegin() const { return map.cbegin(); }
154  iterator end() { return map.end(); }
155  const_iterator end() const { return map.end(); }
156  const_iterator cend() const { return map.cend(); }
158 };
159 
168 {
169  private:
170  static constexpr uint32_t NVecElems = TheISA::NumVecElemPerVecReg;
173 
176 
179 
182 
185 
188 
191 
192  using VecMode = Enums::VecRegRenameMode;
194 
200 
201  public:
202 
204 
206  UnifiedRenameMap() : regFile(nullptr) {};
207 
210 
212  void init(PhysRegFile *_regFile,
213  RegIndex _intZeroReg,
214  RegIndex _floatZeroReg,
216  VecMode _mode);
217 
226  RenameInfo rename(const RegId& arch_reg)
227  {
228  switch (arch_reg.classValue()) {
229  case IntRegClass:
230  return intMap.rename(arch_reg);
231  case FloatRegClass:
232  return floatMap.rename(arch_reg);
233  case VecRegClass:
234  assert(vecMode == Enums::Full);
235  return vecMap.rename(arch_reg);
236  case VecElemClass:
237  assert(vecMode == Enums::Elem);
238  return vecElemMap.rename(arch_reg);
239  case VecPredRegClass:
240  return predMap.rename(arch_reg);
241  case CCRegClass:
242  return ccMap.rename(arch_reg);
243  case MiscRegClass:
244  {
245  // misc regs aren't really renamed, just remapped
246  PhysRegIdPtr phys_reg = lookup(arch_reg);
247  // Set the new register to the previous one to keep the same
248  // mapping throughout the execution.
249  return RenameInfo(phys_reg, phys_reg);
250  }
251 
252  default:
253  panic("rename rename(): unknown reg class %s\n",
254  arch_reg.className());
255  }
256  }
257 
265  PhysRegIdPtr lookup(const RegId& arch_reg) const
266  {
267  switch (arch_reg.classValue()) {
268  case IntRegClass:
269  return intMap.lookup(arch_reg);
270 
271  case FloatRegClass:
272  return floatMap.lookup(arch_reg);
273 
274  case VecRegClass:
275  assert(vecMode == Enums::Full);
276  return vecMap.lookup(arch_reg);
277 
278  case VecElemClass:
279  assert(vecMode == Enums::Elem);
280  return vecElemMap.lookup(arch_reg);
281 
282  case VecPredRegClass:
283  return predMap.lookup(arch_reg);
284 
285  case CCRegClass:
286  return ccMap.lookup(arch_reg);
287 
288  case MiscRegClass:
289  // misc regs aren't really renamed, they keep the same
290  // mapping throughout the execution.
291  return regFile->getMiscRegId(arch_reg.flatIndex());
292 
293  default:
294  panic("rename lookup(): unknown reg class %s\n",
295  arch_reg.className());
296  }
297  }
298 
307  void 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 numFreeEntries() const
357  {
358  return std::min(std::min(
359  std::min(intMap.numFreeEntries(), floatMap.numFreeEntries()),
360  vecMode == Enums::Full ? vecMap.numFreeEntries()
361  : vecElemMap.numFreeEntries()),
362  predMap.numFreeEntries());
363  }
364 
365  unsigned numFreeIntEntries() const { return intMap.numFreeEntries(); }
366  unsigned numFreeFloatEntries() const { return floatMap.numFreeEntries(); }
367  unsigned numFreeVecEntries() const
368  {
369  return vecMode == Enums::Full
370  ? vecMap.numFreeEntries()
371  : vecElemMap.numFreeEntries();
372  }
373  unsigned numFreePredEntries() const { return predMap.numFreeEntries(); }
374  unsigned numFreeCCEntries() const { return ccMap.numFreeEntries(); }
375 
379  bool canRename(uint32_t intRegs, uint32_t floatRegs, uint32_t vectorRegs,
380  uint32_t vecElemRegs, uint32_t vecPredRegs,
381  uint32_t ccRegs) const
382  {
383  return intRegs <= intMap.numFreeEntries() &&
384  floatRegs <= floatMap.numFreeEntries() &&
385  vectorRegs <= vecMap.numFreeEntries() &&
386  vecElemRegs <= vecElemMap.numFreeEntries() &&
387  vecPredRegs <= predMap.numFreeEntries() &&
388  ccRegs <= ccMap.numFreeEntries();
389  }
396  void switchMode(VecMode newVecMode);
397 
402  void switchFreeList(UnifiedFreeList* freeList);
403 
404 };
405 
406 #endif //__CPU_O3_RENAME_MAP_HH__
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:163
Arch2PhysMap::const_iterator const_iterator
Definition: rename_map.hh:71
unsigned numFreeEntries() const
Return the minimum number of free entries across all of the register classes.
Definition: rename_map.hh:356
unsigned numFreeFloatEntries() const
Definition: rename_map.hh:366
Arch2PhysMap map
The acutal arch-to-phys register map.
Definition: rename_map.hh:68
iterator end()
Forward end/cend to the map.
Definition: rename_map.hh:154
Floating-point register.
Definition: reg_class.hh:54
bool isCCPhysReg() const
true if it is a condition-code physical register.
Definition: reg_class.hh:281
iterator begin()
Forward begin/cbegin to the map.
Definition: rename_map.hh:147
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:379
STL pair class.
Definition: stl.hh:58
Simple physical register file class.
Definition: regfile.hh:60
Control (misc) register.
Definition: reg_class.hh:61
bool isVectorPhysReg() const
true if it is a vector physical register.
Definition: reg_class.hh:284
unsigned numFreeCCEntries() const
Definition: rename_map.hh:374
unsigned numFreePredEntries() const
Definition: rename_map.hh:373
SimpleRenameMap ccMap
The condition-code register rename map.
Definition: rename_map.hh:181
SimpleRenameMap predMap
The predicate register rename map.
Definition: rename_map.hh:190
Enums::VecRegRenameMode VecMode
Definition: rename_map.hh:192
TheISA::VecPredReg VecPredReg
Definition: rename_map.hh:172
RegId zeroReg
The architectural index of the zero register.
Definition: rename_map.hh:87
constexpr unsigned NumVecElemPerVecReg
Definition: registers.hh:66
::VecPredRegT< VecElem, NumVecElemPerVecReg, VecPredRegHasPackedRepr, false > VecPredReg
Definition: registers.hh:74
SimpleRenameMap floatMap
The floating-point register rename map.
Definition: rename_map.hh:178
const_iterator cend() const
Definition: rename_map.hh:156
Free list for a single class of registers (e.g., integer or floating point).
Definition: free_list.hh:62
::VecRegT< VecElem, NumVecElemPerVecReg, false > VecReg
Definition: registers.hh:69
bool isVecPredPhysReg() const
Definition: reg_class.hh:290
PhysRegIdPtr getMiscRegId(RegIndex reg_idx)
Gets a misc register PhysRegIdPtr.
Definition: regfile.hh:176
unsigned numFreeVecEntries() const
Definition: rename_map.hh:367
Vector Register Native Elem lane.
Definition: reg_class.hh:58
uint16_t RegIndex
Definition: types.hh:40
unsigned numFreeIntEntries() const
Definition: rename_map.hh:365
Arch2PhysMap::iterator iterator
Definition: rename_map.hh:70
UnifiedRenameMap()
Default constructor.
Definition: rename_map.hh:206
Condition-code register.
Definition: reg_class.hh:60
SimpleRenameMap intMap
The integer register rename map.
Definition: rename_map.hh:175
Unified register rename map for all classes of registers.
Definition: rename_map.hh:167
PhysRegFile * regFile
The register file object is used only to get PhysRegIdPtr on MiscRegs, as they are stored in it...
Definition: rename_map.hh:199
void setEntry(const RegId &arch_reg, PhysRegIdPtr phys_reg)
Update rename map with a specific mapping.
Definition: rename_map.hh:136
SimpleFreeList * freeList
Pointer to the free list from which new physical registers should be allocated in rename() ...
Definition: rename_map.hh:78
void init(unsigned size, SimpleFreeList *_freeList, RegIndex _zeroReg)
Because we have an array of rename maps (one per thread) in the CPU, it&#39;s awkward to initialize this ...
Definition: rename_map.cc:60
void setEntry(const RegId &arch_reg, PhysRegIdPtr phys_reg)
Update rename map with a specific mapping.
Definition: rename_map.hh:307
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:226
unsigned numFreeRegs() const
Return the number of free registers on the list.
Definition: free_list.hh:95
const_iterator end() const
Definition: rename_map.hh:155
bool isFloatPhysReg() const
Definition: reg_class.hh:278
FreeList class that simply holds the list of free integer and floating point registers.
Definition: free_list.hh:115
TheISA::VecReg VecReg
Definition: rename_map.hh:171
Physical register ID.
Definition: reg_class.hh:223
~UnifiedRenameMap()
Destructor.
Definition: rename_map.hh:209
bool isIntPhysReg() const
Definition: reg_class.hh:275
std::pair< PhysRegIdPtr, PhysRegIdPtr > RenameInfo
Pair of a physical register and a physical register.
Definition: rename_map.hh:108
const RegClass & classValue() const
Class accessor.
Definition: reg_class.hh:200
unsigned numFreeEntries() const
Return the number of free entries on the associated free list.
Definition: rename_map.hh:143
SimpleRenameMap vecMap
The vector register rename map.
Definition: rename_map.hh:184
RegIndex flatIndex() const
Index flattening.
Definition: reg_class.hh:179
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
Register ID: describe an architectural register with its class and index.
Definition: reg_class.hh:75
Integer register.
Definition: reg_class.hh:53
Vector Register.
Definition: reg_class.hh:56
const_iterator begin() const
Definition: rename_map.hh:148
SimpleRenameMap::RenameInfo RenameInfo
Definition: rename_map.hh:203
PhysRegIdPtr lookup(const RegId &arch_reg) const
Look up the physical register mapped to an architectural register.
Definition: rename_map.hh:265
bool isVectorPhysElem() const
true if it is a vector element physical register.
Definition: reg_class.hh:287
const_iterator cbegin() const
Definition: rename_map.hh:149
const char * className() const
Return a const char* with the register class name.
Definition: reg_class.hh:202
PhysRegIdPtr lookup(const RegId &arch_reg) const
Look up the physical register mapped to an architectural register.
Definition: rename_map.hh:124
Register rename map for a single class of registers (e.g., integer or floating point).
Definition: rename_map.hh:63
SimpleRenameMap vecElemMap
The vector element register rename map.
Definition: rename_map.hh:187

Generated on Thu May 28 2020 16:21:31 for gem5 by doxygen 1.8.13