gem5  v20.1.0.0
free_list.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016-2018 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_FREE_LIST_HH__
43 #define __CPU_O3_FREE_LIST_HH__
44 
45 #include <iostream>
46 #include <queue>
47 #include <vector>
48 
49 #include "base/logging.hh"
50 #include "base/trace.hh"
51 #include "cpu/o3/comm.hh"
52 #include "cpu/o3/regfile.hh"
53 #include "debug/FreeList.hh"
54 
63 {
64  private:
65 
67  std::queue<PhysRegIdPtr> freeRegs;
68 
69  public:
70 
72 
74  void addReg(PhysRegIdPtr reg) { freeRegs.push(reg); }
75 
77  template<class InputIt>
78  void
79  addRegs(InputIt first, InputIt last) {
80  std::for_each(first, last, [this](typename InputIt::value_type& reg) {
81  this->freeRegs.push(&reg);
82  });
83  }
84 
87  {
88  assert(!freeRegs.empty());
89  PhysRegIdPtr free_reg = freeRegs.front();
90  freeRegs.pop();
91  return free_reg;
92  }
93 
95  unsigned numFreeRegs() const { return freeRegs.size(); }
96 
98  bool hasFreeRegs() const { return !freeRegs.empty(); }
99 };
100 
101 
116 {
117  private:
118 
121  const std::string _name;
122 
125 
128 
133 
140 
143 
149 
150  /*
151  * We give UnifiedRenameMap internal access so it can get at the
152  * internal per-class free lists and associate those with its
153  * per-class rename maps. See UnifiedRenameMap::init().
154  */
155  friend class UnifiedRenameMap;
156 
157  public:
166  UnifiedFreeList(const std::string &_my_name, PhysRegFile *_regFile);
167 
169  std::string name() const { return _name; };
170 
173 
176 
179 
182 
185 
188 
191 
193  void addReg(PhysRegIdPtr freed_reg);
194 
196  template<class InputIt>
197  void addRegs(InputIt first, InputIt last);
198 
200  void addIntReg(PhysRegIdPtr freed_reg) { intList.addReg(freed_reg); }
201 
203  void addFloatReg(PhysRegIdPtr freed_reg) { floatList.addReg(freed_reg); }
204 
206  void addVecReg(PhysRegIdPtr freed_reg) { vecList.addReg(freed_reg); }
207 
209  void addVecElem(PhysRegIdPtr freed_reg) {
210  vecElemList.addReg(freed_reg);
211  }
212 
214  void addVecPredReg(PhysRegIdPtr freed_reg) { predList.addReg(freed_reg); }
215 
217  void addCCReg(PhysRegIdPtr freed_reg) { ccList.addReg(freed_reg); }
218 
220  bool hasFreeIntRegs() const { return intList.hasFreeRegs(); }
221 
223  bool hasFreeFloatRegs() const { return floatList.hasFreeRegs(); }
224 
226  bool hasFreeVecRegs() const { return vecList.hasFreeRegs(); }
227 
229  bool hasFreeVecElems() const { return vecElemList.hasFreeRegs(); }
230 
232  bool hasFreeVecPredRegs() const { return predList.hasFreeRegs(); }
233 
235  bool hasFreeCCRegs() const { return ccList.hasFreeRegs(); }
236 
238  unsigned numFreeIntRegs() const { return intList.numFreeRegs(); }
239 
241  unsigned numFreeFloatRegs() const { return floatList.numFreeRegs(); }
242 
244  unsigned numFreeVecRegs() const { return vecList.numFreeRegs(); }
245 
247  unsigned numFreeVecElems() const { return vecElemList.numFreeRegs(); }
248 
250  unsigned numFreeVecPredRegs() const { return predList.numFreeRegs(); }
251 
253  unsigned numFreeCCRegs() const { return ccList.numFreeRegs(); }
254 };
255 
256 template<class InputIt>
257 inline void
258 UnifiedFreeList::addRegs(InputIt first, InputIt last)
259 {
260  // Are there any registers to add?
261  if (first == last)
262  return;
263 
264  panic_if((first != last) &&
265  first->classValue() != (last-1)->classValue(),
266  "Attempt to add mixed type regs: %s and %s",
267  first->className(),
268  (last-1)->className());
269  switch (first->classValue()) {
270  case IntRegClass:
271  intList.addRegs(first, last);
272  break;
273  case FloatRegClass:
274  floatList.addRegs(first, last);
275  break;
276  case VecRegClass:
277  vecList.addRegs(first, last);
278  break;
279  case VecElemClass:
280  vecElemList.addRegs(first, last);
281  break;
282  case VecPredRegClass:
283  predList.addRegs(first, last);
284  break;
285  case CCRegClass:
286  ccList.addRegs(first, last);
287  break;
288  default:
289  panic("Unexpected RegClass (%s)",
290  first->className());
291  }
292 
293 }
294 
295 inline void
297 {
298  DPRINTF(FreeList,"Freeing register %i (%s).\n", freed_reg->index(),
299  freed_reg->className());
300  //Might want to add in a check for whether or not this register is
301  //already in there. A bit vector or something similar would be useful.
302  switch (freed_reg->classValue()) {
303  case IntRegClass:
304  intList.addReg(freed_reg);
305  break;
306  case FloatRegClass:
307  floatList.addReg(freed_reg);
308  break;
309  case VecRegClass:
310  vecList.addReg(freed_reg);
311  break;
312  case VecElemClass:
313  vecElemList.addReg(freed_reg);
314  break;
315  case VecPredRegClass:
316  predList.addReg(freed_reg);
317  break;
318  case CCRegClass:
319  ccList.addReg(freed_reg);
320  break;
321  default:
322  panic("Unexpected RegClass (%s)",
323  freed_reg->className());
324  }
325 
326  // These assert conditions ensure that the number of free
327  // registers are not more than the # of total Physical Registers.
328  // If this were false, it would mean that registers
329  // have been freed twice, overflowing the free register
330  // pool and potentially crashing SMT workloads.
331  // ----
332  // Comment out for now so as to not potentially break
333  // CMP and single-threaded workloads
334  // ----
335  // assert(freeIntRegs.size() <= numPhysicalIntRegs);
336  // assert(freeFloatRegs.size() <= numPhysicalFloatRegs);
337 }
338 
339 
340 #endif // __CPU_O3_FREE_LIST_HH__
UnifiedFreeList::addVecReg
void addVecReg(PhysRegIdPtr freed_reg)
Adds a vector register back to the free list.
Definition: free_list.hh:206
UnifiedRenameMap
Unified register rename map for all classes of registers.
Definition: rename_map.hh:169
SimpleFreeList::hasFreeRegs
bool hasFreeRegs() const
True iff there are free registers on the list.
Definition: free_list.hh:98
UnifiedFreeList::hasFreeFloatRegs
bool hasFreeFloatRegs() const
Checks if there are any free fp registers.
Definition: free_list.hh:223
UnifiedFreeList::regFile
PhysRegFile * regFile
The register file object is used only to distinguish integer from floating-point physical register in...
Definition: free_list.hh:148
UnifiedFreeList::numFreeVecPredRegs
unsigned numFreeVecPredRegs() const
Returns the number of free predicate registers.
Definition: free_list.hh:250
UnifiedFreeList::UnifiedFreeList
UnifiedFreeList(const std::string &_my_name, PhysRegFile *_regFile)
Constructs a free list.
Definition: free_list.cc:37
UnifiedFreeList::addIntReg
void addIntReg(PhysRegIdPtr freed_reg)
Adds an integer register back to the free list.
Definition: free_list.hh:200
VecElemClass
@ VecElemClass
Vector Register Native Elem lane.
Definition: reg_class.hh:58
UnifiedFreeList::getIntReg
PhysRegIdPtr getIntReg()
Gets a free integer register.
Definition: free_list.hh:175
UnifiedFreeList::addRegs
void addRegs(InputIt first, InputIt last)
Adds a register back to the free list.
Definition: free_list.hh:258
PhysRegId::classValue
const RegClass & classValue() const
Class accessor.
Definition: reg_class.hh:200
UnifiedFreeList::ccList
SimpleFreeList ccList
The list of free condition-code registers.
Definition: free_list.hh:142
UnifiedFreeList::addCCReg
void addCCReg(PhysRegIdPtr freed_reg)
Adds a cc register back to the free list.
Definition: free_list.hh:217
UnifiedFreeList::hasFreeCCRegs
bool hasFreeCCRegs() const
Checks if there are any free cc registers.
Definition: free_list.hh:235
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
X86ISA::reg
Bitfield< 5, 3 > reg
Definition: types.hh:87
SimpleFreeList::SimpleFreeList
SimpleFreeList()
Definition: free_list.hh:71
UnifiedFreeList::floatList
SimpleFreeList floatList
The list of free floating point registers.
Definition: free_list.hh:127
comm.hh
PhysRegId::index
const RegIndex & index() const
Visible RegId methods.
Definition: reg_class.hh:173
UnifiedFreeList::hasFreeVecPredRegs
bool hasFreeVecPredRegs() const
Checks if there are any free predicate registers.
Definition: free_list.hh:232
FloatRegClass
@ FloatRegClass
Floating-point register.
Definition: reg_class.hh:54
UnifiedFreeList::addVecElem
void addVecElem(PhysRegIdPtr freed_reg)
Adds a vector element register back to the free list.
Definition: free_list.hh:209
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:234
SimpleFreeList::numFreeRegs
unsigned numFreeRegs() const
Return the number of free registers on the list.
Definition: free_list.hh:95
SimpleFreeList::addReg
void addReg(PhysRegIdPtr reg)
Add a physical register to the free list.
Definition: free_list.hh:74
UnifiedFreeList
FreeList class that simply holds the list of free integer and floating point registers.
Definition: free_list.hh:115
UnifiedFreeList::numFreeVecRegs
unsigned numFreeVecRegs() const
Returns the number of free vector registers.
Definition: free_list.hh:244
VecPredRegClass
@ VecPredRegClass
Definition: reg_class.hh:59
regfile.hh
UnifiedFreeList::name
std::string name() const
Gives the name of the freelist.
Definition: free_list.hh:169
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
CCRegClass
@ CCRegClass
Condition-code register.
Definition: reg_class.hh:60
UnifiedFreeList::hasFreeVecElems
bool hasFreeVecElems() const
Checks if there are any free vector registers.
Definition: free_list.hh:229
UnifiedFreeList::getVecPredReg
PhysRegIdPtr getVecPredReg()
Gets a free predicate register.
Definition: free_list.hh:187
UnifiedFreeList::addVecPredReg
void addVecPredReg(PhysRegIdPtr freed_reg)
Adds a predicate register back to the free list.
Definition: free_list.hh:214
UnifiedFreeList::numFreeIntRegs
unsigned numFreeIntRegs() const
Returns the number of free integer registers.
Definition: free_list.hh:238
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
SimpleFreeList::addRegs
void addRegs(InputIt first, InputIt last)
Add physical registers to the free list.
Definition: free_list.hh:79
VecRegClass
@ VecRegClass
Vector Register.
Definition: reg_class.hh:56
PhysRegId::className
const char * className() const
Return a const char* with the register class name.
Definition: reg_class.hh:202
UnifiedFreeList::_name
const std::string _name
The object name, for DPRINTF.
Definition: free_list.hh:121
UnifiedFreeList::getCCReg
PhysRegIdPtr getCCReg()
Gets a free cc register.
Definition: free_list.hh:190
UnifiedFreeList::predList
SimpleFreeList predList
The list of free predicate registers.
Definition: free_list.hh:139
SimpleFreeList::getReg
PhysRegIdPtr getReg()
Get the next available register from the free list.
Definition: free_list.hh:86
logging.hh
UnifiedFreeList::getCCList
SimpleFreeList * getCCList()
Returns a pointer to the condition-code free list.
Definition: free_list.hh:172
PhysRegId
Physical register ID.
Definition: reg_class.hh:223
trace.hh
UnifiedFreeList::addFloatReg
void addFloatReg(PhysRegIdPtr freed_reg)
Adds a fp register back to the free list.
Definition: free_list.hh:203
SimpleFreeList::freeRegs
std::queue< PhysRegIdPtr > freeRegs
The actual free list.
Definition: free_list.hh:67
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
UnifiedFreeList::hasFreeIntRegs
bool hasFreeIntRegs() const
Checks if there are any free integer registers.
Definition: free_list.hh:220
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
UnifiedFreeList::numFreeCCRegs
unsigned numFreeCCRegs() const
Returns the number of free cc registers.
Definition: free_list.hh:253
SimpleFreeList
Free list for a single class of registers (e.g., integer or floating point).
Definition: free_list.hh:62
UnifiedFreeList::addReg
void addReg(PhysRegIdPtr freed_reg)
Adds a register back to the free list.
Definition: free_list.hh:296
UnifiedFreeList::numFreeFloatRegs
unsigned numFreeFloatRegs() const
Returns the number of free fp registers.
Definition: free_list.hh:241
UnifiedFreeList::getVecReg
PhysRegIdPtr getVecReg()
Gets a free vector register.
Definition: free_list.hh:181
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:171
UnifiedFreeList::getFloatReg
PhysRegIdPtr getFloatReg()
Gets a free fp register.
Definition: free_list.hh:178

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