gem5 v24.0.0.0
Loading...
Searching...
No Matches
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"
54#include "cpu/o3/free_list.hh"
55#include "cpu/o3/regfile.hh"
56#include "cpu/reg_class.hh"
57
58namespace gem5
59{
60
61namespace 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
174
180
181 public:
182
184
185 typedef std::array<UnifiedRenameMap, MaxThreads> PerThreadUnifiedRenameMap;
186
188 UnifiedRenameMap() : regFile(nullptr) {};
189
192
194 void init(const BaseISA::RegClasses &regClasses,
195 PhysRegFile *_regFile, UnifiedFreeList *freeList);
196
206 rename(const RegId& arch_reg)
207 {
208 if (!arch_reg.isRenameable()) {
209 // misc regs aren't really renamed, just remapped
210 PhysRegIdPtr phys_reg = lookup(arch_reg);
211 // Set the new register to the previous one to keep the same
212 // mapping throughout the execution.
213 return RenameInfo(phys_reg, phys_reg);
214 }
215
216 return renameMaps[arch_reg.classValue()].rename(arch_reg);
217 }
218
227 lookup(const RegId& arch_reg) const
228 {
229 auto reg_class = arch_reg.classValue();
230 if (reg_class == InvalidRegClass) {
231 return &invalidPhysRegId;
232 } else if (reg_class == MiscRegClass) {
233 // misc regs aren't really renamed, they keep the same
234 // mapping throughout the execution.
235 return regFile->getMiscRegId(arch_reg.index());
236 }
237 return renameMaps[reg_class].lookup(arch_reg);
238 }
239
248 void
249 setEntry(const RegId& arch_reg, PhysRegIdPtr phys_reg)
250 {
251 assert(phys_reg->is(arch_reg.classValue()));
252 if (!arch_reg.isRenameable()) {
253 // Misc registers do not actually rename, so don't change
254 // their mappings. We end up here when a commit or squash
255 // tries to update or undo a hardwired misc reg nmapping,
256 // which should always be setting it to what it already is.
257 assert(phys_reg == lookup(arch_reg));
258 return;
259 }
260
261 return renameMaps[arch_reg.classValue()].setEntry(arch_reg, phys_reg);
262 }
263
270 unsigned
272 {
273 auto min_free = std::numeric_limits<unsigned>::max();
274 for (auto &map: renameMaps) {
275 // If this map isn't empty (not used)...
276 if (map.numArchRegs())
277 min_free = std::min(min_free, map.numFreeEntries());
278 }
279 return min_free;
280 }
281
282 unsigned
284 {
285 return renameMaps[type].numFreeEntries();
286 }
287
291 bool canRename(DynInstPtr inst) const;
292};
293
294} // namespace o3
295} // namespace gem5
296
297#endif //__CPU_O3_RENAME_MAP_HH__
Physical register ID.
Definition reg_class.hh:415
constexpr bool is(RegClassType reg_class) const
Definition reg_class.hh:275
Register ID: describe an architectural register with its class and index.
Definition reg_class.hh:94
constexpr bool isRenameable() const
Return true if this register can be renamed.
Definition reg_class.hh:141
constexpr RegClassType classValue() const
Definition reg_class.hh:280
constexpr RegIndex index() const
Index accessors.
Definition reg_class.hh:151
Simple physical register file class.
Definition regfile.hh:66
PhysRegIdPtr getMiscRegId(RegIndex reg_idx)
Gets a misc register PhysRegIdPtr.
Definition regfile.hh:168
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
const_iterator cend() const
unsigned numFreeEntries() const
Return the number of free entries on the associated free list.
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
PhysRegIdPtr lookup(const RegId &arch_reg) const
Look up the physical register mapped to an architectural register.
const_iterator end() const
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.
Arch2PhysMap map
The acutal arch-to-phys register map.
Definition rename_map.hh:76
iterator begin()
Forward begin/cbegin to the map.
void setEntry(const RegId &arch_reg, PhysRegIdPtr phys_reg)
Update rename map with a specific mapping.
std::pair< PhysRegIdPtr, PhysRegIdPtr > RenameInfo
Pair of a physical register and a physical register.
const_iterator cbegin() const
const_iterator begin() const
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.
PhysRegFile * regFile
The register file object is used only to get PhysRegIdPtr on MiscRegs, as they are stored in it.
void setEntry(const RegId &arch_reg, PhysRegIdPtr phys_reg)
Update rename map with a specific mapping.
SimpleRenameMap::RenameInfo RenameInfo
unsigned numFreeEntries(RegClassType type) const
UnifiedRenameMap()
Default constructor.
unsigned minFreeEntries() const
Return the minimum number of free entries across all of the register classes.
PhysRegIdPtr lookup(const RegId &arch_reg) const
Look up the physical register mapped to an architectural register.
std::array< UnifiedRenameMap, MaxThreads > PerThreadUnifiedRenameMap
bool canRename(DynInstPtr inst) const
Return whether there are enough registers to serve the request.
RenameInfo rename(const RegId &arch_reg)
Tell rename map to get a new free physical register to remap the specified architectural register.
std::array< SimpleRenameMap, CCRegClass+1 > renameMaps
static PhysRegId invalidPhysRegId
STL pair class.
Definition stl.hh:58
const FlagsType init
This Stat is Initialized.
Definition info.hh:55
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
RegClassType
Enumerate the classes of registers.
Definition reg_class.hh:60
@ InvalidRegClass
Definition reg_class.hh:71
@ MiscRegClass
Control (misc) register.
Definition reg_class.hh:70

Generated on Tue Jun 18 2024 16:24:02 for gem5 by doxygen 1.11.0