gem5  v20.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/reg_class.hh"
47 #include "debug/Rename.hh"
48 
49 using namespace std;
50 
51 /**** SimpleRenameMap methods ****/
52 
54  : freeList(NULL), zeroReg(IntRegClass,0)
55 {
56 }
57 
58 
59 void
60 SimpleRenameMap::init(unsigned size, SimpleFreeList *_freeList,
61  RegIndex _zeroReg)
62 {
63  assert(freeList == NULL);
64  assert(map.empty());
65 
66  map.resize(size);
67  freeList = _freeList;
68  zeroReg = RegId(IntRegClass, _zeroReg);
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.flatIndex()];
78 
79  if (arch_reg == zeroReg) {
80  assert(prev_reg->isZeroReg());
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.flatIndex()] = 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  RegIndex _intZeroReg,
112  RegIndex _floatZeroReg,
113  UnifiedFreeList *freeList,
114  VecMode _mode)
115 {
116  regFile = _regFile;
117  vecMode = _mode;
118 
119  intMap.init(TheISA::NumIntRegs, &(freeList->intList), _intZeroReg);
120 
121  floatMap.init(TheISA::NumFloatRegs, &(freeList->floatList), _floatZeroReg);
122 
123  vecMap.init(TheISA::NumVecRegs, &(freeList->vecList), (RegIndex)-1);
124 
126  &(freeList->vecElemList), (RegIndex)-1);
127 
129 
130  ccMap.init(TheISA::NumCCRegs, &(freeList->ccList), (RegIndex)-1);
131 
132 }
133 
134 void
136 {
137  if (vecMode == Enums::Elem) {
138 
139  /* The free list should currently be tracking full registers. */
140  panic_if(freeList->hasFreeVecElems(),
141  "The free list is already tracking Vec elems");
142  panic_if(freeList->numFreeVecRegs() !=
144  "The free list has lost vector registers");
145 
146  /* Split the free regs. */
147  while (freeList->hasFreeVecRegs()) {
148  auto vr = freeList->getVecReg();
149  auto range = this->regFile->getRegElemIds(vr);
150  freeList->addRegs(range.first, range.second);
151  }
152 
153  } else if (vecMode == Enums::Full) {
154 
155  /* The free list should currently be tracking register elems. */
156  panic_if(freeList->hasFreeVecRegs(),
157  "The free list is already tracking full Vec");
158  panic_if(freeList->numFreeVecElems() !=
161  "The free list has lost vector register elements");
162 
163  auto range = regFile->getRegIds(VecRegClass);
164  freeList->addRegs(range.first + TheISA::NumVecRegs, range.second);
165 
166  /* We remove the elems from the free list. */
167  while (freeList->hasFreeVecElems())
168  freeList->getVecElem();
169  }
170 }
171 
172 void
174 {
175  if (newVecMode == Enums::Elem && vecMode == Enums::Full) {
176 
177  /* Switch to vector element rename mode. */
178  vecMode = Enums::Elem;
179 
180  /* Split the mapping of each arch reg. */
181  int vec_idx = 0;
182  for (auto &vec: vecMap) {
183  PhysRegFile::IdRange range = this->regFile->getRegElemIds(vec);
184  auto idx = 0;
185  for (auto phys_elem = range.first;
186  phys_elem < range.second; idx++, phys_elem++) {
187 
188  setEntry(RegId(VecElemClass, vec_idx, idx), &(*phys_elem));
189  }
190  vec_idx++;
191  }
192 
193  } else if (newVecMode == Enums::Full && vecMode == Enums::Elem) {
194 
195  /* Switch to full vector register rename mode. */
196  vecMode = Enums::Full;
197 
198  /* To rebuild the arch regs we take the easy road:
199  * 1.- Stitch the elems together into vectors.
200  * 2.- Replace the contents of the register file with the vectors
201  * 3.- Set the remaining registers as free
202  */
204  for (uint32_t i = 0; i < TheISA::NumVecRegs; i++) {
205  VecReg dst = new_RF[i].as<TheISA::VecElem>();
206  for (uint32_t l = 0; l < NVecElems; l++) {
207  RegId s_rid(VecElemClass, i, l);
208  PhysRegIdPtr s_prid = vecElemMap.lookup(s_rid);
209  dst[l] = regFile->readVecElem(s_prid);
210  }
211  }
212 
213  for (uint32_t i = 0; i < TheISA::NumVecRegs; i++) {
214  PhysRegId pregId(VecRegClass, i, 0);
215  regFile->setVecReg(regFile->getTrueId(&pregId), new_RF[i]);
216  }
217 
218  auto range = regFile->getRegIds(VecRegClass);
219  for (uint32_t i = 0; i < TheISA::NumVecRegs; i++) {
220  setEntry(RegId(VecRegClass, i), &(*(range.first + i)));
221  }
222 
223  }
224 }
RegId::getNumPinnedWrites
int getNumPinnedWrites() const
Definition: reg_class.hh:204
PhysRegFile::numVecElemPhysRegs
unsigned numVecElemPhysRegs() const
Definition: regfile.hh:166
SimpleRenameMap::freeList
SimpleFreeList * freeList
Pointer to the free list from which new physical registers should be allocated in rename()
Definition: rename_map.hh:78
ArmISA::VecRegContainer
VecReg::Container VecRegContainer
Definition: registers.hh:71
VecElemClass
@ VecElemClass
Vector Register Native Elem lane.
Definition: reg_class.hh:58
PhysRegFile::readVecElem
const VecElem & readVecElem(PhysRegIdPtr phys_reg) const
Reads a vector element.
Definition: regfile.hh:256
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
UnifiedFreeList::addRegs
void addRegs(InputIt first, InputIt last)
Adds a register back to the free list.
Definition: free_list.hh:258
UnifiedRenameMap::intMap
SimpleRenameMap intMap
The integer register rename map.
Definition: rename_map.hh:177
UnifiedFreeList::ccList
SimpleFreeList ccList
The list of free condition-code registers.
Definition: free_list.hh:142
PhysRegId::isZeroReg
bool isZeroReg() const
Check if this is the zero register.
Definition: reg_class.hh:137
UnifiedRenameMap::switchFreeList
void switchFreeList(UnifiedFreeList *freeList)
Switch freeList of registers from Full to Elem or vicevers depending on vecMode (vector renaming mode...
Definition: rename_map.cc:135
PhysRegId::flatIndex
const PhysRegIndex & flatIndex() const
Flat index accessor.
Definition: reg_class.hh:305
UnifiedRenameMap::regFile
PhysRegFile * regFile
The register file object is used only to get PhysRegIdPtr on MiscRegs, as they are stored in it.
Definition: rename_map.hh:201
PhysRegFile
Simple physical register file class.
Definition: regfile.hh:59
UnifiedFreeList::vecList
SimpleFreeList vecList
The following two are exclusive interfaces.
Definition: free_list.hh:132
UnifiedRenameMap::switchMode
void switchMode(VecMode newVecMode)
Set vector mode to Full or Elem.
Definition: rename_map.cc:173
UnifiedRenameMap::setEntry
void setEntry(const RegId &arch_reg, PhysRegIdPtr phys_reg)
Update rename map with a specific mapping.
Definition: rename_map.hh:311
PhysRegFile::getRegElemIds
IdRange getRegElemIds(PhysRegIdPtr reg)
Get the PhysRegIds of the elems of a vector register.
Definition: regfile.cc:184
UnifiedRenameMap::VecReg
TheISA::VecReg VecReg
Definition: rename_map.hh:173
UnifiedFreeList::floatList
SimpleFreeList floatList
The list of free floating point registers.
Definition: free_list.hh:127
RegId
Register ID: describe an architectural register with its class and index.
Definition: reg_class.hh:75
SimpleRenameMap::init
void init(unsigned size, SimpleFreeList *_freeList, RegIndex _zeroReg)
Because we have an array of rename maps (one per thread) in the CPU, it's awkward to initialize this ...
Definition: rename_map.cc:60
UnifiedRenameMap::vecMap
SimpleRenameMap vecMap
The vector register rename map.
Definition: rename_map.hh:186
ArmISA::VecElem
uint32_t VecElem
Definition: registers.hh:68
UnifiedRenameMap::vecElemMap
SimpleRenameMap vecElemMap
The vector element register rename map.
Definition: rename_map.hh:189
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:234
UnifiedRenameMap::init
void init(PhysRegFile *_regFile, RegIndex _intZeroReg, RegIndex _floatZeroReg, UnifiedFreeList *freeList, VecMode _mode)
Initializes rename map with given parameters.
Definition: rename_map.cc:110
ArmISA::NumVecElemPerVecReg
constexpr unsigned NumVecElemPerVecReg
Definition: registers.hh:66
PhysRegId::setNumPinnedWritesToComplete
void setNumPinnedWritesToComplete(int numWrites)
Definition: reg_class.hh:337
UnifiedFreeList
FreeList class that simply holds the list of free integer and floating point registers.
Definition: free_list.hh:115
PhysRegId::decrNumPinnedWrites
void decrNumPinnedWrites()
Definition: reg_class.hh:327
UnifiedRenameMap::ccMap
SimpleRenameMap ccMap
The condition-code register rename map.
Definition: rename_map.hh:183
UnifiedFreeList::numFreeVecRegs
unsigned numFreeVecRegs() const
Returns the number of free vector registers.
Definition: free_list.hh:244
ArmISA::NumVecPredRegs
const int NumVecPredRegs
Definition: registers.hh:98
SimpleRenameMap::lookup
PhysRegIdPtr lookup(const RegId &arch_reg) const
Look up the physical register mapped to an architectural register.
Definition: rename_map.hh:125
SimpleRenameMap::RenameInfo
std::pair< PhysRegIdPtr, PhysRegIdPtr > RenameInfo
Pair of a physical register and a physical register.
Definition: rename_map.hh:108
ArmISA::NumFloatRegs
const int NumFloatRegs
Definition: registers.hh:83
std::pair
STL pair class.
Definition: stl.hh:58
UnifiedRenameMap::floatMap
SimpleRenameMap floatMap
The floating-point register rename map.
Definition: rename_map.hh:180
rename_map.hh
PhysRegFile::setVecReg
void setVecReg(PhysRegIdPtr phys_reg, const VecRegContainer &val)
Sets a vector register to the given value.
Definition: regfile.hh:326
UnifiedRenameMap::predMap
SimpleRenameMap predMap
The predicate register rename map.
Definition: rename_map.hh:192
ArmISA::NumIntRegs
const int NumIntRegs
Definition: registers.hh:82
PhysRegId::getNumPinnedWrites
int getNumPinnedWrites() const
Definition: reg_class.hh:313
UnifiedFreeList::numFreeVecElems
unsigned numFreeVecElems() const
Returns the number of free vector registers.
Definition: free_list.hh:247
IntRegClass
@ IntRegClass
Integer register.
Definition: reg_class.hh:53
UnifiedRenameMap::VecMode
Enums::VecRegRenameMode VecMode
Definition: rename_map.hh:194
UnifiedFreeList::hasFreeVecElems
bool hasFreeVecElems() const
Checks if there are any free vector registers.
Definition: free_list.hh:229
UnifiedRenameMap::vecMode
VecMode vecMode
Definition: rename_map.hh:195
panic_if
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:197
VecRegClass
@ VecRegClass
Vector Register.
Definition: reg_class.hh:56
ArmISA::NumCCRegs
const int NumCCRegs
Definition: registers.hh:84
SimpleRenameMap::rename
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
PhysRegFile::numVecPhysRegs
unsigned numVecPhysRegs() const
Definition: regfile.hh:161
std
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:587
UnifiedFreeList::predList
SimpleFreeList predList
The list of free predicate registers.
Definition: free_list.hh:139
RegIndex
uint16_t RegIndex
Definition: types.hh:52
SimpleRenameMap::map
Arch2PhysMap map
The acutal arch-to-phys register map.
Definition: rename_map.hh:68
SimpleRenameMap::SimpleRenameMap
SimpleRenameMap()
Definition: rename_map.cc:53
SimpleFreeList::getReg
PhysRegIdPtr getReg()
Get the next available register from the free list.
Definition: free_list.hh:86
PhysRegId::setNumPinnedWrites
void setNumPinnedWrites(int numWrites)
Definition: reg_class.hh:315
reg_class.hh
PhysRegFile::getTrueId
PhysRegIdPtr getTrueId(PhysRegIdPtr reg)
Get the true physical register id.
Definition: regfile.cc:220
PhysRegId
Physical register ID.
Definition: reg_class.hh:223
RegId::flatIndex
RegIndex flatIndex() const
Index flattening.
Definition: reg_class.hh:179
ArmISA::NumVecRegs
const int NumVecRegs
Definition: registers.hh:97
UnifiedFreeList::hasFreeVecRegs
bool hasFreeVecRegs() const
Checks if there are any free vector registers.
Definition: free_list.hh:226
UnifiedFreeList::vecElemList
SimpleFreeList vecElemList
The list of free vector element registers.
Definition: free_list.hh:135
MipsISA::l
Bitfield< 5 > l
Definition: pra_constants.hh:320
UnifiedFreeList::intList
SimpleFreeList intList
The list of free integer registers.
Definition: free_list.hh:124
UnifiedFreeList::getVecElem
PhysRegIdPtr getVecElem()
Gets a free vector elemenet register.
Definition: free_list.hh:184
SimpleRenameMap::zeroReg
RegId zeroReg
The architectural index of the zero register.
Definition: rename_map.hh:87
SimpleFreeList
Free list for a single class of registers (e.g., integer or floating point).
Definition: free_list.hh:62
PhysRegFile::getRegIds
IdRange getRegIds(RegClass cls)
Get the PhysRegIds of the elems of all vector registers.
Definition: regfile.cc:195
UnifiedFreeList::getVecReg
PhysRegIdPtr getVecReg()
Gets a free vector register.
Definition: free_list.hh:181
UnifiedRenameMap::NVecElems
static constexpr uint32_t NVecElems
Definition: rename_map.hh:172

Generated on Wed Sep 30 2020 14:02:09 for gem5 by doxygen 1.8.17