gem5  v19.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  * Authors: Kevin Lim
42  * Steve Reinhardt
43  */
44 
45 #ifndef __CPU_O3_RENAME_MAP_HH__
46 #define __CPU_O3_RENAME_MAP_HH__
47 
48 #include <iostream>
49 #include <utility>
50 #include <vector>
51 
52 #include "arch/types.hh"
53 #include "config/the_isa.hh"
54 #include "cpu/o3/free_list.hh"
55 #include "cpu/o3/regfile.hh"
56 #include "cpu/reg_class.hh"
57 #include "enums/VecRegRenameMode.hh"
58 
67 {
68  private:
72  public:
73  using iterator = Arch2PhysMap::iterator;
74  using const_iterator = Arch2PhysMap::const_iterator;
75  private:
76 
82 
91 
92  public:
93 
95 
97 
103  void init(unsigned size, SimpleFreeList *_freeList, RegIndex _zeroReg);
104 
112 
120  RenameInfo rename(const RegId& arch_reg);
121 
127  PhysRegIdPtr lookup(const RegId& arch_reg) const
128  {
129  assert(arch_reg.flatIndex() <= map.size());
130  return map[arch_reg.flatIndex()];
131  }
132 
139  void setEntry(const RegId& arch_reg, PhysRegIdPtr phys_reg)
140  {
141  assert(arch_reg.flatIndex() <= map.size());
142  map[arch_reg.flatIndex()] = phys_reg;
143  }
144 
146  unsigned numFreeEntries() const { return freeList->numFreeRegs(); }
147 
150  iterator begin() { return map.begin(); }
151  const_iterator begin() const { return map.begin(); }
152  const_iterator cbegin() const { return map.cbegin(); }
157  iterator end() { return map.end(); }
158  const_iterator end() const { return map.end(); }
159  const_iterator cend() const { return map.cend(); }
161 };
162 
171 {
172  private:
173  static constexpr uint32_t NVecElems = TheISA::NumVecElemPerVecReg;
176 
179 
182 
185 
188 
191 
194 
195  using VecMode = Enums::VecRegRenameMode;
197 
203 
204  public:
205 
207 
209  UnifiedRenameMap() : regFile(nullptr) {};
210 
213 
215  void init(PhysRegFile *_regFile,
216  RegIndex _intZeroReg,
217  RegIndex _floatZeroReg,
219  VecMode _mode);
220 
229  RenameInfo rename(const RegId& arch_reg)
230  {
231  switch (arch_reg.classValue()) {
232  case IntRegClass:
233  return intMap.rename(arch_reg);
234  case FloatRegClass:
235  return floatMap.rename(arch_reg);
236  case VecRegClass:
237  assert(vecMode == Enums::Full);
238  return vecMap.rename(arch_reg);
239  case VecElemClass:
240  assert(vecMode == Enums::Elem);
241  return vecElemMap.rename(arch_reg);
242  case VecPredRegClass:
243  return predMap.rename(arch_reg);
244  case CCRegClass:
245  return ccMap.rename(arch_reg);
246  case MiscRegClass:
247  {
248  // misc regs aren't really renamed, just remapped
249  PhysRegIdPtr phys_reg = lookup(arch_reg);
250  // Set the new register to the previous one to keep the same
251  // mapping throughout the execution.
252  return RenameInfo(phys_reg, phys_reg);
253  }
254 
255  default:
256  panic("rename rename(): unknown reg class %s\n",
257  arch_reg.className());
258  }
259  }
260 
268  PhysRegIdPtr 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 setEntry(const RegId& arch_reg, PhysRegIdPtr phys_reg)
311  {
312  switch (arch_reg.classValue()) {
313  case IntRegClass:
314  assert(phys_reg->isIntPhysReg());
315  return intMap.setEntry(arch_reg, phys_reg);
316 
317  case FloatRegClass:
318  assert(phys_reg->isFloatPhysReg());
319  return floatMap.setEntry(arch_reg, phys_reg);
320 
321  case VecRegClass:
322  assert(phys_reg->isVectorPhysReg());
323  assert(vecMode == Enums::Full);
324  return vecMap.setEntry(arch_reg, phys_reg);
325 
326  case VecElemClass:
327  assert(phys_reg->isVectorPhysElem());
328  assert(vecMode == Enums::Elem);
329  return vecElemMap.setEntry(arch_reg, phys_reg);
330 
331  case VecPredRegClass:
332  assert(phys_reg->isVecPredPhysReg());
333  return predMap.setEntry(arch_reg, phys_reg);
334 
335  case CCRegClass:
336  assert(phys_reg->isCCPhysReg());
337  return ccMap.setEntry(arch_reg, phys_reg);
338 
339  case MiscRegClass:
340  // Misc registers do not actually rename, so don't change
341  // their mappings. We end up here when a commit or squash
342  // tries to update or undo a hardwired misc reg nmapping,
343  // which should always be setting it to what it already is.
344  assert(phys_reg == lookup(arch_reg));
345  return;
346 
347  default:
348  panic("rename setEntry(): unknown reg class %s\n",
349  arch_reg.className());
350  }
351  }
352 
359  unsigned numFreeEntries() const
360  {
361  return std::min(std::min(
362  std::min(intMap.numFreeEntries(), floatMap.numFreeEntries()),
363  vecMode == Enums::Full ? vecMap.numFreeEntries()
364  : vecElemMap.numFreeEntries()),
365  predMap.numFreeEntries());
366  }
367 
368  unsigned numFreeIntEntries() const { return intMap.numFreeEntries(); }
369  unsigned numFreeFloatEntries() const { return floatMap.numFreeEntries(); }
370  unsigned numFreeVecEntries() const
371  {
372  return vecMode == Enums::Full
373  ? vecMap.numFreeEntries()
374  : vecElemMap.numFreeEntries();
375  }
376  unsigned numFreePredEntries() const { return predMap.numFreeEntries(); }
377  unsigned numFreeCCEntries() const { return ccMap.numFreeEntries(); }
378 
382  bool 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__
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:167
Arch2PhysMap::const_iterator const_iterator
Definition: rename_map.hh:74
unsigned numFreeEntries() const
Return the minimum number of free entries across all of the register classes.
Definition: rename_map.hh:359
unsigned numFreeFloatEntries() const
Definition: rename_map.hh:369
Arch2PhysMap map
The acutal arch-to-phys register map.
Definition: rename_map.hh:71
iterator end()
Forward end/cend to the map.
Definition: rename_map.hh:157
Floating-point register.
Definition: reg_class.hh:58
bool isCCPhysReg() const
true if it is a condition-code physical register.
Definition: reg_class.hh:287
iterator begin()
Forward begin/cbegin to the map.
Definition: rename_map.hh:150
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
STL pair class.
Definition: stl.hh:61
Simple physical register file class.
Definition: regfile.hh:63
Control (misc) register.
Definition: reg_class.hh:65
bool isVectorPhysReg() const
true if it is a vector physical register.
Definition: reg_class.hh:290
unsigned numFreeCCEntries() const
Definition: rename_map.hh:377
unsigned numFreePredEntries() const
Definition: rename_map.hh:376
SimpleRenameMap ccMap
The condition-code register rename map.
Definition: rename_map.hh:184
SimpleRenameMap predMap
The predicate register rename map.
Definition: rename_map.hh:193
Enums::VecRegRenameMode VecMode
Definition: rename_map.hh:195
::DummyVecPredReg VecPredReg
Definition: registers.hh:58
TheISA::VecPredReg VecPredReg
Definition: rename_map.hh:175
RegId zeroReg
The architectural index of the zero register.
Definition: rename_map.hh:90
SimpleRenameMap floatMap
The floating-point register rename map.
Definition: rename_map.hh:181
const_iterator cend() const
Definition: rename_map.hh:159
Free list for a single class of registers (e.g., integer or floating point).
Definition: free_list.hh:64
bool isVecPredPhysReg() const
Definition: reg_class.hh:296
PhysRegIdPtr getMiscRegId(RegIndex reg_idx)
Gets a misc register PhysRegIdPtr.
Definition: regfile.hh:179
unsigned numFreeVecEntries() const
Definition: rename_map.hh:370
Vector Register Native Elem lane.
Definition: reg_class.hh:62
uint16_t RegIndex
Definition: types.hh:42
unsigned numFreeIntEntries() const
Definition: rename_map.hh:368
Arch2PhysMap::iterator iterator
Definition: rename_map.hh:73
UnifiedRenameMap()
Default constructor.
Definition: rename_map.hh:209
Condition-code register.
Definition: reg_class.hh:64
SimpleRenameMap intMap
The integer register rename map.
Definition: rename_map.hh:178
Unified register rename map for all classes of registers.
Definition: rename_map.hh:170
PhysRegFile * regFile
The register file object is used only to get PhysRegIdPtr on MiscRegs, as they are stored in it...
Definition: rename_map.hh:202
void setEntry(const RegId &arch_reg, PhysRegIdPtr phys_reg)
Update rename map with a specific mapping.
Definition: rename_map.hh:139
SimpleFreeList * freeList
Pointer to the free list from which new physical registers should be allocated in rename() ...
Definition: rename_map.hh:81
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:62
void setEntry(const RegId &arch_reg, PhysRegIdPtr phys_reg)
Update rename map with a specific mapping.
Definition: rename_map.hh:310
::DummyVecReg VecReg
Definition: registers.hh:51
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:229
unsigned numFreeRegs() const
Return the number of free registers on the list.
Definition: free_list.hh:97
const_iterator end() const
Definition: rename_map.hh:158
bool isFloatPhysReg() const
Definition: reg_class.hh:284
FreeList class that simply holds the list of free integer and floating point registers.
Definition: free_list.hh:117
TheISA::VecReg VecReg
Definition: rename_map.hh:174
Physical register ID.
Definition: reg_class.hh:229
~UnifiedRenameMap()
Destructor.
Definition: rename_map.hh:212
bool isIntPhysReg() const
Definition: reg_class.hh:281
std::pair< PhysRegIdPtr, PhysRegIdPtr > RenameInfo
Pair of a physical register and a physical register.
Definition: rename_map.hh:111
const RegClass & classValue() const
Class accessor.
Definition: reg_class.hh:206
unsigned numFreeEntries() const
Return the number of free entries on the associated free list.
Definition: rename_map.hh:146
SimpleRenameMap vecMap
The vector register rename map.
Definition: rename_map.hh:187
RegIndex flatIndex() const
Index flattening.
Definition: reg_class.hh:185
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:74
Register ID: describe an architectural register with its class and index.
Definition: reg_class.hh:79
Integer register.
Definition: reg_class.hh:57
Vector Register.
Definition: reg_class.hh:60
const_iterator begin() const
Definition: rename_map.hh:151
SimpleRenameMap::RenameInfo RenameInfo
Definition: rename_map.hh:206
PhysRegIdPtr lookup(const RegId &arch_reg) const
Look up the physical register mapped to an architectural register.
Definition: rename_map.hh:268
constexpr unsigned NumVecElemPerVecReg
Definition: registers.hh:54
bool isVectorPhysElem() const
true if it is a vector element physical register.
Definition: reg_class.hh:293
const_iterator cbegin() const
Definition: rename_map.hh:152
const char * className() const
Return a const char* with the register class name.
Definition: reg_class.hh:208
PhysRegIdPtr lookup(const RegId &arch_reg) const
Look up the physical register mapped to an architectural register.
Definition: rename_map.hh:127
Register rename map for a single class of registers (e.g., integer or floating point).
Definition: rename_map.hh:66
SimpleRenameMap vecElemMap
The vector element register rename map.
Definition: rename_map.hh:190

Generated on Fri Feb 28 2020 16:26:59 for gem5 by doxygen 1.8.13