gem5  v22.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 <algorithm>
46 #include <array>
47 #include <iostream>
48 #include <limits>
49 #include <utility>
50 #include <vector>
51 
52 #include "arch/generic/isa.hh"
53 #include "cpu/o3/dyn_inst_ptr.hh"
54 #include "cpu/o3/free_list.hh"
55 #include "cpu/o3/regfile.hh"
56 #include "cpu/reg_class.hh"
57 
58 namespace gem5
59 {
60 
61 namespace o3
62 {
63 
72 {
73  private:
77  public:
78  using iterator = Arch2PhysMap::iterator;
79  using const_iterator = Arch2PhysMap::const_iterator;
80  private:
81 
87 
88  public:
89 
91 
97  void init(const RegClass &reg_class, SimpleFreeList *_freeList);
98 
106 
114  RenameInfo rename(const RegId& arch_reg);
115 
122  lookup(const RegId& arch_reg) const
123  {
124  assert(arch_reg.index() <= map.size());
125  return map[arch_reg.index()];
126  }
127 
134  void
135  setEntry(const RegId& arch_reg, PhysRegIdPtr phys_reg)
136  {
137  assert(arch_reg.index() <= map.size());
138  map[arch_reg.index()] = phys_reg;
139  }
140 
142  unsigned numFreeEntries() const { return freeList->numFreeRegs(); }
143 
144  size_t numArchRegs() const { return map.size(); }
145 
148  iterator begin() { return map.begin(); }
149  const_iterator begin() const { return map.begin(); }
150  const_iterator cbegin() const { return map.cbegin(); }
155  iterator end() { return map.end(); }
156  const_iterator end() const { return map.end(); }
157  const_iterator cend() const { return map.cend(); }
159 };
160 
169 {
170  private:
171  std::array<SimpleRenameMap, CCRegClass + 1> renameMaps;
172 
173  static inline PhysRegId invalidPhysRegId{};
174 
180 
181  public:
182 
184 
186  UnifiedRenameMap() : regFile(nullptr) {};
187 
190 
192  void init(const BaseISA::RegClasses &regClasses,
193  PhysRegFile *_regFile, UnifiedFreeList *freeList);
194 
203  RenameInfo
204  rename(const RegId& arch_reg)
205  {
206  if (!arch_reg.isRenameable()) {
207  // misc regs aren't really renamed, just remapped
208  PhysRegIdPtr phys_reg = lookup(arch_reg);
209  // Set the new register to the previous one to keep the same
210  // mapping throughout the execution.
211  return RenameInfo(phys_reg, phys_reg);
212  }
213 
214  return renameMaps[arch_reg.classValue()].rename(arch_reg);
215  }
216 
225  lookup(const RegId& arch_reg) const
226  {
227  auto reg_class = arch_reg.classValue();
228  if (reg_class == InvalidRegClass) {
229  return &invalidPhysRegId;
230  } else if (reg_class == MiscRegClass) {
231  // misc regs aren't really renamed, they keep the same
232  // mapping throughout the execution.
233  return regFile->getMiscRegId(arch_reg.index());
234  }
235  return renameMaps[reg_class].lookup(arch_reg);
236  }
237 
246  void
247  setEntry(const RegId& arch_reg, PhysRegIdPtr phys_reg)
248  {
249  assert(phys_reg->is(arch_reg.classValue()));
250  if (!arch_reg.isRenameable()) {
251  // Misc registers do not actually rename, so don't change
252  // their mappings. We end up here when a commit or squash
253  // tries to update or undo a hardwired misc reg nmapping,
254  // which should always be setting it to what it already is.
255  assert(phys_reg == lookup(arch_reg));
256  return;
257  }
258 
259  return renameMaps[arch_reg.classValue()].setEntry(arch_reg, phys_reg);
260  }
261 
268  unsigned
270  {
271  auto min_free = std::numeric_limits<unsigned>::max();
272  for (auto &map: renameMaps) {
273  // If this map isn't empty (not used)...
274  if (map.numArchRegs())
275  min_free = std::min(min_free, map.numFreeEntries());
276  }
277  return min_free;
278  }
279 
280  unsigned
282  {
283  return renameMaps[type].numFreeEntries();
284  }
285 
289  bool canRename(DynInstPtr inst) const;
290 };
291 
292 } // namespace o3
293 } // namespace gem5
294 
295 #endif //__CPU_O3_RENAME_MAP_HH__
Physical register ID.
Definition: reg_class.hh:392
constexpr bool is(RegClassType reg_class) const
Definition: reg_class.hh:267
Register ID: describe an architectural register with its class and index.
Definition: reg_class.hh:91
constexpr bool isRenameable() const
Return true if this register can be renamed.
Definition: reg_class.hh:138
constexpr RegClassType classValue() const
Definition: reg_class.hh:272
constexpr RegIndex index() const
Index accessors.
Definition: reg_class.hh:148
Simple physical register file class.
Definition: regfile.hh:66
PhysRegIdPtr getMiscRegId(RegIndex reg_idx)
Gets a misc register PhysRegIdPtr.
Definition: regfile.hh:158
Free list for a single class of registers (e.g., integer or floating point).
Definition: free_list.hh:72
unsigned numFreeRegs() const
Return the number of free registers on the list.
Definition: free_list.hh:104
Register rename map for a single class of registers (e.g., integer or floating point).
Definition: rename_map.hh:72
void init(const RegClass &reg_class, SimpleFreeList *_freeList)
Because we have an array of rename maps (one per thread) in the CPU, it's awkward to initialize this ...
Definition: rename_map.cc:62
const_iterator cend() const
Definition: rename_map.hh:157
unsigned numFreeEntries() const
Return the number of free entries on the associated free list.
Definition: rename_map.hh:142
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
size_t numArchRegs() const
Definition: rename_map.hh:144
PhysRegIdPtr lookup(const RegId &arch_reg) const
Look up the physical register mapped to an architectural register.
Definition: rename_map.hh:122
const_iterator end() const
Definition: rename_map.hh:156
SimpleFreeList * freeList
Pointer to the free list from which new physical registers should be allocated in rename()
Definition: rename_map.hh:86
iterator end()
Forward end/cend to the map.
Definition: rename_map.hh:155
Arch2PhysMap map
The acutal arch-to-phys register map.
Definition: rename_map.hh:76
iterator begin()
Forward begin/cbegin to the map.
Definition: rename_map.hh:148
void setEntry(const RegId &arch_reg, PhysRegIdPtr phys_reg)
Update rename map with a specific mapping.
Definition: rename_map.hh:135
std::pair< PhysRegIdPtr, PhysRegIdPtr > RenameInfo
Pair of a physical register and a physical register.
Definition: rename_map.hh:105
const_iterator cbegin() const
Definition: rename_map.hh:150
const_iterator begin() const
Definition: rename_map.hh:149
Arch2PhysMap::const_iterator const_iterator
Definition: rename_map.hh:79
Arch2PhysMap::iterator iterator
Definition: rename_map.hh:78
FreeList class that simply holds the list of free integer and floating point registers.
Definition: free_list.hh:125
Unified register rename map for all classes of registers.
Definition: rename_map.hh:169
void init(const BaseISA::RegClasses &regClasses, PhysRegFile *_regFile, UnifiedFreeList *freeList)
Initializes rename map with given parameters.
Definition: rename_map.cc:110
PhysRegFile * regFile
The register file object is used only to get PhysRegIdPtr on MiscRegs, as they are stored in it.
Definition: rename_map.hh:179
void setEntry(const RegId &arch_reg, PhysRegIdPtr phys_reg)
Update rename map with a specific mapping.
Definition: rename_map.hh:247
SimpleRenameMap::RenameInfo RenameInfo
Definition: rename_map.hh:183
unsigned numFreeEntries(RegClassType type) const
Definition: rename_map.hh:281
UnifiedRenameMap()
Default constructor.
Definition: rename_map.hh:186
~UnifiedRenameMap()
Destructor.
Definition: rename_map.hh:189
PhysRegIdPtr lookup(const RegId &arch_reg) const
Look up the physical register mapped to an architectural register.
Definition: rename_map.hh:225
unsigned numFreeEntries() const
Return the minimum number of free entries across all of the register classes.
Definition: rename_map.hh:269
bool canRename(DynInstPtr inst) const
Return whether there are enough registers to serve the request.
Definition: rename_map.cc:120
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:204
std::array< SimpleRenameMap, CCRegClass+1 > renameMaps
Definition: rename_map.hh:171
static PhysRegId invalidPhysRegId
Definition: rename_map.hh:173
STL pair class.
Definition: stl.hh:58
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
RegClassType
Enumerate the classes of registers.
Definition: reg_class.hh:59
@ InvalidRegClass
Definition: reg_class.hh:69
@ MiscRegClass
Control (misc) register.
Definition: reg_class.hh:68

Generated on Wed Dec 21 2022 10:22:31 for gem5 by doxygen 1.9.1