gem5  v22.1.0.0
rename_map.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016-2018,2019 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 #include "cpu/o3/rename_map.hh"
43 
44 #include <vector>
45 
46 #include "cpu/o3/dyn_inst.hh"
47 #include "cpu/reg_class.hh"
48 #include "debug/Rename.hh"
49 
50 namespace gem5
51 {
52 
53 namespace o3
54 {
55 
57 {
58 }
59 
60 
61 void
62 SimpleRenameMap::init(const RegClass &reg_class, SimpleFreeList *_freeList)
63 {
64  assert(freeList == NULL);
65  assert(map.empty());
66 
67  map.resize(reg_class.numRegs());
68  freeList = _freeList;
69 }
70 
73 {
74  PhysRegIdPtr renamed_reg;
75  // Record the current physical register that is renamed to the
76  // requested architected register.
77  PhysRegIdPtr prev_reg = map[arch_reg.index()];
78 
79  if (arch_reg.is(InvalidRegClass)) {
80  assert(prev_reg->is(InvalidRegClass));
81  renamed_reg = prev_reg;
82  } else if (prev_reg->getNumPinnedWrites() > 0) {
83  // Do not rename if the register is pinned
84  assert(arch_reg.getNumPinnedWrites() == 0); // Prevent pinning the
85  // same register twice
86  DPRINTF(Rename, "Renaming pinned reg, numPinnedWrites %d\n",
87  prev_reg->getNumPinnedWrites());
88  renamed_reg = prev_reg;
89  renamed_reg->decrNumPinnedWrites();
90  } else {
91  renamed_reg = freeList->getReg();
92  map[arch_reg.index()] = renamed_reg;
93  renamed_reg->setNumPinnedWrites(arch_reg.getNumPinnedWrites());
94  renamed_reg->setNumPinnedWritesToComplete(
95  arch_reg.getNumPinnedWrites() + 1);
96  }
97 
98  DPRINTF(Rename, "Renamed reg %d to physical reg %d (%d) old mapping was"
99  " %d (%d)\n",
100  arch_reg, renamed_reg->flatIndex(), renamed_reg->flatIndex(),
101  prev_reg->flatIndex(), prev_reg->flatIndex());
102 
103  return RenameInfo(renamed_reg, prev_reg);
104 }
105 
106 
107 /**** UnifiedRenameMap methods ****/
108 
109 void
111  PhysRegFile *_regFile, UnifiedFreeList *freeList)
112 {
113  regFile = _regFile;
114 
115  for (int i = 0; i < renameMaps.size(); i++)
116  renameMaps[i].init(*regClasses.at(i), &(freeList->freeLists[i]));
117 }
118 
119 bool
121 {
122  for (int i = 0; i < renameMaps.size(); i++) {
123  if (inst->numDestRegs((RegClassType)i) >
124  renameMaps[i].numFreeEntries()) {
125  return false;
126  }
127  }
128  return true;
129 }
130 
131 } // namespace o3
132 } // namespace gem5
#define DPRINTF(x,...)
Definition: trace.hh:186
Physical register ID.
Definition: reg_class.hh:392
int getNumPinnedWrites() const
Definition: reg_class.hh:451
constexpr bool is(RegClassType reg_class) const
Definition: reg_class.hh:267
void decrNumPinnedWrites()
Definition: reg_class.hh:466
void setNumPinnedWrites(int numWrites)
Definition: reg_class.hh:454
void setNumPinnedWritesToComplete(int numWrites)
Definition: reg_class.hh:478
const RegIndex & flatIndex() const
Flat index accessor.
Definition: reg_class.hh:449
constexpr size_t numRegs() const
Definition: reg_class.hh:235
Register ID: describe an architectural register with its class and index.
Definition: reg_class.hh:91
constexpr bool is(RegClassType reg_class) const
Definition: reg_class.hh:267
constexpr RegIndex index() const
Index accessors.
Definition: reg_class.hh:148
int getNumPinnedWrites() const
Definition: reg_class.hh:159
Simple physical register file class.
Definition: regfile.hh:66
Rename handles both single threaded and SMT rename.
Definition: rename.hh:79
Free list for a single class of registers (e.g., integer or floating point).
Definition: free_list.hh:72
PhysRegIdPtr getReg()
Get the next available register from the free list.
Definition: free_list.hh:95
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
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
SimpleFreeList * freeList
Pointer to the free list from which new physical registers should be allocated in rename()
Definition: rename_map.hh:86
Arch2PhysMap map
The acutal arch-to-phys register map.
Definition: rename_map.hh:76
std::pair< PhysRegIdPtr, PhysRegIdPtr > RenameInfo
Pair of a physical register and a physical register.
Definition: rename_map.hh:105
FreeList class that simply holds the list of free integer and floating point registers.
Definition: free_list.hh:125
std::array< SimpleFreeList, CCRegClass+1 > freeLists
Definition: free_list.hh:132
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
bool canRename(DynInstPtr inst) const
Return whether there are enough registers to serve the request.
Definition: rename_map.cc:120
std::array< SimpleRenameMap, CCRegClass+1 > renameMaps
Definition: rename_map.hh:171
STL pair class.
Definition: stl.hh:58
Bitfield< 7 > i
Definition: misc_types.hh:67
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

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